2 FreeRTOS V8.0.0:rc2 - Copyright (C) 2014 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 ***************************************************************************
9 * FreeRTOS provides completely free yet professionally developed, *
10 * robust, strictly quality controlled, supported, and cross *
11 * platform software that has become a de facto standard. *
13 * Help yourself get started quickly and support the FreeRTOS *
14 * project by purchasing a FreeRTOS tutorial book, reference *
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
19 ***************************************************************************
21 This file is part of the FreeRTOS distribution.
23 FreeRTOS is free software; you can redistribute it and/or modify it under
24 the terms of the GNU General Public License (version 2) as published by the
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
28 >>! a combined work that includes FreeRTOS without being obliged to provide
29 >>! the source code for proprietary components outside of the FreeRTOS
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
35 link: http://www.freertos.org/a00114.html
39 ***************************************************************************
41 * Having a problem? Start by reading the FAQ "My application does *
42 * not run, what could be wrong?" *
44 * http://www.FreeRTOS.org/FAQHelp.html *
46 ***************************************************************************
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
49 license and Real Time Engineers Ltd. contact details.
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
57 licenses offer ticketed support, indemnification and middleware.
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
60 engineered and independently SIL3 certified version for use in safety and
61 mission critical applications that require provable dependability.
66 /******************************************************************************
67 * This project provides two demo applications. A simple blinky style project,
68 * and a more comprehensive test and demo application. The
69 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
70 * select between the two. The simply blinky demo is implemented and described
71 * in main_blinky.c. The more comprehensive test and demo application is
72 * implemented and described in main_full.c.
74 * This file implements the code that is not demo specific, including the
75 * hardware setup and FreeRTOS hook functions.
77 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
78 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
79 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
83 /* Standard includes. */
86 /* Scheduler include files. */
91 /* Standard demo includes. */
93 #include "TimerDemo.h"
94 #include "QueueOverwrite.h"
96 /* Xilinx includes. */
98 #include "xparameters.h"
99 #include "xscutimer.h"
101 #include "xil_exception.h"
103 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
104 or 0 to run the more comprehensive test and demo application. */
105 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
107 /*-----------------------------------------------------------*/
110 * Configure the hardware as necessary to run this demo.
112 static void prvSetupHardware( void );
115 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
116 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
118 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
119 extern void main_blinky( void );
121 extern void main_full( void );
122 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
124 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
126 void vApplicationMallocFailedHook( void );
127 void vApplicationIdleHook( void );
128 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName );
129 void vApplicationTickHook( void );
132 * Creates and verifies different files on the volume, demonstrating the use of
133 * various different API functions.
135 extern void vCreateAndVerifySampleFiles( void );
137 /*-----------------------------------------------------------*/
141 /* Configure the hardware ready to run the demo. */
144 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
146 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
158 /*-----------------------------------------------------------*/
160 static void prvSetupHardware( void )
163 static XScuGic InterruptController; /* Interrupt controller instance */
164 extern void FreeRTOS_IRQ_Handler( void );
165 extern void FreeRTOS_SWI_Handler( void );
167 __asm volatile ( "cpsid i" );
170 XScuGic_Config *IntcConfig; /* The configuration parameters of the
171 interrupt controller */
173 * Initialize the interrupt controller driver
175 IntcConfig = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
176 configASSERT( IntcConfig );
177 configASSERT( IntcConfig->CpuBaseAddress == ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET ) );
178 configASSERT( IntcConfig->DistBaseAddress == configINTERRUPT_CONTROLLER_BASE_ADDRESS );
180 Status = XScuGic_CfgInitialize(&InterruptController, IntcConfig, IntcConfig->CpuBaseAddress );
181 configASSERT( Status == XST_SUCCESS );
183 Xil_ExceptionRegisterHandler( XIL_EXCEPTION_ID_IRQ_INT, (Xil_ExceptionHandler)FreeRTOS_IRQ_Handler, &InterruptController);
184 Xil_ExceptionRegisterHandler( XIL_EXCEPTION_ID_SWI_INT, (Xil_ExceptionHandler)FreeRTOS_SWI_Handler, &InterruptController);
186 // Xil_ExceptionEnableMask( XIL_EXCEPTION_ALL );
187 // Xil_ExceptionEnable();
190 * Connect the interrupt controller interrupt handler to the hardware
191 * interrupt handling logic in the ARM processor.
194 Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_UNDEFINED_INT,
195 (Xil_ExceptionHandler)FreeRTOS_ExHandler,
198 Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_PREFETCH_ABORT_INT,
199 (Xil_ExceptionHandler)FreeRTOS_ExHandler,
202 Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_DATA_ABORT_INT,
203 (Xil_ExceptionHandler)FreeRTOS_ExHandler,
207 /*-----------------------------------------------------------*/
209 void vApplicationMallocFailedHook( void )
211 /* Called if a call to pvPortMalloc() fails because there is insufficient
212 free memory available in the FreeRTOS heap. pvPortMalloc() is called
213 internally by FreeRTOS API functions that create tasks, queues, software
214 timers, and semaphores. The size of the FreeRTOS heap is set by the
215 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
216 taskDISABLE_INTERRUPTS();
219 /*-----------------------------------------------------------*/
221 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
226 /* Run time stack overflow checking is performed if
227 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
228 function is called if a stack overflow is detected. */
229 taskDISABLE_INTERRUPTS();
232 /*-----------------------------------------------------------*/
234 void vApplicationIdleHook( void )
236 volatile size_t xFreeHeapSpace;
238 /* This is just a trivial example of an idle hook. It is called on each
239 cycle of the idle task. It must *NOT* attempt to block. In this case the
240 idle task just queries the amount of FreeRTOS heap that remains. See the
241 memory management section on the http://www.FreeRTOS.org web site for memory
242 management options. If there is a lot of heap memory free then the
243 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
245 xFreeHeapSpace = xPortGetFreeHeapSize();
247 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
248 ( void ) xFreeHeapSpace;
250 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY != 1
252 /* If the file system is only going to be accessed from one task then
253 F_FS_THREAD_AWARE can be set to 0 and the set of example files is
254 created before the RTOS scheduler is started. If the file system is
255 going to be access from more than one task then F_FS_THREAD_AWARE must
256 be set to 1 and the set of sample files are created from the idle task
258 #if F_FS_THREAD_AWARE == 1
260 static portBASE_TYPE xCreatedSampleFiles = pdFALSE;
262 /* Initialise the drive and file system, then create a few example
263 files. The output from this function just goes to the stdout window,
264 allowing the output to be viewed when the UDP command console is not
266 if( xCreatedSampleFiles == pdFALSE )
268 vCreateAndVerifySampleFiles();
269 xCreatedSampleFiles = pdTRUE;
276 /*-----------------------------------------------------------*/
278 void vAssertCalled( const char * pcFile, unsigned long ulLine )
280 volatile unsigned long ul = 0;
285 taskENTER_CRITICAL();
287 /* Set ul to a non-zero value using the debugger to step out of this
296 /*-----------------------------------------------------------*/
298 void vApplicationTickHook( void )
300 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
302 /* The full demo includes a software timer demo/test that requires
303 prodding periodically from the tick interrupt. */
304 vTimerPeriodicISRTests();
306 /* Call the periodic queue overwrite from ISR demo. */
307 vQueueOverwritePeriodicISRDemo();
311 /*-----------------------------------------------------------*/
313 void vApplicationIRQHandler( uint32_t ulICCIAR )
315 uint32_t ulInterruptID;
317 /* Re-enable interrupts. */
320 /* The ID of the interrupt can be obtained by bitwise anding the ICCIAR value
322 ulInterruptID = ulICCIAR & 0x3FFUL;
324 /* Call the function installed in the array of installed handler functions. */
325 // intc_func_table[ ulInterruptID ]( 0 );