]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5/src/FreeRTOS_tick_config.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5 / src / FreeRTOS_tick_config.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* FreeRTOS includes. */\r
71 #include "FreeRTOS.h"\r
72 #include "Task.h"\r
73 \r
74 /* Xilinx includes. */\r
75 #include "xscugic.h"\r
76 #include "xttcps.h"\r
77 \r
78 /* Settings to generate the tick from channel 0 of TTC 0. */\r
79 #define tickTTC_ID                      XPAR_PSU_TTC_0_DEVICE_ID\r
80 #define tickINTERRUPT_ID        XPAR_XTTCPS_0_INTR\r
81 \r
82 /* The timer used to generate the tick interrupt. */\r
83 static XTtcPs xTimerInstance;\r
84 \r
85 /*\r
86  * The application must provide a function that configures a peripheral to\r
87  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
88  * in FreeRTOSConfig.h to call the function.  This file contains a function\r
89  * that is suitable for use on the Zynq SoC.\r
90  */\r
91 void vConfigureTickInterrupt( void )\r
92 {\r
93 XTtcPs_Config *pxTimerConfig;\r
94 BaseType_t xStatus;\r
95 XScuGic_Config *pxGICConfig;\r
96 static XScuGic xInterruptController;    /* Interrupt controller instance */\r
97 uint16_t usInterval;\r
98 uint8_t ucPrescale = 0;\r
99 const uint8_t ucRisingEdge = 3;\r
100 \r
101         /* This function is called with the IRQ interrupt disabled, and the IRQ\r
102         interrupt should be left disabled.  It is enabled automatically when the\r
103         scheduler is started. */\r
104 \r
105         /* Ensure XScuGic_CfgInitialize() has been called.  In this demo it has\r
106         already been called from prvSetupHardware() in main(). */\r
107         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
108         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
109         configASSERT( xStatus == XST_SUCCESS );\r
110         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
111 \r
112         /* The interrupt priority must be the lowest possible. */\r
113         XScuGic_SetPriorityTriggerType( &xInterruptController, tickINTERRUPT_ID, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );\r
114 \r
115         /* Install the FreeRTOS tick handler. */\r
116         xStatus = XScuGic_Connect( &xInterruptController, tickINTERRUPT_ID, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, NULL );\r
117         configASSERT( xStatus == XST_SUCCESS );\r
118         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
119 \r
120         /* Initialise the Triple Timer Counter (TTC) that is going to be used to\r
121         generate the tick interrupt. */\r
122         pxTimerConfig = XTtcPs_LookupConfig( tickTTC_ID );\r
123         xStatus = XTtcPs_CfgInitialize( &xTimerInstance, pxTimerConfig, pxTimerConfig->BaseAddress );\r
124         configASSERT( xStatus == XST_SUCCESS );\r
125         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
126 \r
127         /* Configure the interval to be the require tick rate. */\r
128         XTtcPs_CalcIntervalFromFreq( &xTimerInstance, configTICK_RATE_HZ, &usInterval, &ucPrescale );\r
129         XTtcPs_SetInterval( &xTimerInstance, usInterval );\r
130         XTtcPs_SetPrescaler( &xTimerInstance, ucPrescale );\r
131 \r
132         /* Interval mode used. */\r
133         XTtcPs_SetOptions( &xTimerInstance, XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE );\r
134 \r
135         /* Start the timer. */\r
136         XTtcPs_Start( &xTimerInstance );\r
137 \r
138         /* Enable the interrupt in the interrupt controller. */\r
139         XScuGic_Enable( &xInterruptController, tickINTERRUPT_ID );\r
140 \r
141         /* Enable the interrupt in the timer itself. */\r
142         XTtcPs_EnableInterrupts( &xTimerInstance, XTTCPS_IXR_INTERVAL_MASK );\r
143 }\r
144 /*-----------------------------------------------------------*/\r
145 \r
146 void vClearTickInterrupt( void )\r
147 {\r
148 volatile uint32_t ulStatus;\r
149 \r
150         ulStatus = XTtcPs_GetInterruptStatus( &xTimerInstance );\r
151         ( void ) ulStatus;\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 void vApplicationIRQHandler( uint32_t ulICCIAR )\r
156 {\r
157 extern const XScuGic_Config XScuGic_ConfigTable[];\r
158 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
159 uint32_t ulInterruptID;\r
160 const XScuGic_VectorTableEntry *pxVectorEntry;\r
161 \r
162         /* Re-enable interrupts. */\r
163     __asm ( "cpsie i" );\r
164 \r
165         /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value\r
166         with 0x3FF. */\r
167         ulInterruptID = ulICCIAR & 0x3FFUL;\r
168         if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
169         {\r
170                 /* Call the function installed in the array of installed handler\r
171                 functions. */\r
172                 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
173                 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
174         }\r
175 }\r
176 \r
177 \r