]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_SmartFusion2_M2S050_SoftConsole/RTOSDemo/Full-Demo/main_full.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / CORTEX_SmartFusion2_M2S050_SoftConsole / RTOSDemo / Full-Demo / main_full.c
1 /*\r
2     FreeRTOS V8.1.2 - 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /******************************************************************************\r
67  * NOTE 1:  This project provides two demo applications.  A simple blinky style\r
68  * project, and a more comprehensive test and demo application.  The\r
69  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in FreeRTOSConifg.h is used to\r
70  * select between the two.  See the notes on using\r
71  * configCREATE_SIMPLE_BLINKY_DEMO_ONLY in main.c.  This file implements the\r
72  * comprehensive test and demo version.\r
73  *\r
74  * NOTE 2:  This file only contains the source code that is specific to the\r
75  * full demo.  Generic functions, such FreeRTOS hook functions, and functions\r
76  * required to configure the hardware, are defined in main.c.\r
77  ******************************************************************************\r
78  *\r
79  * main_full() creates all the demo application tasks and a software timer, then\r
80  * starts the scheduler.  The web documentation provides more details of the\r
81  * standard demo application tasks, which provide no particular functionality,\r
82  * but do provide a good example of how to use the FreeRTOS API.\r
83  *\r
84  * In addition to the standard demo tasks, the following tasks and tests are\r
85  * defined and/or created within this file:\r
86  *\r
87  * "Check" timer - The check software timer period is initially set to three\r
88  * seconds.  The callback function associated with the check software timer\r
89  * checks that all the standard demo tasks are not only still executing, but\r
90  * are executing without reporting any errors.  If the check software timer\r
91  * discovers that a task has either stalled, or reported an error, then it\r
92  * changes its own execution period from the initial three seconds, to just\r
93  * 200ms.  The check software timer callback function also toggles the green\r
94  * LED each time it is called.  This provides a visual indication of the system\r
95  * status:  If the green LED toggles every three seconds, then no issues have\r
96  * been discovered.  If the green LED toggles every 200ms, then an issue has\r
97  * been discovered with at least one task.\r
98  *\r
99  * FreeRTOS+CLI command console.  The command console is access through UART0\r
100  * using 115200 baud and the Microsemi MSS UART drivers.  Type "help" to see a\r
101  * list of registered commands, which include some basic file system commands\r
102  * (see FreeRTOS+FAT SL comments below). The FreeRTOS+CLI license is different\r
103  * to the FreeRTOS license, see http://www.FreeRTOS.org/cli for license and\r
104  * usage details.\r
105  *\r
106  * FreeRTOS+FAT SL.  FreeRTOS+FAT SL is demonstrated using a RAM disk.  [At the\r
107  * time of writing] The functionality of the file system demo is identical to\r
108  * the functionality of the FreeRTOS Win32 simulator file system demo with the\r
109  * command console being accessed via the UART (as described above) instead of\r
110  * a network terminal.  The FreeRTOS+FAT SL license is different to the FreeRTOS\r
111  * license, see http://www.FreeRTOS.org/fat_sl for license and usage details,\r
112  * and a description of the file system demo functionality.\r
113  *\r
114  * See the documentation page for this demo on the FreeRTOS.org web site for\r
115  * full information, including hardware setup requirements.\r
116  */\r
117 \r
118 /* Standard includes. */\r
119 #include <stdio.h>\r
120 \r
121 /* Kernel includes. */\r
122 #include "FreeRTOS.h"\r
123 #include "task.h"\r
124 #include "timers.h"\r
125 #include "queue.h"\r
126 \r
127 /* Standard demo application includes. */\r
128 #include "integer.h"\r
129 #include "PollQ.h"\r
130 #include "semtest.h"\r
131 #include "dynamic.h"\r
132 #include "BlockQ.h"\r
133 #include "blocktim.h"\r
134 #include "countsem.h"\r
135 #include "GenQTest.h"\r
136 #include "recmutex.h"\r
137 #include "death.h"\r
138 #include "flash_timer.h"\r
139 #include "partest.h"\r
140 #include "UARTCommandConsole.h"\r
141 \r
142 /* Priorities for the demo application tasks. */\r
143 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2UL )\r
144 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1UL )\r
145 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2UL )\r
146 #define mainCREATOR_TASK_PRIORITY                       ( tskIDLE_PRIORITY + 3UL )\r
147 #define mainFLOP_TASK_PRIORITY                          ( tskIDLE_PRIORITY )\r
148 \r
149 /* A block time of zero simply means "don't block". */\r
150 #define mainDONT_BLOCK                                          ( 0UL )\r
151 \r
152 /* The period after which the check timer will expire, in ms, provided no errors\r
153 have been reported by any of the standard demo tasks.  ms are converted to the\r
154 equivalent in ticks using the portTICK_PERIOD_MS constant. */\r
155 #define mainCHECK_TIMER_PERIOD_MS                       ( 3000UL / portTICK_PERIOD_MS )\r
156 \r
157 /* The period at which the check timer will expire, in ms, if an error has been\r
158 reported in one of the standard demo tasks.  ms are converted to the equivalent\r
159 in ticks using the portTICK_PERIOD_MS constant. */\r
160 #define mainERROR_CHECK_TIMER_PERIOD_MS         ( 200UL / portTICK_PERIOD_MS )\r
161 \r
162 /* The standard demo flash timers can be used to flash any number of LEDs.  In\r
163 this case, because only three LEDs are available, and one is in use by the\r
164 check timer, only two are used by the flash timers. */\r
165 #define mainNUMBER_OF_FLASH_TIMERS_LEDS         ( 1 )\r
166 \r
167 /* The LED toggled by the check timer.  The first two LEDs are toggle by the\r
168 standard demo flash timers. */\r
169 #define mainCHECK_LED                                           ( 1 )\r
170 \r
171 /* The size of the stack and the priority used by the UART command console\r
172 task. */\r
173 #define mainUART_COMMAND_CONSOLE_STACK_SIZE             ( configMINIMAL_STACK_SIZE * 2 )\r
174 #define mainUART_COMMAND_CONSOLE_TASK_PRIORITY  ( tskIDLE_PRIORITY )\r
175 \r
176 /*-----------------------------------------------------------*/\r
177 \r
178 /*\r
179  * The check timer callback function, as described at the top of this file.\r
180  */\r
181 static void prvCheckTimerCallback( TimerHandle_t xTimer );\r
182 \r
183 /*\r
184  * Register commands that can be used with FreeRTOS+CLI.  The commands are\r
185  * defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.\r
186  */\r
187 extern void vRegisterSampleCLICommands( void );\r
188 extern void vRegisterFileSystemCLICommands( void );\r
189 \r
190 /* Prepare to run the full demo: Configure the IO, register the CLI\r
191  * commands, and depending on configuration, generate a set of sample files on\r
192  * a RAM disk.\r
193  */\r
194 static void prvPrepareForFullDemo( void );\r
195 \r
196 /*\r
197  * Creates and verifies different files on the volume, demonstrating the use of\r
198  * various different API functions.\r
199  */\r
200 extern void vCreateAndVerifySampleFiles( void );\r
201 \r
202 /*-----------------------------------------------------------*/\r
203 \r
204 void main_full( void )\r
205 {\r
206 TimerHandle_t xCheckTimer = NULL;\r
207 \r
208         /* Prepare to run the full demo: Configure the IO, register the CLI\r
209         commands, and depending on configuration, generate a set of sample files on\r
210         a RAM disk. */\r
211         prvPrepareForFullDemo();\r
212 \r
213         /* Start all the other standard demo/test tasks.  The have not particular\r
214         functionality, but do demonstrate how to use the FreeRTOS API and test the\r
215         kernel port. */\r
216         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
217         vStartDynamicPriorityTasks();\r
218         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
219         vCreateBlockTimeTasks();\r
220         vStartCountingSemaphoreTasks();\r
221         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
222         vStartRecursiveMutexTasks();\r
223         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
224         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
225         vStartLEDFlashTimers( mainNUMBER_OF_FLASH_TIMERS_LEDS );\r
226 \r
227         /* Start the tasks that implements the command console on the UART, as\r
228         described above. */\r
229         vUARTCommandConsoleStart( mainUART_COMMAND_CONSOLE_STACK_SIZE, mainUART_COMMAND_CONSOLE_TASK_PRIORITY );\r
230 \r
231         /* Create the software timer that performs the 'check' functionality,\r
232         as described at the top of this file. */\r
233         xCheckTimer = xTimerCreate( "CheckTimer",                                       /* A text name, purely to help debugging. */\r
234                                                                 ( mainCHECK_TIMER_PERIOD_MS ),  /* The timer period, in this case 3000ms (3s). */\r
235                                                                 pdTRUE,                                                 /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */\r
236                                                                 ( void * ) 0,                                   /* The ID is not used, so can be set to anything. */\r
237                                                                 prvCheckTimerCallback                   /* The callback function that inspects the status of all the other tasks. */\r
238                                                           );\r
239 \r
240         if( xCheckTimer != NULL )\r
241         {\r
242                 xTimerStart( xCheckTimer, mainDONT_BLOCK );\r
243         }\r
244 \r
245         /* The set of tasks created by the following function call have to be\r
246         created last as they keep account of the number of tasks they expect to see\r
247         running. */\r
248         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
249 \r
250         /* Start the scheduler. */\r
251         vTaskStartScheduler();\r
252 \r
253         /* If all is well, the scheduler will now be running, and the following line\r
254         will never be reached.  If the following line does execute, then there was\r
255         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
256         to be created.  See the memory management section on the FreeRTOS web site\r
257         for more details. */\r
258         for( ;; );\r
259 }\r
260 /*-----------------------------------------------------------*/\r
261 \r
262 static void prvCheckTimerCallback( TimerHandle_t xTimer )\r
263 {\r
264 static long lChangedTimerPeriodAlready = pdFALSE;\r
265 unsigned long ulErrorFound = pdFALSE;\r
266 \r
267         /* Check all the demo tasks (other than the flash tasks) to ensure\r
268         they are all still running, and that none have detected an error. */\r
269         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
270         {\r
271                 ulErrorFound = pdTRUE;\r
272         }\r
273 \r
274         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
275         {\r
276                 ulErrorFound = pdTRUE;\r
277         }\r
278 \r
279         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
280         {\r
281                 ulErrorFound = pdTRUE;\r
282         }\r
283 \r
284         if ( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
285         {\r
286                 ulErrorFound = pdTRUE;\r
287         }\r
288 \r
289         if ( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
290         {\r
291                 ulErrorFound = pdTRUE;\r
292         }\r
293 \r
294         if ( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
295         {\r
296                 ulErrorFound = pdTRUE;\r
297         }\r
298 \r
299         if( xIsCreateTaskStillRunning() != pdTRUE )\r
300         {\r
301                 ulErrorFound = pdTRUE;\r
302         }\r
303 \r
304         if( xArePollingQueuesStillRunning() != pdTRUE )\r
305         {\r
306                 ulErrorFound = pdTRUE;\r
307         }\r
308 \r
309         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
310         {\r
311                 ulErrorFound = pdTRUE;\r
312         }\r
313 \r
314         /* Toggle the check LED to give an indication of the system status.  If\r
315         the LED toggles every mainCHECK_TIMER_PERIOD_MS milliseconds then\r
316         everything is ok.  A faster toggle indicates an error. */\r
317         vParTestToggleLED( mainCHECK_LED );\r
318 \r
319         /* Have any errors been latch in ulErrorFound?  If so, shorten the\r
320         period of the check timer to mainERROR_CHECK_TIMER_PERIOD_MS milliseconds.\r
321         This will result in an increase in the rate at which mainCHECK_LED\r
322         toggles. */\r
323         if( ulErrorFound != pdFALSE )\r
324         {\r
325                 if( lChangedTimerPeriodAlready == pdFALSE )\r
326                 {\r
327                         lChangedTimerPeriodAlready = pdTRUE;\r
328 \r
329                         /* This call to xTimerChangePeriod() uses a zero block time.\r
330                         Functions called from inside of a timer callback function must\r
331                         *never* attempt to block. */\r
332                         xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );\r
333                 }\r
334         }\r
335 }\r
336 /*-----------------------------------------------------------*/\r
337 \r
338 static void prvPrepareForFullDemo( void )\r
339 {\r
340         /* If the file system is only going to be accessed from one task then\r
341         F_FS_THREAD_AWARE can be set to 0 and the set of example files are created\r
342         before the RTOS scheduler is started.  If the file system is going to be\r
343         access from more than one task then F_FS_THREAD_AWARE must be set to 1 and\r
344         the     set of sample files are created from the idle task hook function\r
345         vApplicationIdleHook() - which is defined in this file. */\r
346         #if F_FS_THREAD_AWARE == 0\r
347         {\r
348                 /* Initialise the drive and file system, then create a few example\r
349                 files.  The output from this function just goes to the stdout window,\r
350                 allowing the output to be viewed when the UDP command console is not\r
351                 connected. */\r
352                 vCreateAndVerifySampleFiles();\r
353         }\r
354         #endif\r
355 \r
356         /* Register both the standard and file system related CLI commands. */\r
357         vRegisterSampleCLICommands();\r
358         vRegisterFileSystemCLICommands();\r
359 }\r