]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53/src/main.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53 / src / main.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 /******************************************************************************\r
71  * NOTE 1:  This project provides two demo applications.  A simple blinky\r
72  * style project, and a more comprehensive test and demo application.  The\r
73  * mainSELECTED_APPLICATION setting in main.c is used to select between the two.\r
74  * See the notes on using mainSELECTED_APPLICATION where it is defined below.\r
75  *\r
76  * NOTE 2:  This file only contains the source code that is not specific to\r
77  * either the simply blinky or full demos - this includes initialisation code\r
78  * and callback functions.\r
79  */\r
80 \r
81 /* Standard includes. */\r
82 #include <stdio.h>\r
83 \r
84 /* Scheduler include files. */\r
85 #include "FreeRTOS.h"\r
86 #include "task.h"\r
87 \r
88 /* Xilinx includes. */\r
89 #include "platform.h"\r
90 #include "xttcps.h"\r
91 #include "xscugic.h"\r
92 \r
93 /* mainSELECTED_APPLICATION is used to select between two demo applications,\r
94  * as described at the top of this file.\r
95  *\r
96  * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will\r
97  * be run.\r
98  *\r
99  * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo\r
100  * application will be run.\r
101  */\r
102 #define mainSELECTED_APPLICATION        1\r
103 \r
104 /*-----------------------------------------------------------*/\r
105 \r
106 /*\r
107  * Configure the hardware as necessary to run this demo.\r
108  */\r
109 static void prvSetupHardware( void );\r
110 \r
111 /*\r
112  * See the comments at the top of this file and above the\r
113  * mainSELECTED_APPLICATION definition.\r
114  */\r
115 #if ( mainSELECTED_APPLICATION == 0 )\r
116         extern void main_blinky( void );\r
117 #elif ( mainSELECTED_APPLICATION == 1 )\r
118         extern void main_full( void );\r
119 #else\r
120         #error Invalid mainSELECTED_APPLICATION setting.  See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.\r
121 #endif\r
122 \r
123 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
124 within this file. */\r
125 void vApplicationMallocFailedHook( void );\r
126 void vApplicationIdleHook( void );\r
127 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
128 void vApplicationTickHook( void );\r
129 \r
130 /*-----------------------------------------------------------*/\r
131 \r
132 /* The interrupt controller is initialised in this file, and made available to\r
133 other modules. */\r
134 XScuGic xInterruptController;\r
135 \r
136 /*-----------------------------------------------------------*/\r
137 \r
138 int main( void )\r
139 {\r
140         /* Configure the hardware ready to run the demo. */\r
141         prvSetupHardware();\r
142 \r
143         /* The mainSELECTED_APPLICATION setting is described at the top\r
144         of this file. */\r
145         #if( mainSELECTED_APPLICATION == 0 )\r
146         {\r
147                 main_blinky();\r
148         }\r
149         #elif( mainSELECTED_APPLICATION == 1 )\r
150         {\r
151                 main_full();\r
152         }\r
153         #endif\r
154 \r
155         /* Don't expect to reach here. */\r
156         return 0;\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 static void prvSetupHardware( void )\r
161 {\r
162 BaseType_t xStatus;\r
163 XScuGic_Config *pxGICConfig;\r
164 \r
165         /* Ensure no interrupts execute while the scheduler is in an inconsistent\r
166         state.  Interrupts are automatically enabled when the scheduler is\r
167         started. */\r
168         portDISABLE_INTERRUPTS();\r
169 \r
170         /* Obtain the configuration of the GIC. */\r
171         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
172 \r
173         /* Sanity check the FreeRTOSConfig.h settings are correct for the\r
174         hardware. */\r
175         configASSERT( pxGICConfig );\r
176         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );\r
177         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );\r
178 \r
179         /* Install a default handler for each GIC interrupt. */\r
180         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
181         configASSERT( xStatus == XST_SUCCESS );\r
182         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 void vApplicationMallocFailedHook( void )\r
187 {\r
188         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
189         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
190         internally by FreeRTOS API functions that create tasks, queues, software\r
191         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
192         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
193         taskDISABLE_INTERRUPTS();\r
194         for( ;; );\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
199 {\r
200         ( void ) pcTaskName;\r
201         ( void ) pxTask;\r
202 \r
203         /* Run time stack overflow checking is performed if\r
204         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
205         function is called if a stack overflow is detected. */\r
206         taskDISABLE_INTERRUPTS();\r
207         for( ;; );\r
208 }\r
209 /*-----------------------------------------------------------*/\r
210 \r
211 void vApplicationIdleHook( void )\r
212 {\r
213 volatile size_t xFreeHeapSpace;\r
214 \r
215         /* This is just a trivial example of an idle hook.  It is called on each\r
216         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
217         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
218         memory management section on the http://www.FreeRTOS.org web site for memory\r
219         management options.  If there is a lot of heap memory free then the\r
220         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
221         RAM. */\r
222         xFreeHeapSpace = xPortGetFreeHeapSize();\r
223 \r
224         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
225         ( void ) xFreeHeapSpace;\r
226 }\r
227 /*-----------------------------------------------------------*/\r
228 \r
229 void vApplicationTickHook( void )\r
230 {\r
231         #if( mainSELECTED_APPLICATION == 1 )\r
232         {\r
233                 /* Only the comprehensive demo actually uses the tick hook. */\r
234                 extern void vFullDemoTickHook( void );\r
235                 vFullDemoTickHook();\r
236         }\r
237         #endif\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
242 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
243 used by the Idle task. */\r
244 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )\r
245 {\r
246 /* If the buffers to be provided to the Idle task are declared inside this\r
247 function then they must be declared static - otherwise they will be allocated on\r
248 the stack and so not exists after this function exits. */\r
249 static StaticTask_t xIdleTaskTCB;\r
250 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
251 \r
252         /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
253         state will be stored. */\r
254         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
255 \r
256         /* Pass out the array that will be used as the Idle task's stack. */\r
257         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
258 \r
259         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
260         Note that, as the array is necessarily of type StackType_t,\r
261         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
262         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
263 }\r
264 /*-----------------------------------------------------------*/\r
265 \r
266 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
267 application must provide an implementation of vApplicationGetTimerTaskMemory()\r
268 to provide the memory that is used by the Timer service task. */\r
269 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )\r
270 {\r
271 /* If the buffers to be provided to the Timer task are declared inside this\r
272 function then they must be declared static - otherwise they will be allocated on\r
273 the stack and so not exists after this function exits. */\r
274 static StaticTask_t xTimerTaskTCB;\r
275 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
276 \r
277         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
278         task's state will be stored. */\r
279         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
280 \r
281         /* Pass out the array that will be used as the Timer task's stack. */\r
282         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
283 \r
284         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
285         Note that, as the array is necessarily of type StackType_t,\r
286         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
287         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
288 }\r
289 /*-----------------------------------------------------------*/\r
290 \r
291 void *memcpy( void *pvDest, const void *pvSource, size_t xBytes )\r
292 {\r
293 /* The compiler used during development seems to err unless these volatiles are\r
294 included at -O3 optimisation.  */\r
295 volatile unsigned char *pcDest = ( volatile unsigned char * ) pvDest, *pcSource = ( volatile unsigned char * ) pvSource;\r
296 size_t x;\r
297 \r
298         /* Extremely crude standard library implementations in lieu of having a C\r
299         library. */\r
300         if( pvDest != pvSource )\r
301         {\r
302                 for( x = 0; x < xBytes; x++ )\r
303                 {\r
304                         pcDest[ x ] = pcSource[ x ];\r
305                 }\r
306         }\r
307 \r
308         return pvDest;\r
309 }\r
310 /*-----------------------------------------------------------*/\r
311 \r
312 void *memset( void *pvDest, int iValue, size_t xBytes )\r
313 {\r
314 /* The compiler used during development seems to err unless these volatiles are\r
315 included at -O3 optimisation.  */\r
316 volatile unsigned char * volatile pcDest = ( volatile unsigned char * volatile ) pvDest;\r
317 volatile size_t x;\r
318 \r
319         /* Extremely crude standard library implementations in lieu of having a C\r
320         library. */\r
321         for( x = 0; x < xBytes; x++ )\r
322         {\r
323                 pcDest[ x ] = ( unsigned char ) iValue;\r
324         }\r
325 \r
326         return pvDest;\r
327 }\r
328 /*-----------------------------------------------------------*/\r
329 \r
330 int memcmp( const void *pvMem1, const void *pvMem2, size_t xBytes )\r
331 {\r
332 const volatile unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2;\r
333 volatile size_t x;\r
334 \r
335         /* Extremely crude standard library implementations in lieu of having a C\r
336         library. */\r
337     for( x = 0; x < xBytes; x++ )\r
338     {\r
339         if( pucMem1[ x ] != pucMem2[ x ] )\r
340         {\r
341             break;\r
342         }\r
343     }\r
344 \r
345     return xBytes - x;\r
346 }\r
347 /*-----------------------------------------------------------*/\r
348 \r
349 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )\r
350 {\r
351         xil_printf( "ASSERT!  Line %lu of file %s\r\n", ulLineNumber, pcFileName );\r
352         taskENTER_CRITICAL();\r
353         for( ;; );\r
354 }\r
355 \r