3 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
28 /******************************************************************************
29 * This project provides two demo applications. A simple blinky style project,
30 * and a more comprehensive test and demo application. The
31 * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to
32 * select between the two. The simply blinky demo is implemented and described
33 * in main_blinky.c. The more comprehensive test and demo application is
34 * implemented and described in main_full.c.
36 * This file implements the code that is not demo specific, including the
37 * hardware setup, standard FreeRTOS hook functions, and the ISR hander called
38 * by the RTOS after interrupt entry (including nesting) has been taken care of.
40 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
41 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
42 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
46 /* Scheduler include files. */
51 /* Standard demo includes. */
53 #include "TimerDemo.h"
54 #include "QueueOverwrite.h"
55 #include "EventGroupsDemo.h"
57 /* Library includes. */
60 /* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,
61 or 0 to run the more comprehensive test and demo application. */
62 #define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1
64 /*-----------------------------------------------------------*/
67 * Configure the hardware as necessary to run this demo.
69 static void prvSetupHardware( void );
72 * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.
73 * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.
75 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
76 extern void main_blinky( void );
78 extern void main_full( void );
79 #endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */
81 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
83 void vApplicationMallocFailedHook( void );
84 void vApplicationIdleHook( void );
85 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
86 void vApplicationTickHook( void );
88 /* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port
90 void vApplicationIRQHandler( void );
92 /*-----------------------------------------------------------*/
96 /* Configure the hardware ready to run the demo. */
99 /* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top
101 #if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )
113 /*-----------------------------------------------------------*/
115 static void prvSetupHardware( void )
117 /* Disable watchdog */
120 /* Set protect mode in the AIC for easier debugging. THIS IS COMMENTED OUT
121 AS IT RESULTS IN SPURIOUS INTERRUPTS.
122 AIC->AIC_DCR |= AIC_DCR_PROT; */
124 /* Configure ports used by LEDs. */
125 vParTestInitialise();
129 MMU_Initialize( ( uint32_t * ) 0x20C000 );
136 /*-----------------------------------------------------------*/
138 void vApplicationMallocFailedHook( void )
140 /* Called if a call to pvPortMalloc() fails because there is insufficient
141 free memory available in the FreeRTOS heap. pvPortMalloc() is called
142 internally by FreeRTOS API functions that create tasks, queues, software
143 timers, and semaphores. The size of the FreeRTOS heap is set by the
144 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
146 /* Force an assert. */
147 configASSERT( ( volatile void * ) NULL );
149 /*-----------------------------------------------------------*/
151 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
156 /* Run time stack overflow checking is performed if
157 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
158 function is called if a stack overflow is detected. */
160 /* Force an assert. */
161 configASSERT( ( volatile void * ) NULL );
163 /*-----------------------------------------------------------*/
165 void vApplicationIdleHook( void )
167 volatile size_t xFreeHeapSpace;
169 /* This is just a trivial example of an idle hook. It is called on each
170 cycle of the idle task. It must *NOT* attempt to block. In this case the
171 idle task just queries the amount of FreeRTOS heap that remains. See the
172 memory management section on the http://www.FreeRTOS.org web site for memory
173 management options. If there is a lot of heap memory free then the
174 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
176 xFreeHeapSpace = xPortGetFreeHeapSize();
178 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
179 ( void ) xFreeHeapSpace;
181 /*-----------------------------------------------------------*/
183 void vAssertCalled( const char * pcFile, unsigned long ulLine )
185 volatile unsigned long ul = 0;
190 taskENTER_CRITICAL();
192 /* Set ul to a non-zero value using the debugger to step out of this
201 /*-----------------------------------------------------------*/
203 void vApplicationTickHook( void )
205 #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
207 /* The full demo includes a software timer demo/test that requires
208 prodding periodically from the tick interrupt. */
209 vTimerPeriodicISRTests();
211 /* Call the periodic queue overwrite from ISR demo. */
212 vQueueOverwritePeriodicISRDemo();
214 /* Call the periodic event group from ISR demo. */
215 vPeriodicEventGroupsProcessing();
219 /*-----------------------------------------------------------*/
221 /* The function called by the RTOS port layer after it has managed interrupt
223 void vApplicationIRQHandler( void )
225 typedef void (*ISRFunction_t)( void );
226 ISRFunction_t pxISRFunction;
227 volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;
229 /* Obtain the address of the interrupt handler from the AIR. */
230 pxISRFunction = ( ISRFunction_t ) *pulAIC_IVR;
232 /* Write back to the SAMA5's interrupt controller's IVR register in case the
233 CPU is in protect mode. If the interrupt controller is not in protect mode
234 then this write is not necessary. */
235 *pulAIC_IVR = ( uint32_t ) pxISRFunction;
237 /* Ensure the write takes before re-enabling interrupts. */
242 /* Call the installed ISR. */