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