]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A5_SAMA5D4x_EK_IAR/FreeRTOS_tick_config.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D4x_EK_IAR / FreeRTOS_tick_config.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 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. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* FreeRTOS includes. */\r
30 #include "FreeRTOS.h"\r
31 #include "task.h"\r
32 \r
33 /* Library includes. */\r
34 #include "board.h"\r
35 \r
36 /*\r
37  * The FreeRTOS tick handler.  This function must be installed as the handler\r
38  * for the timer used to generate the tick interrupt.  Note that the interrupt\r
39  * generated by the PIT is shared by other system peripherals, so if the PIT is\r
40  * used for Tick generation then FreeRTOS_Tick_Handler() can only be installed\r
41  * directly as the PIT handler if no other system interrupts need to be\r
42  * serviced.  If system interrupts other than the PIT need to be serviced then\r
43  * install System_Handler() as the PIT interrupt handler in place of\r
44  * FreeRTOS_Tick_Handler() and add additional interrupt processing into the\r
45  * implementation of System_Handler().\r
46  */\r
47 extern void FreeRTOS_Tick_Handler( void );\r
48 static void System_Handler( void );\r
49 \r
50 /*-----------------------------------------------------------*/\r
51 \r
52 static void System_Handler( void )\r
53 {\r
54         /* See the comments above the function prototype in this file. */\r
55         FreeRTOS_Tick_Handler();\r
56 }\r
57 /*-----------------------------------------------------------*/\r
58 \r
59 /*\r
60  * The application must provide a function that configures a peripheral to\r
61  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
62  * in FreeRTOSConfig.h to call the function.  This file contains a function\r
63  * that is suitable for use on the Atmel SAMA5.\r
64  */\r
65 void vConfigureTickInterrupt( void )\r
66 {\r
67         /* NOTE:  The PIT interrupt is cleared by the configCLEAR_TICK_INTERRUPT()\r
68         macro in FreeRTOSConfig.h. */\r
69 \r
70         /* Enable the PIT clock. */\r
71         PMC->PMC_PCER0 = 1 << ID_PIT;\r
72 \r
73         /* Initialize the PIT to the desired frequency - specified in uS. */\r
74         PIT_Init( 1000000UL / configTICK_RATE_HZ, ( BOARD_MCK / 2 ) / 1000000 );\r
75 \r
76         /* Enable IRQ / select PIT interrupt. */\r
77         PMC->PMC_PCER1 = ( 1 << ( ID_IRQ - 32 ) );\r
78         AIC->AIC_SSR  = ID_PIT;\r
79 \r
80         /* Ensure interrupt is disabled before setting the mode and installing the\r
81         handler.  The priority of the tick interrupt should always be set to the\r
82         lowest possible. */\r
83         AIC->AIC_IDCR = AIC_IDCR_INTD;\r
84         AIC->AIC_SMR  = AIC_SMR_SRCTYPE_EXT_POSITIVE_EDGE;\r
85         AIC->AIC_SVR = ( uint32_t ) FreeRTOS_Tick_Handler;\r
86 \r
87         /* Start with the interrupt clear. */\r
88         AIC->AIC_ICCR = AIC_ICCR_INTCLR;\r
89 \r
90         /* Enable the interrupt in the AIC and peripheral. */\r
91         AIC_EnableIT( ID_PIT );\r
92         PIT_EnableIT();\r
93 \r
94         /* Enable the peripheral. */\r
95         PIT_Enable();\r
96 \r
97         /* Prevent compiler warnings in the case where System_Handler() is not used\r
98         as the handler.  See the comments above the System_Handler() function\r
99         prototype at the top of this file. */\r
100         ( void ) System_Handler;\r
101 }\r
102 /*-----------------------------------------------------------*/\r
103 \r