2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 /******************************************************************************
\r
73 * See the following URL for information on the commands defined in this file:
\r
74 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
76 ******************************************************************************/
\r
79 /* FreeRTOS includes. */
\r
80 #include "FreeRTOS.h"
\r
83 /* Standard includes. */
\r
89 /* FreeRTOS+CLI includes. */
\r
90 #include "FreeRTOS_CLI.h"
\r
92 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
93 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
96 #ifndef configINCLUDE_QUERY_HEAP_COMMAND
\r
97 #define configINCLUDE_QUERY_HEAP_COMMAND 0
\r
101 * The function that registers the commands that are defined within this file.
\r
103 void vRegisterSampleCLICommands( void );
\r
106 * Implements the task-stats command.
\r
108 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
109 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
113 * Implements the run-time-stats command.
\r
115 #if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
116 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
120 * Implements the echo-three-parameters command.
\r
122 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
125 * Implements the echo-parameters command.
\r
127 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
130 * Implements the "query heap" command.
\r
132 #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
\r
133 static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
137 * Implements the "trace start" and "trace stop" commands;
\r
139 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
140 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
143 /* Structure that defines the "run-time-stats" command line command. This
\r
144 generates a table that shows how much run time each task has */
\r
145 #if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
146 static const CLI_Command_Definition_t xRunTimeStats =
\r
148 "run-time-stats", /* The command string to type. */
\r
149 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
150 prvRunTimeStatsCommand, /* The function to run. */
\r
151 0 /* No parameters are expected. */
\r
155 /* Structure that defines the "task-stats" command line command. This generates
\r
156 a table that gives information on each task in the system. */
\r
157 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
158 static const CLI_Command_Definition_t xTaskStats =
\r
160 "task-stats", /* The command string to type. */
\r
161 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
162 prvTaskStatsCommand, /* The function to run. */
\r
163 0 /* No parameters are expected. */
\r
167 /* Structure that defines the "echo_3_parameters" command line command. This
\r
168 takes exactly three parameters that the command simply echos back one at a
\r
170 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
172 "echo-3-parameters",
\r
173 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
174 prvThreeParameterEchoCommand, /* The function to run. */
\r
175 3 /* Three parameters are expected, which can take any value. */
\r
178 /* Structure that defines the "echo_parameters" command line command. This
\r
179 takes a variable number of parameters that the command simply echos back one at
\r
181 static const CLI_Command_Definition_t xParameterEcho =
\r
184 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
185 prvParameterEchoCommand, /* The function to run. */
\r
186 -1 /* The user can enter any number of commands. */
\r
189 #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
\r
190 /* Structure that defines the "query_heap" command line command. */
\r
191 static const CLI_Command_Definition_t xQueryHeap =
\r
194 "\r\nquery-heap:\r\n Displays the free heap space, and minimum ever free heap space.\r\n",
\r
195 prvQueryHeapCommand, /* The function to run. */
\r
196 0 /* The user can enter any number of commands. */
\r
198 #endif /* configQUERY_HEAP_COMMAND */
\r
200 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
201 /* Structure that defines the "trace" command line command. This takes a single
\r
202 parameter, which can be either "start" or "stop". */
\r
203 static const CLI_Command_Definition_t xStartStopTrace =
\r
206 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
207 prvStartStopTraceCommand, /* The function to run. */
\r
208 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
210 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
212 /*-----------------------------------------------------------*/
\r
214 void vRegisterSampleCLICommands( void )
\r
216 /* Register all the command line commands defined immediately above. */
\r
217 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
218 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
220 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
222 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
226 #if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
228 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
232 #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
\r
234 FreeRTOS_CLIRegisterCommand( &xQueryHeap );
\r
238 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
240 FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
\r
244 /*-----------------------------------------------------------*/
\r
246 #if ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
248 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
250 const char *const pcHeader = " State\tPriority\tStack\t#\r\n************************************************\r\n";
\r
251 BaseType_t xSpacePadding;
\r
253 /* Remove compile time warnings about unused parameters, and check the
\r
254 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
255 write buffer length is adequate, so does not check for buffer overflows. */
\r
256 ( void ) pcCommandString;
\r
257 ( void ) xWriteBufferLen;
\r
258 configASSERT( pcWriteBuffer );
\r
260 /* Generate a table of task stats. */
\r
261 strcpy( pcWriteBuffer, "Task" );
\r
262 pcWriteBuffer += strlen( pcWriteBuffer );
\r
264 /* Minus three for the null terminator and half the number of characters in
\r
265 "Task" so the column lines up with the centre of the heading. */
\r
266 configASSERT( configMAX_TASK_NAME_LEN > 3 );
\r
267 for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
\r
269 /* Add a space to align columns after the task's name. */
\r
270 *pcWriteBuffer = ' ';
\r
273 /* Ensure always terminated. */
\r
274 *pcWriteBuffer = 0x00;
\r
276 strcpy( pcWriteBuffer, pcHeader );
\r
277 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
279 /* There is no more data to return after this single string, so return
\r
284 #endif /* ( ( configUSE_TRACE_FACILITY == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) ) */
\r
285 /*-----------------------------------------------------------*/
\r
287 #if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
\r
289 static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
291 /* Remove compile time warnings about unused parameters, and check the
\r
292 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
293 write buffer length is adequate, so does not check for buffer overflows. */
\r
294 ( void ) pcCommandString;
\r
295 ( void ) xWriteBufferLen;
\r
296 configASSERT( pcWriteBuffer );
\r
298 sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() );
\r
300 /* There is no more data to return after this single string, so return
\r
305 #endif /* configINCLUDE_QUERY_HEAP */
\r
306 /*-----------------------------------------------------------*/
\r
308 #if( ( configGENERATE_RUN_TIME_STATS == 1 ) && ( configUSE_STATS_FORMATTING_FUNCTIONS > 0 ) )
\r
310 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
312 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
314 /* Remove compile time warnings about unused parameters, and check the
\r
315 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
316 write buffer length is adequate, so does not check for buffer overflows. */
\r
317 ( void ) pcCommandString;
\r
318 ( void ) xWriteBufferLen;
\r
319 configASSERT( pcWriteBuffer );
\r
321 /* Generate a table of task stats. */
\r
322 strcpy( pcWriteBuffer, pcHeader );
\r
323 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
325 /* There is no more data to return after this single string, so return
\r
330 #endif /* configGENERATE_RUN_TIME_STATS */
\r
331 /*-----------------------------------------------------------*/
\r
333 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
335 const char *pcParameter;
\r
336 BaseType_t xParameterStringLength, xReturn;
\r
337 static BaseType_t lParameterNumber = 0;
\r
339 /* Remove compile time warnings about unused parameters, and check the
\r
340 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
341 write buffer length is adequate, so does not check for buffer overflows. */
\r
342 ( void ) pcCommandString;
\r
343 ( void ) xWriteBufferLen;
\r
344 configASSERT( pcWriteBuffer );
\r
346 if( lParameterNumber == 0 )
\r
348 /* The first time the function is called after the command has been
\r
349 entered just a header string is returned. */
\r
350 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
352 /* Next time the function is called the first parameter will be echoed
\r
354 lParameterNumber = 1L;
\r
356 /* There is more data to be returned as no parameters have been echoed
\r
362 /* Obtain the parameter string. */
\r
363 pcParameter = FreeRTOS_CLIGetParameter
\r
365 pcCommandString, /* The command string itself. */
\r
366 lParameterNumber, /* Return the next parameter. */
\r
367 &xParameterStringLength /* Store the parameter string length. */
\r
370 /* Sanity check something was returned. */
\r
371 configASSERT( pcParameter );
\r
373 /* Return the parameter string. */
\r
374 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
375 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
376 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
377 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
379 /* If this is the last of the three parameters then there are no more
\r
380 strings to return after this one. */
\r
381 if( lParameterNumber == 3L )
\r
383 /* If this is the last of the three parameters then there are no more
\r
384 strings to return after this one. */
\r
386 lParameterNumber = 0L;
\r
390 /* There are more parameters to return after this one. */
\r
392 lParameterNumber++;
\r
398 /*-----------------------------------------------------------*/
\r
400 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
402 const char *pcParameter;
\r
403 BaseType_t xParameterStringLength, xReturn;
\r
404 static BaseType_t lParameterNumber = 0;
\r
406 /* Remove compile time warnings about unused parameters, and check the
\r
407 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
408 write buffer length is adequate, so does not check for buffer overflows. */
\r
409 ( void ) pcCommandString;
\r
410 ( void ) xWriteBufferLen;
\r
411 configASSERT( pcWriteBuffer );
\r
413 if( lParameterNumber == 0 )
\r
415 /* The first time the function is called after the command has been
\r
416 entered just a header string is returned. */
\r
417 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
419 /* Next time the function is called the first parameter will be echoed
\r
421 lParameterNumber = 1L;
\r
423 /* There is more data to be returned as no parameters have been echoed
\r
429 /* Obtain the parameter string. */
\r
430 pcParameter = FreeRTOS_CLIGetParameter
\r
432 pcCommandString, /* The command string itself. */
\r
433 lParameterNumber, /* Return the next parameter. */
\r
434 &xParameterStringLength /* Store the parameter string length. */
\r
437 if( pcParameter != NULL )
\r
439 /* Return the parameter string. */
\r
440 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
441 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
442 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
443 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
445 /* There might be more parameters to return after this one. */
\r
447 lParameterNumber++;
\r
451 /* No more parameters were found. Make sure the write buffer does
\r
452 not contain a valid string. */
\r
453 pcWriteBuffer[ 0 ] = 0x00;
\r
455 /* No more data to return. */
\r
458 /* Start over the next time this command is executed. */
\r
459 lParameterNumber = 0;
\r
465 /*-----------------------------------------------------------*/
\r
467 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
469 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
471 const char *pcParameter;
\r
472 BaseType_t lParameterStringLength;
\r
474 /* Remove compile time warnings about unused parameters, and check the
\r
475 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
476 write buffer length is adequate, so does not check for buffer overflows. */
\r
477 ( void ) pcCommandString;
\r
478 ( void ) xWriteBufferLen;
\r
479 configASSERT( pcWriteBuffer );
\r
481 /* Obtain the parameter string. */
\r
482 pcParameter = FreeRTOS_CLIGetParameter
\r
484 pcCommandString, /* The command string itself. */
\r
485 1, /* Return the first parameter. */
\r
486 &lParameterStringLength /* Store the parameter string length. */
\r
489 /* Sanity check something was returned. */
\r
490 configASSERT( pcParameter );
\r
492 /* There are only two valid parameter values. */
\r
493 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
495 /* Start or restart the trace. */
\r
500 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
502 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
504 /* End the trace, if one is running. */
\r
506 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
510 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
513 /* There is no more data to return after this single string, so return
\r
518 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r