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