2 FreeRTOS V7.5.0 - 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
64 /* Standard includes. */
\r
68 /* FreeRTOS includes. */
\r
69 #include "FreeRTOS.h"
\r
74 /* FreeRTOS+UDP includes. */
\r
75 #include "FreeRTOS_UDP_IP.h"
\r
76 #include "FreeRTOS_Sockets.h"
\r
78 /* Example includes. */
\r
79 #include "TwoEchoClients.h"
\r
80 #include "CDCCommandConsole.h"
\r
82 /* Library includes. */
\r
83 #include "LPC18xx.h"
\r
85 /* The size of the stack and the priority used by the two echo client tasks. */
\r
86 #define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
87 #define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
89 /* The size of the stack and the priority used by the USB CDC command console
\r
91 #define mainCDC_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
92 #define mainCDC_COMMAND_CONSOLE_TASK_PRIORITY ( 4U )
\r
95 * Register commands that can be used with FreeRTOS+CLI. The commands are
\r
96 * defined in CLI-commands.c.
\r
98 extern void vRegisterCLICommands( void );
\r
101 * Initialise the LED ports, and create a timer that periodically toggles an LED
\r
102 * just to provide a visual indication that the program is running.
\r
104 extern void vLEDsInitialise( void );
\r
106 /*-----------------------------------------------------------*/
\r
108 /* The default IP and MAC address used by the demo. The address configuration
\r
109 defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
\r
110 1 but a DHCP server could not be contacted. See the online documentation for
\r
111 more information. */
\r
112 static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
\r
113 static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
\r
114 static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
\r
115 static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
\r
117 /* The MAC address used by the demo. In production units the MAC address would
\r
118 probably be read from flash memory or an EEPROM. Here it is just hard coded. */
\r
119 const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
\r
121 /*-----------------------------------------------------------*/
\r
124 /******************************************************************************
\r
126 * See the following web page for information on using this demo.
\r
127 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/RTOS_UDP_and_CLI_LPC1830_NGX.shtml
\r
129 ******************************************************************************/
\r
134 /* Prepare the trace recorder library. */
\r
135 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
136 vTraceInitTraceData();
\r
139 /* The examples assume that all priority bits are assigned as preemption
\r
141 NVIC_SetPriorityGrouping( 0UL );
\r
143 /* Start the timer that just toggles an LED to show the demo is running. */
\r
146 /* Start the tasks that implements the command console on the UART, as
\r
147 described above. */
\r
148 vCDCCommandConsoleStart( mainCDC_COMMAND_CONSOLE_STACK_SIZE, mainCDC_COMMAND_CONSOLE_TASK_PRIORITY );
\r
150 /* Register CLI commands. */
\r
151 vRegisterCLICommands();
\r
153 /* Initialise the network interface. Tasks that use the network are
\r
154 created in the network event hook when the network is connected and ready
\r
155 for use. The address values passed in here are used if ipconfigUSE_DHCP is
\r
156 set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
\r
158 FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
\r
160 /* If the trace recorder code is included... */
\r
161 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
163 extern xQueueHandle xNetworkEventQueue;
\r
165 /* Name the queue for viewing in FreeRTOS+Trace. */
\r
166 vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
\r
168 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 */
\r
170 /* Start the FreeRTOS scheduler. */
\r
171 vTaskStartScheduler();
\r
173 /* The following line should never execute. If it does, it means there was
\r
174 insufficient FreeRTOS heap memory available to create the Idle and/or timer
\r
175 tasks. See the memory management section on the http://www.FreeRTOS.org web
\r
176 site for more information. */
\r
179 /*-----------------------------------------------------------*/
\r
181 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
183 ( void ) pcTaskName;
\r
186 /* Run time stack overflow checking is performed if
\r
187 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
188 function is called if a stack overflow is detected. */
\r
189 taskDISABLE_INTERRUPTS();
\r
192 /*-----------------------------------------------------------*/
\r
194 void vApplicationMallocFailedHook( void )
\r
196 /* vApplicationMallocFailedHook() will only be called if
\r
197 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
198 function that will get called if a call to pvPortMalloc() fails.
\r
199 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
200 timer or semaphore is created. It is also called by various parts of the
\r
201 demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
\r
202 size of the heap available to pvPortMalloc() is defined by
\r
203 configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
\r
204 API function can be used to query the size of free heap space that remains
\r
205 (although it does not provide information on how the remaining heap might
\r
207 taskDISABLE_INTERRUPTS();
\r
210 /*-----------------------------------------------------------*/
\r
212 /* Called by FreeRTOS+UDP when the network connects. */
\r
213 void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
\r
215 static portBASE_TYPE xTaskAlreadyCreated = pdFALSE;
\r
217 if( eNetworkEvent == eNetworkUp )
\r
219 /* Create the tasks that transmit to and receive from a standard
\r
220 echo server (see the web documentation for this port) in both
\r
221 standard and zero copy mode. */
\r
222 if( xTaskAlreadyCreated == pdFALSE )
\r
224 vStartEchoClientTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
\r
225 xTaskAlreadyCreated = pdTRUE;
\r
229 /*-----------------------------------------------------------*/
\r
231 /* Called by FreeRTOS+UDP when a reply is received to an outgoing ping request. */
\r
232 void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
\r
234 static const uint8_t *pucSuccess = ( uint8_t * ) "\r\n\r\nPing reply received - ";
\r
235 static const uint8_t *pucInvalidChecksum = ( uint8_t * ) "\r\n\r\nPing reply received with invalid checksum - ";
\r
236 static const uint8_t *pucInvalidData = ( uint8_t * ) "\r\n\r\nPing reply received with invalid data - ";
\r
237 static uint8_t ucMessage[ 50 ];
\r
238 void vOutputString( const uint8_t * const pucMessage );
\r
243 vOutputString( pucSuccess );
\r
246 case eInvalidChecksum :
\r
247 vOutputString( pucInvalidChecksum );
\r
250 case eInvalidData :
\r
251 vOutputString( pucInvalidData );
\r
255 /* It is not possible to get here as all enums have their own
\r
260 sprintf( ( char * ) ucMessage, "identifier %d\r\n\r\n", ( int ) usIdentifier );
\r
261 vOutputString( ucMessage );
\r