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