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 simple blinky style project
\r
30 * that demonstrates low power tickless functionality, and a more comprehensive
\r
31 * test and demo application. The configCREATE_LOW_POWER_DEMO setting, which is
\r
32 * defined in FreeRTOSConfig.h, is used to select between the two. The simply
\r
33 * blinky low power demo is implemented and described in main_low_power.c. The
\r
34 * more 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 standard FreeRTOS hook functions.
\r
40 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
41 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
42 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
46 /* Scheduler include files. */
\r
47 #include "FreeRTOS.h"
\r
50 /* Hardware register addresses and value. */
\r
51 #define mainVTOR ( * ( uint32_t * ) 0xE000ED08 )
\r
52 #define mainNVIC_AUX_ACTLR ( * ( uint32_t * ) 0xE000E008 )
\r
53 #define mainEC_INTERRUPT_CONTROL ( * ( volatile uint32_t * ) 0x4000FC18 )
\r
54 #define mainMMCR_PCR_PROCESSOR_CLOCK_CONTROL ( * ( volatile uint32_t * )( 0x40080120 ) )
\r
55 #define mainCPU_CLOCK_DIVIDER 1
\r
57 /*-----------------------------------------------------------*/
\r
60 * Configure the hardware as necessary to run this demo.
\r
62 static void prvSetupHardware( void );
\r
65 * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.
\r
66 * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.
\r
68 #if( configCREATE_LOW_POWER_DEMO == 1 )
\r
70 extern void main_low_power( void );
\r
74 extern void main_full( void );
\r
76 /* Some of the tests and examples executed as part of the full demo make use
\r
77 of the tick hook to call API functions from an interrupt context. */
\r
78 extern void vFullDemoTickHook( void );
\r
80 #endif /* #if configCREATE_LOW_POWER_DEMO == 1 */
\r
82 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
83 within this file. */
\r
84 void vApplicationMallocFailedHook( void );
\r
85 void vApplicationIdleHook( void );
\r
86 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
87 void vApplicationTickHook( void );
\r
89 /*-----------------------------------------------------------*/
\r
91 /* The variable that is incremented to represent each LED toggle. On the
\r
92 clicker hardware the LED state is set to the value of the least significant bit
\r
93 of this variable. On other hardware, where an LED is not used, the LED just
\r
94 keeps a count of the number of times the LED would otherwise have been toggled.
\r
95 See the comments in main_low_power.c and main_full.c for information on the
\r
96 expected LED toggle rate). */
\r
97 volatile uint32_t ulLED = 0;
\r
99 /*-----------------------------------------------------------*/
\r
103 /* Configure the hardware ready to run the demo. */
\r
104 prvSetupHardware();
\r
106 /* The configCREATE_LOW_POWER_DEMO setting is described at the top
\r
108 #if( configCREATE_LOW_POWER_DEMO == 1 )
\r
118 /* Should not get here. */
\r
121 /*-----------------------------------------------------------*/
\r
123 static void prvSetupHardware( void )
\r
125 /* Disable M4 write buffer: fix MEC1322 hardware bug. */
\r
126 mainNVIC_AUX_ACTLR |= 0x07;
\r
128 /* Set divider to 8 for 8MHz operation, MCLK in silicon chip is 64MHz,
\r
129 CPU=MCLK/Divider. */
\r
130 mainMMCR_PCR_PROCESSOR_CLOCK_CONTROL = mainCPU_CLOCK_DIVIDER;
\r
132 /* Enable alternative NVIC vectors. */
\r
133 mainEC_INTERRUPT_CONTROL = pdTRUE;
\r
135 /* Initialise the LED on the clicker board. */
\r
136 GPIO_Digital_Output( &GPIO_PORT_150_157, _GPIO_PINMASK_4 | _GPIO_PINMASK_5 );
\r
137 GPIO_OUTPUT_PIN_154_bit = 0;
\r
138 GPIO_OUTPUT_PIN_155_bit = 0;
\r
140 /*-----------------------------------------------------------*/
\r
142 void vApplicationMallocFailedHook( void )
\r
144 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
145 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
146 internally by FreeRTOS API functions that create tasks, queues, software
\r
147 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
148 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
150 /* Force an assert. */
\r
151 configASSERT( ( volatile void * ) NULL );
\r
153 /*-----------------------------------------------------------*/
\r
155 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
157 ( void ) pcTaskName;
\r
160 /* Run time stack overflow checking is performed if
\r
161 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
162 function is called if a stack overflow is detected. */
\r
164 /* Force an assert. */
\r
165 configASSERT( ( volatile void * ) NULL );
\r
167 /*-----------------------------------------------------------*/
\r
169 void vApplicationIdleHook( void )
\r
171 volatile size_t xFreeHeapSpace;
\r
173 /* This is just a trivial example of an idle hook. It is called on each
\r
174 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
175 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
176 memory management section on the http://www.FreeRTOS.org web site for memory
\r
177 management options. If there is a lot of heap memory free then the
\r
178 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
180 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
182 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
183 ( void ) xFreeHeapSpace;
\r
185 /*-----------------------------------------------------------*/
\r
187 void vApplicationTickHook( void )
\r
189 /* The full demo includes tests that run from the tick hook. */
\r
190 #if( configCREATE_LOW_POWER_DEMO == 0 )
\r
192 /* Some of the tests and demo tasks executed by the full demo include
\r
193 interaction from an interrupt - for which the tick interrupt is used
\r
194 via the tick hook function. */
\r
195 vFullDemoTickHook();
\r
199 /*-----------------------------------------------------------*/
\r
201 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
202 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
203 used by the Idle task. */
\r
204 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
206 /* If the buffers to be provided to the Idle task are declared inside this
\r
207 function then they must be declared static - otherwise they will be allocated on
\r
208 the stack and so not exists after this function exits. */
\r
209 static StaticTask_t xIdleTaskTCB;
\r
210 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
212 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
213 state will be stored. */
\r
214 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
216 /* Pass out the array that will be used as the Idle task's stack. */
\r
217 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
219 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
220 Note that, as the array is necessarily of type StackType_t,
\r
221 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
222 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
224 /*-----------------------------------------------------------*/
\r
226 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
227 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
228 to provide the memory that is used by the Timer service task. */
\r
229 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
231 /* If the buffers to be provided to the Timer task are declared inside this
\r
232 function then they must be declared static - otherwise they will be allocated on
\r
233 the stack and so not exists after this function exits. */
\r
234 static StaticTask_t xTimerTaskTCB;
\r
235 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
237 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
238 task's state will be stored. */
\r
239 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
241 /* Pass out the array that will be used as the Timer task's stack. */
\r
242 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
244 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
245 Note that, as the array is necessarily of type StackType_t,
\r
246 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
247 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r