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 * See http://www.freertos.org/EFM32-Giant-Gecko-Pearl-Gecko-tickless-RTOS-demo.html
\r
31 * This project provides two demo applications. A simple blinky style project
\r
32 * that demonstrates low power tickless functionality, and a more comprehensive
\r
33 * test and demo application. The configCREATE_LOW_POWER_DEMO setting, which is
\r
34 * defined in FreeRTOSConfig.h, is used to select between the two, and to select
\r
35 * the clock used when demonstrating tickless functionality.
\r
37 * The simply blinky low power demo is implemented and described in
\r
38 * main_low_power.c. The more comprehensive test and demo application is
\r
39 * implemented and described in main_full.c.
\r
41 * This file implements the code that is not demo specific, including the
\r
42 * hardware setup and standard FreeRTOS hook functions.
\r
44 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
45 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
46 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
50 /* FreeRTOS includes. */
\r
51 #include "FreeRTOS.h"
\r
54 /* SiLabs includes. */
\r
57 #include "bsp_trace.h"
\r
60 /*-----------------------------------------------------------*/
\r
63 * Configure the hardware as necessary to run this demo.
\r
65 static void prvSetupHardware( void );
\r
68 * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.
\r
69 * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.
\r
71 #if( configCREATE_LOW_POWER_DEMO != 0 )
\r
72 extern void main_low_power( void );
\r
74 extern void main_full( void );
\r
75 #endif /* #if configCREATE_LOW_POWER_DEMO == 1 */
\r
77 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
78 within this file. */
\r
79 void vApplicationMallocFailedHook( void );
\r
80 void vApplicationIdleHook( void );
\r
81 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
82 void vApplicationTickHook( void );
\r
84 /*-----------------------------------------------------------*/
\r
89 * See the following link for instructions:
\r
90 * http://www.freertos.org/EFM32-Giant-Gecko-Pearl-Gecko-tickless-RTOS-demo.html
\r
93 /* Configure the hardware ready to run the demo. */
\r
96 /* The mainCREATE_LOW_POWER_DEMO setting is described at the top
\r
98 #if( configCREATE_LOW_POWER_DEMO != 0 )
\r
108 /* Should not get here. */
\r
111 /*-----------------------------------------------------------*/
\r
113 static void prvSetupHardware( void )
\r
115 EMU_DCDCInit_TypeDef xDCDInit = EMU_DCDCINIT_STK_DEFAULT;
\r
116 CMU_HFXOInit_TypeDef xHFXOInit = CMU_HFXOINIT_STK_DEFAULT;
\r
121 /* Init DCDC regulator and HFXO with kit specific parameters */
\r
122 EMU_DCDCInit( &xDCDInit );
\r
123 CMU_HFXOInit( &xHFXOInit );
\r
125 /* Switch HFCLK to HFXO and disable HFRCO */
\r
126 CMU_ClockSelectSet( cmuClock_HF, cmuSelect_HFXO );
\r
127 CMU_OscillatorEnable( cmuOsc_HFRCO, false, false );
\r
129 /* Initialize LED driver. */
\r
134 /*-----------------------------------------------------------*/
\r
136 void vApplicationMallocFailedHook( void )
\r
138 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
139 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
140 internally by FreeRTOS API functions that create tasks, queues, software
\r
141 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
142 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
144 /* Force an assert. */
\r
145 configASSERT( ( volatile void * ) NULL );
\r
147 /*-----------------------------------------------------------*/
\r
149 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
151 ( void ) pcTaskName;
\r
154 /* Run time stack overflow checking is performed if
\r
155 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
156 function is called if a stack overflow is detected. */
\r
158 /* Force an assert. */
\r
159 configASSERT( ( volatile void * ) NULL );
\r
161 /*-----------------------------------------------------------*/
\r
163 void vApplicationIdleHook( void )
\r
165 volatile size_t xFreeHeapSpace;
\r
167 /* This is just a trivial example of an idle hook. It is called on each
\r
168 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
169 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
170 memory management section on the http://www.FreeRTOS.org web site for memory
\r
171 management options. If there is a lot of heap memory free then the
\r
172 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
174 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
176 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
177 ( void ) xFreeHeapSpace;
\r
179 /*-----------------------------------------------------------*/
\r
181 void vApplicationTickHook( void )
\r
183 /* The full demo includes tests that run from the tick hook. */
\r
184 #if( configCREATE_LOW_POWER_DEMO == 0 )
\r
186 extern void vFullDemoTickHook( void );
\r
188 /* Some of the tests and demo tasks executed by the full demo include
\r
189 interaction from an interrupt - for which the tick interrupt is used
\r
190 via the tick hook function. */
\r
191 vFullDemoTickHook();
\r
195 /*-----------------------------------------------------------*/
\r
197 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
198 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
199 used by the Idle task. */
\r
200 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
202 /* If the buffers to be provided to the Idle task are declared inside this
\r
203 function then they must be declared static - otherwise they will be allocated on
\r
204 the stack and so not exists after this function exits. */
\r
205 static StaticTask_t xIdleTaskTCB;
\r
206 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
208 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
209 state will be stored. */
\r
210 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
212 /* Pass out the array that will be used as the Idle task's stack. */
\r
213 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
215 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
216 Note that, as the array is necessarily of type StackType_t,
\r
217 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
218 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
220 /*-----------------------------------------------------------*/
\r
222 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
223 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
224 to provide the memory that is used by the Timer service task. */
\r
225 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
227 /* If the buffers to be provided to the Timer task are declared inside this
\r
228 function then they must be declared static - otherwise they will be allocated on
\r
229 the stack and so not exists after this function exits. */
\r
230 static StaticTask_t xTimerTaskTCB;
\r
231 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
233 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
234 task's state will be stored. */
\r
235 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
237 /* Pass out the array that will be used as the Timer task's stack. */
\r
238 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
240 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
241 Note that, as the array is necessarily of type StackType_t,
\r
242 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
243 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r