2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\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
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
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\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
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\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
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
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
66 /* FreeRTOS includes. */
\r
67 #include "FreeRTOS.h"
\r
71 /* FreeRTOS+UDP includes. */
\r
72 #include "FreeRTOS_UDP_IP.h"
\r
74 /* Demo application includes. */
\r
75 #include "UDPCommandInterpreter.h"
\r
76 #include "partest.h"
\r
77 #include "blocktim.h"
\r
78 #include "flash_timer.h"
\r
79 #include "semtest.h"
\r
80 #include "GenQTest.h"
\r
82 #include "IntQueue.h"
\r
83 #include "countsem.h"
\r
84 #include "dynamic.h"
\r
85 #include "QueueOverwrite.h"
\r
86 #include "QueueSet.h"
\r
87 #include "recmutex.h"
\r
89 /* The period after which the check timer will expire, in ms, provided no errors
\r
90 have been reported by any of the standard demo tasks. ms are converted to the
\r
91 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
92 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
94 /* The period at which the check timer will expire, in ms, if an error has been
\r
95 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
96 in ticks using the portTICK_RATE_MS constant. */
\r
97 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
99 /* The priorities of the various demo application tasks. */
\r
100 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
101 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
102 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
103 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
104 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
105 #define mainQUEUE_OVERWRITE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
107 /* The LED controlled by the 'check' software timer. */
\r
108 #define mainCHECK_LED ( 2 )
\r
110 /* The number of LEDs that should be controlled by the flash software timer
\r
111 standard demo. In this case it is only 1 as the starter kit has three LEDs, one
\r
112 of which is controlled by the check timer and one of which is controlled by the
\r
113 ISR triggered task. */
\r
114 #define mainNUM_FLASH_TIMER_LEDS ( 1 )
\r
117 #define mainDONT_BLOCK ( 0 )
\r
119 /* Note: If the application is started without the network cable plugged in
\r
120 then ipconfigUDP_TASK_PRIORITY should be set to 0 in FreeRTOSIPConfig.h to
\r
121 ensure the IP task is created at the idle priority. This is because the Atmel
\r
122 ASF GMAC driver polls the GMAC looking for a connection, and doing so will
\r
123 prevent any lower priority tasks from executing. In this demo the IP task is
\r
124 started at the idle priority, then set to configMAX_PRIORITIES - 2 in the
\r
125 network event hook only after a connection has been established (when the event
\r
126 passed into the network event hook is eNetworkUp). */
\r
127 #define mainCONNECTED_IP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
128 #define mainDISCONNECTED_IP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
130 /* UDP command server task parameters. */
\r
131 #define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
132 #define mainUDP_CLI_PORT_NUMBER ( 5001UL )
\r
133 #define mainUDP_CLI_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2U )
\r
135 /*-----------------------------------------------------------*/
\r
138 * The check timer callback function, as described at the top of this file.
\r
140 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
143 * Creates a set of sample files on a RAM disk.
\r
145 extern void vCreateAndVerifySampleFiles( void );
\r
148 * Register the generic commands that can be used with FreeRTOS+CLI.
\r
150 extern void vRegisterSampleCLICommands( void );
\r
153 * Register the file system commands that can be used with FreeRTOS+CLI.
\r
155 extern void vRegisterFileSystemCLICommands( void );
\r
158 * Register the UDP related commands that can be used with FreeRTOS+CLI.
\r
160 extern void vRegisterUDPCLICommands( void );
\r
162 /*-----------------------------------------------------------*/
\r
164 /* The default IP and MAC address used by the demo. The address configuration
\r
165 defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
\r
166 1 but a DHCP server could not be contacted. See the online documentation for
\r
167 more information. */
\r
168 static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
\r
169 static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
\r
170 static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
\r
171 static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
\r
173 /* The MAC address used by the demo. In production units the MAC address would
\r
174 probably be read from flash memory or an EEPROM. Here it is just hard coded.
\r
175 Note each node on a network must have a unique MAC address. */
\r
176 const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
\r
178 /*-----------------------------------------------------------*/
\r
179 int main_full( void )
\r
181 xTimerHandle xTimer = NULL;
\r
183 /* If the file system is only going to be accessed from one task then
\r
184 F_FS_THREAD_AWARE can be set to 0 and the set of example files are created
\r
185 before the RTOS scheduler is started. If the file system is going to be
\r
186 access from more than one task then F_FS_THREAD_AWARE must be set to 1 and
\r
187 the set of sample files are created from the idle task hook function
\r
188 vApplicationIdleHook() - which is defined in this file. */
\r
189 #if( F_FS_THREAD_AWARE == 0 )
\r
191 /* Initialise the drive and file system, then create a few example
\r
192 files. The output from this function just goes to the stdout window,
\r
193 allowing the output to be viewed when the UDP command console is not
\r
195 vCreateAndVerifySampleFiles();
\r
199 /* Register example generic, file system related and UDP related CLI
\r
200 commands respectively. */
\r
201 vRegisterSampleCLICommands();
\r
202 vRegisterFileSystemCLICommands();
\r
203 vRegisterUDPCLICommands();
\r
205 /* Initialise the network interface. Tasks that use the network are
\r
206 created in the network event hook when the network is connected and ready
\r
207 for use. The address values passed in here are used if ipconfigUSE_DHCP is
\r
208 set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
\r
209 contacted. The Nabto service task is created automatically if
\r
210 ipconfigFREERTOS_PLUS_NABTO is set to 1 in FreeRTOSIPConfig.h. */
\r
211 FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
\r
213 /* Create all the other standard demo tasks. */
\r
214 vStartLEDFlashTimers( mainNUM_FLASH_TIMER_LEDS );
\r
215 vCreateBlockTimeTasks();
\r
216 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
217 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
218 vStartQueuePeekTasks();
\r
219 vStartCountingSemaphoreTasks();
\r
220 vStartDynamicPriorityTasks();
\r
221 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
\r
222 vStartQueueSetTasks();
\r
223 vStartRecursiveMutexTasks();
\r
225 /* Create the software timer that performs the 'check' functionality, as
\r
226 described at the top of this file. */
\r
227 xTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
228 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
229 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
230 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
231 prvCheckTimerCallback ); /* The callback function that inspects the status of all the other tasks. */
\r
233 if( xTimer != NULL )
\r
235 xTimerStart( xTimer, mainDONT_BLOCK );
\r
238 /* Start the scheduler itself. */
\r
239 vTaskStartScheduler();
\r
241 /* If all is well, the scheduler will now be running, and the following line
\r
242 will never be reached. If the following line does execute, then there was
\r
243 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
244 to be created. See the memory management section on the FreeRTOS web site
\r
245 for more details. */
\r
248 /*-----------------------------------------------------------*/
\r
250 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
252 static long lChangedTimerPeriodAlready = pdFALSE;
\r
253 unsigned long ulErrorOccurred = pdFALSE;
\r
255 /* Avoid compiler warnings. */
\r
258 /* Have any of the standard demo tasks detected an error in their
\r
260 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
262 ulErrorOccurred |= ( 0x01UL << 3UL );
\r
264 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
266 ulErrorOccurred |= ( 0x01UL << 4UL );
\r
268 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
270 ulErrorOccurred |= ( 0x01UL << 5UL );
\r
272 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
274 ulErrorOccurred |= ( 0x01UL << 6UL );
\r
276 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
278 ulErrorOccurred |= ( 0x01UL << 8UL );
\r
280 else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
282 ulErrorOccurred |= ( 0x01UL << 9UL );
\r
284 else if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
\r
286 ulErrorOccurred |= ( 0x01UL << 10UL );
\r
288 else if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
290 ulErrorOccurred |= ( 0x01UL << 11UL );
\r
292 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
294 ulErrorOccurred |= ( 0x01UL << 12UL );
\r
297 if( ulErrorOccurred != pdFALSE )
\r
299 /* An error occurred. Increase the frequency at which the check timer
\r
300 toggles its LED to give visual feedback of the potential error
\r
302 if( lChangedTimerPeriodAlready == pdFALSE )
\r
304 lChangedTimerPeriodAlready = pdTRUE;
\r
306 /* This call to xTimerChangePeriod() uses a zero block time.
\r
307 Functions called from inside of a timer callback function must
\r
308 *never* attempt to block as to do so could impact other software
\r
310 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
314 vParTestToggleLED( mainCHECK_LED );
\r
316 /*-----------------------------------------------------------*/
\r
318 /* Called by FreeRTOS+UDP when the network connects. */
\r
319 void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
\r
321 static long lTasksAlreadyCreated = pdFALSE;
\r
323 /* Note: If the application is started without the network cable plugged in
\r
324 then ipconfigUDP_TASK_PRIORITY should be set to 0 in FreeRTOSIPConfig.h to
\r
325 ensure the IP task is created at the idle priority. This is because the Atmel
\r
326 ASF GMAC driver polls the GMAC looking for a connection, and doing so will
\r
327 prevent any lower priority tasks from executing. In this demo the IP task is
\r
328 started at the idle priority, then set to configMAX_PRIORITIES - 2 in the
\r
329 network event hook only after a connection has been established (when the event
\r
330 passed into the network event hook is eNetworkUp). */
\r
331 if( eNetworkEvent == eNetworkUp )
\r
333 vTaskPrioritySet( NULL, mainCONNECTED_IP_TASK_PRIORITY );
\r
335 if( lTasksAlreadyCreated == pdFALSE )
\r
337 /* Create the task that handles the CLI on a UDP port. The port number
\r
338 is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
\r
339 vStartUDPCommandInterpreterTask( mainUDP_CLI_TASK_STACK_SIZE, mainUDP_CLI_PORT_NUMBER, mainUDP_CLI_TASK_PRIORITY );
\r
343 if( eNetworkEvent == eNetworkDown )
\r
345 vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
\r
348 /*-----------------------------------------------------------*/
\r
350 void vFullDemoIdleHook( void )
\r
352 /* If the file system is only going to be accessed from one task then
\r
353 F_FS_THREAD_AWARE can be set to 0 and the set of example files is created
\r
354 before the RTOS scheduler is started. If the file system is going to be
\r
355 access from more than one task then F_FS_THREAD_AWARE must be set to 1 and
\r
356 the set of sample files are created from the idle task hook function. */
\r
357 #if( F_FS_THREAD_AWARE == 1 )
\r
359 static portBASE_TYPE xCreatedSampleFiles = pdFALSE;
\r
361 /* Initialise the drive and file system, then create a few example
\r
362 files. The output from this function just goes to the stdout window,
\r
363 allowing the output to be viewed when the UDP command console is not
\r
365 if( xCreatedSampleFiles == pdFALSE )
\r
367 vCreateAndVerifySampleFiles();
\r
368 xCreatedSampleFiles = pdTRUE;
\r
373 /*-----------------------------------------------------------*/
\r
375 void vFullDemoTickHook( void )
\r
377 /* Call the periodic queue overwrite from ISR demo. */
\r
378 vQueueOverwritePeriodicISRDemo();
\r
380 /* Call the queue set ISR test function. */
\r
381 vQueueSetAccessQueueSetFromISR();
\r
383 /*-----------------------------------------------------------*/
\r
385 /* Called automatically when a reply to an outgoing ping is received. */
\r
386 void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
\r
388 /* This demo has nowhere to output any information so does nothing. */
\r
389 ( void ) usIdentifier;
\r
396 case eInvalidChecksum :
\r
399 case eInvalidData :
\r
403 /* It is not possible to get here as all enums have their own
\r