]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/FreeRTOS_tick_config.c
c8bb6a387743a008fd9bc6888e3c9918c009aa46
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D2x_Xplained_IAR / FreeRTOS_tick_config.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* FreeRTOS includes. */\r
29 #include "FreeRTOS.h"\r
30 #include "task.h"\r
31 \r
32 /* Library includes. */\r
33 #include "peripherals/aic.h"\r
34 #include "peripherals/pio.h"\r
35 #include "peripherals/pit.h"\r
36 #include "board.h"\r
37 \r
38 /*\r
39  * The FreeRTOS tick handler.  This function must be installed as the handler\r
40  * for the timer used to generate the tick interrupt.  Note that the interrupt\r
41  * generated by the PIT is shared by other system peripherals, so if the PIT is\r
42  * used for Tick generation then FreeRTOS_Tick_Handler() can only be installed\r
43  * directly as the PIT handler if no other system interrupts need to be\r
44  * serviced.  If system interrupts other than the PIT need to be serviced then\r
45  * install System_Handler() as the PIT interrupt handler in place of\r
46  * FreeRTOS_Tick_Handler() and add additional interrupt processing into the\r
47  * implementation of System_Handler().\r
48  */\r
49 extern void FreeRTOS_Tick_Handler( void );\r
50 static void System_Handler( void );\r
51 \r
52 /*-----------------------------------------------------------*/\r
53 \r
54 static void System_Handler( void )\r
55 {\r
56         /* See the comments above the function prototype in this file. */\r
57         FreeRTOS_Tick_Handler();\r
58 }\r
59 /*-----------------------------------------------------------*/\r
60 \r
61 /*\r
62  * The application must provide a function that configures a peripheral to\r
63  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
64  * in FreeRTOSConfig.h to call the function.  This file contains a function\r
65  * that is suitable for use on the Atmel SAMA5.\r
66  */\r
67 void vConfigureTickInterrupt( void )\r
68 {\r
69         /* NOTE:  The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()\r
70         macro in FreeRTOSConfig.h. */\r
71 \r
72         /* Enable the PIT clock. */\r
73         PMC->PMC_PCER0 = 1 << ID_PIT;\r
74 \r
75         /* Initialize the PIT to the desired frequency - specified in uS. */\r
76         pit_init( 1000000UL / configTICK_RATE_HZ );\r
77 \r
78         /* Configure interrupt on PIT.  Note this is on the system interrupt, which\r
79         is shared with other system peripherals, so System_Handler() must be\r
80         installed in place of FreeRTOS_Tick_Handler() if other system handlers are\r
81         required.  The tick must be given the lowest priority (0 in the SAMA5 AIC) */\r
82         aic_configure( ID_PIT, AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE );\r
83         aic_set_source_vector( ID_PIT, FreeRTOS_Tick_Handler );\r
84         /* See commend directly above IRQ_ConfigureIT( ID_PIT, 0, System_Handler ); */\r
85         aic_enable( ID_PIT );\r
86         pit_enable_it();\r
87 \r
88         /* Enable the pit. */\r
89         pit_enable();\r
90 \r
91         /* Prevent compiler warnings in the case where System_Handler() is not used\r
92         as the handler.  See the comments above the System_Handler() function\r
93         prototype at the top of this file. */\r
94         ( void ) System_Handler;\r
95 }\r
96 /*-----------------------------------------------------------*/\r
97 \r