]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4_SimpleLink_CC3220SF_CCS/Full_Demo/main_full.c
Update license information text files for the CLI, TCP and UDP products to be correct...
[freertos] / FreeRTOS / Demo / CORTEX_M4_SimpleLink_CC3220SF_CCS / Full_Demo / main_full.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 /******************************************************************************\r
31  * NOTE 1:  This project provides two demo applications.  A simple blinky\r
32  * style project, and a more comprehensive test and demo application.  The\r
33  * configCREATE_SIMPLE_TICKLESS_DEMO setting in FreeRTOSConfig.h is used to\r
34  * select between the two.  See the notes on using\r
35  * configCREATE_SIMPLY_BLINKY_DEMO_ONLY in main.c.  This file implements the\r
36  * comprehensive version.\r
37  *\r
38  * NOTE 2:  This file only contains the source code that is specific to the\r
39  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
40  * required to configure the hardware, are defined in main.c.\r
41  *\r
42  * See http://www.FreeRTOS.org/TI_CC3220_SimpleLink_FreeRTOS_Demo.html for\r
43  * instructions.\r
44  *\r
45  ******************************************************************************\r
46  *\r
47  * main_full() creates all the demo application tasks and software timers, then\r
48  * starts the scheduler.  The web documentation provides more details of the\r
49  * standard demo application tasks, which provide no particular functionality,\r
50  * but do provide a good example of how to use the FreeRTOS API.\r
51  *\r
52  * In addition to the standard demo tasks, the following tasks and tests are\r
53  * defined and/or created within this file:\r
54  *\r
55  * "Reg test" tasks - These fill the core registers with known values, then\r
56  * check that each register maintains its expected value for the lifetime of the\r
57  * task.  Each task uses a different set of values.  The reg test tasks execute\r
58  * with a very low priority, so get preempted very frequently.  A register\r
59  * containing an unexpected value is indicative of an error in the context\r
60  * switching mechanism.\r
61  *\r
62  * "Check" task - The check task period is initially set to three seconds.  The\r
63  * task checks that all the standard demo tasks, and the register check tasks,\r
64  * are not only still executing, but are executing without reporting any errors.\r
65  * If the check task discovers that a task has either stalled, or reported an\r
66  * error, then it changes its own execution period from the initial three\r
67  * seconds, to just 200ms.  The check task also toggles an LED each time it is\r
68  * called.  This provides a visual indication of the system status:  If the LED\r
69  * toggles every three seconds, then no issues have been discovered.  If the LED\r
70  * toggles every 200ms, then an issue has been discovered with at least one\r
71  * task.\r
72  */\r
73 \r
74 /* Standard includes. */\r
75 #include <stdio.h>\r
76 \r
77 /* Kernel includes. */\r
78 #include "FreeRTOS.h"\r
79 #include "task.h"\r
80 #include "timers.h"\r
81 #include "semphr.h"\r
82 \r
83 /* Standard demo application includes. */\r
84 #include "semtest.h"\r
85 #include "countsem.h"\r
86 #include "GenQTest.h"\r
87 #include "recmutex.h"\r
88 #include "partest.h"\r
89 #include "TimerDemo.h"\r
90 #include "EventGroupsDemo.h"\r
91 #include "TaskNotify.h"\r
92 #include "IntSemTest.h"\r
93 #include "StaticAllocation.h"\r
94 #include "StreamBufferDemo.h"\r
95 #include "MessageBufferDemo.h"\r
96 \r
97 /* Priorities for the demo application tasks. */\r
98 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
99 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
100 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
101 #define mainUART_COMMAND_CONSOLE_STACK_SIZE     ( configMINIMAL_STACK_SIZE * 2UL )\r
102 #define mainCOM_TEST_TASK_PRIORITY                      ( tskIDLE_PRIORITY + 2 )\r
103 #define mainCHECK_TASK_PRIORITY                         ( configMAX_PRIORITIES - 1 )\r
104 #define mainQUEUE_OVERWRITE_PRIORITY            ( tskIDLE_PRIORITY )\r
105 \r
106 /* The priority used by the UART command console task. */\r
107 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY  ( configMAX_PRIORITIES - 2 )\r
108 \r
109 /* A block time of zero simply means "don't block". */\r
110 #define mainDONT_BLOCK                                          ( 0UL )\r
111 \r
112 /* The period of the check task, in ms, provided no errors have been reported by\r
113 any of the standard demo tasks.  ms are converted to the equivalent in ticks\r
114 using the pdMS_TO_TICKS() macro constant. */\r
115 #define mainNO_ERROR_CHECK_TASK_PERIOD          ( pdMS_TO_TICKS( 3000UL ) )\r
116 \r
117 /* The period of the check task, in ms, if an error has been reported in one of\r
118 the standard demo tasks.  ms are converted to the equivalent in ticks using the\r
119 pdMS_TO_TICKS() macro. */\r
120 #define mainERROR_CHECK_TASK_PERIOD             ( pdMS_TO_TICKS( 200UL ) )\r
121 \r
122 /* Parameters that are passed into the register check tasks solely for the\r
123 purpose of ensuring parameters are passed into tasks correctly. */\r
124 #define mainREG_TEST_TASK_1_PARAMETER           ( ( void * ) 0x12345678 )\r
125 #define mainREG_TEST_TASK_2_PARAMETER           ( ( void * ) 0x87654321 )\r
126 \r
127 /* The base period used by the timer test tasks. */\r
128 #define mainTIMER_TEST_PERIOD                           ( 50 )\r
129 \r
130 /*-----------------------------------------------------------*/\r
131 \r
132 \r
133 /*\r
134  * The check task, as described at the top of this file.\r
135  */\r
136 static void prvCheckTask( void *pvParameters );\r
137 \r
138 /*\r
139  * Register check tasks, and the tasks used to write over and check the contents\r
140  * of the FPU registers, as described at the top of this file.  The nature of\r
141  * these files necessitates that they are written in an assembly file, but the\r
142  * entry points are kept in the C file for the convenience of checking the task\r
143  * parameter.\r
144  */\r
145 static void prvRegTestTaskEntry1( void *pvParameters );\r
146 extern void vRegTest1Implementation( void );\r
147 static void prvRegTestTaskEntry2( void *pvParameters );\r
148 extern void vRegTest2Implementation( void );\r
149 \r
150 /*\r
151  * Register commands that can be used with FreeRTOS+CLI.  The commands are\r
152  * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.\r
153  */\r
154 extern void vRegisterSampleCLICommands( void );\r
155 \r
156 /*\r
157  * The task that manages the FreeRTOS+CLI input and output.\r
158  */\r
159 extern void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );\r
160 \r
161 /*\r
162  * When the full demo is build the idle hook is used to create some timers that\r
163  * cannot be created in main() because the timer demo tasks need the entire\r
164  * command queue.\r
165  */\r
166 void vFullDemoIdleHook( void );\r
167 \r
168 /*\r
169  * Toggles the LED built onto the Launchpad hardware.\r
170  */\r
171 extern void vMainToggleLED( void );\r
172 \r
173 /*-----------------------------------------------------------*/\r
174 \r
175 /* The following two variables are used to communicate the status of the\r
176 register check tasks to the check task.  If the variables keep incrementing,\r
177 then the register check tasks have not discovered any errors.  If a variable\r
178 stops incrementing, then an error has been found. */\r
179 volatile unsigned long ulRegTest1LoopCounter = 0UL, ulRegTest2LoopCounter = 0UL;\r
180 \r
181 /*-----------------------------------------------------------*/\r
182 \r
183 void main_full( void )\r
184 {\r
185         vStartStaticallyAllocatedTasks();\r
186         vStartCountingSemaphoreTasks();\r
187         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
188         vStartRecursiveMutexTasks();\r
189         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
190         vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
191         vStartEventGroupTasks();\r
192         vStartTaskNotifyTask();\r
193         vStartInterruptSemaphoreTasks();\r
194         vStartStreamBufferTasks();\r
195         vStartMessageBufferTasks();\r
196 \r
197         /* Create the register check tasks, as described at the top of this     file */\r
198         xTaskCreate( prvRegTestTaskEntry1, "Reg1", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
199         xTaskCreate( prvRegTestTaskEntry2, "Reg2", configMINIMAL_STACK_SIZE, mainREG_TEST_TASK_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
200 \r
201         /* Create the task that performs the 'check' functionality,     as described at\r
202         the top of this file. */\r
203         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
204 \r
205         /* Start the scheduler. */\r
206         vTaskStartScheduler();\r
207 \r
208         /* If all is well, the scheduler will now be running, and the following\r
209         line will never be reached.  If the following line does execute, then\r
210         there was insufficient FreeRTOS heap memory available for the Idle and/or\r
211         timer tasks to be created.  See the memory management section on the\r
212         FreeRTOS web site for more details on the FreeRTOS heap\r
213         http://www.freertos.org/a00111.html. */\r
214         for( ;; );\r
215 }\r
216 /*-----------------------------------------------------------*/\r
217 \r
218 static void prvCheckTask( void *pvParameters )\r
219 {\r
220 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_TASK_PERIOD;\r
221 TickType_t xLastExecutionTime;\r
222 static unsigned long ulLastRegTest1Value = 0, ulLastRegTest2Value = 0;\r
223 unsigned long ulErrorFound = pdFALSE;\r
224 \r
225         /* Just to stop compiler warnings. */\r
226         ( void ) pvParameters;\r
227 \r
228         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()\r
229         works correctly. */\r
230         xLastExecutionTime = xTaskGetTickCount();\r
231 \r
232         /* Cycle for ever, delaying then checking all the other tasks are still\r
233         operating without error.  The onboard LED is toggled on each iteration.\r
234         If an error is detected then the delay period is decreased from\r
235         mainNO_ERROR_CHECK_TASK_PERIOD to mainERROR_CHECK_TASK_PERIOD.  This has the\r
236         effect of increasing the rate at which the onboard LED toggles, and in so\r
237         doing gives visual feedback of the system status. */\r
238         for( ;; )\r
239         {\r
240                 /* Delay until it is time to execute again. */\r
241                 vTaskDelayUntil( &xLastExecutionTime, xDelayPeriod );\r
242 \r
243                 /* Check all the demo tasks to ensure that they are all still running,\r
244                 and that none have detected an error. */\r
245                 if( xAreStaticAllocationTasksStillRunning() != pdTRUE )\r
246                 {\r
247                     ulErrorFound |= 1UL << 0UL;\r
248                 }\r
249 \r
250                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
251                 {\r
252                         ulErrorFound |= 1UL << 5UL;\r
253                 }\r
254 \r
255                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
256                 {\r
257                         ulErrorFound |= 1UL << 6UL;\r
258                 }\r
259 \r
260                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
261                 {\r
262                         ulErrorFound |= 1UL << 8UL;\r
263                 }\r
264 \r
265                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
266                 {\r
267                         ulErrorFound |= 1UL << 10UL;\r
268                 }\r
269 \r
270                 if( xAreInterruptSemaphoreTasksStillRunning() != pdTRUE )\r
271                 {\r
272                         ulErrorFound |= 1UL << 14UL;\r
273                 }\r
274 \r
275                 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) mainNO_ERROR_CHECK_TASK_PERIOD ) != pdPASS )\r
276                 {\r
277                         ulErrorFound |= 1UL << 9UL;\r
278                 }\r
279 \r
280                 if( xAreEventGroupTasksStillRunning() != pdPASS )\r
281                 {\r
282                         ulErrorFound |= 1UL << 12UL;\r
283                 }\r
284 \r
285                 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
286                 {\r
287                         ulErrorFound |= 1UL << 13UL;\r
288                 }\r
289 \r
290                 if( xAreStreamBufferTasksStillRunning() != pdTRUE )\r
291                 {\r
292                         ulErrorFound |= 1UL << 14UL;\r
293                 }\r
294 \r
295                 if( xAreMessageBufferTasksStillRunning() != pdTRUE )\r
296                 {\r
297                         ulErrorFound |= 1UL << 15UL;\r
298                 }\r
299 \r
300                 /* Check that the register test 1 task is still running. */\r
301                 if( ulLastRegTest1Value == ulRegTest1LoopCounter )\r
302                 {\r
303                         ulErrorFound |= 1UL << 16UL;\r
304                 }\r
305                 ulLastRegTest1Value = ulRegTest1LoopCounter;\r
306 \r
307                 /* Check that the register test 2 task is still running. */\r
308                 if( ulLastRegTest2Value == ulRegTest2LoopCounter )\r
309                 {\r
310                         ulErrorFound |= 1UL << 17UL;\r
311                 }\r
312                 ulLastRegTest2Value = ulRegTest2LoopCounter;\r
313 \r
314                 /* Toggle the check LED to give an indication of the system status.  If\r
315                 the LED toggles every mainNO_ERROR_CHECK_TASK_PERIOD milliseconds then\r
316                 everything is ok.  A faster toggle indicates an error. */\r
317                 vMainToggleLED();\r
318 \r
319                 if( ulErrorFound != pdFALSE )\r
320                 {\r
321                         /* An error has been detected in one of the tasks - flash the LED\r
322                         at a higher frequency to give visible feedback that something has\r
323                         gone wrong (it might just be that the loop back connector required\r
324                         by the comtest tasks has not been fitted). */\r
325                         xDelayPeriod = mainERROR_CHECK_TASK_PERIOD;\r
326                 }\r
327         }\r
328 }\r
329 /*-----------------------------------------------------------*/\r
330 \r
331 static void prvRegTestTaskEntry1( void *pvParameters )\r
332 {\r
333         /* Although the regtest task is written in assembler, its entry point is\r
334         written in C for convenience of checking the task parameter is being passed\r
335         in correctly. */\r
336         if( pvParameters == mainREG_TEST_TASK_1_PARAMETER )\r
337         {\r
338                 /* Start the part of the test that is written in assembler. */\r
339                 vRegTest1Implementation();\r
340         }\r
341 \r
342         /* The following line will only execute if the task parameter is found to\r
343         be incorrect.  The check task will detect that the regtest loop counter is\r
344         not being incremented and flag an error. */\r
345         vTaskDelete( NULL );\r
346 }\r
347 /*-----------------------------------------------------------*/\r
348 \r
349 static void prvRegTestTaskEntry2( void *pvParameters )\r
350 {\r
351         /* Although the regtest task is written in assembler, its entry point is\r
352         written in C for convenience of checking the task parameter is being passed\r
353         in correctly. */\r
354         if( pvParameters == mainREG_TEST_TASK_2_PARAMETER )\r
355         {\r
356                 /* Start the part of the test that is written in assembler. */\r
357                 vRegTest2Implementation();\r
358         }\r
359 \r
360         /* The following line will only execute if the task parameter is found to\r
361         be incorrect.  The check task will detect that the regtest loop counter is\r
362         not being incremented and flag an error. */\r
363         vTaskDelete( NULL );\r
364 }\r
365 /*-----------------------------------------------------------*/\r
366 \r
367 #if( configCREATE_SIMPLE_TICKLESS_DEMO == 0 )\r
368 \r
369         void vApplicationTickHook( void )\r
370         {\r
371                 /* This function will be called by each tick interrupt if\r
372                 configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be\r
373                 added here, but the tick hook is called from an interrupt context, so\r
374                 code must not attempt to block, and only the interrupt safe FreeRTOS API\r
375                 functions can be used (those that end in FromISR()). */\r
376 \r
377                 /* The full demo includes a software timer demo/test that requires\r
378                 prodding periodically from the tick interrupt. */\r
379                 vTimerPeriodicISRTests();\r
380 \r
381                 /* Call the periodic event group from ISR demo. */\r
382                 vPeriodicEventGroupsProcessing();\r
383 \r
384                 /* Use task notifications from an interrupt. */\r
385                 xNotifyTaskFromISR();\r
386 \r
387                 /* Use mutexes from interrupts. */\r
388                 vInterruptSemaphorePeriodicTest();\r
389 \r
390                 /* Writes to stream buffer byte by byte to test the stream buffer trigger\r
391                 level functionality. */\r
392                 vPeriodicStreamBufferProcessing();\r
393         }\r
394 \r
395 #endif\r
396 /*-----------------------------------------------------------*/\r
397 \r
398 \r
399 \r
400 \r
401 \r