]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R4_RM48_TMS570_CCS5/main_full.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / CORTEX_R4_RM48_TMS570_CCS5 / main_full.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /******************************************************************************\r
71  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
72  * project, and a more comprehensive test and demo application.  The\r
73  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
74  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
75  * in main.c.  This file implements the comprehensive test and demo version.\r
76  *\r
77  * NOTE 2:  This file only contains the source code that is specific to the\r
78  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
79  * required to configure the hardware, are defined in main.c.\r
80  ******************************************************************************\r
81  *\r
82  * main_full() creates all the demo application tasks and software timers,\r
83  * then starts the scheduler.  The web documentation provides more details of\r
84  * the standard demo application tasks, which provide no particular\r
85  * functionality, but do provide a good example of how to use the FreeRTOS API.\r
86  *\r
87  * In addition to the standard demo tasks, the following tasks and tests are\r
88  * defined and/or created within this file:\r
89  *\r
90  * "Check" timer - The check software timer period is set to three seconds.\r
91  * The callback function associated with the check software timer checks that\r
92  * all the standard demo tasks are not only still executing, but are executing\r
93  * without reporting any errors.  If the check software timer discovers that a\r
94  * task has either stalled, or reported an error, then the error is logged and\r
95  * the check software timer toggles the red LEDs.  If an error has never been\r
96  * latched, the check software timer toggles the green LEDs.  Therefore, if the\r
97  * system is executing correctly, the green LEDs will toggle every three\r
98  * seconds, and if an error has ever been detected, the red LEDs will toggle\r
99  * every three seconds.\r
100  *\r
101  * "Reg test" tasks - These fill both the core and floating point registers\r
102  * with known values, then check that each register maintains its expected\r
103  * value for the lifetime of the tasks.  Each task uses a different set of\r
104  * values.  The reg test tasks execute with a very low priority, so get\r
105  * preempted very frequently.  A register containing an unexpected value is\r
106  * indicative of an error in the context switching mechanism.\r
107  *\r
108  * "LED" software timer - The callback function associated with the LED\r
109  * software time maintains a pattern of spinning white LEDs.\r
110  *\r
111  * See the documentation page for this demo on the FreeRTOS.org web site for\r
112  * full information, including hardware setup requirements.\r
113  */\r
114 \r
115 /* Standard includes. */\r
116 #include <stdio.h>\r
117 \r
118 /* Kernel includes. */\r
119 #include "FreeRTOS.h"\r
120 #include "task.h"\r
121 #include "timers.h"\r
122 #include "semphr.h"\r
123 \r
124 /* Standard demo application includes. */\r
125 #include "integer.h"\r
126 #include "PollQ.h"\r
127 #include "semtest.h"\r
128 #include "dynamic.h"\r
129 #include "BlockQ.h"\r
130 #include "blocktim.h"\r
131 #include "countsem.h"\r
132 #include "GenQTest.h"\r
133 #include "recmutex.h"\r
134 #include "death.h"\r
135 #include "partest.h"\r
136 #include "flop.h"\r
137 #include "serial.h"\r
138 #include "comtest.h"\r
139 \r
140 /* Priorities for the demo application tasks. */\r
141 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
142 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
143 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
144 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
145 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
146 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
147 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
148 \r
149 /* A block time of zero simply means "don't block". */\r
150 #define mainDONT_BLOCK                                          ( 0UL )\r
151 \r
152 /* The period after which the check timer will expire, converted to ticks. */\r
153 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
154 \r
155 /* The period after which the LED timer will expire, converted to ticks. */\r
156 #define mainLED_TIMER_PERIOD_MS                         ( 75UL / portTICK_PERIOD_MS )\r
157 \r
158 /* Constants for the ComTest tasks. */\r
159 #define mainCOM_TEST_BAUD_RATE                          ( ( unsigned long ) 19200 )\r
160 #define mainCOM_TEST_LED                                        ( 100 )\r
161 \r
162 /*-----------------------------------------------------------*/\r
163 \r
164 /*\r
165  * The check timer callback function, as described at the top of this file.\r
166  */\r
167 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
168 \r
169 /*\r
170  * The LED timer callback function, as described at the top of this file.\r
171  */\r
172 static void prvLEDTimerCallback( TimerHandle_t xTimer );\r
173 \r
174 /*\r
175  * The reg test tasks, as described at the top of this file.\r
176  */\r
177 extern void vRegTestTask1( void *pvParameters );\r
178 extern void vRegTestTask2( void *pvParameters );\r
179 \r
180 /*-----------------------------------------------------------*/\r
181 \r
182 /* Variables that are incremented on each iteration of the reg test tasks -\r
183 provided the tasks have not reported any errors.  The check task inspects these\r
184 variables to ensure they are still incrementing as expected.  If a variable\r
185 stops incrementing then it is likely that its associate task has stalled. */\r
186 volatile unsigned long ulRegTest1Counter = 0, ulRegTest2Counter = 0;\r
187 \r
188 /*-----------------------------------------------------------*/\r
189 \r
190 void main_full( void )\r
191 {\r
192 TimerHandle_t xTimer = NULL;\r
193 \r
194         /* Start all the standard demo/test tasks.  These have not particular\r
195         functionality, but do demonstrate how to use the FreeRTOS API, and test the\r
196         kernel port. */\r
197         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
198         vStartDynamicPriorityTasks();\r
199         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
200         vCreateBlockTimeTasks();\r
201         vStartCountingSemaphoreTasks();\r
202         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
203         vStartRecursiveMutexTasks();\r
204         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
205         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
206         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
207         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
208 \r
209         /* Create the register test tasks, as described at the top of this file. */\r
210         xTaskCreate( vRegTestTask1, "Reg1...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
211         xTaskCreate( vRegTestTask2, "Reg2...", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
212 \r
213 \r
214         /* Create the software timer that performs the 'check' functionality,\r
215         as described at the top of this file. */\r
216         xTimer = xTimerCreate( "CheckTimer",                                    /* A text name, purely to help debugging. */\r
217                                                         ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
218                                                         pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
219                                                         ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
220                                                         prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
221                                                  );\r
222 \r
223         if( xTimer != NULL )\r
224         {\r
225                 xTimerStart( xTimer, mainDONT_BLOCK );\r
226         }\r
227 \r
228         /* Create the software timer that performs the 'LED spin' functionality,\r
229         as described at the top of this file. */\r
230         xTimer = xTimerCreate( "LEDTimer",                                      /* A text name, purely to help debugging. */\r
231                                                         ( mainLED_TIMER_PERIOD_MS ),/* The timer period, in this case 75ms. */\r
232                                                         pdTRUE,                                         /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
233                                                         ( void * ) 0,                           /* The ID is not used, so can be set to anything. */\r
234                                                         prvLEDTimerCallback                     /* The callback function that toggles the white LEDs. */\r
235                                                  );\r
236 \r
237         if( xTimer != NULL )\r
238         {\r
239                 xTimerStart( xTimer, mainDONT_BLOCK );\r
240         }\r
241 \r
242         /* The set of tasks created by the following function call have to be\r
243         created last as they keep account of the number of tasks they expect to see\r
244         running. */\r
245         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
246 \r
247         /* Start the scheduler. */\r
248         vTaskStartScheduler();\r
249 \r
250         /* If all is well, the scheduler will now be running, and the following line\r
251         will never be reached.  If the following line does execute, then there was\r
252         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
253         to be created.  See the memory management section on the FreeRTOS web site\r
254         for more details. */\r
255         for( ;; );\r
256 }\r
257 /*-----------------------------------------------------------*/\r
258 \r
259 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
260 {\r
261 static long lChangeToRedLEDsAlready = pdFALSE;\r
262 static unsigned long ulLastRegTest1Counter = 0, ulLastRegTest2Counter = 0;\r
263 unsigned long ulErrorFound = pdFALSE;\r
264 /* LEDs are defaulted to use the Green LEDs.  The Red LEDs are used if an error\r
265 is found. */\r
266 static unsigned long ulLED1 = 8, ulLED2 = 11;\r
267 const unsigned long ulRedLED1 = 6, ulRedLED2 = 9;\r
268 \r
269         /* Check all the demo tasks (other than the flash tasks) to ensure\r
270         they are all still running, and that none have detected an error. */\r
271 \r
272         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
273         {\r
274                 ulErrorFound = pdTRUE;\r
275         }\r
276 \r
277         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
278         {\r
279                 ulErrorFound = pdTRUE;\r
280         }\r
281 \r
282         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
283         {\r
284                 ulErrorFound = pdTRUE;\r
285         }\r
286 \r
287         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
288         {\r
289                 ulErrorFound = pdTRUE;\r
290         }\r
291 \r
292         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
293         {\r
294                 ulErrorFound = pdTRUE;\r
295         }\r
296 \r
297         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
298         {\r
299                 ulErrorFound = pdTRUE;\r
300         }\r
301 \r
302         if( xIsCreateTaskStillRunning() != pdTRUE )\r
303         {\r
304                 ulErrorFound = pdTRUE;\r
305         }\r
306 \r
307         if( xArePollingQueuesStillRunning() != pdTRUE )\r
308         {\r
309                 ulErrorFound = pdTRUE;\r
310         }\r
311 \r
312         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
313         {\r
314                 ulErrorFound = pdTRUE;\r
315         }\r
316 \r
317         if( xAreMathsTaskStillRunning() != pdTRUE )\r
318         {\r
319                 ulErrorFound = pdTRUE;\r
320         }\r
321 \r
322         if( xAreComTestTasksStillRunning() != pdTRUE )\r
323         {\r
324                 ulErrorFound = pdTRUE;\r
325         }\r
326 \r
327         /* Check the reg test tasks are still cycling.  They will stop\r
328         incrementing their loop counters if they encounter an error. */\r
329         if( ulRegTest1Counter == ulLastRegTest1Counter )\r
330         {\r
331                 ulErrorFound = pdTRUE;\r
332         }\r
333 \r
334         if( ulRegTest2Counter == ulLastRegTest2Counter )\r
335         {\r
336                 ulErrorFound = pdTRUE;\r
337         }\r
338 \r
339         ulLastRegTest1Counter = ulRegTest1Counter;\r
340         ulLastRegTest2Counter = ulRegTest2Counter;\r
341 \r
342         /* Toggle the check LEDs to give an indication of the system status.  If\r
343         the green LEDs are toggling, then no errors have been detected.  If the red\r
344         LEDs are toggling, then an error has been reported in at least one task. */\r
345         vParTestToggleLED( ulLED1 );\r
346         vParTestToggleLED( ulLED2 );\r
347 \r
348         /* Have any errors been latch in ulErrorFound?  If so, ensure the gree LEDs\r
349         are off, then switch to using the red LEDs. */\r
350         if( ulErrorFound != pdFALSE )\r
351         {\r
352                 if( lChangeToRedLEDsAlready == pdFALSE )\r
353                 {\r
354                         lChangeToRedLEDsAlready = pdTRUE;\r
355 \r
356                         /* An error has been found.  Switch to use the red LEDs. */\r
357                         vParTestSetLED( ulLED1, pdFALSE );\r
358                         vParTestSetLED( ulLED2, pdFALSE );\r
359                         ulLED1 = ulRedLED1;\r
360                         ulLED2 = ulRedLED2;\r
361                 }\r
362         }\r
363 }\r
364 /*-----------------------------------------------------------*/\r
365 \r
366 static void prvLEDTimerCallback( TimerHandle_t xTimer )\r
367 {\r
368 const unsigned long ulNumWhiteLEDs = 6;\r
369 static unsigned long ulLit1 = 2, ulLit2 = 1;\r
370 \r
371         vParTestSetLED( ulLit2, pdFALSE );\r
372 \r
373         ulLit2 = ulLit1;\r
374         ulLit1++;\r
375 \r
376         if( ulLit1 >= ulNumWhiteLEDs )\r
377         {\r
378                 ulLit1 = 0;\r
379         }\r
380 \r
381         vParTestSetLED( ulLit1, pdTRUE );\r
382 }\r
383 /*-----------------------------------------------------------*/\r
384 \r