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
72 * See http://www.freertos.org/RTOS-Xilinx-Zynq.html for instructions.
\r
74 * This project provides three demo applications. A simple blinky style
\r
75 * project, a more comprehensive test and demo application, and an lwIP example.
\r
76 * The mainSELECTED_APPLICATION setting (defined in this file) is used to
\r
77 * select between the three. The simply blinky demo is implemented and
\r
78 * described in main_blinky.c. The more comprehensive test and demo application
\r
79 * is implemented and described in main_full.c. The lwIP example is implemented
\r
80 * and described in main_lwIP.c.
\r
82 * This file implements the code that is not demo specific, including the
\r
83 * hardware setup and FreeRTOS hook functions.
\r
85 * !!! IMPORTANT NOTE !!!
\r
86 * The GCC libraries that ship with the Xilinx SDK make use of the floating
\r
87 * point registers. To avoid this causing corruption it is necessary to avoid
\r
88 * their use. For this reason main.c contains very basic C implementations of
\r
89 * the standard C library functions memset(), memcpy() and memcmp(), which are
\r
90 * are used by FreeRTOS itself. Defining these functions in the project
\r
91 * prevents the linker pulling them in from the library. Any other standard C
\r
92 * library functions that are used by the application must likewise be defined
\r
95 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
96 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
97 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
101 /* Standard includes. */
\r
103 #include <limits.h>
\r
105 /* Scheduler include files. */
\r
106 #include "FreeRTOS.h"
\r
108 #include "semphr.h"
\r
110 /* Standard demo includes. */
\r
111 #include "partest.h"
\r
112 #include "TimerDemo.h"
\r
113 #include "QueueOverwrite.h"
\r
114 #include "EventGroupsDemo.h"
\r
115 #include "TaskNotify.h"
\r
116 #include "IntSemTest.h"
\r
118 /* Xilinx includes. */
\r
119 #include "platform.h"
\r
120 #include "xparameters.h"
\r
121 #include "xscutimer.h"
\r
122 #include "xscugic.h"
\r
123 #include "xil_exception.h"
\r
125 /* mainSELECTED_APPLICATION is used to select between three demo applications,
\r
126 * as described at the top of this file.
\r
128 * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will
\r
131 * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo
\r
132 * application will be run.
\r
134 * When mainSELECTED_APPLICATION is set to 2 the lwIP example will be run.
\r
136 #define mainSELECTED_APPLICATION 1
\r
138 /*-----------------------------------------------------------*/
\r
141 * Configure the hardware as necessary to run this demo.
\r
143 static void prvSetupHardware( void );
\r
146 * See the comments at the top of this file and above the
\r
147 * mainSELECTED_APPLICATION definition.
\r
149 #if ( mainSELECTED_APPLICATION == 0 )
\r
150 extern void main_blinky( void );
\r
151 #elif ( mainSELECTED_APPLICATION == 1 )
\r
152 extern void main_full( void );
\r
153 #elif ( mainSELECTED_APPLICATION == 2 )
\r
154 extern void main_lwIP( void );
\r
156 #error Invalid mainSELECTED_APPLICATION setting. See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.
\r
160 * The Xilinx projects use a BSP that do not allow the start up code to be
\r
161 * altered easily. Therefore the vector table used by FreeRTOS is defined in
\r
162 * FreeRTOS_asm_vectors.S, which is part of this project. Switch to use the
\r
163 * FreeRTOS vector table.
\r
165 extern void vPortInstallFreeRTOSVectorTable( void );
\r
167 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
168 within this file. */
\r
169 void vApplicationMallocFailedHook( void );
\r
170 void vApplicationIdleHook( void );
\r
171 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
172 void vApplicationTickHook( void );
\r
174 /* The private watchdog is used as the timer that generates run time
\r
175 stats. This frequency means it will overflow quite quickly. */
\r
176 XScuWdt xWatchDogInstance;
\r
178 /*-----------------------------------------------------------*/
\r
180 /* The interrupt controller is initialised in this file, and made available to
\r
182 XScuGic xInterruptController;
\r
184 /*-----------------------------------------------------------*/
\r
188 /* See http://www.freertos.org/RTOS-Xilinx-Zynq.html for instructions. */
\r
190 /* Configure the hardware ready to run the demo. */
\r
191 prvSetupHardware();
\r
193 /* The mainSELECTED_APPLICATION setting is described at the top of this
\r
195 #if( mainSELECTED_APPLICATION == 0 )
\r
199 #elif( mainSELECTED_APPLICATION == 1 )
\r
209 /* Don't expect to reach here. */
\r
212 /*-----------------------------------------------------------*/
\r
214 static void prvSetupHardware( void )
\r
216 BaseType_t xStatus;
\r
217 XScuGic_Config *pxGICConfig;
\r
219 /* Ensure no interrupts execute while the scheduler is in an inconsistent
\r
220 state. Interrupts are automatically enabled when the scheduler is
\r
222 portDISABLE_INTERRUPTS();
\r
224 /* Obtain the configuration of the GIC. */
\r
225 pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
\r
227 /* Sanity check the FreeRTOSConfig.h settings are correct for the
\r
229 configASSERT( pxGICConfig );
\r
230 configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
\r
231 configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
\r
233 /* Install a default handler for each GIC interrupt. */
\r
234 xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
\r
235 configASSERT( xStatus == XST_SUCCESS );
\r
236 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
238 /* Initialise the LED port. */
\r
239 vParTestInitialise();
\r
241 /* The Xilinx projects use a BSP that do not allow the start up code to be
\r
242 altered easily. Therefore the vector table used by FreeRTOS is defined in
\r
243 FreeRTOS_asm_vectors.S, which is part of this project. Switch to use the
\r
244 FreeRTOS vector table. */
\r
245 vPortInstallFreeRTOSVectorTable();
\r
247 /*-----------------------------------------------------------*/
\r
249 void vApplicationMallocFailedHook( void )
\r
251 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
252 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
253 internally by FreeRTOS API functions that create tasks, queues, software
\r
254 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
255 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
256 taskDISABLE_INTERRUPTS();
\r
259 /*-----------------------------------------------------------*/
\r
261 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
263 ( void ) pcTaskName;
\r
266 /* Run time stack overflow checking is performed if
\r
267 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
268 function is called if a stack overflow is detected. */
\r
269 taskDISABLE_INTERRUPTS();
\r
272 /*-----------------------------------------------------------*/
\r
274 void vApplicationIdleHook( void )
\r
276 volatile size_t xFreeHeapSpace, xMinimumEverFreeHeapSpace;
\r
278 /* This is just a trivial example of an idle hook. It is called on each
\r
279 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
280 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
281 memory management section on the http://www.FreeRTOS.org web site for memory
\r
282 management options. If there is a lot of heap memory free then the
\r
283 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
285 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
286 xMinimumEverFreeHeapSpace = xPortGetMinimumEverFreeHeapSize();
\r
288 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
289 ( void ) xFreeHeapSpace;
\r
290 ( void ) xMinimumEverFreeHeapSpace;
\r
292 /*-----------------------------------------------------------*/
\r
294 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
296 volatile unsigned long ul = 0;
\r
301 taskENTER_CRITICAL();
\r
303 /* Set ul to a non-zero value using the debugger to step out of this
\r
310 taskEXIT_CRITICAL();
\r
312 /*-----------------------------------------------------------*/
\r
314 void vApplicationTickHook( void )
\r
316 #if( mainSELECTED_APPLICATION == 1 )
\r
318 /* The full demo includes a software timer demo/test that requires
\r
319 prodding periodically from the tick interrupt. */
\r
320 vTimerPeriodicISRTests();
\r
322 /* Call the periodic queue overwrite from ISR demo. */
\r
323 vQueueOverwritePeriodicISRDemo();
\r
325 /* Call the periodic event group from ISR demo. */
\r
326 vPeriodicEventGroupsProcessing();
\r
328 /* Use task notifications from an interrupt. */
\r
329 xNotifyTaskFromISR();
\r
331 /* Use mutexes from interrupts. */
\r
332 vInterruptSemaphorePeriodicTest();
\r
336 /*-----------------------------------------------------------*/
\r
338 void *memcpy( void *pvDest, const void *pvSource, size_t xBytes )
\r
340 /* The compiler used during development seems to err unless these volatiles are
\r
341 included at -O3 optimisation. */
\r
342 volatile unsigned char *pcDest = ( volatile unsigned char * ) pvDest, *pcSource = ( volatile unsigned char * ) pvSource;
\r
345 /* Extremely crude standard library implementations in lieu of having a C
\r
347 if( pvDest != pvSource )
\r
349 for( x = 0; x < xBytes; x++ )
\r
351 pcDest[ x ] = pcSource[ x ];
\r
357 /*-----------------------------------------------------------*/
\r
359 void *memset( void *pvDest, int iValue, size_t xBytes )
\r
361 /* The compiler used during development seems to err unless these volatiles are
\r
362 included at -O3 optimisation. */
\r
363 volatile unsigned char * volatile pcDest = ( volatile unsigned char * volatile ) pvDest;
\r
366 /* Extremely crude standard library implementations in lieu of having a C
\r
368 for( x = 0; x < xBytes; x++ )
\r
370 pcDest[ x ] = ( unsigned char ) iValue;
\r
375 /*-----------------------------------------------------------*/
\r
377 int memcmp( const void *pvMem1, const void *pvMem2, size_t xBytes )
\r
379 const volatile unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2;
\r
382 /* Extremely crude standard library implementations in lieu of having a C
\r
384 for( x = 0; x < xBytes; x++ )
\r
386 if( pucMem1[ x ] != pucMem2[ x ] )
\r
394 /*-----------------------------------------------------------*/
\r
396 void vInitialiseTimerForRunTimeStats( void )
\r
398 XScuWdt_Config *pxWatchDogInstance;
\r
400 const uint32_t ulMaxDivisor = 0xff, ulDivisorShift = 0x08;
\r
402 pxWatchDogInstance = XScuWdt_LookupConfig( XPAR_SCUWDT_0_DEVICE_ID );
\r
403 XScuWdt_CfgInitialize( &xWatchDogInstance, pxWatchDogInstance, pxWatchDogInstance->BaseAddr );
\r
405 ulValue = XScuWdt_GetControlReg( &xWatchDogInstance );
\r
406 ulValue |= ulMaxDivisor << ulDivisorShift;
\r
407 XScuWdt_SetControlReg( &xWatchDogInstance, ulValue );
\r
409 XScuWdt_LoadWdt( &xWatchDogInstance, UINT_MAX );
\r
410 XScuWdt_SetTimerMode( &xWatchDogInstance );
\r
411 XScuWdt_Start( &xWatchDogInstance );
\r
413 /*-----------------------------------------------------------*/
\r
415 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
416 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
417 used by the Idle task. */
\r
418 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
420 /* If the buffers to be provided to the Idle task are declared inside this
\r
421 function then they must be declared static - otherwise they will be allocated on
\r
422 the stack and so not exists after this function exits. */
\r
423 static StaticTask_t xIdleTaskTCB;
\r
424 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
426 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
427 state will be stored. */
\r
428 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
430 /* Pass out the array that will be used as the Idle task's stack. */
\r
431 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
433 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
434 Note that, as the array is necessarily of type StackType_t,
\r
435 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
436 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
438 /*-----------------------------------------------------------*/
\r
440 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
441 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
442 to provide the memory that is used by the Timer service task. */
\r
443 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
445 /* If the buffers to be provided to the Timer task are declared inside this
\r
446 function then they must be declared static - otherwise they will be allocated on
\r
447 the stack and so not exists after this function exits. */
\r
448 static StaticTask_t xTimerTaskTCB;
\r
449 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
451 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
452 task's state will be stored. */
\r
453 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
455 /* Pass out the array that will be used as the Timer task's stack. */
\r
456 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
458 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
459 Note that, as the array is necessarily of type StackType_t,
\r
460 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
461 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r