]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Full-Demo/main_full.c
e10db76f5188b0cad7a6938164b2bb0f37689acf
[freertos] / FreeRTOS / Demo / CORTEX_SmartFusion2_M2S050_SoftConsole / RTOSDemo / Full-Demo / main_full.c
1 /*\r
2     FreeRTOS V8.2.3 - Copyright (C) 2015 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  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in FreeRTOSConifg.h is used to\r
74  * select between the two.  See the notes on using\r
75  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY in main.c.  This file implements the\r
76  * comprehensive test and demo version.\r
77  *\r
78  * NOTE 2:  This file only contains the source code that is specific to the\r
79  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
80  * required to configure the hardware, are defined in main.c.\r
81  ******************************************************************************\r
82  *\r
83  * main_full() creates all the demo application tasks and a software timer, then\r
84  * starts the scheduler.  The web documentation provides more details of the\r
85  * standard demo application tasks, which provide no particular functionality,\r
86  * but do provide a good example of how to use the FreeRTOS API.\r
87  *\r
88  * In addition to the standard demo tasks, the following tasks and tests are\r
89  * defined and/or created within this file:\r
90  *\r
91  * "Check" timer - The check software timer period is initially set to three\r
92  * seconds.  The callback function associated with the check software timer\r
93  * checks that all the standard demo tasks are not only still executing, but\r
94  * are executing without reporting any errors.  If the check software timer\r
95  * discovers that a task has either stalled, or reported an error, then it\r
96  * changes its own execution period from the initial three seconds, to just\r
97  * 200ms.  The check software timer callback function also toggles the green\r
98  * LED each time it is called.  This provides a visual indication of the system\r
99  * status:  If the green LED toggles every three seconds, then no issues have\r
100  * been discovered.  If the green LED toggles every 200ms, then an issue has\r
101  * been discovered with at least one task.\r
102  *\r
103  * FreeRTOS+CLI command console.  The command console is access through UART0\r
104  * using 115200 baud and the Microsemi MSS UART drivers.  Type "help" to see a\r
105  * list of registered commands, which include some basic file system commands\r
106  * (see FreeRTOS+FAT SL comments below). The FreeRTOS+CLI license is different\r
107  * to the FreeRTOS license, see http://www.FreeRTOS.org/cli for license and\r
108  * usage details.\r
109  *\r
110  * FreeRTOS+FAT SL.  FreeRTOS+FAT SL is demonstrated using a RAM disk.  [At the\r
111  * time of writing] The functionality of the file system demo is identical to\r
112  * the functionality of the FreeRTOS Win32 simulator file system demo with the\r
113  * command console being accessed via the UART (as described above) instead of\r
114  * a network terminal.  The FreeRTOS+FAT SL license is different to the FreeRTOS\r
115  * license, see http://www.FreeRTOS.org/fat_sl for license and usage details,\r
116  * and a description of the file system demo functionality.\r
117  *\r
118  * See the documentation page for this demo on the FreeRTOS.org web site for\r
119  * full information, including hardware setup requirements.\r
120  */\r
121 \r
122 /* Standard includes. */\r
123 #include <stdio.h>\r
124 \r
125 /* Kernel includes. */\r
126 #include "FreeRTOS.h"\r
127 #include "task.h"\r
128 #include "timers.h"\r
129 #include "queue.h"\r
130 \r
131 /* Standard demo application includes. */\r
132 #include "integer.h"\r
133 #include "PollQ.h"\r
134 #include "semtest.h"\r
135 #include "dynamic.h"\r
136 #include "BlockQ.h"\r
137 #include "blocktim.h"\r
138 #include "countsem.h"\r
139 #include "GenQTest.h"\r
140 #include "recmutex.h"\r
141 #include "death.h"\r
142 #include "flash_timer.h"\r
143 #include "partest.h"\r
144 #include "UARTCommandConsole.h"\r
145 \r
146 /* Priorities for the demo application tasks. */\r
147 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
148 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
149 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
150 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
151 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
152 \r
153 /* A block time of zero simply means "don't block". */\r
154 #define mainDONT_BLOCK                                          ( 0UL )\r
155 \r
156 /* The period after which the check timer will expire, in ms, provided no errors\r
157 have been reported by any of the standard demo tasks.  ms are converted to the\r
158 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
159 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
160 \r
161 /* The period at which the check timer will expire, in ms, if an error has been\r
162 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
163 in ticks using the portTICK_PERIOD_MS constant. */\r
164 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
165 \r
166 /* The standard demo flash timers can be used to flash any number of LEDs.  In\r
167 this case, because only three LEDs are available, and one is in use by the\r
168 check timer, only two are used by the flash timers. */\r
169 #define mainNUMBER_OF_FLASH_TIMERS_LEDS         ( 1 )\r
170 \r
171 /* The LED toggled by the check timer.  The first two LEDs are toggle by the\r
172 standard demo flash timers. */\r
173 #define mainCHECK_LED                                           ( 1 )\r
174 \r
175 /* The size of the stack and the priority used by the UART command console\r
176 task. */\r
177 #define mainUART_COMMAND_CONSOLE_STACK_SIZE             ( configMINIMAL_STACK_SIZE * 2 )\r
178 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY  ( tskIDLE_PRIORITY )\r
179 \r
180 /*-----------------------------------------------------------*/\r
181 \r
182 /*\r
183  * The check timer callback function, as described at the top of this file.\r
184  */\r
185 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
186 \r
187 /*\r
188  * Register commands that can be used with FreeRTOS+CLI.  The commands are\r
189  * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.\r
190  */\r
191 extern void vRegisterSampleCLICommands( void );\r
192 extern void vRegisterFileSystemCLICommands( void );\r
193 \r
194 /* Prepare to run the full demo: Configure the IO, register the CLI\r
195  * commands, and depending on configuration, generate a set of sample files on\r
196  * a RAM disk.\r
197  */\r
198 static void prvPrepareForFullDemo( void );\r
199 \r
200 /*\r
201  * Creates and verifies different files on the volume, demonstrating the use of\r
202  * various different API functions.\r
203  */\r
204 extern void vCreateAndVerifySampleFiles( void );\r
205 \r
206 /*-----------------------------------------------------------*/\r
207 \r
208 void main_full( void )\r
209 {\r
210 TimerHandle_t xCheckTimer = NULL;\r
211 \r
212         /* Prepare to run the full demo: Configure the IO, register the CLI\r
213         commands, and depending on configuration, generate a set of sample files on\r
214         a RAM disk. */\r
215         prvPrepareForFullDemo();\r
216 \r
217         /* Start all the other standard demo/test tasks.  The have not particular\r
218         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
219         kernel port. */\r
220         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
221         vStartDynamicPriorityTasks();\r
222         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
223         vCreateBlockTimeTasks();\r
224         vStartCountingSemaphoreTasks();\r
225         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
226         vStartRecursiveMutexTasks();\r
227         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
228         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
229         vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );\r
230 \r
231         /* Start the tasks that implements the command console on the UART, as\r
232         described above. */\r
233         vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );\r
234 \r
235         /* Create the software timer that performs the 'check' functionality,\r
236         as described at the top of this file. */\r
237         xCheckTimer = xTimerCreate( "CheckTimer",                                       /* A text name, purely to help debugging. */\r
238                                                                 ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
239                                                                 pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
240                                                                 ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
241                                                                 prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
242                                                           );\r
243 \r
244         if( xCheckTimer != NULL )\r
245         {\r
246                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
247         }\r
248 \r
249         /* The set of tasks created by the following function call have to be\r
250         created last as they keep account of the number of tasks they expect to see\r
251         running. */\r
252         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
253 \r
254         /* Start the scheduler. */\r
255         vTaskStartScheduler();\r
256 \r
257         /* If all is well, the scheduler will now be running, and the following line\r
258         will never be reached.  If the following line does execute, then there was\r
259         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
260         to be created.  See the memory management section on the FreeRTOS web site\r
261         for more details. */\r
262         for( ;; );\r
263 }\r
264 /*-----------------------------------------------------------*/\r
265 \r
266 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
267 {\r
268 static long lChangedTimerPeriodAlready = pdFALSE;\r
269 unsigned long ulErrorFound = pdFALSE;\r
270 \r
271         /* Check all the demo tasks (other than the flash tasks) to ensure\r
272         they are all still running, and that none have detected an error. */\r
273         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
274         {\r
275                 ulErrorFound = pdTRUE;\r
276         }\r
277 \r
278         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
279         {\r
280                 ulErrorFound = pdTRUE;\r
281         }\r
282 \r
283         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
284         {\r
285                 ulErrorFound = pdTRUE;\r
286         }\r
287 \r
288         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
289         {\r
290                 ulErrorFound = pdTRUE;\r
291         }\r
292 \r
293         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
294         {\r
295                 ulErrorFound = pdTRUE;\r
296         }\r
297 \r
298         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
299         {\r
300                 ulErrorFound = pdTRUE;\r
301         }\r
302 \r
303         if( xIsCreateTaskStillRunning() != pdTRUE )\r
304         {\r
305                 ulErrorFound = pdTRUE;\r
306         }\r
307 \r
308         if( xArePollingQueuesStillRunning() != pdTRUE )\r
309         {\r
310                 ulErrorFound = pdTRUE;\r
311         }\r
312 \r
313         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
314         {\r
315                 ulErrorFound = pdTRUE;\r
316         }\r
317 \r
318         /* Toggle the check LED to give an indication of the system status.  If\r
319         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
320         everything is ok.  A faster toggle indicates an error. */\r
321         vParTestToggleLED( mainCHECK_LED );\r
322 \r
323         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
324         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
325         This will result in an increase in the rate at which mainCHECK_LED\r
326         toggles. */\r
327         if( ulErrorFound != pdFALSE )\r
328         {\r
329                 if( lChangedTimerPeriodAlready == pdFALSE )\r
330                 {\r
331                         lChangedTimerPeriodAlready = pdTRUE;\r
332 \r
333                         /* This call to xTimerChangePeriod() uses a zero block time.\r
334                         Functions called from inside of a timer callback function must\r
335                         *never* attempt to block. */\r
336                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
337                 }\r
338         }\r
339 }\r
340 /*-----------------------------------------------------------*/\r
341 \r
342 static void prvPrepareForFullDemo( void )\r
343 {\r
344         /* If the file system is only going to be accessed from one task then\r
345         F_FS_THREAD_AWARE can be set to 0 and the set of example files are created\r
346         before the RTOS scheduler is started.  If the file system is going to be\r
347         access from more than one task then F_FS_THREAD_AWARE must be set to 1 and\r
348         the     set of sample files are created from the idle task hook function\r
349         vApplicationIdleHook() - which is defined in this file. */\r
350         #if F_FS_THREAD_AWARE == 0\r
351         {\r
352                 /* Initialise the drive and file system, then create a few example\r
353                 files.  The output from this function just goes to the stdout window,\r
354                 allowing the output to be viewed when the UDP command console is not\r
355                 connected. */\r
356                 vCreateAndVerifySampleFiles();\r
357         }\r
358         #endif\r
359 \r
360         /* Register both the standard and file system related CLI commands. */\r
361         vRegisterSampleCLICommands();\r
362         vRegisterFileSystemCLICommands();\r
363 }\r