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