]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53/src/FreeRTOS_tick_config.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53 / src / 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 /* Xilinx includes. */\r
34 #include "platform.h"\r
35 #include "xttcps.h"\r
36 #include "xscugic.h"\r
37 \r
38 /* Timer used to generate the tick interrupt. */\r
39 static XTtcPs xRTOSTickTimerInstance;\r
40 \r
41 /*-----------------------------------------------------------*/\r
42 \r
43 void vConfigureTickInterrupt( void )\r
44 {\r
45 BaseType_t xStatus;\r
46 XTtcPs_Config *pxTimerConfiguration;\r
47 XInterval usInterval;\r
48 uint8_t ucPrescale;\r
49 const uint8_t ucLevelSensitive = 1;\r
50 extern XScuGic xInterruptController;\r
51 \r
52         pxTimerConfiguration = XTtcPs_LookupConfig( XPAR_XTTCPS_3_DEVICE_ID );\r
53 \r
54         /* Initialise the device. */\r
55         xStatus = XTtcPs_CfgInitialize( &xRTOSTickTimerInstance, pxTimerConfiguration, pxTimerConfiguration->BaseAddress );\r
56 \r
57         if( xStatus != XST_SUCCESS )\r
58         {\r
59                 /* Not sure how to do this before XTtcPs_CfgInitialize is called as\r
60                 *xRTOSTickTimerInstance is set within XTtcPs_CfgInitialize(). */\r
61                 XTtcPs_Stop( &xRTOSTickTimerInstance );\r
62                 xStatus = XTtcPs_CfgInitialize( &xRTOSTickTimerInstance, pxTimerConfiguration, pxTimerConfiguration->BaseAddress );\r
63                 configASSERT( xStatus == XST_SUCCESS );\r
64         }\r
65 \r
66         /* Set the options. */\r
67         XTtcPs_SetOptions( &xRTOSTickTimerInstance, ( XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE ) );\r
68 \r
69         /* Derive values from the tick rate. */\r
70         XTtcPs_CalcIntervalFromFreq( &xRTOSTickTimerInstance, configTICK_RATE_HZ, &( usInterval ), &( ucPrescale ) );\r
71 \r
72         /* Set the interval and prescale. */\r
73         XTtcPs_SetInterval( &xRTOSTickTimerInstance, usInterval );\r
74         XTtcPs_SetPrescaler( &xRTOSTickTimerInstance, ucPrescale );\r
75 \r
76         /* The priority must be the lowest possible. */\r
77         XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_XTTCPS_3_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucLevelSensitive );\r
78 \r
79         /* Connect to the interrupt controller. */\r
80         xStatus = XScuGic_Connect( &xInterruptController, XPAR_XTTCPS_3_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xRTOSTickTimerInstance );\r
81         configASSERT( xStatus == XST_SUCCESS);\r
82 \r
83         /* Enable the interrupt in the GIC. */\r
84         XScuGic_Enable( &xInterruptController, XPAR_XTTCPS_3_INTR );\r
85 \r
86         /* Enable the interrupts in the timer. */\r
87         XTtcPs_EnableInterrupts( &xRTOSTickTimerInstance, XTTCPS_IXR_INTERVAL_MASK );\r
88 \r
89         /* Start the timer. */\r
90         XTtcPs_Start( &xRTOSTickTimerInstance );\r
91 }\r
92 /*-----------------------------------------------------------*/\r
93 \r
94 void vClearTickInterrupt( void )\r
95 {\r
96 volatile uint32_t ulInterruptStatus;\r
97 \r
98         /* Read the interrupt status, then write it back to clear the interrupt. */\r
99         ulInterruptStatus = XTtcPs_GetInterruptStatus( &xRTOSTickTimerInstance );\r
100         XTtcPs_ClearInterruptStatus( &xRTOSTickTimerInstance, ulInterruptStatus );\r
101         __asm volatile( "DSB SY" );\r
102         __asm volatile( "ISB SY" );\r
103 }\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 void vApplicationIRQHandler( uint32_t ulICCIAR )\r
107 {\r
108 extern const XScuGic_Config XScuGic_ConfigTable[];\r
109 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
110 uint32_t ulInterruptID;\r
111 const XScuGic_VectorTableEntry *pxVectorEntry;\r
112 \r
113         /* Interrupts cannot be re-enabled until the source of the interrupt is\r
114         cleared. The ID of the interrupt is obtained by bitwise ANDing the ICCIAR\r
115         value with 0x3FF. */\r
116         ulInterruptID = ulICCIAR & 0x3FFUL;\r
117         if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
118         {\r
119                 /* Call the function installed in the array of installed handler\r
120                 functions. */\r
121                 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
122                 configASSERT( pxVectorEntry );\r
123                 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
124         }\r
125 }\r
126 \r
127 \r
128 \r