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 two demo applications. A simple blinky style project,
\r
98 * and a more comprehensive test and demo application. The
\r
99 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
100 * select between the two. The simply blinky demo is implemented and described
\r
101 * in main_blinky.c. The more comprehensive test and demo application is
\r
102 * implemented and described in main_full.c.
\r
104 * This file implements the code that is not demo specific, including the
\r
105 * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
\r
106 * by the RTOS after interrupt entry (including nesting) has been taken care of.
\r
108 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
109 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
110 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
114 /* Scheduler include files. */
\r
115 #include "FreeRTOS.h"
\r
117 #include "semphr.h"
\r
119 /* Standard demo includes. */
\r
120 #include "partest.h"
\r
121 #include "TimerDemo.h"
\r
122 #include "QueueOverwrite.h"
\r
123 #include "EventGroupsDemo.h"
\r
125 /* Library includes. */
\r
128 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
129 or 0 to run the more comprehensive test and demo application. */
\r
130 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
132 /*-----------------------------------------------------------*/
\r
135 * Configure the hardware as necessary to run this demo.
\r
137 static void prvSetupHardware( void );
\r
140 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
141 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
143 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
144 extern void main_blinky( void );
\r
146 extern void main_full( void );
\r
147 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
149 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
150 within this file. */
\r
151 void vApplicationMallocFailedHook( void );
\r
152 void vApplicationIdleHook( void );
\r
153 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
154 void vApplicationTickHook( void );
\r
156 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
\r
158 void vApplicationIRQHandler( void );
\r
160 /*-----------------------------------------------------------*/
\r
164 /* Configure the hardware ready to run the demo. */
\r
165 prvSetupHardware();
\r
167 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
169 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
181 /*-----------------------------------------------------------*/
\r
183 static void prvSetupHardware( void )
\r
185 /* Disable watchdog */
\r
186 WDT_Disable( WDT );
\r
188 /* Set protect mode in the AIC for easier debugging. */
\r
189 AIC->AIC_DCR |= AIC_DCR_PROT;
\r
191 /* Configure ports used by LEDs. */
\r
192 vParTestInitialise();
\r
194 #if defined (ddram)
\r
195 MMU_Initialize( ( uint32_t * ) 0x30C000 );
\r
197 CP15_EnableDcache();
\r
198 CP15_EnableIcache();
\r
201 /*-----------------------------------------------------------*/
\r
203 void vApplicationMallocFailedHook( void )
\r
205 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
206 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
207 internally by FreeRTOS API functions that create tasks, queues, software
\r
208 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
209 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
211 /* Force an assert. */
\r
212 configASSERT( ( volatile void * ) NULL );
\r
214 /*-----------------------------------------------------------*/
\r
216 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
218 ( void ) pcTaskName;
\r
221 /* Run time stack overflow checking is performed if
\r
222 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
223 function is called if a stack overflow is detected. */
\r
225 /* Force an assert. */
\r
226 configASSERT( ( volatile void * ) NULL );
\r
228 /*-----------------------------------------------------------*/
\r
230 void vApplicationIdleHook( void )
\r
232 volatile size_t xFreeHeapSpace;
\r
234 /* This is just a trivial example of an idle hook. It is called on each
\r
235 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
236 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
237 memory management section on the http://www.FreeRTOS.org web site for memory
\r
238 management options. If there is a lot of heap memory free then the
\r
239 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
241 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
243 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
244 ( void ) xFreeHeapSpace;
\r
246 /*-----------------------------------------------------------*/
\r
248 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
250 volatile unsigned long ul = 0;
\r
255 taskENTER_CRITICAL();
\r
257 /* Set ul to a non-zero value using the debugger to step out of this
\r
264 taskEXIT_CRITICAL();
\r
266 /*-----------------------------------------------------------*/
\r
268 void vApplicationTickHook( void )
\r
270 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
\r
272 /* The full demo includes a software timer demo/test that requires
\r
273 prodding periodically from the tick interrupt. */
\r
274 vTimerPeriodicISRTests();
\r
276 /* Call the periodic queue overwrite from ISR demo. */
\r
277 vQueueOverwritePeriodicISRDemo();
\r
279 /* Call the periodic event group from ISR demo. */
\r
280 vPeriodicEventGroupsProcessing();
\r
284 /*-----------------------------------------------------------*/
\r
286 /* The function called by the RTOS port layer after it has managed interrupt
\r
288 void vApplicationIRQHandler( void )
\r
290 typedef void (*ISRFunction_t)( void );
\r
291 ISRFunction_t pxISRFunction;
\r
292 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
\r
294 /* Obtain the address of the interrupt handler from the AIR. */
\r
295 pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
\r
297 /* Write back to the SAMA5's interrupt controller's IVR register in case the
\r
298 CPU is in protect mode. If the interrupt controller is not in protect mode
\r
299 then this write is not necessary. */
\r
300 *pulAIC_IVR = ( uint32_t ) pxISRFunction;
\r
302 /* Ensure the write takes before re-enabling interrupts. */
\r
307 /* Call the installed ISR. */
\r