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