2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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 low power project that
\r
30 * demonstrates the FreeRTOS tickless mode, and a more comprehensive test and
\r
31 * demo application. The configCREATE_LOW_POWER_DEMO setting (defined at the
\r
32 * top of FreeRTOSConfig.h) is used to select between the two. The low power
\r
33 * demo is implemented and described in main_low_power.c. The more
\r
34 * comprehensive test and demo application is implemented and described in
\r
37 * This file implements the code that is not demo specific, including the
\r
38 * hardware setup and FreeRTOS hook functions.
\r
41 /* Standard includes. */
\r
44 /* Kernel includes. */
\r
45 #include "FreeRTOS.h"
\r
48 /* Standard demo includes - just needed for the LED (ParTest) initialisation
\r
50 #include "partest.h"
\r
52 /* Atmel library includes. */
\r
55 /*-----------------------------------------------------------*/
\r
58 * Set up the hardware ready to run this demo.
\r
60 static void prvSetupHardware( void );
\r
63 * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.
\r
64 * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.
\r
65 * configCREATE_LOW_POWER_DEMO is defined at the top of main.c.
\r
67 extern void main_low_power( void );
\r
68 extern void main_full( void );
\r
70 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
71 within this file. */
\r
72 void vApplicationMallocFailedHook( void );
\r
73 void vApplicationIdleHook( void );
\r
74 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
75 void vApplicationTickHook( void );
\r
77 /* A handler for a button interrupt. The button's only purpose is to bring the
\r
78 CPU out of sleep mode early. */
\r
79 static void prvButtonISR( void );
\r
81 /*-----------------------------------------------------------*/
\r
83 /* See the documentation page for this demo on the FreeRTOS.org web site for
\r
84 full information - including hardware setup requirements. */
\r
87 /* Prepare the hardware to run this demo. */
\r
90 /* The configCREATE_LOW_POWER_DEMO setting is described at the top of
\r
92 #if( configCREATE_LOW_POWER_DEMO == 1 )
\r
104 /*-----------------------------------------------------------*/
\r
106 static void prvButtonISR( void )
\r
108 /* The button doesn't do anything other than providing a means for brining
\r
109 the MCU out of sleep mode early. */
\r
110 if( eic_line_interrupt_is_pending( EIC, GPIO_PUSH_BUTTON_EIC_LINE ) )
\r
112 eic_line_clear_interrupt( EIC, GPIO_PUSH_BUTTON_EIC_LINE );
\r
115 /*-----------------------------------------------------------*/
\r
117 static void prvSetupHardware( void )
\r
119 extern void SystemCoreClockUpdate( void );
\r
120 struct eic_line_config xEICLineConfiguration;
\r
122 /* Configure the external interrupt controller so button pushes can
\r
123 generate interrupts. */
\r
124 xEICLineConfiguration.eic_mode = EIC_MODE_EDGE_TRIGGERED;
\r
125 xEICLineConfiguration.eic_edge = EIC_EDGE_FALLING_EDGE;
\r
126 xEICLineConfiguration.eic_level = EIC_LEVEL_LOW_LEVEL;
\r
127 xEICLineConfiguration.eic_filter = EIC_FILTER_DISABLED;
\r
128 xEICLineConfiguration.eic_async = EIC_ASYNCH_MODE;
\r
130 eic_line_set_config( EIC, GPIO_PUSH_BUTTON_EIC_LINE, &xEICLineConfiguration );
\r
131 eic_line_set_callback( EIC, GPIO_PUSH_BUTTON_EIC_LINE, prvButtonISR, EIC_5_IRQn, 0 );
\r
132 eic_line_enable( EIC, GPIO_PUSH_BUTTON_EIC_LINE );
\r
134 /* ASF function to setup clocking. */
\r
137 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
138 NVIC_SetPriorityGrouping( 0 );
\r
140 /* Atmel library function to setup for the evaluation kit being used. */
\r
143 /* Initialise the sleep manager in case the low power demo is being used. */
\r
146 /*-----------------------------------------------------------*/
\r
148 void vApplicationMallocFailedHook( void )
\r
150 /* vApplicationMallocFailedHook() will only be called if
\r
151 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
152 function that will get called if a call to pvPortMalloc() fails.
\r
153 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
154 timer or semaphore is created. It is also called by various parts of the
\r
155 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
156 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
157 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
158 to query the size of free heap space that remains (although it does not
\r
159 provide information on how the remaining heap might be fragmented). */
\r
160 taskDISABLE_INTERRUPTS();
\r
163 /*-----------------------------------------------------------*/
\r
165 void vApplicationIdleHook( void )
\r
167 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
168 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
169 task. It is essential that code added to this hook function never attempts
\r
170 to block in any way (for example, call xQueueReceive() with a block time
\r
171 specified, or call vTaskDelay()). If the application makes use of the
\r
172 vTaskDelete() API function (as this demo application does) then it is also
\r
173 important that vApplicationIdleHook() is permitted to return to its calling
\r
174 function, because it is the responsibility of the idle task to clean up
\r
175 memory allocated by the kernel to any task that has since been deleted. */
\r
177 /*-----------------------------------------------------------*/
\r
179 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
181 ( void ) pcTaskName;
\r
184 /* Run time stack overflow checking is performed if
\r
185 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
186 function is called if a stack overflow is detected. */
\r
187 taskDISABLE_INTERRUPTS();
\r
190 /*-----------------------------------------------------------*/
\r
192 void vApplicationTickHook( void )
\r
194 /* This function will be called by each tick interrupt if
\r
195 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
196 added here, but the tick hook is called from an interrupt context, so
\r
197 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
198 functions can be used (those that end in FromISR()). */
\r
200 /*-----------------------------------------------------------*/
\r
202 void vAssertCalled( void )
\r
204 volatile unsigned long ul = 0;
\r
206 taskENTER_CRITICAL();
\r
208 /* Set ul to a non-zero value using the debugger to step out of this
\r
212 __asm volatile( "NOP" );
\r
215 taskEXIT_CRITICAL();
\r