]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Giant_Gecko_Simplicity_Studio/main.c
d35fa541ac0d3f6df4e6a897925b089b97757249
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Giant_Gecko_Simplicity_Studio / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * See http://www.freertos.org/EFM32-Giant-Gecko-Pearl-Gecko-tickless-RTOS-demo.html\r
30  *\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
36  *\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
40  *\r
41  * This file implements the code that is not demo specific, including the\r
42  * hardware setup and standard FreeRTOS hook functions.\r
43  *\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
47  *\r
48  */\r
49 \r
50 /* FreeRTOS includes. */\r
51 #include "FreeRTOS.h"\r
52 #include "task.h"\r
53 \r
54 /* SiLabs includes. */\r
55 #include "em_chip.h"\r
56 #include "bsp.h"\r
57 #include "bsp_trace.h"\r
58 #include "sleep.h"\r
59 \r
60 /*-----------------------------------------------------------*/\r
61 \r
62 /*\r
63  * Configure the hardware as necessary to run this demo.\r
64  */\r
65 static void prvSetupHardware( void );\r
66 \r
67 /*\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
70  */\r
71 #if( configCREATE_LOW_POWER_DEMO != 0 )\r
72         extern void main_low_power( void );\r
73 #else\r
74         extern void main_full( void );\r
75 #endif /* #if configCREATE_LOW_POWER_DEMO == 1 */\r
76 \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
83 \r
84 /*-----------------------------------------------------------*/\r
85 \r
86 int main( void )\r
87 {\r
88         /*\r
89          * See the following link for instructions:\r
90          * http://www.freertos.org/EFM32-Giant-Gecko-Pearl-Gecko-tickless-RTOS-demo.html\r
91          */\r
92 \r
93         /* Configure the hardware ready to run the demo. */\r
94         prvSetupHardware();\r
95 \r
96         /* The mainCREATE_LOW_POWER_DEMO setting is described at the top\r
97         of this file. */\r
98         #if( configCREATE_LOW_POWER_DEMO != 0 )\r
99         {\r
100                 main_low_power();\r
101         }\r
102         #else\r
103         {\r
104                 main_full();\r
105         }\r
106         #endif\r
107 \r
108         /* Should not get here. */\r
109         return 0;\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 static void prvSetupHardware( void )\r
114 {\r
115         /* Library initialisation routines. */\r
116         CHIP_Init();\r
117         BSP_TraceProfilerSetup();\r
118         SLEEP_Init( NULL, NULL );\r
119         BSP_LedsInit();\r
120 \r
121         SLEEP_SleepBlockBegin( configENERGY_MODE );\r
122 }\r
123 /*-----------------------------------------------------------*/\r
124 \r
125 void vApplicationMallocFailedHook( void )\r
126 {\r
127         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
128         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
129         internally by FreeRTOS API functions that create tasks, queues, software\r
130         timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
131         configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
132 \r
133         /* Force an assert. */\r
134         configASSERT( ( volatile void * ) NULL );\r
135 }\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
139 {\r
140         ( void ) pcTaskName;\r
141         ( void ) pxTask;\r
142 \r
143         /* Run time stack overflow checking is performed if\r
144         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
145         function is called if a stack overflow is detected. */\r
146 \r
147         /* Force an assert. */\r
148         configASSERT( ( volatile void * ) NULL );\r
149 }\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 void vApplicationIdleHook( void )\r
153 {\r
154 volatile size_t xFreeHeapSpace;\r
155 \r
156         /* This is just a trivial example of an idle hook.  It is called on each\r
157         cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
158         idle task just queries the amount of FreeRTOS heap that remains.  See the\r
159         memory management section on the http://www.FreeRTOS.org web site for memory\r
160         management options.  If there is a lot of heap memory free then the\r
161         configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
162         RAM. */\r
163         xFreeHeapSpace = xPortGetFreeHeapSize();\r
164 \r
165         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
166         ( void ) xFreeHeapSpace;\r
167 }\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 void vApplicationTickHook( void )\r
171 {\r
172         /* The full demo includes tests that run from the tick hook. */\r
173         #if( configCREATE_LOW_POWER_DEMO == 0 )\r
174         {\r
175         extern void vFullDemoTickHook( void );\r
176 \r
177                 /* Some of the tests and demo tasks executed by the full demo include\r
178                 interaction from an interrupt - for which the tick interrupt is used\r
179                 via the tick hook function. */\r
180                 vFullDemoTickHook();\r
181         }\r
182         #endif\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
187 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
188 used by the Idle task. */\r
189 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )\r
190 {\r
191 /* If the buffers to be provided to the Idle task are declared inside this\r
192 function then they must be declared static - otherwise they will be allocated on\r
193 the stack and so not exists after this function exits. */\r
194 static StaticTask_t xIdleTaskTCB;\r
195 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
196 \r
197         /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
198         state will be stored. */\r
199         *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
200 \r
201         /* Pass out the array that will be used as the Idle task's stack. */\r
202         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
203 \r
204         /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
205         Note that, as the array is necessarily of type StackType_t,\r
206         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
207         *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
208 }\r
209 /*-----------------------------------------------------------*/\r
210 \r
211 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
212 application must provide an implementation of vApplicationGetTimerTaskMemory()\r
213 to provide the memory that is used by the Timer service task. */\r
214 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )\r
215 {\r
216 /* If the buffers to be provided to the Timer task are declared inside this\r
217 function then they must be declared static - otherwise they will be allocated on\r
218 the stack and so not exists after this function exits. */\r
219 static StaticTask_t xTimerTaskTCB;\r
220 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
221 \r
222         /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
223         task's state will be stored. */\r
224         *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
225 \r
226         /* Pass out the array that will be used as the Timer task's stack. */\r
227         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
228 \r
229         /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\r
230         Note that, as the array is necessarily of type StackType_t,\r
231         configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
232         *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
233 }\r
234 \r