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