]> git.sur5r.net Git - freertos/blob - FreeRTOS-Plus/Demo/FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC/CLI-commands.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS-Plus / Demo / FreeRTOS_Plus_UDP_and_CLI_LPC1830_GCC / CLI-commands.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\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
12      *                                                                       *\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
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \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
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \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
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \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
54 \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
58 \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
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66  /******************************************************************************\r
67  *\r
68  * See the following URL for information on the commands defined in this file:\r
69  * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml\r
70  *\r
71  ******************************************************************************/\r
72 \r
73 \r
74 /* FreeRTOS includes. */\r
75 #include "FreeRTOS.h"\r
76 #include "task.h"\r
77 \r
78 /* Standard includes. */\r
79 #include <stdint.h>\r
80 #include <stdio.h>\r
81 #include <stdlib.h>\r
82 \r
83 /* FreeRTOS+CLI includes. */\r
84 #include "FreeRTOS_CLI.h"\r
85 \r
86 /* FreeRTOS+UDP includes, just to make the stats available to the CLI\r
87 commands. */\r
88 #include "FreeRTOS_UDP_IP.h"\r
89 #include "FreeRTOS_Sockets.h"\r
90 \r
91 #ifndef  configINCLUDE_TRACE_RELATED_CLI_COMMANDS\r
92         #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0\r
93 #endif\r
94 \r
95 \r
96 /*\r
97  * Implements the run-time-stats command.\r
98  */\r
99 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
100 \r
101 /*\r
102  * Implements the task-stats command.\r
103  */\r
104 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
105 \r
106 /*\r
107  * Implements the echo-three-parameters command.\r
108  */\r
109 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
110 \r
111 /*\r
112  * Implements the echo-parameters command.\r
113  */\r
114 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
115 \r
116 /*\r
117  * Defines a command that prints out IP address information.\r
118  */\r
119 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
120 \r
121 /*\r
122  * Defines a command that prints out the gathered demo debug stats.\r
123  */\r
124 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
125 \r
126 /*\r
127  * Defines a command that sends an ICMP ping request to an IP address.\r
128  */\r
129 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
130 \r
131 /*\r
132  * Implements the "trace start" and "trace stop" commands;\r
133  */\r
134 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
135         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );\r
136 #endif\r
137 \r
138 /* Structure that defines the "ip-config" command line command. */\r
139 static const CLI_Command_Definition_t xIPConfig =\r
140 {\r
141         "ip-config",\r
142         "ip-config:\r\n Displays IP address configuration\r\n\r\n",\r
143         prvDisplayIPConfig,\r
144         0\r
145 };\r
146 \r
147 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
148         /* Structure that defines the "ip-debug-stats" command line command. */\r
149         static const CLI_Command_Definition_t xIPDebugStats =\r
150         {\r
151                 "ip-debug-stats", /* The command string to type. */\r
152                 "ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",\r
153                 prvDisplayIPDebugStats, /* The function to run. */\r
154                 0 /* No parameters are expected. */\r
155         };\r
156 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
157 \r
158 /* Structure that defines the "run-time-stats" command line command.   This\r
159 generates a table that shows how much run time each task has */\r
160 static const CLI_Command_Definition_t xRunTimeStats =\r
161 {\r
162         "run-time-stats", /* The command string to type. */\r
163         "run-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n\r\n",\r
164         prvRunTimeStatsCommand, /* The function to run. */\r
165         0 /* No parameters are expected. */\r
166 };\r
167 \r
168 /* Structure that defines the "task-stats" command line command.  This generates\r
169 a table that gives information on each task in the system. */\r
170 static const CLI_Command_Definition_t xTaskStats =\r
171 {\r
172         "task-stats", /* The command string to type. */\r
173         "task-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n\r\n",\r
174         prvTaskStatsCommand, /* The function to run. */\r
175         0 /* No parameters are expected. */\r
176 };\r
177 \r
178 /* Structure that defines the "echo_3_parameters" command line command.  This\r
179 takes exactly three parameters that the command simply echos back one at a\r
180 time. */\r
181 static const CLI_Command_Definition_t xThreeParameterEcho =\r
182 {\r
183         "echo-3-parameters",\r
184         "echo-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n\r\n",\r
185         prvThreeParameterEchoCommand, /* The function to run. */\r
186         3 /* Three parameters are expected, which can take any value. */\r
187 };\r
188 \r
189 /* Structure that defines the "echo_parameters" command line command.  This\r
190 takes a variable number of parameters that the command simply echos back one at\r
191 a time. */\r
192 static const CLI_Command_Definition_t xParameterEcho =\r
193 {\r
194         "echo-parameters",\r
195         "echo-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n\r\n",\r
196         prvParameterEchoCommand, /* The function to run. */\r
197         -1 /* The user can enter any number of commands. */\r
198 };\r
199 \r
200 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
201 \r
202         /* Structure that defines the "ping" command line command.  This takes an IP\r
203         address or host name and (optionally) the number of bytes to ping as\r
204         parameters. */\r
205         static const CLI_Command_Definition_t xPing =\r
206         {\r
207                 "ping",\r
208                 "ping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n\r\n",\r
209                 prvPingCommand, /* The function to run. */\r
210                 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */\r
211         };\r
212 \r
213 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
214 \r
215 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
216         /* Structure that defines the "trace" command line command.  This takes a single\r
217         parameter, which can be either "start" or "stop". */\r
218         static const CLI_Command_Definition_t xStartStopTrace =\r
219         {\r
220                 "trace",\r
221                 "trace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n\r\n",\r
222                 prvStartStopTraceCommand, /* The function to run. */\r
223                 1 /* One parameter is expected.  Valid values are "start" and "stop". */\r
224         };\r
225 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r
226 \r
227 /*-----------------------------------------------------------*/\r
228 \r
229 void vRegisterCLICommands( void )\r
230 {\r
231         /* Register all the command line commands defined immediately above. */\r
232         FreeRTOS_CLIRegisterCommand( &xTaskStats );\r
233         FreeRTOS_CLIRegisterCommand( &xRunTimeStats );\r
234         FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );\r
235         FreeRTOS_CLIRegisterCommand( &xParameterEcho );\r
236         FreeRTOS_CLIRegisterCommand( &xIPDebugStats );\r
237         FreeRTOS_CLIRegisterCommand( &xIPConfig );\r
238 \r
239         #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
240         {\r
241                 FreeRTOS_CLIRegisterCommand( &xPing );\r
242         }\r
243         #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
244 \r
245         #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
246                 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );\r
247         #endif\r
248 }\r
249 /*-----------------------------------------------------------*/\r
250 \r
251 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
252 {\r
253 const char *const pcHeader = "Task          State  Priority  Stack      #\r\n************************************************\r\n";\r
254 \r
255         /* Remove compile time warnings about unused parameters, and check the\r
256         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
257         write buffer length is adequate, so does not check for buffer overflows. */\r
258         ( void ) pcCommandString;\r
259         ( void ) xWriteBufferLen;\r
260         configASSERT( pcWriteBuffer );\r
261 \r
262         /* Generate a table of task stats. */\r
263         strcpy( pcWriteBuffer, pcHeader );\r
264         vTaskList( pcWriteBuffer + strlen( pcHeader ) );\r
265 \r
266         /* There is no more data to return after this single string, so return\r
267         pdFALSE. */\r
268         return pdFALSE;\r
269 }\r
270 /*-----------------------------------------------------------*/\r
271 \r
272 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
273 {\r
274 const char * const pcHeader = "Task            Abs Time      % Time\r\n****************************************\r\n";\r
275 \r
276         /* Remove compile time warnings about unused parameters, and check the\r
277         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
278         write buffer length is adequate, so does not check for buffer overflows. */\r
279         ( void ) pcCommandString;\r
280         ( void ) xWriteBufferLen;\r
281         configASSERT( pcWriteBuffer );\r
282 \r
283         /* Generate a table of task stats. */\r
284         strcpy( pcWriteBuffer, pcHeader );\r
285         vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );\r
286 \r
287         /* There is no more data to return after this single string, so return\r
288         pdFALSE. */\r
289         return pdFALSE;\r
290 }\r
291 /*-----------------------------------------------------------*/\r
292 \r
293 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
294 {\r
295 const char *pcParameter;\r
296 BaseType_t xParameterStringLength, xReturn;\r
297 static BaseType_t lParameterNumber = 0;\r
298 \r
299         /* Remove compile time warnings about unused parameters, and check the\r
300         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
301         write buffer length is adequate, so does not check for buffer overflows. */\r
302         ( void ) pcCommandString;\r
303         ( void ) xWriteBufferLen;\r
304         configASSERT( pcWriteBuffer );\r
305 \r
306         if( lParameterNumber == 0 )\r
307         {\r
308                 /* The first time the function is called after the command has been\r
309                 entered just a header string is returned. */\r
310                 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );\r
311 \r
312                 /* Next time the function is called the first parameter will be echoed\r
313                 back. */\r
314                 lParameterNumber = 1L;\r
315 \r
316                 /* There is more data to be returned as no parameters have been echoed\r
317                 back yet. */\r
318                 xReturn = pdPASS;\r
319         }\r
320         else\r
321         {\r
322                 /* Obtain the parameter string. */\r
323                 pcParameter = FreeRTOS_CLIGetParameter\r
324                                                 (\r
325                                                         pcCommandString,                /* The command string itself. */\r
326                                                         lParameterNumber,               /* Return the next parameter. */\r
327                                                         &xParameterStringLength /* Store the parameter string length. */\r
328                                                 );\r
329 \r
330                 /* Sanity check something was returned. */\r
331                 configASSERT( pcParameter );\r
332 \r
333                 /* Return the parameter string. */\r
334                 memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
335                 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
336                 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
337                 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
338 \r
339                 /* If this is the last of the three parameters then there are no more\r
340                 strings to return after this one. */\r
341                 if( lParameterNumber == 3L )\r
342                 {\r
343                         /* If this is the last of the three parameters then there are no more\r
344                         strings to return after this one. */\r
345                         xReturn = pdFALSE;\r
346                         lParameterNumber = 0L;\r
347                 }\r
348                 else\r
349                 {\r
350                         /* There are more parameters to return after this one. */\r
351                         xReturn = pdTRUE;\r
352                         lParameterNumber++;\r
353                 }\r
354         }\r
355 \r
356         return xReturn;\r
357 }\r
358 /*-----------------------------------------------------------*/\r
359 \r
360 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
361 {\r
362 const char *pcParameter;\r
363 BaseType_t xParameterStringLength, xReturn;\r
364 static BaseType_t lParameterNumber = 0;\r
365 \r
366         /* Remove compile time warnings about unused parameters, and check the\r
367         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
368         write buffer length is adequate, so does not check for buffer overflows. */\r
369         ( void ) pcCommandString;\r
370         ( void ) xWriteBufferLen;\r
371         configASSERT( pcWriteBuffer );\r
372 \r
373         if( lParameterNumber == 0 )\r
374         {\r
375                 /* The first time the function is called after the command has been\r
376                 entered just a header string is returned. */\r
377                 sprintf( pcWriteBuffer, "The parameters were:\r\n" );\r
378 \r
379                 /* Next time the function is called the first parameter will be echoed\r
380                 back. */\r
381                 lParameterNumber = 1L;\r
382 \r
383                 /* There is more data to be returned as no parameters have been echoed\r
384                 back yet. */\r
385                 xReturn = pdPASS;\r
386         }\r
387         else\r
388         {\r
389                 /* Obtain the parameter string. */\r
390                 pcParameter = FreeRTOS_CLIGetParameter\r
391                                                 (\r
392                                                         pcCommandString,                /* The command string itself. */\r
393                                                         lParameterNumber,               /* Return the next parameter. */\r
394                                                         &xParameterStringLength /* Store the parameter string length. */\r
395                                                 );\r
396 \r
397                 if( pcParameter != NULL )\r
398                 {\r
399                         /* Return the parameter string. */\r
400                         memset( pcWriteBuffer, 0x00, xWriteBufferLen );\r
401                         sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );\r
402                         strncat( pcWriteBuffer, pcParameter, xParameterStringLength );\r
403                         strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );\r
404 \r
405                         /* There might be more parameters to return after this one. */\r
406                         xReturn = pdTRUE;\r
407                         lParameterNumber++;\r
408                 }\r
409                 else\r
410                 {\r
411                         /* No more parameters were found.  Make sure the write buffer does\r
412                         not contain a valid string. */\r
413                         pcWriteBuffer[ 0 ] = 0x00;\r
414 \r
415                         /* No more data to return. */\r
416                         xReturn = pdFALSE;\r
417 \r
418                         /* Start over the next time this command is executed. */\r
419                         lParameterNumber = 0;\r
420                 }\r
421         }\r
422 \r
423         return xReturn;\r
424 }\r
425 /*-----------------------------------------------------------*/\r
426 \r
427 #if ipconfigSUPPORT_OUTGOING_PINGS == 1\r
428 \r
429         static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
430         {\r
431         char * pcParameter;\r
432         BaseType_t lParameterStringLength, xReturn;\r
433         uint32_t ulIPAddress, ulBytesToPing;\r
434         const uint32_t ulDefaultBytesToPing = 8UL;\r
435         char cBuffer[ 16 ];\r
436 \r
437                 /* Remove compile time warnings about unused parameters, and check the\r
438                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
439                 write buffer length is adequate, so does not check for buffer overflows. */\r
440                 ( void ) pcCommandString;\r
441                 ( void ) xWriteBufferLen;\r
442                 configASSERT( pcWriteBuffer );\r
443 \r
444                 /* Start with an empty string. */\r
445                 pcWriteBuffer[ 0 ] = 0x00;\r
446 \r
447                 /* Obtain the number of bytes to ping. */\r
448                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
449                                                                 (\r
450                                                                         pcCommandString,                /* The command string itself. */\r
451                                                                         2,                                              /* Return the second parameter. */\r
452                                                                         &lParameterStringLength /* Store the parameter string length. */\r
453                                                                 );\r
454 \r
455                 if( pcParameter == NULL )\r
456                 {\r
457                         /* The number of bytes was not specified, so default it. */\r
458                         ulBytesToPing = ulDefaultBytesToPing;\r
459                 }\r
460                 else\r
461                 {\r
462                         ulBytesToPing = atol( pcParameter );\r
463                 }\r
464 \r
465                 /* Obtain the IP address string. */\r
466                 pcParameter = ( char * ) FreeRTOS_CLIGetParameter\r
467                                                                 (\r
468                                                                         pcCommandString,                /* The command string itself. */\r
469                                                                         1,                                              /* Return the first parameter. */\r
470                                                                         &lParameterStringLength /* Store the parameter string length. */\r
471                                                                 );\r
472 \r
473                 /* Sanity check something was returned. */\r
474                 configASSERT( pcParameter );\r
475 \r
476                 /* Attempt to obtain the IP address.   If the first character is not a\r
477                 digit, assume the host name has been passed in. */\r
478                 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )\r
479                 {\r
480                         ulIPAddress = FreeRTOS_inet_addr( pcParameter );\r
481                 }\r
482                 else\r
483                 {\r
484                         /* Terminate the host name. */\r
485                         pcParameter[ lParameterStringLength ] = 0x00;\r
486 \r
487                         /* Attempt to resolve host. */\r
488                         ulIPAddress = FreeRTOS_gethostbyname( pcParameter );\r
489                 }\r
490 \r
491                 /* Convert IP address, which may have come from a DNS lookup, to string. */\r
492                 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );\r
493 \r
494                 if( ulIPAddress != 0 )\r
495                 {\r
496                         xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );\r
497                 }\r
498                 else\r
499                 {\r
500                         xReturn = pdFALSE;\r
501                 }\r
502 \r
503                 if( xReturn == pdFALSE )\r
504                 {\r
505                         sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );\r
506                 }\r
507                 else\r
508                 {\r
509                         sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, xReturn );\r
510                 }\r
511 \r
512                 return pdFALSE;\r
513         }\r
514         /*-----------------------------------------------------------*/\r
515 \r
516 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */\r
517 \r
518 #if configINCLUDE_DEMO_DEBUG_STATS != 0\r
519 \r
520         static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
521         {\r
522         static BaseType_t xIndex = -1;\r
523         extern xExampleDebugStatEntry_t xIPTraceValues[];\r
524         BaseType_t xReturn;\r
525 \r
526                 /* Remove compile time warnings about unused parameters, and check the\r
527                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
528                 write buffer length is adequate, so does not check for buffer overflows. */\r
529                 ( void ) pcCommandString;\r
530                 ( void ) xWriteBufferLen;\r
531                 configASSERT( pcWriteBuffer );\r
532 \r
533                 xIndex++;\r
534 \r
535                 if( xIndex < xExampleDebugStatEntries() )\r
536                 {\r
537                         sprintf( pcWriteBuffer, "%s %d\r\n", xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );\r
538                         xReturn = pdPASS;\r
539                 }\r
540                 else\r
541                 {\r
542                         /* Reset the index for the next time it is called. */\r
543                         xIndex = -1;\r
544 \r
545                         /* Ensure nothing remains in the write buffer. */\r
546                         pcWriteBuffer[ 0 ] = 0x00;\r
547                         xReturn = pdFALSE;\r
548                 }\r
549 \r
550                 return xReturn;\r
551         }\r
552         /*-----------------------------------------------------------*/\r
553 \r
554 #endif /* configINCLUDE_DEMO_DEBUG_STATS */\r
555 \r
556 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
557 {\r
558 static BaseType_t xIndex = 0;\r
559 BaseType_t xReturn;\r
560 uint32_t ulAddress;\r
561 \r
562         /* Remove compile time warnings about unused parameters, and check the\r
563         write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
564         write buffer length is adequate, so does not check for buffer overflows. */\r
565         ( void ) pcCommandString;\r
566         ( void ) xWriteBufferLen;\r
567         configASSERT( pcWriteBuffer );\r
568 \r
569         switch( xIndex )\r
570         {\r
571                 case 0 :\r
572                         FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );\r
573                         sprintf( pcWriteBuffer, "\r\nIP address " );\r
574                         xReturn = pdTRUE;\r
575                         xIndex++;\r
576                         break;\r
577 \r
578                 case 1 :\r
579                         FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );\r
580                         sprintf( pcWriteBuffer, "\r\nNet mask " );\r
581                         xReturn = pdTRUE;\r
582                         xIndex++;\r
583                         break;\r
584 \r
585                 case 2 :\r
586                         FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );\r
587                         sprintf( pcWriteBuffer, "\r\nGateway address " );\r
588                         xReturn = pdTRUE;\r
589                         xIndex++;\r
590                         break;\r
591 \r
592                 case 3 :\r
593                         FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );\r
594                         sprintf( pcWriteBuffer, "\r\nDNS server address " );\r
595                         xReturn = pdTRUE;\r
596                         xIndex++;\r
597                         break;\r
598 \r
599                 default :\r
600                         ulAddress = 0;\r
601                         sprintf( pcWriteBuffer, "\r\n\r\n" );\r
602                         xReturn = pdFALSE;\r
603                         xIndex = 0;\r
604                         break;\r
605         }\r
606 \r
607         if( ulAddress != 0 )\r
608         {\r
609                 FreeRTOS_inet_ntoa( ulAddress,  &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) );\r
610         }\r
611 \r
612         return xReturn;\r
613 }\r
614 /*-----------------------------------------------------------*/\r
615 \r
616 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1\r
617 \r
618         static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )\r
619         {\r
620         const char *pcParameter;\r
621         BaseType_t lParameterStringLength;\r
622 \r
623                 /* Remove compile time warnings about unused parameters, and check the\r
624                 write buffer is not NULL.  NOTE - for simplicity, this example assumes the\r
625                 write buffer length is adequate, so does not check for buffer overflows. */\r
626                 ( void ) pcCommandString;\r
627                 ( void ) xWriteBufferLen;\r
628                 configASSERT( pcWriteBuffer );\r
629 \r
630                 /* Obtain the parameter string. */\r
631                 pcParameter = FreeRTOS_CLIGetParameter\r
632                                                 (\r
633                                                         pcCommandString,                /* The command string itself. */\r
634                                                         1,                                              /* Return the first parameter. */\r
635                                                         &lParameterStringLength /* Store the parameter string length. */\r
636                                                 );\r
637 \r
638                 /* Sanity check something was returned. */\r
639                 configASSERT( pcParameter );\r
640 \r
641                 /* There are only two valid parameter values. */\r
642                 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )\r
643                 {\r
644                         /* Start or restart the trace. */\r
645                         vTraceStop();\r
646                         vTraceClear();\r
647                         vTraceStart();\r
648 \r
649                         sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );\r
650                 }\r
651                 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )\r
652                 {\r
653                         /* End the trace, if one is running. */\r
654                         vTraceStop();\r
655                         sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );\r
656                 }\r
657                 else\r
658                 {\r
659                         sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );\r
660                 }\r
661 \r
662                 /* There is no more data to return after this single string, so return\r
663                 pdFALSE. */\r
664                 return pdFALSE;\r
665         }\r
666 \r
667 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */\r