]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/IA32_flat_GCC_Galileo_Gen_2/Full_Demo/main_full.c
Update copyright date ready for tagging V10.1.0.
[freertos] / FreeRTOS / Demo / IA32_flat_GCC_Galileo_Gen_2 / Full_Demo / main_full.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2018 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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /******************************************************************************\r
29  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
30  * project, and a more comprehensive test and demo application.  The\r
31  * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
32  * between the two.  See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
33  * in main.c.  This file implements the comprehensive test and demo version.\r
34  *\r
35  * NOTE 2:  This file only contains the source code that is specific to the\r
36  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
37  * required to configure the hardware, are defined in main.c.\r
38  *\r
39  ******************************************************************************\r
40  *\r
41  * See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage\r
42  * instructions.\r
43  *\r
44  * main_full() creates all the demo application tasks and software timers, then\r
45  * starts the scheduler.  The web documentation provides more details of the\r
46  * standard demo application tasks, which provide no particular functionality,\r
47  * but do provide a good example of how to use the FreeRTOS API.\r
48  *\r
49  * In addition to the standard demo tasks, the following tasks and tests are\r
50  * defined and/or created within this file:\r
51  *\r
52  * "Reg test" tasks - These fill both the core and floating point registers with\r
53  * known values, then check that each register maintains its expected value for\r
54  * the lifetime of the task.  Each task uses a different set of values.  The reg\r
55  * test tasks execute with a very low priority, so get preempted very\r
56  * frequently.  A register containing an unexpected value is indicative of an\r
57  * error in the context switching mechanism.\r
58  *\r
59  * "Check" task - The check task period is set to five seconds.  The task checks\r
60  * that all the standard demo tasks, and the register check tasks, are not only\r
61  * still executing, but are executing without reporting any errors.  The check\r
62  * task toggles an LED on each iteration.  If the LED toggles every 5 seconds\r
63  * then no errors have been found.  If the LED toggles every 1 second then a\r
64  * potential error has been detected.\r
65  */\r
66 \r
67 /* Standard includes. */\r
68 #include <stdio.h>\r
69 #include <stdlib.h>\r
70 #include <string.h>\r
71 #include <stdint.h>\r
72 \r
73 /* FreeRTOS includes. */\r
74 #include "FreeRTOS.h"\r
75 #include "task.h"\r
76 #include "timers.h"\r
77 \r
78 /* Standard demo includes. */\r
79 #include "blocktim.h"\r
80 #include "flash_timer.h"\r
81 #include "semtest.h"\r
82 #include "GenQTest.h"\r
83 #include "QPeek.h"\r
84 #include "countsem.h"\r
85 #include "dynamic.h"\r
86 #include "QueueOverwrite.h"\r
87 #include "QueueSet.h"\r
88 #include "recmutex.h"\r
89 #include "EventGroupsDemo.h"\r
90 #include "death.h"\r
91 #include "TimerDemo.h"\r
92 #include "BlockQ.h"\r
93 #include "flop.h"\r
94 #include "TaskNotify.h"\r
95 #include "IntQueue.h"\r
96 \r
97 /* Galileo includes. */\r
98 #include "galileo_support.h"\r
99 \r
100 /* The rate at which the check task cycles if no errors have been detected, and\r
101 if a [potential] error has been detected.  Increasing the toggle rate in the\r
102 presense of an error gives visual feedback of the system status. */\r
103 #define mainNO_ERROR_CHECK_TASK_PERIOD          pdMS_TO_TICKS( 5000UL )\r
104 #define mainERROR_CHECK_TASK_PERIOD                     pdMS_TO_TICKS( 1000UL )\r
105 \r
106 /* The priorities of the various demo application tasks. */\r
107 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )\r
108 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
109 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
110 #define mainQUEUE_OVERWRITE_TASK_PRIORITY       ( tskIDLE_PRIORITY )\r
111 #define mainMATHS_TASK_PRIORITY                         ( tskIDLE_PRIORITY )\r
112 \r
113 /* The base period used by the timer test tasks. */\r
114 #define mainTIMER_TEST_PERIOD                           ( 50 )\r
115 \r
116 /* Parameters that are passed into the check tasks for no other purpose other\r
117 than to check the port does this correctly. */\r
118 #define mainREG_TEST_1_PARAMETER                        ( 0x12345678UL )\r
119 #define mainREG_TEST_2_PARAMETER                        ( 0x87654321UL )\r
120 \r
121 /*-----------------------------------------------------------*/\r
122 \r
123 /*\r
124  * The function that implements the check task, as described at the top of this\r
125  * file.\r
126  */\r
127 static void prvCheckTask( void *pvParameters );\r
128 \r
129 /*\r
130  * Entry points for the register check tasks, as described at the top of this\r
131  * file.\r
132  */\r
133 static void prvRegTest1Entry( void *pvParameters );\r
134 static void prvRegTest2Entry( void *pvParameters );\r
135 \r
136 /*\r
137  * The implementation of the register check tasks, which are implemented in\r
138  * RegTest.S.  These functions are called by prvRegTest1Entry() and\r
139  * prvRegTest2Entry() respectively.\r
140  */\r
141 extern void vRegTest1( void );\r
142 extern void vRegTest2( void );\r
143 \r
144 /*-----------------------------------------------------------*/\r
145 \r
146 /* Constants used by the register check tasks when checking the FPU registers. */\r
147 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
148 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
149 \r
150 /* Counters used by the register check tasks to indicate that they are still\r
151 executing without having discovered any errors. */\r
152 volatile uint32_t ulRegTest1Counter, ulRegTest2Counter;\r
153 volatile uint32_t ulCheckLoops = 0;\r
154 \r
155 /*-----------------------------------------------------------*/\r
156 \r
157 /* See http://www.FreeRTOS.org/RTOS_Intel_Quark_Galileo_GCC.html for usage\r
158 instructions. */\r
159 void main_full( void )\r
160 {\r
161         /* Create all the other standard demo tasks. */\r
162         vCreateBlockTimeTasks();\r
163         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
164         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
165         vStartQueuePeekTasks();\r
166         vStartCountingSemaphoreTasks();\r
167         vStartDynamicPriorityTasks();\r
168         vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );\r
169         vStartQueueSetTasks();\r
170         vStartRecursiveMutexTasks();\r
171         vStartEventGroupTasks();\r
172         vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
173         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
174         vStartTaskNotifyTask();\r
175         vStartInterruptQueueTasks();\r
176 \r
177         #if configSUPPORT_FPU == 1\r
178         {\r
179                 vStartMathTasks( mainMATHS_TASK_PRIORITY );\r
180         }\r
181         #endif /* configSUPPORT_FPU */\r
182 \r
183         /* Create the 'check' task, as described at the top of this file. */\r
184         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE * 2, NULL, configMAX_PRIORITIES - 1, NULL );\r
185 \r
186         /* Create the register test tasks, as described at the top of this file. */\r
187         xTaskCreate( prvRegTest1Entry, "Reg1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );\r
188         xTaskCreate( prvRegTest2Entry, "Reg2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );\r
189 \r
190         /* Death tasks must be created last as they check the number of tasks\r
191         running against the number of tasks expected to be running as part of their\r
192         sanity checks. */\r
193         vCreateSuicidalTasks( tskIDLE_PRIORITY );\r
194 \r
195         /* Display HPET Information (Disable in HPET.H). */\r
196         vCreateHPETInfoUpdateTask();\r
197 \r
198         /* Start the scheduler itself. */\r
199         vTaskStartScheduler();\r
200 \r
201         /* If all is well, the scheduler will now be running, and the following line\r
202         will never be reached.  If the following line does execute, then there was\r
203         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
204         to be created.  See the memory management section on the FreeRTOS web site\r
205         for more details. */\r
206         for( ;; );\r
207 }\r
208 /*-----------------------------------------------------------*/\r
209 \r
210 static void prvRegTest1Entry( void *pvParameters )\r
211 {\r
212         /* Remove compiler warning if configASSERT() is not defined. */\r
213         ( void ) pvParameters;\r
214 \r
215         /* Check the parameter is passed in correctly. */\r
216         configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_1_PARAMETER );\r
217 \r
218         /* Tell FreeRTOS that this task needs a floating point context. */\r
219         portTASK_USES_FLOATING_POINT();\r
220 \r
221         /* Call the assembly file routine that performs the 'reg test' functionality\r
222         as described at the top of this file. */\r
223         vRegTest1();\r
224 }\r
225 /*-----------------------------------------------------------*/\r
226 \r
227 static void prvRegTest2Entry( void *pvParameters )\r
228 {\r
229         /* Remove compiler warning if configASSERT() is not defined. */\r
230         ( void ) pvParameters;\r
231 \r
232         /* Check the parameter is passed in correctly. */\r
233         configASSERT( ( ( uint32_t) pvParameters ) == mainREG_TEST_2_PARAMETER );\r
234 \r
235         /* Tell FreeRTOS that this task needs a floating point context. */\r
236         portTASK_USES_FLOATING_POINT();\r
237 \r
238         /* Call the assembly file routine that performs the 'reg test' functionality\r
239         as described at the top of this file. */\r
240         vRegTest2();\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 static void prvCheckTask( void *pvParameters )\r
245 {\r
246 uint32_t ulLastRegTest1Counter = 0UL, ulLastRegTest2Counter = 0UL;\r
247 uint32_t ulErrorOccurred, ulElapsedTimeInSeconds = 0UL;\r
248 TickType_t xLastExpireTime, xBlockTime = mainNO_ERROR_CHECK_TASK_PERIOD;\r
249 BaseType_t xErrorFlag = pdFALSE;\r
250 \r
251         /* Avoid compiler warnings. */\r
252         ( void ) pvParameters;\r
253 \r
254         /* Initialise the last expire time to the current time. */\r
255         xLastExpireTime = xTaskGetTickCount();\r
256 \r
257         /* Message to wait for an update - first update won't happen for X seconds. */\r
258         g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR, "Starting task check loop - Please wait for a status update." );\r
259         g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR, "No task errors encountered." );\r
260 \r
261         for( ;; )\r
262         {\r
263                 vTaskDelayUntil( &xLastExpireTime, xBlockTime );\r
264                 ulElapsedTimeInSeconds += xBlockTime;\r
265 \r
266                 /* Have any of the standard demo tasks detected an error in their\r
267                 operation?  If so, latch the offending test in a bit map so it can be\r
268                 printed to the terminal.  Once one error has occurred the cycle rate is\r
269                 increased to increase the rate at which the LED toggles, which can cause\r
270                 further errors to be detected (as some tests will not expect the\r
271                 increased cycle rate). */\r
272 \r
273                 ulErrorOccurred = 0UL;\r
274 \r
275                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
276                 {\r
277                         ulErrorOccurred |= ( 0x01UL << 0UL );\r
278                 }\r
279 \r
280                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
281                 {\r
282                         ulErrorOccurred |= ( 0x01UL << 1UL );\r
283                 }\r
284 \r
285                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
286                 {\r
287                         ulErrorOccurred |= ( 0x01UL << 2UL );\r
288                 }\r
289 \r
290                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
291                 {\r
292                         ulErrorOccurred |= ( 0x01UL << 3UL );\r
293                 }\r
294 \r
295                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
296                 {\r
297                         ulErrorOccurred |= ( 0x01UL << 4UL );\r
298                 }\r
299 \r
300                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
301                 {\r
302                         ulErrorOccurred |= ( 0x01UL << 5UL );\r
303                 }\r
304 \r
305                 if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )\r
306                 {\r
307                         ulErrorOccurred |= ( 0x01UL << 6UL );\r
308                 }\r
309 \r
310                 if( xAreQueueSetTasksStillRunning() != pdTRUE )\r
311                 {\r
312                         ulErrorOccurred |= ( 0x01UL << 7UL );\r
313                 }\r
314 \r
315                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
316                 {\r
317                         ulErrorOccurred |= ( 0x01UL << 8UL );\r
318                 }\r
319 \r
320                 if( xAreEventGroupTasksStillRunning() != pdTRUE )\r
321                 {\r
322                         ulErrorOccurred |= ( 0x01UL << 9UL );\r
323                 }\r
324 \r
325                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
326                 {\r
327                         ulErrorOccurred |= ( 0x01UL << 10UL );\r
328                 }\r
329 \r
330                 if( xAreTimerDemoTasksStillRunning( xBlockTime ) != pdTRUE )\r
331                 {\r
332                         ulErrorOccurred |= ( 0x01UL << 11UL );\r
333                 }\r
334 \r
335                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
336                 {\r
337                         ulErrorOccurred |= ( 0x01UL << 12UL );\r
338                 }\r
339 \r
340                 if( xAreTaskNotificationTasksStillRunning() != pdTRUE )\r
341                 {\r
342                         ulErrorOccurred |= ( 1UL << 13UL );\r
343                 }\r
344 \r
345                 if( xAreIntQueueTasksStillRunning() != pdTRUE )\r
346                 {\r
347                         ulErrorOccurred |= ( 1UL << 14UL );\r
348                 }\r
349 \r
350                 #if configSUPPORT_FPU == 1\r
351                 {\r
352                         if( xAreMathsTaskStillRunning() != pdTRUE )\r
353                         {\r
354                                 ulErrorOccurred |= ( 0x01UL << 15UL );\r
355                         }\r
356                 }\r
357                 #endif /* configSUPPORT_FPU */\r
358 \r
359                 /* Check the register test tasks are still looping. */\r
360                 if( ulRegTest1Counter == ulLastRegTest1Counter )\r
361                 {\r
362                         ulErrorOccurred |= ( 0x01UL << 16UL );\r
363                 }\r
364                 else\r
365                 {\r
366                         ulLastRegTest1Counter = ulRegTest1Counter;\r
367                 }\r
368 \r
369                 if( ulRegTest2Counter == ulLastRegTest2Counter )\r
370                 {\r
371                         ulErrorOccurred |= ( 0x01UL << 17UL );\r
372                 }\r
373                 else\r
374                 {\r
375                         ulLastRegTest2Counter = ulRegTest2Counter;\r
376                 }\r
377 \r
378                 if( ulErrorOccurred != 0UL )\r
379                 {\r
380                         /* Decrease the block time, which will increase the rate at\r
381                         which the LED blinks - and in so doing - give visual feedback of\r
382                         the error status. */\r
383                         xBlockTime = mainERROR_CHECK_TASK_PERIOD;\r
384                 }\r
385 \r
386                 /* Print the hex bit pattern, time, and the loop number - just to make\r
387                 sure the task is still cycling. */\r
388                 g_printf_rcc( 5, 2, DEFAULT_SCREEN_COLOR,\r
389                         "Status code: 0x%08x at task check time : %8ds,  loop #: %8d\r",\r
390                         ulErrorOccurred, ( ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );\r
391 \r
392                 /* Print the current free heap size and the minimum ever free heap\r
393                 size. */\r
394                 g_printf_rcc( 6, 2, DEFAULT_SCREEN_COLOR,\r
395                         "Current free heap: %d bytes, Min. free heap: %d bytes\r",\r
396                         xPortGetFreeHeapSize(), xPortGetMinimumEverFreeHeapSize() );\r
397 \r
398                 /* Show the first error that occurred on a separate line. */\r
399                 if( ( xErrorFlag == pdFALSE ) && ( ulErrorOccurred != pdFALSE ) )\r
400                 {\r
401                         xErrorFlag = pdTRUE;\r
402                         g_printf_rcc( 7, 2, ANSI_COLOR_RED,\r
403                                 "Error  code: 0x%08x at check time : %8ds (First Error),  loop#: %8d \r",\r
404                                 ulErrorOccurred, (  ulElapsedTimeInSeconds / 1000 ), ( ulCheckLoops + 1 ) );\r
405                 }\r
406 \r
407                 /* Flash the LED */\r
408                 ulBlinkLED();\r
409 \r
410                 /* Crude Overflow check to keep printf() statements <= 8 digits long */\r
411                 ulCheckLoops++;\r
412                 if( ulCheckLoops > 10000000UL )\r
413                 {\r
414                         ulCheckLoops = 0UL;\r
415                 }\r
416         }\r
417 }\r
418 /*-----------------------------------------------------------*/\r
419 \r