2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
28 /* Standard includes. */
\r
32 /* FreeRTOS includes. */
\r
33 #include "FreeRTOS.h"
\r
38 /* FreeRTOS+UDP includes. */
\r
39 #include "FreeRTOS_UDP_IP.h"
\r
40 #include "FreeRTOS_Sockets.h"
\r
42 /* Example includes. */
\r
43 #include "TwoEchoClients.h"
\r
44 #include "CDCCommandConsole.h"
\r
46 /* Library includes. */
\r
47 #include "LPC18xx.h"
\r
49 /* The size of the stack and the priority used by the two echo client tasks. */
\r
50 #define mainECHO_CLIENT_TASK_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
51 #define mainECHO_CLIENT_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
53 /* The size of the stack and the priority used by the USB CDC command console
\r
55 #define mainCDC_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
56 #define mainCDC_COMMAND_CONSOLE_TASK_PRIORITY ( 4U )
\r
59 * Register commands that can be used with FreeRTOS+CLI. The commands are
\r
60 * defined in CLI-commands.c.
\r
62 extern void vRegisterCLICommands( void );
\r
65 * Initialise the LED ports, and create a timer that periodically toggles an LED
\r
66 * just to provide a visual indication that the program is running.
\r
68 extern void vLEDsInitialise( void );
\r
70 /*-----------------------------------------------------------*/
\r
72 /* The default IP and MAC address used by the demo. The address configuration
\r
73 defined here will be used if ipconfigUSE_DHCP is 0, or if ipconfigUSE_DHCP is
\r
74 1 but a DHCP server could not be contacted. See the online documentation for
\r
75 more information. */
\r
76 static const uint8_t ucIPAddress[ 4 ] = { configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 };
\r
77 static const uint8_t ucNetMask[ 4 ] = { configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 };
\r
78 static const uint8_t ucGatewayAddress[ 4 ] = { configGATEWAY_ADDR0, configGATEWAY_ADDR1, configGATEWAY_ADDR2, configGATEWAY_ADDR3 };
\r
79 static const uint8_t ucDNSServerAddress[ 4 ] = { configDNS_SERVER_ADDR0, configDNS_SERVER_ADDR1, configDNS_SERVER_ADDR2, configDNS_SERVER_ADDR3 };
\r
81 /* The MAC address used by the demo. In production units the MAC address would
\r
82 probably be read from flash memory or an EEPROM. Here it is just hard coded. */
\r
83 const uint8_t ucMACAddress[ 6 ] = { configMAC_ADDR0, configMAC_ADDR1, configMAC_ADDR2, configMAC_ADDR3, configMAC_ADDR4, configMAC_ADDR5 };
\r
85 /*-----------------------------------------------------------*/
\r
88 /******************************************************************************
\r
90 * See the following web page for information on using this demo.
\r
91 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/RTOS_UDP_and_CLI_LPC1830_NGX.shtml
\r
93 ******************************************************************************/
\r
98 /* Prepare the trace recorder library. */
\r
99 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
100 vTraceInitTraceData();
\r
103 /* The examples assume that all priority bits are assigned as preemption
\r
105 NVIC_SetPriorityGrouping( 0UL );
\r
107 /* Start the timer that just toggles an LED to show the demo is running. */
\r
110 /* Start the tasks that implements the command console on the UART, as
\r
111 described above. */
\r
112 vCDCCommandConsoleStart( mainCDC_COMMAND_CONSOLE_STACK_SIZE, mainCDC_COMMAND_CONSOLE_TASK_PRIORITY );
\r
114 /* Register CLI commands. */
\r
115 vRegisterCLICommands();
\r
117 /* Initialise the network interface. Tasks that use the network are
\r
118 created in the network event hook when the network is connected and ready
\r
119 for use. The address values passed in here are used if ipconfigUSE_DHCP is
\r
120 set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be
\r
122 FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
\r
124 /* If the trace recorder code is included... */
\r
125 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
127 extern xQueueHandle xNetworkEventQueue;
\r
129 /* Name the queue for viewing in FreeRTOS+Trace. */
\r
130 vTraceSetQueueName( xNetworkEventQueue, "IPStackEvent" );
\r
132 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 */
\r
134 /* Start the FreeRTOS scheduler. */
\r
135 vTaskStartScheduler();
\r
137 /* The following line should never execute. If it does, it means there was
\r
138 insufficient FreeRTOS heap memory available to create the Idle and/or timer
\r
139 tasks. See the memory management section on the http://www.FreeRTOS.org web
\r
140 site for more information. */
\r
143 /*-----------------------------------------------------------*/
\r
145 void vApplicationStackOverflowHook( xTaskHandle pxTask, char *pcTaskName )
\r
147 ( void ) pcTaskName;
\r
150 /* Run time stack overflow checking is performed if
\r
151 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
152 function is called if a stack overflow is detected. */
\r
153 taskDISABLE_INTERRUPTS();
\r
156 /*-----------------------------------------------------------*/
\r
158 void vApplicationMallocFailedHook( void )
\r
160 /* vApplicationMallocFailedHook() will only be called if
\r
161 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
162 function that will get called if a call to pvPortMalloc() fails.
\r
163 pvPortMalloc() is called internally by the kernel whenever a task, queue,
\r
164 timer or semaphore is created. It is also called by various parts of the
\r
165 demo application. If heap_1.c, heap_2.c or heap_4.c are used, then the
\r
166 size of the heap available to pvPortMalloc() is defined by
\r
167 configTOTAL_HEAP_SIZE in FreeRTOSConfig.h, and the xPortGetFreeHeapSize()
\r
168 API function can be used to query the size of free heap space that remains
\r
169 (although it does not provide information on how the remaining heap might
\r
171 taskDISABLE_INTERRUPTS();
\r
174 /*-----------------------------------------------------------*/
\r
176 /* Called by FreeRTOS+UDP when the network connects. */
\r
177 void vApplicationIPNetworkEventHook( eIPCallbackEvent_t eNetworkEvent )
\r
179 static BaseType_t xTaskAlreadyCreated = pdFALSE;
\r
181 if( eNetworkEvent == eNetworkUp )
\r
183 /* Create the tasks that transmit to and receive from a standard
\r
184 echo server (see the web documentation for this port) in both
\r
185 standard and zero copy mode. */
\r
186 if( xTaskAlreadyCreated == pdFALSE )
\r
188 vStartEchoClientTasks( mainECHO_CLIENT_TASK_STACK_SIZE, mainECHO_CLIENT_TASK_PRIORITY );
\r
189 xTaskAlreadyCreated = pdTRUE;
\r
193 /*-----------------------------------------------------------*/
\r
195 /* Called by FreeRTOS+UDP when a reply is received to an outgoing ping request. */
\r
196 void vApplicationPingReplyHook( ePingReplyStatus_t eStatus, uint16_t usIdentifier )
\r
198 static const char *pcSuccess = "\r\n\r\nPing reply received - ";
\r
199 static const char *pcInvalidChecksum = "\r\n\r\nPing reply received with invalid checksum - ";
\r
200 static const char *pcInvalidData = "\r\n\r\nPing reply received with invalid data - ";
\r
201 static char cMessage[ 50 ];
\r
202 void vOutputString( const char * const pcMessage );
\r
207 vOutputString( pcSuccess );
\r
210 case eInvalidChecksum :
\r
211 vOutputString( pcInvalidChecksum );
\r
214 case eInvalidData :
\r
215 vOutputString( pcInvalidData );
\r
219 /* It is not possible to get here as all enums have their own
\r
224 sprintf( cMessage, "identifier %d\r\n\r\n", ( int ) usIdentifier );
\r
225 vOutputString( cMessage );
\r