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 * See http://www.freertos.org/EFM32-Giant-Gecko-Pearl-Gecko-tickless-RTOS-demo.html
\r
32 * This project provides two demo applications. A simple blinky style project
\r
33 * that demonstrates low power tickless functionality, and a more comprehensive
\r
34 * test and demo application. The configCREATE_LOW_POWER_DEMO setting, which is
\r
35 * defined in FreeRTOSConfig.h, is used to select between the two, and to select
\r
36 * the clock used when demonstrating tickless functionality.
\r
38 * The simply blinky low power demo is implemented and described in
\r
39 * main_low_power.c. The more comprehensive test and demo application is
\r
40 * implemented and described in main_full.c.
\r
42 * This file implements the code that is not demo specific, including the
\r
43 * hardware setup and standard FreeRTOS hook functions.
\r
45 * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON
\r
46 * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO
\r
47 * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!
\r
51 /* FreeRTOS includes. */
\r
52 #include "FreeRTOS.h"
\r
55 /* SiLabs includes. */
\r
56 #include "em_chip.h"
\r
58 #include "bsp_trace.h"
\r
61 /*-----------------------------------------------------------*/
\r
64 * Configure the hardware as necessary to run this demo.
\r
66 static void prvSetupHardware( void );
\r
69 * main_low_power() is used when configCREATE_LOW_POWER_DEMO is set to 1.
\r
70 * main_full() is used when configCREATE_LOW_POWER_DEMO is set to 0.
\r
72 #if( configCREATE_LOW_POWER_DEMO != 0 )
\r
73 extern void main_low_power( void );
\r
75 extern void main_full( void );
\r
76 #endif /* #if configCREATE_LOW_POWER_DEMO == 1 */
\r
78 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
79 within this file. */
\r
80 void vApplicationMallocFailedHook( void );
\r
81 void vApplicationIdleHook( void );
\r
82 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
83 void vApplicationTickHook( void );
\r
85 /*-----------------------------------------------------------*/
\r
90 * See the following link for instructions:
\r
91 * http://www.freertos.org/EFM32-Giant-Gecko-Pearl-Gecko-tickless-RTOS-demo.html
\r
94 /* Configure the hardware ready to run the demo. */
\r
97 /* The mainCREATE_LOW_POWER_DEMO setting is described at the top
\r
99 #if( configCREATE_LOW_POWER_DEMO != 0 )
\r
109 /* Should not get here. */
\r
112 /*-----------------------------------------------------------*/
\r
114 static void prvSetupHardware( void )
\r
116 /* Library initialisation routines. */
\r
118 BSP_TraceProfilerSetup();
\r
119 SLEEP_Init( NULL, NULL );
\r
122 SLEEP_SleepBlockBegin( configENERGY_MODE );
\r
124 /*-----------------------------------------------------------*/
\r
126 void vApplicationMallocFailedHook( void )
\r
128 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
129 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
130 internally by FreeRTOS API functions that create tasks, queues, software
\r
131 timers, and semaphores. The size of the FreeRTOS heap is set by the
\r
132 configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */
\r
134 /* Force an assert. */
\r
135 configASSERT( ( volatile void * ) NULL );
\r
137 /*-----------------------------------------------------------*/
\r
139 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
141 ( void ) pcTaskName;
\r
144 /* Run time stack overflow checking is performed if
\r
145 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
146 function is called if a stack overflow is detected. */
\r
148 /* Force an assert. */
\r
149 configASSERT( ( volatile void * ) NULL );
\r
151 /*-----------------------------------------------------------*/
\r
153 void vApplicationIdleHook( void )
\r
155 volatile size_t xFreeHeapSpace;
\r
157 /* This is just a trivial example of an idle hook. It is called on each
\r
158 cycle of the idle task. It must *NOT* attempt to block. In this case the
\r
159 idle task just queries the amount of FreeRTOS heap that remains. See the
\r
160 memory management section on the http://www.FreeRTOS.org web site for memory
\r
161 management options. If there is a lot of heap memory free then the
\r
162 configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up
\r
164 xFreeHeapSpace = xPortGetFreeHeapSize();
\r
166 /* Remove compiler warning about xFreeHeapSpace being set but never used. */
\r
167 ( void ) xFreeHeapSpace;
\r
169 /*-----------------------------------------------------------*/
\r
171 void vApplicationTickHook( void )
\r
173 /* The full demo includes tests that run from the tick hook. */
\r
174 #if( configCREATE_LOW_POWER_DEMO == 0 )
\r
176 extern void vFullDemoTickHook( void );
\r
178 /* Some of the tests and demo tasks executed by the full demo include
\r
179 interaction from an interrupt - for which the tick interrupt is used
\r
180 via the tick hook function. */
\r
181 vFullDemoTickHook();
\r
185 /*-----------------------------------------------------------*/
\r
187 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
\r
188 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
\r
189 used by the Idle task. */
\r
190 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
\r
192 /* If the buffers to be provided to the Idle task are declared inside this
\r
193 function then they must be declared static - otherwise they will be allocated on
\r
194 the stack and so not exists after this function exits. */
\r
195 static StaticTask_t xIdleTaskTCB;
\r
196 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
\r
198 /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
\r
199 state will be stored. */
\r
200 *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
\r
202 /* Pass out the array that will be used as the Idle task's stack. */
\r
203 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\r
205 /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
\r
206 Note that, as the array is necessarily of type StackType_t,
\r
207 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
208 *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
\r
210 /*-----------------------------------------------------------*/
\r
212 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
\r
213 application must provide an implementation of vApplicationGetTimerTaskMemory()
\r
214 to provide the memory that is used by the Timer service task. */
\r
215 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
\r
217 /* If the buffers to be provided to the Timer task are declared inside this
\r
218 function then they must be declared static - otherwise they will be allocated on
\r
219 the stack and so not exists after this function exits. */
\r
220 static StaticTask_t xTimerTaskTCB;
\r
221 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
\r
223 /* Pass out a pointer to the StaticTask_t structure in which the Timer
\r
224 task's state will be stored. */
\r
225 *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
\r
227 /* Pass out the array that will be used as the Timer task's stack. */
\r
228 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\r
230 /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
\r
231 Note that, as the array is necessarily of type StackType_t,
\r
232 configMINIMAL_STACK_SIZE is specified in words, not bytes. */
\r
233 *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
\r