2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
29 * This project provides two demo applications. A simple blinky style project,
\r
30 * and a more comprehensive test and demo application. The
\r
31 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
\r
32 * select between the two. The simply blinky demo is implemented and described
\r
33 * in main_blinky.c. The more comprehensive test and demo application is
\r
34 * implemented and described in main_full.c.
\r
36 * This file implements the code that is not demo specific, including the
\r
37 * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
\r
38 * by the RTOS after interrupt entry (including nesting) has been taken care of.
\r
42 * This demo is NOT configured to use the LED built onto the SAMA6D2
\r
45 * The LED driver PIN_LED definitions have been altered in
\r
46 * board_sama5d2-xplained.h to remap them to GPIOs terminating on pins 30,
\r
47 * 32 and 34 of J17. (This change is conditional on the preprocessor
\r
48 * #define "LEDS_ON_J17".) These GPIOs are configured to be "high drive"
\r
49 * push-pull outputs; they can source up to 18mA at 1.8v. Low
\r
50 * forward-voltage LEDs may be connected via 100 ohm resistors to pins
\r
51 * 30, 32 and 34 with their cathodes to pin 35/36 (GND).
\r
56 * Procedure to download and execute code from RAM
\r
57 * -----------------------------------------------
\r
59 * 1. Close jumper JP9(BOOT_DIS) and JP2(DEBUG_DIS).
\r
60 * 2. Open jumper JP1(EDBG_DIS).
\r
61 * 3. Power on the board by USB connection on J14(EDBG_JTAG).
\r
62 * 4. Open
\93EDBG Virtual COM Port
\94 with setting
\9357600,8,N,1
\94.
\r
63 * 5. Type
\93#
\94 on HyperTerminal and get
\93>
\94 as a reply.
\r
64 * 6. Don
\92t reset the board during debugging. For IAR, set the Debugger to CMSIS
\r
65 * DAP, with the "Disabled(no reset)" option.
\r
68 /* Scheduler include files. */
\r
69 #include "FreeRTOS.h"
\r
73 /* Standard demo includes. */
\r
74 #include "partest.h"
\r
75 #include "TimerDemo.h"
\r
76 #include "QueueOverwrite.h"
\r
77 #include "EventGroupsDemo.h"
\r
79 /* Library includes. */
\r
80 #include "board_sama5d2-xplained.h"
\r
81 #include "peripherals/wdt.h"
\r
82 #include "peripherals/pio.h"
\r
85 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
\r
86 or 0 to run the more comprehensive test and demo application. */
\r
87 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
\r
89 /*-----------------------------------------------------------*/
\r
92 * Configure the hardware as necessary to run this demo.
\r
94 static void prvSetupHardware( void );
\r
97 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
\r
98 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
\r
100 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1
\r
101 extern void main_blinky( void );
\r
103 extern void main_full( void );
\r
104 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
\r
106 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
107 within this file. */
\r
108 void vApplicationMallocFailedHook( void );
\r
109 void vApplicationIdleHook( void );
\r
110 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
111 void vApplicationTickHook( void );
\r
113 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
\r
115 void vApplicationIRQHandler( void );
\r
117 /*-----------------------------------------------------------*/
\r
121 /* Configure the hardware ready to run the demo. */
\r
122 prvSetupHardware();
\r
124 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
\r
126 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
\r
138 /*-----------------------------------------------------------*/
\r
140 static void prvSetupHardware( void )
\r
142 /* Disable watchdog */
\r
145 /* Set protect mode in the AIC for easier debugging. */
\r
146 AIC->AIC_DCR |= AIC_DCR_PROT;
\r
148 /* Configure ports used by LEDs. */
\r
149 vParTestInitialise();
\r
151 #if defined (ddram)
\r
152 MMU_Initialize( ( uint32_t * ) 0x30C000 );
\r
154 CP15_EnableDcache();
\r
155 CP15_EnableIcache();
\r
158 /*-----------------------------------------------------------*/
\r
160 void vApplicationMallocFailedHook( void )
\r
162 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
163 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
164 internally by FreeRTOS API functions that create tasks, queues, software
\r
165 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
166 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
168 /* Force an assert. */
\r
169 configASSERT( ( volatile void * ) NULL );
\r
171 /*-----------------------------------------------------------*/
\r
173 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
175 ( void ) pcTaskName;
\r
178 /* Run time stack overflow checking is performed if
\r
179 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
180 function is called if a stack overflow is detected. */
\r
182 /* Force an assert. */
\r
183 configASSERT( ( volatile void * ) NULL );
\r
185 /*-----------------------------------------------------------*/
\r
187 void vApplicationIdleHook( void )
\r
189 volatile size_t xFreeHeapSpace;
\r
191 /* This is just a trivial example of an idle hook. It is called on each
\r
192 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
193 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
194 memory management section on the http://www.FreeRTOS.org web site for memory
\r
195 management options. If there is a lot of heap memory free then the
\r
196 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
198 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
200 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
201 ( void ) xFreeHeapSpace;
\r
203 /*-----------------------------------------------------------*/
\r
205 void vAssertCalled( const char * pcFile, unsigned long ulLine )
\r
207 volatile unsigned long ul = 0;
\r
212 taskENTER_CRITICAL();
\r
214 /* Set ul to a non-zero value using the debugger to step out of this
\r
221 taskEXIT_CRITICAL();
\r
223 /*-----------------------------------------------------------*/
\r
225 void vApplicationTickHook( void )
\r
227 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
\r
229 /* The full demo includes a software timer demo/test that requires
\r
230 prodding periodically from the tick interrupt. */
\r
231 vTimerPeriodicISRTests();
\r
233 /* Call the periodic queue overwrite from ISR demo. */
\r
234 vQueueOverwritePeriodicISRDemo();
\r
236 /* Call the periodic event group from ISR demo. */
\r
237 vPeriodicEventGroupsProcessing();
\r
241 /*-----------------------------------------------------------*/
\r
243 /* The function called by the RTOS port layer after it has managed interrupt
\r
245 void vApplicationIRQHandler( void )
\r
247 typedef void (*ISRFunction_t)( void );
\r
248 ISRFunction_t pxISRFunction;
\r
249 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
\r
251 /* Obtain the address of the interrupt handler from the AIR. */
\r
252 pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
\r
254 /* Write back to the SAMA5's interrupt controller's IVR register in case the
\r
255 CPU is in protect mode. If the interrupt controller is not in protect mode
\r
256 then this write is not necessary. */
\r
257 *pulAIC_IVR = ( uint32_t ) pxISRFunction;
\r
259 /* Ensure the write takes before re-enabling interrupts. */
\r
264 /* Call the installed ISR. */
\r
268 /* Keep the linker quiet. */
\r
269 size_t __write(int, const unsigned char *, size_t);
\r
270 size_t __write(int f, const unsigned char *p, size_t s)
\r