2 * FreeRTOS Kernel V10.3.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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /******************************************************************************
\r
30 * See the following URL for information on the commands defined in this file:
\r
31 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
33 ******************************************************************************/
\r
36 /* FreeRTOS includes. */
\r
37 #include "FreeRTOS.h"
\r
40 /* Standard includes. */
\r
45 /* FreeRTOS+CLI includes. */
\r
46 #include "FreeRTOS_CLI.h"
\r
48 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
49 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
54 * Implements the run-time-stats command.
\r
56 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
59 * Implements the task-stats command.
\r
61 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
64 * Implements the echo-three-parameters command.
\r
66 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
69 * Implements the echo-parameters command.
\r
71 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
74 * Implements the "trace start" and "trace stop" commands;
\r
76 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
77 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
80 /* Structure that defines the "run-time-stats" command line command. This
\r
81 generates a table that shows how much run time each task has */
\r
82 static const CLI_Command_Definition_t xRunTimeStats =
\r
84 "run-time-stats", /* The command string to type. */
\r
85 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
86 prvRunTimeStatsCommand, /* The function to run. */
\r
87 0 /* No parameters are expected. */
\r
90 /* Structure that defines the "task-stats" command line command. This generates
\r
91 a table that gives information on each task in the system. */
\r
92 static const CLI_Command_Definition_t xTaskStats =
\r
94 "task-stats", /* The command string to type. */
\r
95 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
96 prvTaskStatsCommand, /* The function to run. */
\r
97 0 /* No parameters are expected. */
\r
100 /* Structure that defines the "echo_3_parameters" command line command. This
\r
101 takes exactly three parameters that the command simply echos back one at a
\r
103 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
105 "echo-3-parameters",
\r
106 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
107 prvThreeParameterEchoCommand, /* The function to run. */
\r
108 3 /* Three parameters are expected, which can take any value. */
\r
111 /* Structure that defines the "echo_parameters" command line command. This
\r
112 takes a variable number of parameters that the command simply echos back one at
\r
114 static const CLI_Command_Definition_t xParameterEcho =
\r
117 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
118 prvParameterEchoCommand, /* The function to run. */
\r
119 -1 /* The user can enter any number of commands. */
\r
122 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
123 /* Structure that defines the "trace" command line command. This takes a single
\r
124 parameter, which can be either "start" or "stop". */
\r
125 static const CLI_Command_Definition_t xStartStopTrace =
\r
128 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
129 prvStartStopTraceCommand, /* The function to run. */
\r
130 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
132 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
134 /*-----------------------------------------------------------*/
\r
136 void vRegisterSampleCLICommands( void )
\r
138 /* Register all the command line commands defined immediately above. */
\r
139 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
140 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
141 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
142 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
144 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
146 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
150 /*-----------------------------------------------------------*/
\r
152 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
154 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
156 /* Remove compile time warnings about unused parameters, and check the
\r
157 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
158 write buffer length is adequate, so does not check for buffer overflows. */
\r
159 ( void ) pcCommandString;
\r
160 ( void ) xWriteBufferLen;
\r
161 configASSERT( pcWriteBuffer );
\r
163 /* Generate a table of task stats. */
\r
164 strcpy( pcWriteBuffer, pcHeader );
\r
165 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
167 /* There is no more data to return after this single string, so return
\r
171 /*-----------------------------------------------------------*/
\r
173 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
175 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
177 /* Remove compile time warnings about unused parameters, and check the
\r
178 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
179 write buffer length is adequate, so does not check for buffer overflows. */
\r
180 ( void ) pcCommandString;
\r
181 ( void ) xWriteBufferLen;
\r
182 configASSERT( pcWriteBuffer );
\r
184 /* Generate a table of task stats. */
\r
185 strcpy( pcWriteBuffer, pcHeader );
\r
186 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
188 /* There is no more data to return after this single string, so return
\r
192 /*-----------------------------------------------------------*/
\r
194 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
196 const char *pcParameter;
\r
197 BaseType_t xParameterStringLength, xReturn;
\r
198 static BaseType_t lParameterNumber = 0;
\r
200 /* Remove compile time warnings about unused parameters, and check the
\r
201 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
202 write buffer length is adequate, so does not check for buffer overflows. */
\r
203 ( void ) pcCommandString;
\r
204 ( void ) xWriteBufferLen;
\r
205 configASSERT( pcWriteBuffer );
\r
207 if( lParameterNumber == 0 )
\r
209 /* The first time the function is called after the command has been
\r
210 entered just a header string is returned. */
\r
211 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
213 /* Next time the function is called the first parameter will be echoed
\r
215 lParameterNumber = 1L;
\r
217 /* There is more data to be returned as no parameters have been echoed
\r
223 /* Obtain the parameter string. */
\r
224 pcParameter = FreeRTOS_CLIGetParameter
\r
226 pcCommandString, /* The command string itself. */
\r
227 lParameterNumber, /* Return the next parameter. */
\r
228 &xParameterStringLength /* Store the parameter string length. */
\r
231 /* Sanity check something was returned. */
\r
232 configASSERT( pcParameter );
\r
234 /* Return the parameter string. */
\r
235 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
236 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
237 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
238 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
240 /* If this is the last of the three parameters then there are no more
\r
241 strings to return after this one. */
\r
242 if( lParameterNumber == 3L )
\r
244 /* If this is the last of the three parameters then there are no more
\r
245 strings to return after this one. */
\r
247 lParameterNumber = 0L;
\r
251 /* There are more parameters to return after this one. */
\r
253 lParameterNumber++;
\r
259 /*-----------------------------------------------------------*/
\r
261 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
263 const char *pcParameter;
\r
264 BaseType_t xParameterStringLength, xReturn;
\r
265 static BaseType_t lParameterNumber = 0;
\r
267 /* Remove compile time warnings about unused parameters, and check the
\r
268 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
269 write buffer length is adequate, so does not check for buffer overflows. */
\r
270 ( void ) pcCommandString;
\r
271 ( void ) xWriteBufferLen;
\r
272 configASSERT( pcWriteBuffer );
\r
274 if( lParameterNumber == 0 )
\r
276 /* The first time the function is called after the command has been
\r
277 entered just a header string is returned. */
\r
278 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
280 /* Next time the function is called the first parameter will be echoed
\r
282 lParameterNumber = 1L;
\r
284 /* There is more data to be returned as no parameters have been echoed
\r
290 /* Obtain the parameter string. */
\r
291 pcParameter = FreeRTOS_CLIGetParameter
\r
293 pcCommandString, /* The command string itself. */
\r
294 lParameterNumber, /* Return the next parameter. */
\r
295 &xParameterStringLength /* Store the parameter string length. */
\r
298 if( pcParameter != NULL )
\r
300 /* Return the parameter string. */
\r
301 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
302 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
303 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
304 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
306 /* There might be more parameters to return after this one. */
\r
308 lParameterNumber++;
\r
312 /* No more parameters were found. Make sure the write buffer does
\r
313 not contain a valid string. */
\r
314 pcWriteBuffer[ 0 ] = 0x00;
\r
316 /* No more data to return. */
\r
319 /* Start over the next time this command is executed. */
\r
320 lParameterNumber = 0;
\r
326 /*-----------------------------------------------------------*/
\r
328 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
330 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
332 const char *pcParameter;
\r
333 BaseType_t lParameterStringLength;
\r
335 /* Remove compile time warnings about unused parameters, and check the
\r
336 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
337 write buffer length is adequate, so does not check for buffer overflows. */
\r
338 ( void ) pcCommandString;
\r
339 ( void ) xWriteBufferLen;
\r
340 configASSERT( pcWriteBuffer );
\r
342 /* Obtain the parameter string. */
\r
343 pcParameter = FreeRTOS_CLIGetParameter
\r
345 pcCommandString, /* The command string itself. */
\r
346 1, /* Return the first parameter. */
\r
347 &lParameterStringLength /* Store the parameter string length. */
\r
350 /* Sanity check something was returned. */
\r
351 configASSERT( pcParameter );
\r
353 /* There are only two valid parameter values. */
\r
354 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
356 /* Start or restart the trace. */
\r
361 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
363 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
365 /* End the trace, if one is running. */
\r
367 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
371 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
374 /* There is no more data to return after this single string, so return
\r
379 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r