]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5/src/main.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5 / src / main.c
1 /*
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /******************************************************************************
71  * NOTE 1:  This project provides two demo applications.  A simple blinky
72  * style project, and a more comprehensive test and demo application.  The
73  * mainSELECTED_APPLICATION setting in main.c is used to select between the two.
74  * See the notes on using mainSELECTED_APPLICATION where it is defined below.
75  *
76  * NOTE 2:  This file only contains the source code that is not specific to
77  * either the simply blinky or full demos - this includes initialisation code
78  * and callback functions.
79  */
80
81 /* Standard includes. */
82 #include <stdio.h>
83
84 /* Scheduler include files. */
85 #include "FreeRTOS.h"
86 #include "task.h"
87
88 /* Xilinx includes. */
89 #include "platform.h"
90 #include "xparameters.h"
91 #include "xscugic.h"
92 #include "xil_printf.h"
93
94 /* mainSELECTED_APPLICATION is used to select between two demo applications,
95  * as described at the top of this file.
96  *
97  * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will
98  * be run.
99  *
100  * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo
101  * application will be run.
102  */
103 #define mainSELECTED_APPLICATION        0
104
105 /*-----------------------------------------------------------*/
106
107 /*
108  * Configure the hardware as necessary to run this demo.
109  */
110 static void prvSetupHardware( void );
111
112 /*
113  * See the comments at the top of this file and above the
114  * mainSELECTED_APPLICATION definition.
115  */
116 #if ( mainSELECTED_APPLICATION == 0 )
117         extern void main_blinky( void );
118 #elif ( mainSELECTED_APPLICATION == 1 )
119         extern void main_full( void );
120 #else
121         #error Invalid mainSELECTED_APPLICATION setting.  See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.
122 #endif
123
124 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
125 within this file. */
126 void vApplicationMallocFailedHook( void );
127 void vApplicationIdleHook( void );
128 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
129 void vApplicationTickHook( void );
130
131 /*-----------------------------------------------------------*/
132
133 /* The interrupt controller is initialised in this file, and made available to
134 other modules. */
135 XScuGic xInterruptController;
136
137 /*-----------------------------------------------------------*/
138
139 int main( void )
140 {
141         /* Configure the hardware ready to run the demo. */
142         prvSetupHardware();
143
144         /* The mainSELECTED_APPLICATION setting is described at the top
145         of this file. */
146         #if( mainSELECTED_APPLICATION == 0 )
147         {
148                 main_blinky();
149         }
150         #elif( mainSELECTED_APPLICATION == 1 )
151         {
152                 main_full();
153         }
154         #endif
155
156         /* Don't expect to reach here. */
157         return 0;
158 }
159 /*-----------------------------------------------------------*/
160
161 static void prvSetupHardware( void )
162 {
163 BaseType_t xStatus;
164 XScuGic_Config *pxGICConfig;
165
166         /* Ensure no interrupts execute while the scheduler is in an inconsistent
167         state.  Interrupts are automatically enabled when the scheduler is
168         started. */
169         portDISABLE_INTERRUPTS();
170
171         init_platform();
172
173         /* Obtain the configuration of the GIC. */
174         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
175
176         /* Sanity check the FreeRTOSConfig.h settings are correct for the
177         hardware. */
178         configASSERT( pxGICConfig );
179         configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
180         configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
181
182         /* Install a default handler for each GIC interrupt. */
183         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
184         configASSERT( xStatus == XST_SUCCESS );
185         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
186
187         /* Ensure the FPU is accessible by enabling access to CP 10 and 11. */
188         __asm volatile( "MRC    p15, 0, r0, c1, c0, 2   \n"     \
189                                         "ORR    r0, r0, #(0xF << 20)    \n" \
190                                         "MCR    p15, 0, r0, c1, c0, 2   \n" \
191                                         "ISB                                                      " );
192
193
194         /* Ensure the FPU is enabled. */
195         __asm volatile( "VMRS   r0, FPEXC                       \n"             \
196                                         "ORR    r1, r0, #(1<<30)        \n"             \
197                                         "VMSR   FPEXC, r1                       \n"             \
198                                         ::: "r0", "r1" );
199 }
200 /*-----------------------------------------------------------*/
201
202 void vApplicationMallocFailedHook( void )
203 {
204         /* Called if a call to pvPortMalloc() fails because there is insufficient
205         free memory available in the FreeRTOS heap.  pvPortMalloc() is called
206         internally by FreeRTOS API functions that create tasks, queues, software
207         timers, and semaphores.  The size of the FreeRTOS heap is set by the
208         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
209         taskDISABLE_INTERRUPTS();
210         for( ;; );
211 }
212 /*-----------------------------------------------------------*/
213
214 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
215 {
216         ( void ) pcTaskName;
217         ( void ) pxTask;
218
219         /* Run time stack overflow checking is performed if
220         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
221         function is called if a stack overflow is detected. */
222         taskDISABLE_INTERRUPTS();
223         for( ;; );
224 }
225 /*-----------------------------------------------------------*/
226
227 void vApplicationIdleHook( void )
228 {
229 volatile size_t xFreeHeapSpace;
230
231         /* This is just a trivial example of an idle hook.  It is called on each
232         cycle of the idle task.  It must *NOT* attempt to block.  In this case the
233         idle task just queries the amount of FreeRTOS heap that remains.  See the
234         memory management section on the http://www.FreeRTOS.org web site for memory
235         management options.  If there is a lot of heap memory free then the
236         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
237         RAM. */
238         xFreeHeapSpace = xPortGetFreeHeapSize();
239
240         /* Remove compiler warning about xFreeHeapSpace being set but never used. */
241         ( void ) xFreeHeapSpace;
242 }
243 /*-----------------------------------------------------------*/
244
245 void vApplicationTickHook( void )
246 {
247         #if( mainSELECTED_APPLICATION == 1 )
248         {
249                 /* Only the comprehensive demo actually uses the tick hook. */
250                 extern void vFullDemoTickHook( void );
251                 vFullDemoTickHook();
252         }
253         #endif
254 }
255 /*-----------------------------------------------------------*/
256
257 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
258 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
259 used by the Idle task. */
260 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
261 {
262 /* If the buffers to be provided to the Idle task are declared inside this
263 function then they must be declared static - otherwise they will be allocated on
264 the stack and so not exists after this function exits. */
265 static StaticTask_t xIdleTaskTCB;
266 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
267
268         /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
269         state will be stored. */
270         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
271
272         /* Pass out the array that will be used as the Idle task's stack. */
273         *ppxIdleTaskStackBuffer = uxIdleTaskStack;
274
275         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
276         Note that, as the array is necessarily of type StackType_t,
277         configMINIMAL_STACK_SIZE is specified in words, not bytes. */
278         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
279 }
280 /*-----------------------------------------------------------*/
281
282 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
283 application must provide an implementation of vApplicationGetTimerTaskMemory()
284 to provide the memory that is used by the Timer service task. */
285 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
286 {
287 /* If the buffers to be provided to the Timer task are declared inside this
288 function then they must be declared static - otherwise they will be allocated on
289 the stack and so not exists after this function exits. */
290 static StaticTask_t xTimerTaskTCB;
291 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
292
293         /* Pass out a pointer to the StaticTask_t structure in which the Timer
294         task's state will be stored. */
295         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
296
297         /* Pass out the array that will be used as the Timer task's stack. */
298         *ppxTimerTaskStackBuffer = uxTimerTaskStack;
299
300         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
301         Note that, as the array is necessarily of type StackType_t,
302         configMINIMAL_STACK_SIZE is specified in words, not bytes. */
303         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
304 }
305 /*-----------------------------------------------------------*/
306
307 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )
308 {
309         xil_printf( "ASSERT!  Line %lu of file %s\r\n", ulLineNumber, pcFileName );
310         taskENTER_CRITICAL();
311         for( ;; );
312 }
313
314