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
73 #include "FreeRTOS_Sockets.h"
\r
75 /* UDP demo includes. */
\r
76 #include "UDPCommandInterpreter.h"
\r
77 #include "TwoEchoClients.h"
\r
79 /* Standard demo includes. */
\r
80 #include "partest.h"
\r
81 #include "blocktim.h"
\r
82 #include "flash_timer.h"
\r
83 #include "semtest.h"
\r
84 #include "GenQTest.h"
\r
86 #include "IntQueue.h"
\r
87 #include "countsem.h"
\r
88 #include "dynamic.h"
\r
89 #include "QueueOverwrite.h"
\r
90 #include "QueueSet.h"
\r
91 #include "recmutex.h"
\r
93 /* The period after which the check timer will expire, in ms, provided no errors
\r
94 have been reported by any of the standard demo tasks. ms are converted to the
\r
95 equivalent in ticks using the portTICK_RATE_MS constant. */
\r
96 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_RATE_MS )
\r
98 /* The period at which the check timer will expire, in ms, if an error has been
\r
99 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
100 in ticks using the portTICK_RATE_MS constant. */
\r
101 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_RATE_MS )
\r
103 /* The priorities of the various demo application tasks. */
\r
104 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
105 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
107 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
108 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
109 #define mainQUEUE_OVERWRITE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
111 /* The LED controlled by the 'check' software timer. */
\r
112 #define mainCHECK_LED ( 2 )
\r
114 /* The number of LEDs that should be controlled by the flash software timer
\r
115 standard demo. In this case it is only 1 as the starter kit has three LEDs, one
\r
116 of which is controlled by the check timer and one of which is controlled by the
\r
117 ISR triggered task. */
\r
118 #define mainNUM_FLASH_TIMER_LEDS ( 1 )
\r
121 #define mainDONT_BLOCK ( 0 )
\r
123 /* Note: If the application is started without the network cable plugged in
\r
124 then ipconfigUDP_TASK_PRIORITY should be set to 0 in FreeRTOSIPConfig.h to
\r
125 ensure the IP task is created at the idle priority. This is because the Atmel
\r
126 ASF GMAC driver polls the GMAC looking for a connection, and doing so will
\r
127 prevent any lower priority tasks from executing. In this demo the IP task is
\r
128 started at the idle priority, then set to configMAX_PRIORITIES - 2 in the
\r
129 network event hook only after a connection has been established (when the event
\r
130 passed into the network event hook is eNetworkUp). */
\r
131 #define mainCONNECTED_IP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )
\r
132 #define mainDISCONNECTED_IP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
134 /* UDP command server task parameters. */
\r
135 #define mainUDP_CLI_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
136 #define mainUDP_CLI_PORT_NUMBER ( 5001UL )
\r
137 #define mainUDP_CLI_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2U )
\r
139 /* Set to 1 to include the UDP echo client tasks. */
\r
140 #define mainINCLUDE_ECHO_CLIENT_TASKS 1
\r
142 /*-----------------------------------------------------------*/
\r
145 * The check timer callback function, as described at the top of this file.
\r
147 static void prvCheckTimerCallback( xTimerHandle xTimer );
\r
150 * Creates a set of sample files on a RAM disk.
\r
152 extern void vCreateAndVerifySampleFiles( void );
\r
155 * Register the generic commands that can be used with FreeRTOS+CLI.
\r
157 extern void vRegisterSampleCLICommands( void );
\r
160 * Register the file system commands that can be used with FreeRTOS+CLI.
\r
162 extern void vRegisterFileSystemCLICommands( void );
\r
165 * Register the UDP related commands that can be used with FreeRTOS+CLI.
\r
167 extern void vRegisterUDPCLICommands( void );
\r
170 * Initialise the LCD and output a bitmap.
\r
172 extern void vInitialiseLCD( void );
\r
174 /*-----------------------------------------------------------*/
\r
176 /* The default IP and MAC address used by the demo. The address configuration
\r
177 defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
\r
178 1 but a DHCP server could not be contacted. See the online documentation for
\r
179 more information. */
\r
180 static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
\r
181 static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
\r
182 static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
\r
183 static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
\r
185 /* The MAC address used by the demo. In production units the MAC address would
\r
186 probably be read from flash memory or an EEPROM. Here it is just hard coded.
\r
187 Note each node on a network must have a unique MAC address. */
\r
188 const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
\r
190 /*-----------------------------------------------------------*/
\r
191 int main_full( void )
\r
193 xTimerHandle xTimer = NULL;
\r
195 /* Initialise the LCD and output the bitmap. */
\r
198 /* If the file system is only going to be accessed from one task then
\r
199 F_FS_THREAD_AWARE can be set to 0 and the set of example files are created
\r
200 before the RTOS scheduler is started. If the file system is going to be
\r
201 access from more than one task then F_FS_THREAD_AWARE must be set to 1 and
\r
202 the set of sample files are created from the idle task hook function
\r
203 vApplicationIdleHook() - which is defined in this file. */
\r
204 #if( F_FS_THREAD_AWARE == 0 )
\r
206 /* Initialise the drive and file system, then create a few example
\r
207 files. The output from this function just goes to the stdout window,
\r
208 allowing the output to be viewed when the UDP command console is not
\r
210 vCreateAndVerifySampleFiles();
\r
214 /* Register example generic, file system related and UDP related CLI
\r
215 commands respectively. */
\r
216 vRegisterSampleCLICommands();
\r
217 vRegisterFileSystemCLICommands();
\r
218 vRegisterUDPCLICommands();
\r
220 /* Initialise the network interface. Tasks that use the network are
\r
221 created in the network event hook when the network is connected and ready
\r
222 for use. The address values passed in here are used if ipconfigUSE_DHCP is
\r
223 set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
\r
224 contacted. The Nabto service task is created automatically if
\r
225 ipconfigFREERTOS_PLUS_NABTO is set to 1 in FreeRTOSIPConfig.h. */
\r
226 FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
\r
228 /* Create all the other standard demo tasks. */
\r
229 vStartLEDFlashTimers( mainNUM_FLASH_TIMER_LEDS );
\r
230 vCreateBlockTimeTasks();
\r
231 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
232 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
233 vStartQueuePeekTasks();
\r
234 vStartCountingSemaphoreTasks();
\r
235 vStartDynamicPriorityTasks();
\r
236 vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_TASK_PRIORITY );
\r
237 vStartQueueSetTasks();
\r
238 vStartRecursiveMutexTasks();
\r
240 /* Create the software timer that performs the 'check' functionality, as
\r
241 described at the top of this file. */
\r
242 xTimer = xTimerCreate( ( const signed char * ) "CheckTimer",/* A text name, purely to help debugging. */
\r
243 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 3000ms (3s). */
\r
244 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
245 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
246 prvCheckTimerCallback ); /* The callback function that inspects the status of all the other tasks. */
\r
248 if( xTimer != NULL )
\r
250 xTimerStart( xTimer, mainDONT_BLOCK );
\r
253 /* Start the scheduler itself. */
\r
254 vTaskStartScheduler();
\r
256 /* If all is well, the scheduler will now be running, and the following line
\r
257 will never be reached. If the following line does execute, then there was
\r
258 insufficient FreeRTOS heap memory available for the idle and/or timer tasks
\r
259 to be created. See the memory management section on the FreeRTOS web site
\r
260 for more details. */
\r
263 /*-----------------------------------------------------------*/
\r
265 static void prvCheckTimerCallback( xTimerHandle xTimer )
\r
267 static long lChangedTimerPeriodAlready = pdFALSE;
\r
268 unsigned long ulErrorOccurred = pdFALSE;
\r
270 /* Avoid compiler warnings. */
\r
273 /* Have any of the standard demo tasks detected an error in their
\r
275 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
277 ulErrorOccurred |= ( 0x01UL << 3UL );
\r
279 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
281 ulErrorOccurred |= ( 0x01UL << 4UL );
\r
283 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
285 ulErrorOccurred |= ( 0x01UL << 5UL );
\r
287 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
289 ulErrorOccurred |= ( 0x01UL << 6UL );
\r
291 else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )
\r
293 ulErrorOccurred |= ( 0x01UL << 8UL );
\r
295 else if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
297 ulErrorOccurred |= ( 0x01UL << 9UL );
\r
299 else if( xIsQueueOverwriteTaskStillRunning() != pdTRUE )
\r
301 ulErrorOccurred |= ( 0x01UL << 10UL );
\r
303 else if( xAreQueueSetTasksStillRunning() != pdTRUE )
\r
305 ulErrorOccurred |= ( 0x01UL << 11UL );
\r
307 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
309 ulErrorOccurred |= ( 0x01UL << 12UL );
\r
312 if( ulErrorOccurred != pdFALSE )
\r
314 /* An error occurred. Increase the frequency at which the check timer
\r
315 toggles its LED to give visual feedback of the potential error
\r
317 if( lChangedTimerPeriodAlready == pdFALSE )
\r
319 lChangedTimerPeriodAlready = pdTRUE;
\r
321 /* This call to xTimerChangePeriod() uses a zero block time.
\r
322 Functions called from inside of a timer callback function must
\r
323 *never* attempt to block as to do so could impact other software
\r
325 xTimerChangePeriod( xTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
329 vParTestToggleLED( mainCHECK_LED );
\r
331 /*-----------------------------------------------------------*/
\r
333 /* Called by FreeRTOS+UDP when the network connects. */
\r
334 void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
\r
336 static long lTasksAlreadyCreated = pdFALSE;
\r
337 const unsigned long ulXCoord = 3, ulYCoord = 3, ulIPAddressOffset = 45;
\r
338 unsigned long ulIPAddress;
\r
339 char cIPAddress[ 20 ];
\r
341 /* Note: If the application is started without the network cable plugged in
\r
342 then ipconfigUDP_TASK_PRIORITY should be set to 0 in FreeRTOSIPConfig.h to
\r
343 ensure the IP task is created at the idle priority. This is because the Atmel
\r
344 ASF GMAC driver polls the GMAC looking for a connection, and doing so will
\r
345 prevent any lower priority tasks from executing. In this demo the IP task is
\r
346 started at the idle priority, then set to configMAX_PRIORITIES - 2 in the
\r
347 network event hook only after a connection has been established (when the event
\r
348 passed into the network event hook is eNetworkUp). */
\r
349 if( eNetworkEvent == eNetworkUp )
\r
351 if( lTasksAlreadyCreated == pdFALSE )
\r
353 /* Create the task that handles the CLI on a UDP port. The port number
\r
354 is set using the configUDP_CLI_PORT_NUMBER setting in FreeRTOSConfig.h. */
\r
355 vStartUDPCommandInterpreterTask( mainUDP_CLI_TASK_STACK_SIZE, mainUDP_CLI_PORT_NUMBER, mainUDP_CLI_TASK_PRIORITY );
\r
357 #if( mainINCLUDE_ECHO_CLIENT_TASKS == 1 )
\r
359 vStartEchoClientTasks( configMINIMAL_STACK_SIZE, tskIDLE_PRIORITY );
\r
364 /* Obtain the IP address, convert it to a string, then display. */
\r
365 FreeRTOS_GetAddressConfiguration( &ulIPAddress, NULL, NULL, NULL );
\r
366 FreeRTOS_inet_ntoa( ulIPAddress, cIPAddress );
\r
367 ili93xx_draw_string( ulXCoord, ulYCoord, ( uint8_t * ) "IP: " );
\r
368 ili93xx_draw_string( ulXCoord + ulIPAddressOffset, ulYCoord, ( uint8_t * ) cIPAddress );
\r
370 /* Set the IP task up to the desired priority now it has connected. */
\r
371 vTaskPrioritySet( NULL, mainCONNECTED_IP_TASK_PRIORITY );
\r
374 if( eNetworkEvent == eNetworkDown )
\r
376 vTaskPrioritySet( NULL, tskIDLE_PRIORITY );
\r
379 /*-----------------------------------------------------------*/
\r
381 void vFullDemoIdleHook( void )
\r
383 /* If the file system is only going to be accessed from one task then
\r
384 F_FS_THREAD_AWARE can be set to 0 and the set of example files is created
\r
385 before the RTOS scheduler is started. If the file system is going to be
\r
386 access from more than one task then F_FS_THREAD_AWARE must be set to 1 and
\r
387 the set of sample files are created from the idle task hook function. */
\r
388 #if( F_FS_THREAD_AWARE == 1 )
\r
390 static portBASE_TYPE xCreatedSampleFiles = pdFALSE;
\r
392 /* Initialise the drive and file system, then create a few example
\r
393 files. The output from this function just goes to the stdout window,
\r
394 allowing the output to be viewed when the UDP command console is not
\r
396 if( xCreatedSampleFiles == pdFALSE )
\r
398 vCreateAndVerifySampleFiles();
\r
399 xCreatedSampleFiles = pdTRUE;
\r
404 /*-----------------------------------------------------------*/
\r
406 void vFullDemoTickHook( void )
\r
408 /* Call the periodic queue overwrite from ISR demo. */
\r
409 vQueueOverwritePeriodicISRDemo();
\r
411 /* Call the queue set ISR test function. */
\r
412 vQueueSetAccessQueueSetFromISR();
\r
414 /*-----------------------------------------------------------*/
\r
416 /* Called automatically when a reply to an outgoing ping is received. */
\r
417 void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
\r
419 /* This demo has nowhere to output any information so does nothing. */
\r
420 ( void ) usIdentifier;
\r
423 /*-----------------------------------------------------------*/
\r