]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Giant_Gecko_Simplicity_Studio/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Giant_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_chip.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         /* Library initialisation routines. */\r
117         CHIP_Init();\r
118         BSP_TraceProfilerSetup();\r
119         SLEEP_Init( NULL, NULL );\r
120         BSP_LedsInit();\r
121 \r
122         SLEEP_SleepBlockBegin( configENERGY_MODE );\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 void vApplicationMallocFailedHook( void )\r
127 {\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
133 \r
134         /* Force an assert. */\r
135         configASSERT( ( volatile void * ) NULL );\r
136 }\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
140 {\r
141         ( void ) pcTaskName;\r
142         ( void ) pxTask;\r
143 \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
147 \r
148         /* Force an assert. */\r
149         configASSERT( ( volatile void * ) NULL );\r
150 }\r
151 /*-----------------------------------------------------------*/\r
152 \r
153 void vApplicationIdleHook( void )\r
154 {\r
155 volatile size_t xFreeHeapSpace;\r
156 \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
163         RAM. */\r
164         xFreeHeapSpace = xPortGetFreeHeapSize();\r
165 \r
166         /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
167         ( void ) xFreeHeapSpace;\r
168 }\r
169 /*-----------------------------------------------------------*/\r
170 \r
171 void vApplicationTickHook( void )\r
172 {\r
173         /* The full demo includes tests that run from the tick hook. */\r
174         #if( configCREATE_LOW_POWER_DEMO == 0 )\r
175         {\r
176         extern void vFullDemoTickHook( void );\r
177 \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
182         }\r
183         #endif\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \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
191 {\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
197 \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
201 \r
202         /* Pass out the array that will be used as the Idle task's stack. */\r
203         *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
204 \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
209 }\r
210 /*-----------------------------------------------------------*/\r
211 \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
216 {\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
222 \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
226 \r
227         /* Pass out the array that will be used as the Timer task's stack. */\r
228         *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
229 \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
234 }\r
235 \r