]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/IA32_flat_GCC_Galileo_Gen_2/Full_Demo/main_full.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / IA32_flat_GCC_Galileo_Gen_2 / Full_Demo / 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  *\r
83  * See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage\r
84  * instructions.\r
85  *\r
86  * main_full() creates all the demo application tasks and software timers, then\r
87  * starts the scheduler.  The web documentation provides more details of the\r
88  * standard demo application tasks, which provide no particular functionality,\r
89  * but do provide a good example of how to use the FreeRTOS API.\r
90  *\r
91  * In addition to the standard demo tasks, the following tasks and tests are\r
92  * defined and/or created within this file:\r
93  *\r
94  * "Reg test" tasks - These fill both the core and floating point registers with\r
95  * known values, then check that each register maintains its expected value for\r
96  * the lifetime of the task.  Each task uses a different set of values.  The reg\r
97  * test tasks execute with a very low priority, so get preempted very\r
98  * frequently.  A register containing an unexpected value is indicative of an\r
99  * error in the context switching mechanism.\r
100  *\r
101  * "Check" task - The check task period is set to five seconds.  The task checks\r
102  * that all the standard demo tasks, and the register check tasks, are not only\r
103  * still executing, but are executing without reporting any errors.  The check\r
104  * task toggles an LED on each iteration.  If the LED toggles every 5 seconds\r
105  * then no errors have been found.  If the LED toggles every 1 second then a\r
106  * potential error has been detected.\r
107  */\r
108 \r
109 /* Standard includes. */\r
110 #include <stdio.h>\r
111 #include <stdlib.h>\r
112 #include <string.h>\r
113 #include <stdint.h>\r
114 \r
115 /* FreeRTOS includes. */\r
116 #include "FreeRTOS.h"\r
117 #include "task.h"\r
118 #include "timers.h"\r
119 \r
120 /* Standard demo includes. */\r
121 #include "blocktim.h"\r
122 #include "flash_timer.h"\r
123 #include "semtest.h"\r
124 #include "GenQTest.h"\r
125 #include "QPeek.h"\r
126 #include "countsem.h"\r
127 #include "dynamic.h"\r
128 #include "QueueOverwrite.h"\r
129 #include "QueueSet.h"\r
130 #include "recmutex.h"\r
131 #include "EventGroupsDemo.h"\r
132 #include "death.h"\r
133 #include "TimerDemo.h"\r
134 #include "BlockQ.h"\r
135 #include "flop.h"\r
136 #include "TaskNotify.h"\r
137 #include "IntQueue.h"\r
138 \r
139 /* Galileo includes. */\r
140 #include "galileo_support.h"\r
141 \r
142 /* The rate at which the check task cycles if no errors have been detected, and\r
143 if a [potential] error has been detected.  Increasing the toggle rate in the\r
144 presense of an error gives visual feedback of the system status. */\r
145 #define mainNO_ERROR_CHECK_TASK_PERIOD          pdMS_TO_TICKS( 5000UL )\r
146 #define mainERROR_CHECK_TASK_PERIOD                     pdMS_TO_TICKS( 1000UL )\r
147 \r
148 /* The priorities of the various demo application tasks. */\r
149 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
150 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
151 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
152 #define mainQUEUE_OVERWRITE_TASK_PRIORITY       ( tskIDLE_PRIORITY )\r
153 #define mainMATHS_TASK_PRIORITY                         ( tskIDLE_PRIORITY )\r
154 \r
155 /* The base period used by the timer test tasks. */\r
156 #define mainTIMER_TEST_PERIOD                           ( 50 )\r
157 \r
158 /* Parameters that are passed into the check tasks for no other purpose other\r
159 than to check the port does this correctly. */\r
160 #define mainREG_TEST_1_PARAMETER                        ( 0x12345678UL )\r
161 #define mainREG_TEST_2_PARAMETER                        ( 0x87654321UL )\r
162 \r
163 /*-----------------------------------------------------------*/\r
164 \r
165 /*\r
166  * The function that implements the check task, as described at the top of this\r
167  * file.\r
168  */\r
169 static void prvCheckTask( void *pvParameters );\r
170 \r
171 /*\r
172  * Entry points for the register check tasks, as described at the top of this\r
173  * file.\r
174  */\r
175 static void prvRegTest1Entry( void *pvParameters );\r
176 static void prvRegTest2Entry( void *pvParameters );\r
177 \r
178 /*\r
179  * The implementation of the register check tasks, which are implemented in\r
180  * RegTest.S.  These functions are called by prvRegTest1Entry() and\r
181  * prvRegTest2Entry() respectively.\r
182  */\r
183 extern void vRegTest1( void );\r
184 extern void vRegTest2( void );\r
185 \r
186 /*-----------------------------------------------------------*/\r
187 \r
188 /* Constants used by the register check tasks when checking the FPU registers. */\r
189 const double dRegTest1_st7 = 7.0, dRegTest1_st6 = 6.0, dRegTest1_st5 = 5.0, dRegTest1_st4 = 4.0, dRegTest1_st3 = 3.0, dRegTest1_st2 = 2.0, dRegTest1_st1 = 1.0;\r
190 const double dRegTest2_st7 = 700.0, dRegTest2_st6 = 600.0, dRegTest2_st5 = 500.0, dRegTest2_st4 = 400.0, dRegTest2_st3 = 300.0, dRegTest2_st2 = 200.0, dRegTest2_st1 = 100.0;\r
191 \r
192 /* Counters used by the register check tasks to indicate that they are still\r
193 executing without having discovered any errors. */\r
194 volatile uint32_t ulRegTest1Counter, ulRegTest2Counter;\r
195 volatile uint32_t ulCheckLoops = 0;\r
196 \r
197 /*-----------------------------------------------------------*/\r
198 \r
199 /* See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage\r
200 instructions. */\r
201 void main_full( void )\r
202 {\r
203         /* Create all the other standard demo tasks. */\r
204         vCreateBlockTimeTasks();\r
205         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
206         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
207         vStartQueuePeekTasks();\r
208         vStartCountingSemaphoreTasks();\r
209         vStartDynamicPriorityTasks();\r
210         vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );\r
211         vStartQueueSetTasks();\r
212         vStartRecursiveMutexTasks();\r
213         vStartEventGroupTasks();\r
214         vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
215         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
216         vStartTaskNotifyTask();\r
217         vStartInterruptQueueTasks();\r
218 \r
219         #if configSUPPORT_FPU == 1\r
220         {\r
221                 vStartMathTasks( mainMATHS_TASK_PRIORITY );\r
222         }\r
223         #endif /* configSUPPORT_FPU */\r
224 \r
225         /* Create the 'check' task, as described at the top of this file. */\r
226         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 1, NULL );\r
227 \r
228         /* Create the register test tasks, as described at the top of this file. */\r
229         xTaskCreate( prvRegTest1Entry, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
230         xTaskCreate( prvRegTest2Entry, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
231 \r
232         /* Death tasks must be created last as they check the number of tasks\r
233         running against the number of tasks expected to be running as part of their\r
234         sanity checks. */\r
235         vCreateSuicidalTasks( tskIDLE_PRIORITY );\r
236 \r
237         /* Display HPET Information (Disable in HPET.H). */\r
238         vCreateHPETInfoUpdateTask();\r
239 \r
240         /* Start the scheduler itself. */\r
241         vTaskStartScheduler();\r
242 \r
243         /* If all is well, the scheduler will now be running, and the following line\r
244         will never be reached.  If the following line does execute, then there was\r
245         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
246         to be created.  See the memory management section on the FreeRTOS web site\r
247         for more details. */\r
248         for( ;; );\r
249 }\r
250 /*-----------------------------------------------------------*/\r
251 \r
252 static void prvRegTest1Entry( void *pvParameters )\r
253 {\r
254         /* Remove compiler warning if configASSERT() is not defined. */\r
255         ( void ) pvParameters;\r
256 \r
257         /* Check the parameter is passed in correctly. */\r
258         configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_1_PARAMETER );\r
259 \r
260         /* Tell FreeRTOS that this task needs a floating point context. */\r
261         portTASK_USES_FLOATING_POINT();\r
262 \r
263         /* Call the assembly file routine that performs the 'reg test' functionality\r
264         as described at the top of this file. */\r
265         vRegTest1();\r
266 }\r
267 /*-----------------------------------------------------------*/\r
268 \r
269 static void prvRegTest2Entry( void *pvParameters )\r
270 {\r
271         /* Remove compiler warning if configASSERT() is not defined. */\r
272         ( void ) pvParameters;\r
273 \r
274         /* Check the parameter is passed in correctly. */\r
275         configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_2_PARAMETER );\r
276 \r
277         /* Tell FreeRTOS that this task needs a floating point context. */\r
278         portTASK_USES_FLOATING_POINT();\r
279 \r
280         /* Call the assembly file routine that performs the 'reg test' functionality\r
281         as described at the top of this file. */\r
282         vRegTest2();\r
283 }\r
284 /*-----------------------------------------------------------*/\r
285 \r
286 static void prvCheckTask( void *pvParameters )\r
287 {\r
288 uint32_t ulLastRegTest1Counter = 0UL, ulLastRegTest2Counter = 0UL;\r
289 uint32_t ulErrorOccurred, ulElapsedTimeInSeconds = 0UL;\r
290 TickType_t xLastExpireTime, xBlockTime = mainNO_ERROR_CHECK_TASK_PERIOD;\r
291 BaseType_t xErrorFlag = pdFALSE;\r
292 \r
293         /* Avoid compiler warnings. */\r
294         ( void ) pvParameters;\r
295 \r
296         /* Initialise the last expire time to the current time. */\r
297         xLastExpireTime = xTaskGetTickCount();\r
298 \r
299         /* Message to wait for an update - first update won't happen for X seconds. */\r
300         g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR, "Starting task check loop - Please wait for a status update." );\r
301         g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR, "No task errors encountered." );\r
302 \r
303         for( ;; )\r
304         {\r
305                 vTaskDelayUntil( &xLastExpireTime, xBlockTime );\r
306                 ulElapsedTimeInSeconds += xBlockTime;\r
307 \r
308                 /* Have any of the standard demo tasks detected an error in their\r
309                 operation?  If so, latch the offending test in a bit map so it can be\r
310                 printed to the terminal.  Once one error has occurred the cycle rate is\r
311                 increased to increase the rate at which the LED toggles, which can cause\r
312                 further errors to be detected (as some tests will not expect the\r
313                 increased cycle rate). */\r
314 \r
315                 ulErrorOccurred = 0UL;\r
316 \r
317                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
318                 {\r
319                         ulErrorOccurred |= ( 0x01UL << 0UL );\r
320                 }\r
321 \r
322                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
323                 {\r
324                         ulErrorOccurred |= ( 0x01UL << 1UL );\r
325                 }\r
326 \r
327                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
328                 {\r
329                         ulErrorOccurred |= ( 0x01UL << 2UL );\r
330                 }\r
331 \r
332                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
333                 {\r
334                         ulErrorOccurred |= ( 0x01UL << 3UL );\r
335                 }\r
336 \r
337                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
338                 {\r
339                         ulErrorOccurred |= ( 0x01UL << 4UL );\r
340                 }\r
341 \r
342                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
343                 {\r
344                         ulErrorOccurred |= ( 0x01UL << 5UL );\r
345                 }\r
346 \r
347                 if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )\r
348                 {\r
349                         ulErrorOccurred |= ( 0x01UL << 6UL );\r
350                 }\r
351 \r
352                 if( xAreQueueSetTasksStillRunning() != pdTRUE )\r
353                 {\r
354                         ulErrorOccurred |= ( 0x01UL << 7UL );\r
355                 }\r
356 \r
357                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
358                 {\r
359                         ulErrorOccurred |= ( 0x01UL << 8UL );\r
360                 }\r
361 \r
362                 if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
363                 {\r
364                         ulErrorOccurred |= ( 0x01UL << 9UL );\r
365                 }\r
366 \r
367                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
368                 {\r
369                         ulErrorOccurred |= ( 0x01UL << 10UL );\r
370                 }\r
371 \r
372                 if( xAreTimerDemoTasksStillRunning( xBlockTime ) != pdTRUE )\r
373                 {\r
374                         ulErrorOccurred |= ( 0x01UL << 11UL );\r
375                 }\r
376 \r
377                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
378                 {\r
379                         ulErrorOccurred |= ( 0x01UL << 12UL );\r
380                 }\r
381 \r
382                 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
383                 {\r
384                         ulErrorOccurred |= ( 1UL << 13UL );\r
385                 }\r
386 \r
387                 if( xAreIntQueueTasksStillRunning() != pdTRUE )\r
388                 {\r
389                         ulErrorOccurred |= ( 1UL << 14UL );\r
390                 }\r
391 \r
392                 #if configSUPPORT_FPU == 1\r
393                 {\r
394                         if( xAreMathsTaskStillRunning() != pdTRUE )\r
395                         {\r
396                                 ulErrorOccurred |= ( 0x01UL << 15UL );\r
397                         }\r
398                 }\r
399                 #endif /* configSUPPORT_FPU */\r
400 \r
401                 /* Check the register test tasks are still looping. */\r
402                 if( ulRegTest1Counter == ulLastRegTest1Counter )\r
403                 {\r
404                         ulErrorOccurred |= ( 0x01UL << 16UL );\r
405                 }\r
406                 else\r
407                 {\r
408                         ulLastRegTest1Counter = ulRegTest1Counter;\r
409                 }\r
410 \r
411                 if( ulRegTest2Counter == ulLastRegTest2Counter )\r
412                 {\r
413                         ulErrorOccurred |= ( 0x01UL << 17UL );\r
414                 }\r
415                 else\r
416                 {\r
417                         ulLastRegTest2Counter = ulRegTest2Counter;\r
418                 }\r
419 \r
420                 if( ulErrorOccurred != 0UL )\r
421                 {\r
422                         /* Decrease the block time, which will increase the rate at\r
423                         which the LED blinks - and in so doing - give visual feedback of\r
424                         the error status. */\r
425                         xBlockTime = mainERROR_CHECK_TASK_PERIOD;\r
426                 }\r
427 \r
428                 /* Print the hex bit pattern, time, and the loop number - just to make\r
429                 sure the task is still cycling. */\r
430                 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR,\r
431                         "Status code: 0x%08x at task check time : %8ds,  loop #: %8d\r",\r
432                         ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );\r
433 \r
434                 /* Print the current free heap size and the minimum ever free heap\r
435                 size. */\r
436                 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR,\r
437                         "Current free heap: %d bytes, Min. free heap: %d bytes\r",\r
438                         xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() );\r
439 \r
440                 /* Show the first error that occurred on a separate line. */\r
441                 if( ( xErrorFlag == pdFALSE ) && ( ulErrorOccurred != pdFALSE ) )\r
442                 {\r
443                         xErrorFlag = pdTRUE;\r
444                         g_printf_rcc( 7, 2, ANSI_COLOR_RED,\r
445                                 "Error  code: 0x%08x at check time : %8ds (First Error),  loop#: %8d \r",\r
446                                 ulErrorOccurred, (  ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );\r
447                 }\r
448 \r
449                 /* Flash the LED */\r
450                 ulBlinkLED();\r
451 \r
452                 /* Crude Overflow check to keep printf() statements <= 8 digits long */\r
453                 ulCheckLoops++;\r
454                 if( ulCheckLoops > 10000000UL )\r
455                 {\r
456                         ulCheckLoops = 0UL;\r
457                 }\r
458         }\r
459 }\r
460 /*-----------------------------------------------------------*/\r
461 \r