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