]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_ATSAM3S-EK2_Atmel_Studio/src/main_full.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / CORTEX_ATSAM3S-EK2_Atmel_Studio / src / main_full.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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  * main_full() creates all the demo application tasks and a software timer, then\r
41  * starts the scheduler.  The web documentation provides more details of the\r
42  * standard demo application tasks, which provide no particular functionality,\r
43  * but do provide a good example of how to use the FreeRTOS API.\r
44  *\r
45  * In addition to the standard demo tasks, the following tasks and tests are\r
46  * defined and/or created within this file:\r
47  *\r
48  * "Check" timer - The check software timer period is initially set to three\r
49  * seconds.  The callback function associated with the check software timer\r
50  * checks that all the standard demo tasks are not only still executing, but\r
51  * are executing without reporting any errors.  If the check software timer\r
52  * discovers that a task has either stalled, or reported an error, then it\r
53  * changes its own execution period from the initial three seconds, to just\r
54  * 200ms.  The check software timer callback function also toggles the green\r
55  * LED each time it is called.  This provides a visual indication of the system\r
56  * status:  If the green LED toggles every three seconds, then no issues have\r
57  * been discovered.  If the green LED toggles every 200ms, then an issue has\r
58  * been discovered with at least one task.\r
59  *\r
60  * See the documentation page for this demo on the FreeRTOS.org web site for\r
61  * full information, including hardware setup requirements.\r
62  */\r
63 \r
64 /* Standard includes. */\r
65 #include <stdio.h>\r
66 \r
67 /* Kernel includes. */\r
68 #include "FreeRTOS.h"\r
69 #include "task.h"\r
70 #include "timers.h"\r
71 #include "semphr.h"\r
72 \r
73 /* Standard demo application includes. */\r
74 #include "integer.h"\r
75 #include "PollQ.h"\r
76 #include "semtest.h"\r
77 #include "dynamic.h"\r
78 #include "BlockQ.h"\r
79 #include "blocktim.h"\r
80 #include "countsem.h"\r
81 #include "GenQTest.h"\r
82 #include "recmutex.h"\r
83 #include "death.h"\r
84 #include "flash_timer.h"\r
85 #include "partest.h"\r
86 #include "comtest2.h"\r
87 \r
88 \r
89 /* Atmel library includes. */\r
90 #include "asf.h"\r
91 \r
92 /* Priorities for the demo application tasks. */\r
93 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
94 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
95 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
96 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
97 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
98 #define mainCOM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 2 )\r
99 \r
100 /* A block time of zero simply means "don't block". */\r
101 #define mainDONT_BLOCK                                          ( 0UL )\r
102 \r
103 /* The period after which the check timer will expire, in ms, provided no errors\r
104 have been reported by any of the standard demo tasks.  ms are converted to the\r
105 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
106 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
107 \r
108 /* The period at which the check timer will expire, in ms, if an error has been\r
109 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
110 in ticks using the portTICK_PERIOD_MS constant. */\r
111 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
112 \r
113 /* The standard demo flash timers can be used to flash any number of LEDs.  In\r
114 this case, because only three LEDs are available, and one is in use by the\r
115 check timer, only two are used by the flash timers. */\r
116 #define mainNUMBER_OF_FLASH_TIMERS_LEDS         ( 2 )\r
117 \r
118 /* The LED toggled by the check timer.  The first two LEDs are toggle by the\r
119 standard demo flash timers. */\r
120 #define mainCHECK_LED                                           ( 2 )\r
121 \r
122 /* Baud rate used by the comtest tasks. */\r
123 #define mainCOM_TEST_BAUD_RATE                          ( 115200 )\r
124 \r
125 /* The LED used by the comtest tasks. In this case, there are no LEDs available\r
126 for the comtest, so the LED number is deliberately out of range. */\r
127 #define mainCOM_TEST_LED                                        ( 3 )\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 /*\r
132  * The check timer callback function, as described at the top of this file.\r
133  */\r
134 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
135 \r
136 /*-----------------------------------------------------------*/\r
137 \r
138 void main_full( void )\r
139 {\r
140 TimerHandle_t xCheckTimer = NULL;\r
141 \r
142         /* Start all the other standard demo/test tasks.  The have not particular\r
143         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
144         kernel port. */\r
145         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
146         vStartDynamicPriorityTasks();\r
147         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
148         vCreateBlockTimeTasks();\r
149         vStartCountingSemaphoreTasks();\r
150         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
151         vStartRecursiveMutexTasks();\r
152         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
153         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
154         vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );\r
155         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
156 \r
157         /* Create the software timer that performs the 'check' functionality,\r
158         as described at the top of this file. */\r
159         xCheckTimer = xTimerCreate( "CheckTimer",                                       /* A text name, purely to help debugging. */\r
160                                                                 ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
161                                                                 pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
162                                                                 ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
163                                                                 prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
164                                                           );\r
165 \r
166         if( xCheckTimer != NULL )\r
167         {\r
168                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
169         }\r
170 \r
171         /* The set of tasks created by the following function call have to be\r
172         created last as they keep account of the number of tasks they expect to see\r
173         running. */\r
174         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
175 \r
176         /* Start the scheduler. */\r
177         vTaskStartScheduler();\r
178 \r
179         /* If all is well, the scheduler will now be running, and the following line\r
180         will never be reached.  If the following line does execute, then there was\r
181         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
182         to be created.  See the memory management section on the FreeRTOS web site\r
183         for more details. */\r
184         for( ;; );\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
189 {\r
190 static long lChangedTimerPeriodAlready = pdFALSE;\r
191 unsigned long ulErrorFound = pdFALSE;\r
192 \r
193         /* Check all the demo tasks (other than the flash tasks) to ensure\r
194         they are all still running, and that none have detected an error. */\r
195 \r
196         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
197         {\r
198                 ulErrorFound = pdTRUE;\r
199         }\r
200 \r
201         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
202         {\r
203                 ulErrorFound = pdTRUE;\r
204         }\r
205 \r
206         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
207         {\r
208                 ulErrorFound = pdTRUE;\r
209         }\r
210 \r
211         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
212         {\r
213                 ulErrorFound = pdTRUE;\r
214         }\r
215 \r
216         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
217         {\r
218                 ulErrorFound = pdTRUE;\r
219         }\r
220 \r
221         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
222         {\r
223                 ulErrorFound = pdTRUE;\r
224         }\r
225 \r
226         if( xIsCreateTaskStillRunning() != pdTRUE )\r
227         {\r
228                 ulErrorFound = pdTRUE;\r
229         }\r
230 \r
231         if( xArePollingQueuesStillRunning() != pdTRUE )\r
232         {\r
233                 ulErrorFound = pdTRUE;\r
234         }\r
235 \r
236         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
237         {\r
238                 ulErrorFound = pdTRUE;\r
239         }\r
240 \r
241         if( xAreComTestTasksStillRunning() != pdTRUE )\r
242         {\r
243                 ulErrorFound = pdTRUE;\r
244         }\r
245 \r
246         /* Toggle the check LED to give an indication of the system status.  If\r
247         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
248         everything is ok.  A faster toggle indicates an error. */\r
249         vParTestToggleLED( mainCHECK_LED );\r
250 \r
251         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
252         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
253         This will result in an increase in the rate at which mainCHECK_LED\r
254         toggles. */\r
255         if( ulErrorFound != pdFALSE )\r
256         {\r
257                 if( lChangedTimerPeriodAlready == pdFALSE )\r
258                 {\r
259                         lChangedTimerPeriodAlready = pdTRUE;\r
260 \r
261                         /* This call to xTimerChangePeriod() uses a zero block time.\r
262                         Functions called from inside of a timer callback function must\r
263                         *never* attempt to block. */\r
264                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
265                 }\r
266         }\r
267 }\r
268 /*-----------------------------------------------------------*/\r
269 \r