2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\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
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\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
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
42 * This file implements the code that is not demo specific.
\r
44 * See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for
\r
49 /* Standard includes. */
\r
53 #include <ti/drivers/GPIO.h>
\r
54 #include <ti/boards/CC3220SF_LAUNCHXL/Board.h>
\r
56 /* Kernel includes. */
\r
57 #include "FreeRTOS.h"
\r
60 /*-----------------------------------------------------------*/
\r
63 * Set up the hardware ready to run this demo.
\r
65 static void prvSetupHardware( void );
\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
71 extern void main_blinky( void );
\r
72 extern void main_full( void );
\r
74 /*-----------------------------------------------------------*/
\r
78 /* See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for
\r
82 /* Prepare the hardware to run this demo. */
\r
85 /* The configCREATE_SIMPLE_TICKLESS_DEMO setting is described at the top
\r
87 #if( configCREATE_SIMPLE_TICKLESS_DEMO == 1 )
\r
99 /*-----------------------------------------------------------*/
\r
101 static void prvSetupHardware( void )
\r
103 /* Call board init functions */
\r
104 Board_initGeneral();
\r
106 GPIO_write( Board_LED0, Board_GPIO_LED_OFF );
\r
108 /*-----------------------------------------------------------*/
\r
110 void vMainToggleLED( void )
\r
112 static uint32_t ulLEDState = Board_GPIO_LED_OFF;
\r
114 ulLEDState = !ulLEDState;
\r
115 GPIO_write( Board_LED0, ulLEDState );
\r
117 /*-----------------------------------------------------------*/
\r
119 void vApplicationMallocFailedHook( void )
\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
134 /*-----------------------------------------------------------*/
\r
136 void vApplicationIdleHook( void )
\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
148 /*-----------------------------------------------------------*/
\r
150 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
152 ( void ) pcTaskName;
\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
161 /*-----------------------------------------------------------*/
\r
163 void *malloc( size_t xSize )
\r
165 /* There should not be a heap defined, so trap any attempts to call
\r
167 taskDISABLE_INTERRUPTS();
\r
170 /*-----------------------------------------------------------*/
\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
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
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
187 /* Pass out the array that will be used as the Idle task's stack. */
\r
188 *ppxIdleTaskStackBuffer = uxIdleTaskStack;
\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
195 /*-----------------------------------------------------------*/
\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
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
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
212 /* Pass out the array that will be used as the Timer task's stack. */
\r
213 *ppxTimerTaskStackBuffer = uxTimerTaskStack;
\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
220 /*-----------------------------------------------------------*/
\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
225 volatile BaseType_t xSetToNonZeroToStepOutOfLoop = 0;
\r
227 taskENTER_CRITICAL();
\r
228 while( xSetToNonZeroToStepOutOfLoop == 0 )
\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
238 /*-----------------------------------------------------------*/
\r
240 /* To enable the libraries to build. */
\r
241 void PowerCC32XX_enterLPDS( void *driverlibFunc )
\r
243 ( void ) driverlibFunc;
\r
245 /* This function is not implemented so trap any calls to it by halting
\r
247 configASSERT( driverlibFunc == NULL );
\r