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