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
29 /******************************************************************************
\r
31 * See the following URL for information on the commands defined in this file:
\r
32 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
34 ******************************************************************************/
\r
37 /* FreeRTOS includes. */
\r
38 #include "FreeRTOS.h"
\r
41 /* Standard includes. */
\r
46 /* FreeRTOS+CLI includes. */
\r
47 #include "FreeRTOS_CLI.h"
\r
49 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
50 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
55 * Implements the run-time-stats command.
\r
57 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
60 * Implements the task-stats command.
\r
62 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
65 * Implements the echo-three-parameters command.
\r
67 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
70 * Implements the echo-parameters command.
\r
72 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
75 * Implements the "trace start" and "trace stop" commands;
\r
77 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
78 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
81 /* Structure that defines the "run-time-stats" command line command. This
\r
82 generates a table that shows how much run time each task has */
\r
83 static const CLI_Command_Definition_t xRunTimeStats =
\r
85 "run-time-stats", /* The command string to type. */
\r
86 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
87 prvRunTimeStatsCommand, /* The function to run. */
\r
88 0 /* No parameters are expected. */
\r
91 /* Structure that defines the "task-stats" command line command. This generates
\r
92 a table that gives information on each task in the system. */
\r
93 static const CLI_Command_Definition_t xTaskStats =
\r
95 "task-stats", /* The command string to type. */
\r
96 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
97 prvTaskStatsCommand, /* The function to run. */
\r
98 0 /* No parameters are expected. */
\r
101 /* Structure that defines the "echo_3_parameters" command line command. This
\r
102 takes exactly three parameters that the command simply echos back one at a
\r
104 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
106 "echo-3-parameters",
\r
107 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
108 prvThreeParameterEchoCommand, /* The function to run. */
\r
109 3 /* Three parameters are expected, which can take any value. */
\r
112 /* Structure that defines the "echo_parameters" command line command. This
\r
113 takes a variable number of parameters that the command simply echos back one at
\r
115 static const CLI_Command_Definition_t xParameterEcho =
\r
118 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
119 prvParameterEchoCommand, /* The function to run. */
\r
120 -1 /* The user can enter any number of commands. */
\r
123 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
124 /* Structure that defines the "trace" command line command. This takes a single
\r
125 parameter, which can be either "start" or "stop". */
\r
126 static const CLI_Command_Definition_t xStartStopTrace =
\r
129 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
130 prvStartStopTraceCommand, /* The function to run. */
\r
131 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
133 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
135 /*-----------------------------------------------------------*/
\r
137 void vRegisterSampleCLICommands( void )
\r
139 /* Register all the command line commands defined immediately above. */
\r
140 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
141 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
142 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
143 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
145 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
147 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
151 /*-----------------------------------------------------------*/
\r
153 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
155 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
157 /* Remove compile time warnings about unused parameters, and check the
\r
158 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
159 write buffer length is adequate, so does not check for buffer overflows. */
\r
160 ( void ) pcCommandString;
\r
161 ( void ) xWriteBufferLen;
\r
162 configASSERT( pcWriteBuffer );
\r
164 /* Generate a table of task stats. */
\r
165 strcpy( pcWriteBuffer, pcHeader );
\r
166 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
168 /* There is no more data to return after this single string, so return
\r
172 /*-----------------------------------------------------------*/
\r
174 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
176 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
178 /* Remove compile time warnings about unused parameters, and check the
\r
179 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
180 write buffer length is adequate, so does not check for buffer overflows. */
\r
181 ( void ) pcCommandString;
\r
182 ( void ) xWriteBufferLen;
\r
183 configASSERT( pcWriteBuffer );
\r
185 /* Generate a table of task stats. */
\r
186 strcpy( pcWriteBuffer, pcHeader );
\r
187 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
189 /* There is no more data to return after this single string, so return
\r
193 /*-----------------------------------------------------------*/
\r
195 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
197 const char *pcParameter;
\r
198 BaseType_t xParameterStringLength, xReturn;
\r
199 static BaseType_t lParameterNumber = 0;
\r
201 /* Remove compile time warnings about unused parameters, and check the
\r
202 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
203 write buffer length is adequate, so does not check for buffer overflows. */
\r
204 ( void ) pcCommandString;
\r
205 ( void ) xWriteBufferLen;
\r
206 configASSERT( pcWriteBuffer );
\r
208 if( lParameterNumber == 0 )
\r
210 /* The first time the function is called after the command has been
\r
211 entered just a header string is returned. */
\r
212 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
214 /* Next time the function is called the first parameter will be echoed
\r
216 lParameterNumber = 1L;
\r
218 /* There is more data to be returned as no parameters have been echoed
\r
224 /* Obtain the parameter string. */
\r
225 pcParameter = FreeRTOS_CLIGetParameter
\r
227 pcCommandString, /* The command string itself. */
\r
228 lParameterNumber, /* Return the next parameter. */
\r
229 &xParameterStringLength /* Store the parameter string length. */
\r
232 /* Sanity check something was returned. */
\r
233 configASSERT( pcParameter );
\r
235 /* Return the parameter string. */
\r
236 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
237 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
238 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
239 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
241 /* If this is the last of the three parameters then there are no more
\r
242 strings to return after this one. */
\r
243 if( lParameterNumber == 3L )
\r
245 /* If this is the last of the three parameters then there are no more
\r
246 strings to return after this one. */
\r
248 lParameterNumber = 0L;
\r
252 /* There are more parameters to return after this one. */
\r
254 lParameterNumber++;
\r
260 /*-----------------------------------------------------------*/
\r
262 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
264 const char *pcParameter;
\r
265 BaseType_t xParameterStringLength, xReturn;
\r
266 static BaseType_t lParameterNumber = 0;
\r
268 /* Remove compile time warnings about unused parameters, and check the
\r
269 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
270 write buffer length is adequate, so does not check for buffer overflows. */
\r
271 ( void ) pcCommandString;
\r
272 ( void ) xWriteBufferLen;
\r
273 configASSERT( pcWriteBuffer );
\r
275 if( lParameterNumber == 0 )
\r
277 /* The first time the function is called after the command has been
\r
278 entered just a header string is returned. */
\r
279 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
281 /* Next time the function is called the first parameter will be echoed
\r
283 lParameterNumber = 1L;
\r
285 /* There is more data to be returned as no parameters have been echoed
\r
291 /* Obtain the parameter string. */
\r
292 pcParameter = FreeRTOS_CLIGetParameter
\r
294 pcCommandString, /* The command string itself. */
\r
295 lParameterNumber, /* Return the next parameter. */
\r
296 &xParameterStringLength /* Store the parameter string length. */
\r
299 if( pcParameter != NULL )
\r
301 /* Return the parameter string. */
\r
302 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
303 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
304 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
305 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
307 /* There might be more parameters to return after this one. */
\r
309 lParameterNumber++;
\r
313 /* No more parameters were found. Make sure the write buffer does
\r
314 not contain a valid string. */
\r
315 pcWriteBuffer[ 0 ] = 0x00;
\r
317 /* No more data to return. */
\r
320 /* Start over the next time this command is executed. */
\r
321 lParameterNumber = 0;
\r
327 /*-----------------------------------------------------------*/
\r
329 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
331 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
333 const char *pcParameter;
\r
334 BaseType_t lParameterStringLength;
\r
336 /* Remove compile time warnings about unused parameters, and check the
\r
337 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
338 write buffer length is adequate, so does not check for buffer overflows. */
\r
339 ( void ) pcCommandString;
\r
340 ( void ) xWriteBufferLen;
\r
341 configASSERT( pcWriteBuffer );
\r
343 /* Obtain the parameter string. */
\r
344 pcParameter = FreeRTOS_CLIGetParameter
\r
346 pcCommandString, /* The command string itself. */
\r
347 1, /* Return the first parameter. */
\r
348 &lParameterStringLength /* Store the parameter string length. */
\r
351 /* Sanity check something was returned. */
\r
352 configASSERT( pcParameter );
\r
354 /* There are only two valid parameter values. */
\r
355 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
357 /* Start or restart the trace. */
\r
362 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
364 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
366 /* End the trace, if one is running. */
\r
368 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
372 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
375 /* There is no more data to return after this single string, so return
\r
380 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r