2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /******************************************************************************
\r
97 * This project provides three demo applications. A simple blinky style
\r
98 * project, a more comprehensive test and demo application, and an lwIP example.
\r
99 * The mainSELECTED_APPLICATION setting (defined in this file) is used to
\r
100 * select between the three. The simply blinky demo is implemented and
\r
101 * described in main_blinky.c. The more comprehensive test and demo application
\r
102 * is implemented and described in main_full.c. The lwIP example is implemented
\r
103 * and described in main_lwIP.c.
\r
105 * This file implements the code that is not demo specific, including the
\r
106 * hardware setup and FreeRTOS hook functions.
\r
108 * !!! IMPORTANT NOTE !!!
\r
109 * The GCC libraries that ship with the Xilinx SDK make use of the floating
\r
110 * point registers. To avoid this causing corruption it is necessary to avoid
\r
111 * their use. For this reason main.c contains very basic C implementations of
\r
112 * the standard C library functions memset(), memcpy() and memcmp(), which are
\r
113 * are used by FreeRTOS itself. Defining these functions in the project
\r
114 * prevents the linker pulling them in from the library. Any other standard C
\r
115 * library functions that are used by the application must likewise be defined
\r
118 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
119 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
120 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
124 /* Standard includes. */
\r
126 #include <limits.h>
\r
128 /* Scheduler include files. */
\r
129 #include "FreeRTOS.h"
\r
131 #include "semphr.h"
\r
133 /* Standard demo includes. */
\r
134 #include "partest.h"
\r
135 #include "TimerDemo.h"
\r
136 #include "QueueOverwrite.h"
\r
137 #include "EventGroupsDemo.h"
\r
138 #include "TaskNotify.h"
\r
139 #include "IntSemTest.h"
\r
141 /* Xilinx includes. */
\r
142 #include "platform.h"
\r
143 #include "xparameters.h"
\r
144 #include "xscutimer.h"
\r
145 #include "xscugic.h"
\r
146 #include "xil_exception.h"
\r
148 /* mainSELECTED_APPLICATION is used to select between three demo applications,
\r
149 * as described at the top of this file.
\r
151 * When mainSELECTED_APPLICATION is set to 0 the simple blinky example will
\r
154 * When mainSELECTED_APPLICATION is set to 1 the comprehensive test and demo
\r
155 * application will be run.
\r
157 * When mainSELECTED_APPLICATION is set to 2 the lwIP example will be run.
\r
159 #define mainSELECTED_APPLICATION 0
\r
161 /*-----------------------------------------------------------*/
\r
164 * Configure the hardware as necessary to run this demo.
\r
166 static void prvSetupHardware( void );
\r
169 * See the comments at the top of this file and above the
\r
170 * mainSELECTED_APPLICATION definition.
\r
172 #if ( mainSELECTED_APPLICATION == 0 )
\r
173 extern void main_blinky( void );
\r
174 #elif ( mainSELECTED_APPLICATION == 1 )
\r
175 extern void main_full( void );
\r
176 #elif ( mainSELECTED_APPLICATION == 2 )
\r
177 extern void main_lwIP( void );
\r
179 #error Invalid mainSELECTED_APPLICATION setting. See the comments at the top of this file and above the mainSELECTED_APPLICATION definition.
\r
183 * The Xilinx projects use a BSP that do not allow the start up code to be
\r
184 * altered easily. Therefore the vector table used by FreeRTOS is defined in
\r
185 * FreeRTOS_asm_vectors.S, which is part of this project. Switch to use the
\r
186 * FreeRTOS vector table.
\r
188 extern void vPortInstallFreeRTOSVectorTable( void );
\r
190 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
191 within this file. */
\r
192 void vApplicationMallocFailedHook( void );
\r
193 void vApplicationIdleHook( void );
\r
194 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
195 void vApplicationTickHook( void );
\r
197 /* The private watchdog is used as the timer that generates run time
\r
198 stats. This frequency means it will overflow quite quickly. */
\r
199 XScuWdt xWatchDogInstance;
\r
201 /*-----------------------------------------------------------*/
\r
203 /* The interrupt controller is initialised in this file, and made available to
\r
205 XScuGic xInterruptController;
\r
207 /*-----------------------------------------------------------*/
\r
211 /* Configure the hardware ready to run the demo. */
\r
212 prvSetupHardware();
\r
214 /* The mainSELECTED_APPLICATION setting is described at the top
\r
216 #if( mainSELECTED_APPLICATION == 0 )
\r
220 #elif( mainSELECTED_APPLICATION == 1 )
\r
230 /* Don't expect to reach here. */
\r
233 /*-----------------------------------------------------------*/
\r
235 static void prvSetupHardware( void )
\r
237 BaseType_t xStatus;
\r
238 XScuGic_Config *pxGICConfig;
\r
240 /* Ensure no interrupts execute while the scheduler is in an inconsistent
\r
241 state. Interrupts are automatically enabled when the scheduler is
\r
243 portDISABLE_INTERRUPTS();
\r
245 /* Obtain the configuration of the GIC. */
\r
246 pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
\r
248 /* Sanity check the FreeRTOSConfig.h settings are correct for the
\r
250 configASSERT( pxGICConfig );
\r
251 configASSERT( pxGICConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
\r
252 configASSERT( pxGICConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
\r
254 /* Install a default handler for each GIC interrupt. */
\r
255 xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
\r
256 configASSERT( xStatus == XST_SUCCESS );
\r
257 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
259 /* Initialise the LED port. */
\r
260 vParTestInitialise();
\r
262 /* The Xilinx projects use a BSP that do not allow the start up code to be
\r
263 altered easily. Therefore the vector table used by FreeRTOS is defined in
\r
264 FreeRTOS_asm_vectors.S, which is part of this project. Switch to use the
\r
265 FreeRTOS vector table. */
\r
266 vPortInstallFreeRTOSVectorTable();
\r
268 /*-----------------------------------------------------------*/
\r
270 void vApplicationMallocFailedHook( void )
\r
272 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
273 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
274 internally by FreeRTOS API functions that create tasks, queues, software
\r
275 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
276 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
277 taskDISABLE_INTERRUPTS();
\r
280 /*-----------------------------------------------------------*/
\r
282 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
284 ( void ) pcTaskName;
\r
287 /* Run time stack overflow checking is performed if
\r
288 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
289 function is called if a stack overflow is detected. */
\r
290 taskDISABLE_INTERRUPTS();
\r
293 /*-----------------------------------------------------------*/
\r
295 void vApplicationIdleHook( void )
\r
297 volatile size_t xFreeHeapSpace;
\r
299 /* This is just a trivial example of an idle hook. It is called on each
\r
300 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
301 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
302 memory management section on the http://www.FreeRTOS.org web site for memory
\r
303 management options. If there is a lot of heap memory free then the
\r
304 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
306 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
308 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
309 ( void ) xFreeHeapSpace;
\r
311 /*-----------------------------------------------------------*/
\r
313 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
315 volatile unsigned long ul = 0;
\r
320 taskENTER_CRITICAL();
\r
322 /* Set ul to a non-zero value using the debugger to step out of this
\r
329 taskEXIT_CRITICAL();
\r
331 /*-----------------------------------------------------------*/
\r
333 void vApplicationTickHook( void )
\r
335 #if( mainSELECTED_APPLICATION == 1 )
\r
337 /* The full demo includes a software timer demo/test that requires
\r
338 prodding periodically from the tick interrupt. */
\r
339 vTimerPeriodicISRTests();
\r
341 /* Call the periodic queue overwrite from ISR demo. */
\r
342 vQueueOverwritePeriodicISRDemo();
\r
344 /* Call the periodic event group from ISR demo. */
\r
345 vPeriodicEventGroupsProcessing();
\r
347 /* Use task notifications from an interrupt. */
\r
348 xNotifyTaskFromISR();
\r
350 /* Use mutexes from interrupts. */
\r
351 vInterruptSemaphorePeriodicTest();
\r
355 /*-----------------------------------------------------------*/
\r
357 void *memcpy( void *pvDest, const void *pvSource, size_t ulBytes )
\r
359 unsigned char *pcDest = ( unsigned char * ) pvDest, *pcSource = ( unsigned char * ) pvSource;
\r
362 for( x = 0; x < ulBytes; x++ )
\r
364 *pcDest = *pcSource;
\r
371 /*-----------------------------------------------------------*/
\r
373 void *memset( void *pvDest, int iValue, size_t ulBytes )
\r
375 unsigned char *pcDest = ( unsigned char * ) pvDest;
\r
378 for( x = 0; x < ulBytes; x++ )
\r
380 *pcDest = ( unsigned char ) iValue;
\r
386 /*-----------------------------------------------------------*/
\r
388 int memcmp( const void *pvMem1, const void *pvMem2, size_t ulBytes )
\r
390 const unsigned char *pucMem1 = pvMem1, *pucMem2 = pvMem2;
\r
393 for( x = 0; x < ulBytes; x++ )
\r
395 if( pucMem1[ x ] != pucMem2[ x ] )
\r
401 return ulBytes - x;
\r
403 /*-----------------------------------------------------------*/
\r
405 void vInitialiseTimerForRunTimeStats( void )
\r
407 XScuWdt_Config *pxWatchDogInstance;
\r
409 const uint32_t ulMaxDivisor = 0xff, ulDivisorShift = 0x08;
\r
411 pxWatchDogInstance = XScuWdt_LookupConfig( XPAR_SCUWDT_0_DEVICE_ID );
\r
412 XScuWdt_CfgInitialize( &xWatchDogInstance, pxWatchDogInstance, pxWatchDogInstance->BaseAddr );
\r
414 ulValue = XScuWdt_GetControlReg( &xWatchDogInstance );
\r
415 ulValue |= ulMaxDivisor << ulDivisorShift;
\r
416 XScuWdt_SetControlReg( &xWatchDogInstance, ulValue );
\r
418 XScuWdt_LoadWdt( &xWatchDogInstance, UINT_MAX );
\r
419 XScuWdt_SetTimerMode( &xWatchDogInstance );
\r
420 XScuWdt_Start( &xWatchDogInstance );
\r