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