]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_SimpleLink_CC3220SF_CCS/main.c
Add SimpleLink CC3220SF demo.
[freertos] / FreeRTOS / Demo / CORTEX_M4_SimpleLink_CC3220SF_CCS / main.c
1 /*
2     FreeRTOS V9.0.1 - Copyright (C) 2017 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /******************************************************************************
71  * This project provides two demo applications.  A simple blinky style project,
72  * and a more comprehensive test and demo application.  The
73  * configCREATE_SIMPLE_TICKLESS_DEMO setting (defined in FreeRTOSConfig.h) is
74  * used to select between the two.  The simply blinky demo is implemented and
75  * described in main_blinky.c.  The more comprehensive test and demo application
76  * is implemented and described in main_full.c.
77  *
78  * The blinky demo uses FreeRTOS's tickless idle mode to reduce power
79  * consumption.  See the notes on the web page below regarding the difference
80  * in power saving that can be achieved between using the generic tickless
81  * implementation (as used by the blinky demo) and a tickless implementation
82  * that is tailored specifically to the CC3220.
83  *
84  * This file implements the code that is not demo specific.
85  *
86  * See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for
87  * instructions.
88  *
89  */
90
91 /* Standard includes. */
92 #include <stdio.h>
93
94 /* TI includes. */
95 #include <ti/drivers/GPIO.h>
96 #include <ti/boards/CC3220SF_LAUNCHXL/Board.h>
97
98 /* Kernel includes. */
99 #include "FreeRTOS.h"
100 #include "task.h"
101
102 /*-----------------------------------------------------------*/
103
104 /*
105  * Set up the hardware ready to run this demo.
106  */
107 static void prvSetupHardware( void );
108
109 /*
110  * main_blinky() is used when configCREATE_SIMPLE_TICKLESS_DEMO is set to 1.
111  * main_full() is used when configCREATE_SIMPLE_TICKLESS_DEMO is set to 0.
112  */
113 extern void main_blinky( void );
114 extern void main_full( void );
115
116 /*-----------------------------------------------------------*/
117
118 int main( void )
119 {
120         /* See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for
121     instructions. */
122
123
124         /* Prepare the hardware to run this demo. */
125         prvSetupHardware();
126
127         /* The configCREATE_SIMPLE_TICKLESS_DEMO setting is described at the top
128         of this file. */
129         #if( configCREATE_SIMPLE_TICKLESS_DEMO == 1 )
130         {
131                 main_blinky();
132         }
133         #else
134         {
135                 main_full();
136         }
137         #endif
138
139         return 0;
140 }
141 /*-----------------------------------------------------------*/
142
143 static void prvSetupHardware( void )
144 {
145     /* Call board init functions */
146     Board_initGeneral();
147     Board_initGPIO();
148     GPIO_write( Board_LED0, Board_GPIO_LED_OFF );
149 }
150 /*-----------------------------------------------------------*/
151
152 void vMainToggleLED( void )
153 {
154 static uint32_t ulLEDState = Board_GPIO_LED_OFF;
155
156     ulLEDState = !ulLEDState;
157     GPIO_write( Board_LED0, ulLEDState );
158 }
159 /*-----------------------------------------------------------*/
160
161 void vApplicationMallocFailedHook( void )
162 {
163         /* vApplicationMallocFailedHook() will only be called if
164         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook
165         function that will get called if a call to pvPortMalloc() fails.
166         pvPortMalloc() is called internally by the kernel whenever a task, queue,
167         timer or semaphore is created.  It is also called by various parts of the
168         demo application.  If heap_1.c or heap_2.c are used, then the size of the
169         heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
170         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
171         to query the size of free heap space that remains (although it does not
172         provide information on how the remaining heap might be fragmented). */
173         taskDISABLE_INTERRUPTS();
174         for( ;; );
175 }
176 /*-----------------------------------------------------------*/
177
178 void vApplicationIdleHook( void )
179 {
180         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
181         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle
182         task.  It is essential that code added to this hook function never attempts
183         to block in any way (for example, call xQueueReceive() with a block time
184         specified, or call vTaskDelay()).  If the application makes use of the
185         vTaskDelete() API function (as this demo application does) then it is also
186         important that vApplicationIdleHook() is permitted to return to its calling
187         function, because it is the responsibility of the idle task to clean up
188         memory allocated by the kernel to any task that has since been deleted. */
189 }
190 /*-----------------------------------------------------------*/
191
192 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
193 {
194         ( void ) pcTaskName;
195         ( void ) pxTask;
196
197         /* Run time stack overflow checking is performed if
198         configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook
199         function is called if a stack overflow is detected. */
200         taskDISABLE_INTERRUPTS();
201         for( ;; );
202 }
203 /*-----------------------------------------------------------*/
204
205 void *malloc( size_t xSize )
206 {
207         /* There should not be a heap defined, so trap any attempts to call
208         malloc. */
209         taskDISABLE_INTERRUPTS();
210         for( ;; );
211 }
212 /*-----------------------------------------------------------*/
213
214 /* configUSE_STATIC_ALLOCATION is set to 1, so the application must provide an
215 implementation of vApplicationGetIdleTaskMemory() to provide the memory that is
216 used by the Idle task. */
217 void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
218 {
219 /* If the buffers to be provided to the Idle task are declared inside this
220 function then they must be declared static - otherwise they will be allocated on
221 the stack and so not exists after this function exits. */
222 static StaticTask_t xIdleTaskTCB;
223 static StackType_t uxIdleTaskStack[ configMINIMAL_STACK_SIZE ];
224
225     /* Pass out a pointer to the StaticTask_t structure in which the Idle task's
226     state will be stored. */
227     *ppxIdleTaskTCBBuffer = &xIdleTaskTCB;
228
229     /* Pass out the array that will be used as the Idle task's stack. */
230     *ppxIdleTaskStackBuffer = uxIdleTaskStack;
231
232     /* Pass out the size of the array pointed to by *ppxIdleTaskStackBuffer.
233     Note that, as the array is necessarily of type StackType_t,
234     configMINIMAL_STACK_SIZE is specified in words, not bytes. */
235     *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
236 }
237 /*-----------------------------------------------------------*/
238
239 /* configUSE_STATIC_ALLOCATION and configUSE_TIMERS are both set to 1, so the
240 application must provide an implementation of vApplicationGetTimerTaskMemory()
241 to provide the memory that is used by the Timer service task. */
242 void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )
243 {
244 /* If the buffers to be provided to the Timer task are declared inside this
245 function then they must be declared static - otherwise they will be allocated on
246 the stack and so not exists after this function exits. */
247 static StaticTask_t xTimerTaskTCB;
248 static StackType_t uxTimerTaskStack[ configTIMER_TASK_STACK_DEPTH ];
249
250     /* Pass out a pointer to the StaticTask_t structure in which the Timer
251     task's state will be stored. */
252     *ppxTimerTaskTCBBuffer = &xTimerTaskTCB;
253
254     /* Pass out the array that will be used as the Timer task's stack. */
255     *ppxTimerTaskStackBuffer = uxTimerTaskStack;
256
257     /* Pass out the size of the array pointed to by *ppxTimerTaskStackBuffer.
258     Note that, as the array is necessarily of type StackType_t,
259     configMINIMAL_STACK_SIZE is specified in words, not bytes. */
260     *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
261 }
262 /*-----------------------------------------------------------*/
263
264 /* Catch asserts so the file and line number of the assert can be viewed. */
265 void vMainAssertCalled( const char *pcFileName, uint32_t ulLineNumber )
266 {
267     taskENTER_CRITICAL();
268     for( ;; )
269     {
270         /* Use the variables to prevent compiler warnings and in an attempt to
271         ensure they can be viewed in the debugger.  If the variables get
272         optimised away then set copy their values to file scope or globals then
273         view the variables they are copied to. */
274         ( void ) pcFileName;
275         ( void ) ulLineNumber;
276     }
277 }
278 /*-----------------------------------------------------------*/
279
280 /* To enable the libraries to build. */
281 void PowerCC32XX_enterLPDS( void *driverlibFunc )
282 {
283     ( void ) driverlibFunc;
284
285     /* This function is not implemented so trap any calls to it by halting
286     here. */
287     configASSERT( driverlibFunc == NULL  );
288 }