]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53/src/main.c
72d4edd2bbe3ad62dedcd3b3f6068b919195a175
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53 / src / main.c
1 /*\r
2     FreeRTOS V9.0.0rc1 - 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  * This project provides two demo applications.  A simple blinky style project,\r
72  * and a more comprehensive test and demo application.  The\r
73  * mainSELECTED_APPLICATION setting (defined in this file) is used to select\r
74  * between the two.  The simply blinky demo is implemented and described in\r
75  * main_blinky.c.  The more comprehensive test and demo application is\r
76  * implemented and described in main_full.c.\r
77  *\r
78  * This file implements the code that is not demo specific, including the\r
79  * hardware setup and FreeRTOS hook functions.\r
80  *\r
81  * !!! IMPORTANT NOTE !!!\r
82  * Some GCC libraries can make use of the floating point registers.  To avoid\r
83  * this causing corruption it is necessary to avoid their use.  For this reason\r
84  * main.c contains very basic C implementations of the standard C library\r
85  * functions memset(), memcpy() and memcmp(), which are are used by FreeRTOS\r
86  * itself.  Defining these functions in the project prevents the linker pulling\r
87  * them in from the library.  Any other standard C library functions that are\r
88  * used by the application must likewise be defined in C.\r
89  *\r
90  * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
91  * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
92  * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
93  *\r
94  */\r
95 \r
96 /* Standard includes. */\r
97 #include <stdio.h>\r
98 \r
99 /* Scheduler include files. */\r
100 #include "FreeRTOS.h"\r
101 #include "task.h"\r
102 #include "semphr.h"\r
103 \r
104 /* Standard demo includes. */\r
105 #include "partest.h"\r
106 #include "QueueOverwrite.h"\r
107 #include "EventGroupsDemo.h"\r
108 #include "TaskNotify.h"\r
109 #include "IntSemTest.h"\r
110 \r
111 /* Xilinx includes. */\r
112 #include "platform.h"\r
113 #include "xttcps.h"\r
114 #include "xscugic.h"\r
115 \r
116 /* mainSELECTED_APPLICATION is used to select between two demo applications,\r
117  * as described at the top of this file.\r
118  *\r
119  * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will\r
120  * be run.\r
121  *\r
122  * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo\r
123  * application will be run.\r
124  */\r
125 #define mainSELECTED_APPLICATION        0\r
126 \r
127 /*-----------------------------------------------------------*/\r
128 \r
129 /*\r
130  * Configure the hardware as necessary to run this demo.\r
131  */\r
132 static void prvSetupHardware( void );\r
133 \r
134 /*\r
135  * See the comments at the top of this file and above the\r
136  * mainSELECTED_APPLICATION definition.\r
137  */\r
138 #if ( mainSELECTED_APPLICATION == 0 )\r
139         extern void main_blinky( void );\r
140 #elif ( mainSELECTED_APPLICATION == 1 )\r
141         extern void main_full( void );\r
142 #else\r
143         #error Invalid mainSELECTED_APPLICATION setting.  See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.\r
144 #endif\r
145 \r
146 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
147 within this file. */\r
148 void vApplicationMallocFailedHook( void );\r
149 void vApplicationIdleHook( void );\r
150 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
151 void vApplicationTickHook( void );\r
152 \r
153 /*-----------------------------------------------------------*/\r
154 \r
155 /* The interrupt controller is initialised in this file, and made available to\r
156 other modules. */\r
157 XScuGic xInterruptController;\r
158 \r
159 /*-----------------------------------------------------------*/\r
160 \r
161 int main( void )\r
162 {\r
163         /* Configure the hardware ready to run the demo. */\r
164         prvSetupHardware();\r
165 \r
166         /* The mainSELECTED_APPLICATION setting is described at the top\r
167         of this file. */\r
168         #if( mainSELECTED_APPLICATION == 0 )\r
169         {\r
170                 main_blinky();\r
171         }\r
172         #elif( mainSELECTED_APPLICATION == 1 )\r
173         {\r
174                 main_full();\r
175         }\r
176         #endif\r
177 \r
178         /* Don't expect to reach here. */\r
179         return 0;\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 static void prvSetupHardware( void )\r
184 {\r
185 BaseType_t xStatus;\r
186 XScuGic_Config *pxGICConfig;\r
187 \r
188         /* Ensure no interrupts execute while the scheduler is in an inconsistent\r
189         state.  Interrupts are automatically enabled when the scheduler is\r
190         started. */\r
191         portDISABLE_INTERRUPTS();\r
192 \r
193         /* Obtain the configuration of the GIC. */\r
194         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
195 \r
196         /* Sanity check the FreeRTOSConfig.h settings are correct for the\r
197         hardware. */\r
198         configASSERT( pxGICConfig );\r
199         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );\r
200         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );\r
201 \r
202         /* Install a default handler for each GIC interrupt. */\r
203         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
204         configASSERT( xStatus == XST_SUCCESS );\r
205         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
206 }\r
207 /*-----------------------------------------------------------*/\r
208 \r
209 void vApplicationMallocFailedHook( void )\r
210 {\r
211         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
212         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
213         internally by FreeRTOS API functions that create tasks, queues, software\r
214         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
215         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
216         taskDISABLE_INTERRUPTS();\r
217         for( ;; );\r
218 }\r
219 /*-----------------------------------------------------------*/\r
220 \r
221 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
222 {\r
223         ( void ) pcTaskName;\r
224         ( void ) pxTask;\r
225 \r
226         /* Run time stack overflow checking is performed if\r
227         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
228         function is called if a stack overflow is detected. */\r
229         taskDISABLE_INTERRUPTS();\r
230         for( ;; );\r
231 }\r
232 /*-----------------------------------------------------------*/\r
233 \r
234 void vApplicationIdleHook( void )\r
235 {\r
236 volatile size_t xFreeHeapSpace;\r
237 \r
238         /* This is just a trivial example of an idle hook.  It is called on each\r
239         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
240         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
241         memory management section on the http://www.FreeRTOS.org web site for memory\r
242         management options.  If there is a lot of heap memory free then the\r
243         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
244         RAM. */\r
245         xFreeHeapSpace = xPortGetFreeHeapSize();\r
246 \r
247         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
248         ( void ) xFreeHeapSpace;\r
249 }\r
250 /*-----------------------------------------------------------*/\r
251 \r
252 void vAssertCalled( const char * pcFile, unsigned long ulLine )\r
253 {\r
254 volatile unsigned long ul = 0;\r
255 \r
256         ( void ) pcFile;\r
257         ( void ) ulLine;\r
258 \r
259         taskENTER_CRITICAL();\r
260         {\r
261                 #if( configUSE_TRACE_FACILITY == 1 )\r
262                 {\r
263                         vTraceStop();\r
264                 }\r
265                 #endif\r
266 \r
267                 /* Set ul to a non-zero value using the debugger to step out of this\r
268                 function. */\r
269                 while( ul == 0 )\r
270                 {\r
271                         portNOP();\r
272                 }\r
273         }\r
274         taskEXIT_CRITICAL();\r
275 }\r
276 /*-----------------------------------------------------------*/\r
277 \r
278 void vApplicationTickHook( void )\r
279 {\r
280         #if( mainSELECTED_APPLICATION == 1 )\r
281         {\r
282                 /* Call the periodic event group from ISR demo. */\r
283                 vPeriodicEventGroupsProcessing();\r
284 \r
285                 /* Use task notifications from an interrupt. */\r
286                 xNotifyTaskFromISR();\r
287 \r
288                 /* Use mutexes from interrupts. */\r
289                 vInterruptSemaphorePeriodicTest();\r
290         }\r
291         #endif\r
292 }\r
293 /*-----------------------------------------------------------*/\r
294 \r
295 void *memcpy( void *pvDest, const void *pvSource, size_t xBytes )\r
296 {\r
297 /* The compiler used during development seems to err unless these volatiles are\r
298 included at -O3 optimisation.  */\r
299 volatile unsigned char *pcDest = ( volatile unsigned char * ) pvDest, *pcSource = ( volatile unsigned char * ) pvSource;\r
300 size_t x;\r
301 \r
302         /* Extremely crude standard library implementations in lieu of having a C\r
303         library. */\r
304         if( pvDest != pvSource )\r
305         {\r
306                 for( x = 0; x < xBytes; x++ )\r
307                 {\r
308                         pcDest[ x ] = pcSource[ x ];\r
309                 }\r
310         }\r
311 \r
312         return pvDest;\r
313 }\r
314 /*-----------------------------------------------------------*/\r
315 \r
316 void *memset( void *pvDest, int iValue, size_t xBytes )\r
317 {\r
318 /* The compiler used during development seems to err unless these volatiles are\r
319 included at -O3 optimisation.  */\r
320 volatile unsigned char * volatile pcDest = ( volatile unsigned char * volatile ) pvDest;\r
321 volatile size_t x;\r
322 \r
323         /* Extremely crude standard library implementations in lieu of having a C\r
324         library. */\r
325         for( x = 0; x < xBytes; x++ )\r
326         {\r
327                 pcDest[ x ] = ( unsigned char ) iValue;\r
328         }\r
329 \r
330         return pvDest;\r
331 }\r
332 /*-----------------------------------------------------------*/\r
333 \r
334 int memcmp( const void *pvMem1, const void *pvMem2, size_t xBytes )\r
335 {\r
336 const volatile unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2;\r
337 volatile size_t x;\r
338 \r
339         /* Extremely crude standard library implementations in lieu of having a C\r
340         library. */\r
341     for( x = 0; x < xBytes; x++ )\r
342     {\r
343         if( pucMem1[ x ] != pucMem2[ x ] )\r
344         {\r
345             break;\r
346         }\r
347     }\r
348 \r
349     return xBytes - x;\r
350 }\r
351 /*-----------------------------------------------------------*/\r
352 \r