]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_SimpleLink_CC3220SF_CCS/main.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_M4_SimpleLink_CC3220SF_CCS / 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  * This project provides two demo applications.  A simple blinky style project,\r
31  * and a more comprehensive test and demo application.  The\r
32  * configCREATE_SIMPLE_TICKLESS_DEMO setting (defined in FreeRTOSConfig.h) is\r
33  * used to select between the two.  The simply blinky demo is implemented and\r
34  * described in main_blinky.c.  The more comprehensive test and demo application\r
35  * is implemented and described in main_full.c.\r
36  *\r
37  * The blinky demo uses FreeRTOS's tickless idle mode to reduce power\r
38  * consumption.  See the notes on the web page below regarding the difference\r
39  * in power saving that can be achieved between using the generic tickless\r
40  * implementation (as used by the blinky demo) and a tickless implementation\r
41  * that is tailored specifically to the CC3220.\r
42  *\r
43  * This file implements the code that is not demo specific.\r
44  *\r
45  * See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for\r
46  * instructions.\r
47  *\r
48  */\r
49 \r
50 /* Standard includes. */\r
51 #include <stdio.h>\r
52 \r
53 /* TI includes. */\r
54 #include <ti/drivers/GPIO.h>\r
55 #include <ti/boards/CC3220SF_LAUNCHXL/Board.h>\r
56 \r
57 /* Kernel includes. */\r
58 #include "FreeRTOS.h"\r
59 #include "task.h"\r
60 \r
61 /*-----------------------------------------------------------*/\r
62 \r
63 /*\r
64  * Set up the hardware ready to run this demo.\r
65  */\r
66 static void prvSetupHardware( void );\r
67 \r
68 /*\r
69  * main_blinky() is used when configCREATE_SIMPLE_TICKLESS_DEMO is set to 1.\r
70  * main_full() is used when configCREATE_SIMPLE_TICKLESS_DEMO is set to 0.\r
71  */\r
72 extern void main_blinky( void );\r
73 extern void main_full( void );\r
74 \r
75 /*-----------------------------------------------------------*/\r
76 \r
77 int main( void )\r
78 {\r
79         /* See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for\r
80     instructions. */\r
81 \r
82 \r
83         /* Prepare the hardware to run this demo. */\r
84         prvSetupHardware();\r
85 \r
86         /* The configCREATE_SIMPLE_TICKLESS_DEMO setting is described at the top\r
87         of this file. */\r
88         #if( configCREATE_SIMPLE_TICKLESS_DEMO == 1 )\r
89         {\r
90                 main_blinky();\r
91         }\r
92         #else\r
93         {\r
94                 main_full();\r
95         }\r
96         #endif\r
97 \r
98         return 0;\r
99 }\r
100 /*-----------------------------------------------------------*/\r
101 \r
102 static void prvSetupHardware( void )\r
103 {\r
104     /* Call board init functions */\r
105     Board_initGeneral();\r
106     Board_initGPIO();\r
107     GPIO_write( Board_LED0, Board_GPIO_LED_OFF );\r
108 }\r
109 /*-----------------------------------------------------------*/\r
110 \r
111 void vMainToggleLED( void )\r
112 {\r
113 static uint32_t ulLEDState = Board_GPIO_LED_OFF;\r
114 \r
115     ulLEDState = !ulLEDState;\r
116     GPIO_write( Board_LED0, ulLEDState );\r
117 }\r
118 /*-----------------------------------------------------------*/\r
119 \r
120 void vApplicationMallocFailedHook( void )\r
121 {\r
122         /* vApplicationMallocFailedHook() will only be called if\r
123         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
124         function that will get called if a call to pvPortMalloc() fails.\r
125         pvPortMalloc() is called internally by the kernel whenever a task, queue,\r
126         timer or semaphore is created.  It is also called by various parts of the\r
127         demo application.  If heap_1.c or heap_2.c are used, then the size of the\r
128         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
129         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
130         to query the size of free heap space that remains (although it does not\r
131         provide information on how the remaining heap might be fragmented). */\r
132         taskDISABLE_INTERRUPTS();\r
133         for( ;; );\r
134 }\r
135 /*-----------------------------------------------------------*/\r
136 \r
137 void vApplicationIdleHook( void )\r
138 {\r
139         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set\r
140         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle\r
141         task.  It is essential that code added to this hook function never attempts\r
142         to block in any way (for example, call xQueueReceive() with a block time\r
143         specified, or call vTaskDelay()).  If the application makes use of the\r
144         vTaskDelete() API function (as this demo application does) then it is also\r
145         important that vApplicationIdleHook() is permitted to return to its calling\r
146         function, because it is the responsibility of the idle task to clean up\r
147         memory allocated by the kernel to any task that has since been deleted. */\r
148 }\r
149 /*-----------------------------------------------------------*/\r
150 \r
151 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
152 {\r
153         ( void ) pcTaskName;\r
154         ( void ) pxTask;\r
155 \r
156         /* Run time stack overflow checking is performed if\r
157         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
158         function is called if a stack overflow is detected. */\r
159         taskDISABLE_INTERRUPTS();\r
160         for( ;; );\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 void *malloc( size_t xSize )\r
165 {\r
166         /* There should not be a heap defined, so trap any attempts to call\r
167         malloc. */\r
168         taskDISABLE_INTERRUPTS();\r
169         for( ;; );\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an\r
174 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is\r
175 used by the Idle task. */\r
176 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )\r
177 {\r
178 /* If the buffers to be provided to the Idle task are declared inside this\r
179 function then they must be declared static - otherwise they will be allocated on\r
180 the stack and so not exists after this function exits. */\r
181 static StaticTask_t xIdleTaskTCB;\r
182 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];\r
183 \r
184     /* Pass out a pointer to the StaticTask_t structure in which the Idle task's\r
185     state will be stored. */\r
186     *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;\r
187 \r
188     /* Pass out the array that will be used as the Idle task's stack. */\r
189     *ppxIdleTaskStackBuffer = uxIdleTaskStack;\r
190 \r
191     /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.\r
192     Note that, as the array is necessarily of type StackType_t,\r
193     configMINIMAL_STACK_SIZE is specified in words, not bytes. */\r
194     *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;\r
195 }\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the\r
199 application must provide an implementation of vApplicationGetTimerTaskMemory()\r
200 to provide the memory that is used by the Timer service task. */\r
201 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )\r
202 {\r
203 /* If the buffers to be provided to the Timer 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 xTimerTaskTCB;\r
207 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];\r
208 \r
209     /* Pass out a pointer to the StaticTask_t structure in which the Timer\r
210     task's state will be stored. */\r
211     *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;\r
212 \r
213     /* Pass out the array that will be used as the Timer task's stack. */\r
214     *ppxTimerTaskStackBuffer = uxTimerTaskStack;\r
215 \r
216     /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.\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     *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;\r
220 }\r
221 /*-----------------------------------------------------------*/\r
222 \r
223 /* Catch asserts so the file and line number of the assert can be viewed. */\r
224 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )\r
225 {\r
226 volatile BaseType_t xSetToNonZeroToStepOutOfLoop = 0;\r
227 \r
228     taskENTER_CRITICAL();\r
229     while( xSetToNonZeroToStepOutOfLoop == 0 )\r
230     {\r
231         /* Use the variables to prevent compiler warnings and in an attempt to\r
232         ensure they can be viewed in the debugger.  If the variables get\r
233         optimised away then set copy their values to file scope or globals then\r
234         view the variables they are copied to. */\r
235         ( void ) pcFileName;\r
236         ( void ) ulLineNumber;\r
237     }\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 /* To enable the libraries to build. */\r
242 void PowerCC32XX_enterLPDS( void *driverlibFunc )\r
243 {\r
244     ( void ) driverlibFunc;\r
245 \r
246     /* This function is not implemented so trap any calls to it by halting\r
247     here. */\r
248     configASSERT( driverlibFunc == NULL  );\r
249 }\r