2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
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.
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 ***************************************************************************
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
25 ***************************************************************************
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. *
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 *
37 ***************************************************************************
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()?
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.
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.
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.
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.
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.
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.
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.
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.
81 /* Standard includes. */
84 /* Scheduler include files. */
88 /* Xilinx includes. */
90 #include "xparameters.h"
92 #include "xil_printf.h"
94 /* mainSELECTED_APPLICATION is used to select between two demo applications,
95 * as described at the top of this file.
97 * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will
100 * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo
101 * application will be run.
103 #define mainSELECTED_APPLICATION 0
105 /*-----------------------------------------------------------*/
108 * Configure the hardware as necessary to run this demo.
110 static void prvSetupHardware( void );
113 * See the comments at the top of this file and above the
114 * mainSELECTED_APPLICATION definition.
116 #if ( mainSELECTED_APPLICATION == 0 )
117 extern void main_blinky( void );
118 #elif ( mainSELECTED_APPLICATION == 1 )
119 extern void main_full( void );
121 #error Invalid mainSELECTED_APPLICATION setting. See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.
124 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
126 void vApplicationMallocFailedHook( void );
127 void vApplicationIdleHook( void );
128 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
129 void vApplicationTickHook( void );
131 /*-----------------------------------------------------------*/
133 /* The interrupt controller is initialised in this file, and made available to
135 XScuGic xInterruptController;
137 /*-----------------------------------------------------------*/
141 /* Configure the hardware ready to run the demo. */
144 /* The mainSELECTED_APPLICATION setting is described at the top
146 #if( mainSELECTED_APPLICATION == 0 )
150 #elif( mainSELECTED_APPLICATION == 1 )
156 /* Don't expect to reach here. */
159 /*-----------------------------------------------------------*/
161 static void prvSetupHardware( void )
164 XScuGic_Config *pxGICConfig;
166 /* Ensure no interrupts execute while the scheduler is in an inconsistent
167 state. Interrupts are automatically enabled when the scheduler is
169 portDISABLE_INTERRUPTS();
173 /* Obtain the configuration of the GIC. */
174 pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
176 /* Sanity check the FreeRTOSConfig.h settings are correct for the
178 configASSERT( pxGICConfig );
179 configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
180 configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
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. */
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" \
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" \
200 /*-----------------------------------------------------------*/
202 void vApplicationMallocFailedHook( void )
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();
212 /*-----------------------------------------------------------*/
214 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
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();
225 /*-----------------------------------------------------------*/
227 void vApplicationIdleHook( void )
229 volatile size_t xFreeHeapSpace;
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
238 xFreeHeapSpace = xPortGetFreeHeapSize();
240 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
241 ( void ) xFreeHeapSpace;
243 /*-----------------------------------------------------------*/
245 void vApplicationTickHook( void )
247 #if( mainSELECTED_APPLICATION == 1 )
249 /* Only the comprehensive demo actually uses the tick hook. */
250 extern void vFullDemoTickHook( void );
255 /*-----------------------------------------------------------*/
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 )
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 ];
268 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
269 state will be stored. */
270 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
272 /* Pass out the array that will be used as the Idle task's stack. */
273 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
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;
280 /*-----------------------------------------------------------*/
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 )
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 ];
293 /* Pass out a pointer to the StaticTask_t structure in which the Timer
294 task's state will be stored. */
295 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
297 /* Pass out the array that will be used as the Timer task's stack. */
298 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
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;
305 /*-----------------------------------------------------------*/
307 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )
309 xil_printf( "ASSERT! Line %lu of file %s\r\n", ulLineNumber, pcFileName );
310 taskENTER_CRITICAL();