2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /******************************************************************************
\r
71 * NOTE 1: This project provides two demo applications. A simple blinky
\r
72 * style project, and a more comprehensive test and demo application. The
\r
73 * mainSELECTED_APPLICATION setting in main.c is used to select between the two.
\r
74 * See the notes on using mainSELECTED_APPLICATION where it is defined below.
\r
76 * NOTE 2: This file only contains the source code that is not specific to
\r
77 * either the simply blinky or full demos - this includes initialisation code
\r
78 * and callback functions.
\r
81 /* Standard includes. */
\r
84 /* Scheduler include files. */
\r
85 #include "FreeRTOS.h"
\r
88 /* Xilinx includes. */
\r
89 #include "platform.h"
\r
91 #include "xscugic.h"
\r
93 /* mainSELECTED_APPLICATION is used to select between two demo applications,
\r
94 * as described at the top of this file.
\r
96 * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will
\r
99 * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo
\r
100 * application will be run.
\r
102 #define mainSELECTED_APPLICATION 1
\r
104 /*-----------------------------------------------------------*/
\r
107 * Configure the hardware as necessary to run this demo.
\r
109 static void prvSetupHardware( void );
\r
112 * See the comments at the top of this file and above the
\r
113 * mainSELECTED_APPLICATION definition.
\r
115 #if ( mainSELECTED_APPLICATION == 0 )
\r
116 extern void main_blinky( void );
\r
117 #elif ( mainSELECTED_APPLICATION == 1 )
\r
118 extern void main_full( void );
\r
120 #error Invalid mainSELECTED_APPLICATION setting. See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.
\r
123 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
124 within this file. */
\r
125 void vApplicationMallocFailedHook( void );
\r
126 void vApplicationIdleHook( void );
\r
127 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
128 void vApplicationTickHook( void );
\r
130 /*-----------------------------------------------------------*/
\r
132 /* The interrupt controller is initialised in this file, and made available to
\r
134 XScuGic xInterruptController;
\r
136 /*-----------------------------------------------------------*/
\r
140 /* Configure the hardware ready to run the demo. */
\r
141 prvSetupHardware();
\r
143 /* The mainSELECTED_APPLICATION setting is described at the top
\r
145 #if( mainSELECTED_APPLICATION == 0 )
\r
149 #elif( mainSELECTED_APPLICATION == 1 )
\r
155 /* Don't expect to reach here. */
\r
158 /*-----------------------------------------------------------*/
\r
160 static void prvSetupHardware( void )
\r
162 BaseType_t xStatus;
\r
163 XScuGic_Config *pxGICConfig;
\r
165 /* Ensure no interrupts execute while the scheduler is in an inconsistent
\r
166 state. Interrupts are automatically enabled when the scheduler is
\r
168 portDISABLE_INTERRUPTS();
\r
170 /* Obtain the configuration of the GIC. */
\r
171 pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
\r
173 /* Sanity check the FreeRTOSConfig.h settings are correct for the
\r
175 configASSERT( pxGICConfig );
\r
176 configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
\r
177 configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
\r
179 /* Install a default handler for each GIC interrupt. */
\r
180 xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
\r
181 configASSERT( xStatus == XST_SUCCESS );
\r
182 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
184 /*-----------------------------------------------------------*/
\r
186 void vApplicationMallocFailedHook( void )
\r
188 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
189 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
190 internally by FreeRTOS API functions that create tasks, queues, software
\r
191 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
192 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
193 taskDISABLE_INTERRUPTS();
\r
196 /*-----------------------------------------------------------*/
\r
198 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
200 ( void ) pcTaskName;
\r
203 /* Run time stack overflow checking is performed if
\r
204 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
205 function is called if a stack overflow is detected. */
\r
206 taskDISABLE_INTERRUPTS();
\r
209 /*-----------------------------------------------------------*/
\r
211 void vApplicationIdleHook( void )
\r
213 volatile size_t xFreeHeapSpace;
\r
215 /* This is just a trivial example of an idle hook. It is called on each
\r
216 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
217 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
218 memory management section on the http://www.FreeRTOS.org web site for memory
\r
219 management options. If there is a lot of heap memory free then the
\r
220 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
222 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
224 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
225 ( void ) xFreeHeapSpace;
\r
227 /*-----------------------------------------------------------*/
\r
229 void vApplicationTickHook( void )
\r
231 #if( mainSELECTED_APPLICATION == 1 )
\r
233 /* Only the comprehensive demo actually uses the tick hook. */
\r
234 extern void vFullDemoTickHook( void );
\r
235 vFullDemoTickHook();
\r
239 /*-----------------------------------------------------------*/
\r
241 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
242 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
243 used by the Idle task. */
\r
244 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
246 /* If the buffers to be provided to the Idle task are declared inside this
\r
247 function then they must be declared static - otherwise they will be allocated on
\r
248 the stack and so not exists after this function exits. */
\r
249 static StaticTask_t xIdleTaskTCB;
\r
250 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
252 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
253 state will be stored. */
\r
254 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
256 /* Pass out the array that will be used as the Idle task's stack. */
\r
257 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
259 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
260 Note that, as the array is necessarily of type StackType_t,
\r
261 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
262 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
264 /*-----------------------------------------------------------*/
\r
266 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
267 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
268 to provide the memory that is used by the Timer service task. */
\r
269 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
271 /* If the buffers to be provided to the Timer task are declared inside this
\r
272 function then they must be declared static - otherwise they will be allocated on
\r
273 the stack and so not exists after this function exits. */
\r
274 static StaticTask_t xTimerTaskTCB;
\r
275 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
277 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
278 task's state will be stored. */
\r
279 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
281 /* Pass out the array that will be used as the Timer task's stack. */
\r
282 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
284 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
285 Note that, as the array is necessarily of type StackType_t,
\r
286 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
287 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r
289 /*-----------------------------------------------------------*/
\r
291 void *memcpy( void *pvDest, const void *pvSource, size_t xBytes )
\r
293 /* The compiler used during development seems to err unless these volatiles are
\r
294 included at -O3 optimisation. */
\r
295 volatile unsigned char *pcDest = ( volatile unsigned char * ) pvDest, *pcSource = ( volatile unsigned char * ) pvSource;
\r
298 /* Extremely crude standard library implementations in lieu of having a C
\r
300 if( pvDest != pvSource )
\r
302 for( x = 0; x < xBytes; x++ )
\r
304 pcDest[ x ] = pcSource[ x ];
\r
310 /*-----------------------------------------------------------*/
\r
312 void *memset( void *pvDest, int iValue, size_t xBytes )
\r
314 /* The compiler used during development seems to err unless these volatiles are
\r
315 included at -O3 optimisation. */
\r
316 volatile unsigned char * volatile pcDest = ( volatile unsigned char * volatile ) pvDest;
\r
319 /* Extremely crude standard library implementations in lieu of having a C
\r
321 for( x = 0; x < xBytes; x++ )
\r
323 pcDest[ x ] = ( unsigned char ) iValue;
\r
328 /*-----------------------------------------------------------*/
\r
330 int memcmp( const void *pvMem1, const void *pvMem2, size_t xBytes )
\r
332 const volatile unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2;
\r
335 /* Extremely crude standard library implementations in lieu of having a C
\r
337 for( x = 0; x < xBytes; x++ )
\r
339 if( pucMem1[ x ] != pucMem2[ x ] )
\r
347 /*-----------------------------------------------------------*/
\r
349 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )
\r
351 xil_printf( "ASSERT! Line %lu of file %s\r\n", ulLineNumber, pcFileName );
\r
352 taskENTER_CRITICAL();
\r