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 low power project that
\r
31 * demonstrates the FreeRTOS tickless mode, and a more comprehensive test and
\r
32 * demo application. The configCREATE_LOW_POWER_DEMO setting (defined at the
\r
33 * top of FreeRTOSConfig.h) is used to select between the two. The low power
\r
34 * demo is implemented and described in main_low_power.c. The more
\r
35 * comprehensive test and demo application is implemented and described in
\r
38 * This file implements the code that is not demo specific, including the
\r
39 * hardware setup and FreeRTOS hook functions.
\r
42 /* Standard includes. */
\r
45 /* Kernel includes. */
\r
46 #include "FreeRTOS.h"
\r
49 /* Standard demo includes - just needed for the LED (ParTest) initialisation
\r
51 #include "partest.h"
\r
53 /* Atmel library includes. */
\r
56 /*-----------------------------------------------------------*/
\r
59 * Set up the hardware ready to run this demo.
\r
61 static void prvSetupHardware( void );
\r
64 * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.
\r
65 * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.
\r
66 * configCREATE_LOW_POWER_DEMO is defined at the top of main.c.
\r
68 extern void main_low_power( void );
\r
69 extern void main_full( void );
\r
71 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
72 within this file. */
\r
73 void vApplicationMallocFailedHook( void );
\r
74 void vApplicationIdleHook( void );
\r
75 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
76 void vApplicationTickHook( void );
\r
78 /* A handler for a button interrupt. The button's only purpose is to bring the
\r
79 CPU out of sleep mode early. */
\r
80 static void prvButtonISR( void );
\r
82 /*-----------------------------------------------------------*/
\r
84 /* See the documentation page for this demo on the FreeRTOS.org web site for
\r
85 full information - including hardware setup requirements. */
\r
88 /* Prepare the hardware to run this demo. */
\r
91 /* The configCREATE_LOW_POWER_DEMO setting is described at the top of
\r
93 #if( configCREATE_LOW_POWER_DEMO == 1 )
\r
105 /*-----------------------------------------------------------*/
\r
107 static void prvButtonISR( void )
\r
109 /* The button doesn't do anything other than providing a means for brining
\r
110 the MCU out of sleep mode early. */
\r
111 if( eic_line_interrupt_is_pending( EIC, GPIO_PUSH_BUTTON_EIC_LINE ) )
\r
113 eic_line_clear_interrupt( EIC, GPIO_PUSH_BUTTON_EIC_LINE );
\r
116 /*-----------------------------------------------------------*/
\r
118 static void prvSetupHardware( void )
\r
120 extern void SystemCoreClockUpdate( void );
\r
121 struct eic_line_config xEICLineConfiguration;
\r
123 /* Configure the external interrupt controller so button pushes can
\r
124 generate interrupts. */
\r
125 xEICLineConfiguration.eic_mode = EIC_MODE_EDGE_TRIGGERED;
\r
126 xEICLineConfiguration.eic_edge = EIC_EDGE_FALLING_EDGE;
\r
127 xEICLineConfiguration.eic_level = EIC_LEVEL_LOW_LEVEL;
\r
128 xEICLineConfiguration.eic_filter = EIC_FILTER_DISABLED;
\r
129 xEICLineConfiguration.eic_async = EIC_ASYNCH_MODE;
\r
131 eic_line_set_config( EIC, GPIO_PUSH_BUTTON_EIC_LINE, &xEICLineConfiguration );
\r
132 eic_line_set_callback( EIC, GPIO_PUSH_BUTTON_EIC_LINE, prvButtonISR, EIC_5_IRQn, 0 );
\r
133 eic_line_enable( EIC, GPIO_PUSH_BUTTON_EIC_LINE );
\r
135 /* ASF function to setup clocking. */
\r
138 /* Ensure all priority bits are assigned as preemption priority bits. */
\r
139 NVIC_SetPriorityGrouping( 0 );
\r
141 /* Atmel library function to setup for the evaluation kit being used. */
\r
144 /* Initialise the sleep manager in case the low power demo is being used. */
\r
147 /*-----------------------------------------------------------*/
\r
149 void vApplicationMallocFailedHook( void )
\r
151 /* vApplicationMallocFailedHook() will only be called if
\r
152 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
153 function that will get called if a call to pvPortMalloc() fails.
\r
154 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
155 timer or semaphore is created. It is also called by various parts of the
\r
156 demo application. If heap_1.c or heap_2.c are used, then the size of the
\r
157 heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
158 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
159 to query the size of free heap space that remains (although it does not
\r
160 provide information on how the remaining heap might be fragmented). */
\r
161 taskDISABLE_INTERRUPTS();
\r
164 /*-----------------------------------------------------------*/
\r
166 void vApplicationIdleHook( void )
\r
168 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
169 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
170 task. It is essential that code added to this hook function never attempts
\r
171 to block in any way (for example, call xQueueReceive() with a block time
\r
172 specified, or call vTaskDelay()). If the application makes use of the
\r
173 vTaskDelete() API function (as this demo application does) then it is also
\r
174 important that vApplicationIdleHook() is permitted to return to its calling
\r
175 function, because it is the responsibility of the idle task to clean up
\r
176 memory allocated by the kernel to any task that has since been deleted. */
\r
178 /*-----------------------------------------------------------*/
\r
180 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
182 ( void ) pcTaskName;
\r
185 /* Run time stack overflow checking is performed if
\r
186 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
187 function is called if a stack overflow is detected. */
\r
188 taskDISABLE_INTERRUPTS();
\r
191 /*-----------------------------------------------------------*/
\r
193 void vApplicationTickHook( void )
\r
195 /* This function will be called by each tick interrupt if
\r
196 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h. User code can be
\r
197 added here, but the tick hook is called from an interrupt context, so
\r
198 code must not attempt to block, and only the interrupt safe FreeRTOS API
\r
199 functions can be used (those that end in FromISR()). */
\r
201 /*-----------------------------------------------------------*/
\r
203 void vAssertCalled( void )
\r
205 volatile unsigned long ul = 0;
\r
207 taskENTER_CRITICAL();
\r
209 /* Set ul to a non-zero value using the debugger to step out of this
\r
213 __asm volatile( "NOP" );
\r
216 taskEXIT_CRITICAL();
\r