2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
30 * This project provides two demo applications. A simple blinky style project,
\r
31 * and a more comprehensive test and demo application. The
\r
32 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
33 * select between the two. The simply blinky demo is implemented and described
\r
34 * in main_blinky.c. The more comprehensive test and demo application is
\r
35 * implemented and described in main_full.c.
\r
37 * This file implements the code that is not demo specific, including the
\r
38 * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
\r
39 * by the RTOS after interrupt entry (including nesting) has been taken care of.
\r
43 * This demo is NOT configured to use the LED built onto the SAMA6D2
\r
46 * The LED driver PIN_LED definitions have been altered in
\r
47 * board_sama5d2-xplained.h to remap them to GPIOs terminating on pins 30,
\r
48 * 32 and 34 of J17. (This change is conditional on the preprocessor
\r
49 * #define "LEDS_ON_J17".) These GPIOs are configured to be "high drive"
\r
50 * push-pull outputs; they can source up to 18mA at 1.8v. Low
\r
51 * forward-voltage LEDs may be connected via 100 ohm resistors to pins
\r
52 * 30, 32 and 34 with their cathodes to pin 35/36 (GND).
\r
57 * Procedure to download and execute code from RAM
\r
58 * -----------------------------------------------
\r
60 * 1. Close jumper JP9(BOOT_DIS) and JP2(DEBUG_DIS).
\r
61 * 2. Open jumper JP1(EDBG_DIS).
\r
62 * 3. Power on the board by USB connection on J14(EDBG_JTAG).
\r
63 * 4. Open
\93EDBG Virtual COM Port
\94 with setting
\9357600,8,N,1
\94.
\r
64 * 5. Type
\93#
\94 on HyperTerminal and get
\93>
\94 as a reply.
\r
65 * 6. Don
\92t reset the board during debugging. For IAR, set the Debugger to CMSIS
\r
66 * DAP, with the "Disabled(no reset)" option.
\r
69 /* Scheduler include files. */
\r
70 #include "FreeRTOS.h"
\r
74 /* Standard demo includes. */
\r
75 #include "partest.h"
\r
76 #include "TimerDemo.h"
\r
77 #include "QueueOverwrite.h"
\r
78 #include "EventGroupsDemo.h"
\r
80 /* Library includes. */
\r
81 #include "board_sama5d2-xplained.h"
\r
82 #include "peripherals/wdt.h"
\r
83 #include "peripherals/pio.h"
\r
86 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
87 or 0 to run the more comprehensive test and demo application. */
\r
88 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
90 /*-----------------------------------------------------------*/
\r
93 * Configure the hardware as necessary to run this demo.
\r
95 static void prvSetupHardware( void );
\r
98 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
99 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
101 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
102 extern void main_blinky( void );
\r
104 extern void main_full( void );
\r
105 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
107 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
108 within this file. */
\r
109 void vApplicationMallocFailedHook( void );
\r
110 void vApplicationIdleHook( void );
\r
111 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
112 void vApplicationTickHook( void );
\r
114 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
\r
116 void vApplicationIRQHandler( void );
\r
118 /*-----------------------------------------------------------*/
\r
122 /* Configure the hardware ready to run the demo. */
\r
123 prvSetupHardware();
\r
125 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
127 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
139 /*-----------------------------------------------------------*/
\r
141 static void prvSetupHardware( void )
\r
143 /* Disable watchdog */
\r
146 /* Set protect mode in the AIC for easier debugging. */
\r
147 AIC->AIC_DCR |= AIC_DCR_PROT;
\r
149 /* Configure ports used by LEDs. */
\r
150 vParTestInitialise();
\r
152 #if defined (ddram)
\r
153 MMU_Initialize( ( uint32_t * ) 0x30C000 );
\r
155 CP15_EnableDcache();
\r
156 CP15_EnableIcache();
\r
159 /*-----------------------------------------------------------*/
\r
161 void vApplicationMallocFailedHook( void )
\r
163 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
164 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
165 internally by FreeRTOS API functions that create tasks, queues, software
\r
166 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
167 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
169 /* Force an assert. */
\r
170 configASSERT( ( volatile void * ) NULL );
\r
172 /*-----------------------------------------------------------*/
\r
174 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
176 ( void ) pcTaskName;
\r
179 /* Run time stack overflow checking is performed if
\r
180 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
181 function is called if a stack overflow is detected. */
\r
183 /* Force an assert. */
\r
184 configASSERT( ( volatile void * ) NULL );
\r
186 /*-----------------------------------------------------------*/
\r
188 void vApplicationIdleHook( void )
\r
190 volatile size_t xFreeHeapSpace;
\r
192 /* This is just a trivial example of an idle hook. It is called on each
\r
193 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
194 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
195 memory management section on the http://www.FreeRTOS.org web site for memory
\r
196 management options. If there is a lot of heap memory free then the
\r
197 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
199 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
201 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
202 ( void ) xFreeHeapSpace;
\r
204 /*-----------------------------------------------------------*/
\r
206 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
208 volatile unsigned long ul = 0;
\r
213 taskENTER_CRITICAL();
\r
215 /* Set ul to a non-zero value using the debugger to step out of this
\r
222 taskEXIT_CRITICAL();
\r
224 /*-----------------------------------------------------------*/
\r
226 void vApplicationTickHook( void )
\r
228 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
\r
230 /* The full demo includes a software timer demo/test that requires
\r
231 prodding periodically from the tick interrupt. */
\r
232 vTimerPeriodicISRTests();
\r
234 /* Call the periodic queue overwrite from ISR demo. */
\r
235 vQueueOverwritePeriodicISRDemo();
\r
237 /* Call the periodic event group from ISR demo. */
\r
238 vPeriodicEventGroupsProcessing();
\r
242 /*-----------------------------------------------------------*/
\r
244 /* The function called by the RTOS port layer after it has managed interrupt
\r
246 void vApplicationIRQHandler( void )
\r
248 typedef void (*ISRFunction_t)( void );
\r
249 ISRFunction_t pxISRFunction;
\r
250 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
\r
252 /* Obtain the address of the interrupt handler from the AIR. */
\r
253 pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
\r
255 /* Write back to the SAMA5's interrupt controller's IVR register in case the
\r
256 CPU is in protect mode. If the interrupt controller is not in protect mode
\r
257 then this write is not necessary. */
\r
258 *pulAIC_IVR = ( uint32_t ) pxISRFunction;
\r
260 /* Ensure the write takes before re-enabling interrupts. */
\r
265 /* Call the installed ISR. */
\r
269 /* Keep the linker quiet. */
\r
270 size_t __write(int, const unsigned char *, size_t);
\r
271 size_t __write(int f, const unsigned char *p, size_t s)
\r