]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5/src/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5 / src / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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 /******************************************************************************\r
29  * NOTE 1:  This project provides two demo applications.  A simple blinky\r
30  * style project, and a more comprehensive test and demo application.  The\r
31  * mainSELECTED_APPLICATION setting in main.c is used to select between the two.\r
32  * See the notes on using mainSELECTED_APPLICATION where it is defined below.\r
33  *\r
34  * NOTE 2:  This file only contains the source code that is not specific to\r
35  * either the simply blinky or full demos - this includes initialisation code\r
36  * and callback functions.\r
37  */\r
38 \r
39 /* Standard includes. */\r
40 #include <stdio.h>\r
41 \r
42 /* Scheduler include files. */\r
43 #include "FreeRTOS.h"\r
44 #include "task.h"\r
45 \r
46 /* Xilinx includes. */\r
47 #include "platform.h"\r
48 #include "xparameters.h"\r
49 #include "xscugic.h"\r
50 #include "xil_printf.h"\r
51 \r
52 /* mainSELECTED_APPLICATION is used to select between two demo applications,\r
53  * as described at the top of this file.\r
54  *\r
55  * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will\r
56  * be run.\r
57  *\r
58  * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo\r
59  * application will be run.\r
60  */\r
61 #define mainSELECTED_APPLICATION        0\r
62 \r
63 /*-----------------------------------------------------------*/\r
64 \r
65 /*\r
66  * Configure the hardware as necessary to run this demo.\r
67  */\r
68 static void prvSetupHardware( void );\r
69 \r
70 /*\r
71  * See the comments at the top of this file and above the\r
72  * mainSELECTED_APPLICATION definition.\r
73  */\r
74 #if ( mainSELECTED_APPLICATION == 0 )\r
75         extern void main_blinky( void );\r
76 #elif ( mainSELECTED_APPLICATION == 1 )\r
77         extern void main_full( void );\r
78 #else\r
79         #error Invalid mainSELECTED_APPLICATION setting.  See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.\r
80 #endif\r
81 \r
82 /* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
83 within this file. */\r
84 void vApplicationMallocFailedHook( void );\r
85 void vApplicationIdleHook( void );\r
86 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
87 void vApplicationTickHook( void );\r
88 \r
89 /*-----------------------------------------------------------*/\r
90 \r
91 /* The interrupt controller is initialised in this file, and made available to\r
92 other modules. */\r
93 XScuGic xInterruptController;\r
94 \r
95 /*-----------------------------------------------------------*/\r
96 \r
97 int main( void )\r
98 {\r
99         /* Configure the hardware ready to run the demo. */\r
100         prvSetupHardware();\r
101 \r
102         /* The mainSELECTED_APPLICATION setting is described at the top\r
103         of this file. */\r
104         #if( mainSELECTED_APPLICATION == 0 )\r
105         {\r
106                 main_blinky();\r
107         }\r
108         #elif( mainSELECTED_APPLICATION == 1 )\r
109         {\r
110                 main_full();\r
111         }\r
112         #endif\r
113 \r
114         /* Don't expect to reach here. */\r
115         return 0;\r
116 }\r
117 /*-----------------------------------------------------------*/\r
118 \r
119 static void prvSetupHardware( void )\r
120 {\r
121 BaseType_t xStatus;\r
122 XScuGic_Config *pxGICConfig;\r
123 \r
124         /* Ensure no interrupts execute while the scheduler is in an inconsistent\r
125         state.  Interrupts are automatically enabled when the scheduler is\r
126         started. */\r
127         portDISABLE_INTERRUPTS();\r
128 \r
129         init_platform();\r
130 \r
131         /* Obtain the configuration of the GIC. */\r
132         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
133 \r
134         /* Sanity check the FreeRTOSConfig.h settings are correct for the\r
135         hardware. */\r
136         configASSERT( pxGICConfig );\r
137         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );\r
138         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );\r
139 \r
140         /* Install a default handler for each GIC interrupt. */\r
141         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
142         configASSERT( xStatus == XST_SUCCESS );\r
143         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
144 \r
145         /* Ensure the FPU is accessible by enabling access to CP 10 and 11. */\r
146         __asm volatile( "MRC    p15, 0, r0, c1, c0, 2   \n"     \\r
147                                         "ORR    r0, r0, #(0xF << 20)    \n" \\r
148                                         "MCR    p15, 0, r0, c1, c0, 2   \n" \\r
149                                         "ISB                                                      " );\r
150 \r
151 \r
152         /* Ensure the FPU is enabled. */\r
153         __asm volatile( "VMRS   r0, FPEXC                       \n"             \\r
154                                         "ORR    r1, r0, #(1<<30)        \n"             \\r
155                                         "VMSR   FPEXC, r1                       \n"             \\r
156                                         ::: "r0", "r1" );\r
157 }\r
158 /*-----------------------------------------------------------*/\r
159 \r
160 void vApplicationMallocFailedHook( void )\r
161 {\r
162         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
163         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
164         internally by FreeRTOS API functions that create tasks, queues, software\r
165         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
166         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
167         taskDISABLE_INTERRUPTS();\r
168         for( ;; );\r
169 }\r
170 /*-----------------------------------------------------------*/\r
171 \r
172 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
173 {\r
174         ( void ) pcTaskName;\r
175         ( void ) pxTask;\r
176 \r
177         /* Run time stack overflow checking is performed if\r
178         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
179         function is called if a stack overflow is detected. */\r
180         taskDISABLE_INTERRUPTS();\r
181         for( ;; );\r
182 }\r
183 /*-----------------------------------------------------------*/\r
184 \r
185 void vApplicationIdleHook( void )\r
186 {\r
187 volatile size_t xFreeHeapSpace;\r
188 \r
189         /* This is just a trivial example of an idle hook.  It is called on each\r
190         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
191         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
192         memory management section on the http://www.FreeRTOS.org web site for memory\r
193         management options.  If there is a lot of heap memory free then the\r
194         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
195         RAM. */\r
196         xFreeHeapSpace = xPortGetFreeHeapSize();\r
197 \r
198         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
199         ( void ) xFreeHeapSpace;\r
200 }\r
201 /*-----------------------------------------------------------*/\r
202 \r
203 void vApplicationTickHook( void )\r
204 {\r
205         #if( mainSELECTED_APPLICATION == 1 )\r
206         {\r
207                 /* Only the comprehensive demo actually uses the tick hook. */\r
208                 extern void vFullDemoTickHook( void );\r
209                 vFullDemoTickHook();\r
210         }\r
211         #endif\r
212 }\r
213 /*-----------------------------------------------------------*/\r
214 \r
215 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
216 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
217 used by the Idle task. */\r
218 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )\r
219 {\r
220 /* If the buffers to be provided to the Idle task are declared inside this\r
221 function then they must be declared static - otherwise they will be allocated on\r
222 the stack and so not exists after this function exits. */\r
223 static StaticTask_t xIdleTaskTCB;\r
224 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
225 \r
226         /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
227         state will be stored. */\r
228         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
229 \r
230         /* Pass out the array that will be used as the Idle task's stack. */\r
231         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
232 \r
233         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
234         Note that, as the array is necessarily of type StackType_t,\r
235         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
236         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
237 }\r
238 /*-----------------------------------------------------------*/\r
239 \r
240 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
241 application must provide an implementation of vApplicationGetTimerTaskMemory()\r
242 to provide the memory that is used by the Timer service task. */\r
243 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )\r
244 {\r
245 /* If the buffers to be provided to the Timer task are declared inside this\r
246 function then they must be declared static - otherwise they will be allocated on\r
247 the stack and so not exists after this function exits. */\r
248 static StaticTask_t xTimerTaskTCB;\r
249 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
250 \r
251         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
252         task's state will be stored. */\r
253         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
254 \r
255         /* Pass out the array that will be used as the Timer task's stack. */\r
256         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
257 \r
258         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
259         Note that, as the array is necessarily of type StackType_t,\r
260         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
261         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
262 }\r
263 /*-----------------------------------------------------------*/\r
264 \r
265 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )\r
266 {\r
267         xil_printf( "ASSERT!  Line %lu of file %s\r\n", ulLineNumber, pcFileName );\r
268         taskENTER_CRITICAL();\r
269         for( ;; );\r
270 }\r
271 \r
272 \r