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