2 FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\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
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
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\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
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\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
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\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
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
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
67 /******************************************************************************
\r
69 * See the following URL for information on the commands defined in this file:
\r
70 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
72 ******************************************************************************/
\r
75 /* FreeRTOS includes. */
\r
76 #include "FreeRTOS.h"
\r
79 /* Standard includes. */
\r
85 /* FreeRTOS+CLI includes. */
\r
86 #include "FreeRTOS_CLI.h"
\r
88 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
89 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
94 * Implements the task-stats command.
\r
96 static portBASE_TYPE prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
99 * Implements the run-time-stats command.
\r
101 static portBASE_TYPE prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
104 * Implements the echo-three-parameters command.
\r
106 static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
109 * Implements the echo-parameters command.
\r
111 static portBASE_TYPE prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
114 * Implements the "trace start" and "trace stop" commands;
\r
116 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
117 static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
120 /* Structure that defines the "run-time-stats" command line command. This
\r
121 generates a table that shows how much run time each task has */
\r
122 static const CLI_Command_Definition_t xRunTimeStats =
\r
124 "run-time-stats", /* The command string to type. */
\r
125 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
126 prvRunTimeStatsCommand, /* The function to run. */
\r
127 0 /* No parameters are expected. */
\r
130 /* Structure that defines the "task-stats" command line command. This generates
\r
131 a table that gives information on each task in the system. */
\r
132 static const CLI_Command_Definition_t xTaskStats =
\r
134 "task-stats", /* The command string to type. */
\r
135 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
136 prvTaskStatsCommand, /* The function to run. */
\r
137 0 /* No parameters are expected. */
\r
140 /* Structure that defines the "echo_3_parameters" command line command. This
\r
141 takes exactly three parameters that the command simply echos back one at a
\r
143 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
145 "echo-3-parameters",
\r
146 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
147 prvThreeParameterEchoCommand, /* The function to run. */
\r
148 3 /* Three parameters are expected, which can take any value. */
\r
151 /* Structure that defines the "echo_parameters" command line command. This
\r
152 takes a variable number of parameters that the command simply echos back one at
\r
154 static const CLI_Command_Definition_t xParameterEcho =
\r
157 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
158 prvParameterEchoCommand, /* The function to run. */
\r
159 -1 /* The user can enter any number of commands. */
\r
162 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
163 /* Structure that defines the "trace" command line command. This takes a single
\r
164 parameter, which can be either "start" or "stop". */
\r
165 static const CLI_Command_Definition_t xStartStopTrace =
\r
168 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
169 prvStartStopTraceCommand, /* The function to run. */
\r
170 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
172 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
174 /*-----------------------------------------------------------*/
\r
176 void vRegisterSampleCLICommands( void )
\r
178 /* Register all the command line commands defined immediately above. */
\r
179 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
180 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
181 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
182 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
184 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
186 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
190 /*-----------------------------------------------------------*/
\r
192 static portBASE_TYPE prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
194 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
196 /* Remove compile time warnings about unused parameters, and check the
\r
197 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
198 write buffer length is adequate, so does not check for buffer overflows. */
\r
199 ( void ) pcCommandString;
\r
200 ( void ) xWriteBufferLen;
\r
201 configASSERT( pcWriteBuffer );
\r
203 /* Generate a table of task stats. */
\r
204 strcpy( pcWriteBuffer, pcHeader );
\r
205 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
207 /* There is no more data to return after this single string, so return
\r
211 /*-----------------------------------------------------------*/
\r
213 static portBASE_TYPE prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
215 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
217 /* Remove compile time warnings about unused parameters, and check the
\r
218 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
219 write buffer length is adequate, so does not check for buffer overflows. */
\r
220 ( void ) pcCommandString;
\r
221 ( void ) xWriteBufferLen;
\r
222 configASSERT( pcWriteBuffer );
\r
224 /* Generate a table of task stats. */
\r
225 strcpy( pcWriteBuffer, pcHeader );
\r
226 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
228 /* There is no more data to return after this single string, so return
\r
232 /*-----------------------------------------------------------*/
\r
234 static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
236 const char *pcParameter;
\r
237 portBASE_TYPE xParameterStringLength, xReturn;
\r
238 static portBASE_TYPE lParameterNumber = 0;
\r
240 /* Remove compile time warnings about unused parameters, and check the
\r
241 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
242 write buffer length is adequate, so does not check for buffer overflows. */
\r
243 ( void ) pcCommandString;
\r
244 ( void ) xWriteBufferLen;
\r
245 configASSERT( pcWriteBuffer );
\r
247 if( lParameterNumber == 0 )
\r
249 /* The first time the function is called after the command has been
\r
250 entered just a header string is returned. */
\r
251 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
253 /* Next time the function is called the first parameter will be echoed
\r
255 lParameterNumber = 1L;
\r
257 /* There is more data to be returned as no parameters have been echoed
\r
263 /* Obtain the parameter string. */
\r
264 pcParameter = FreeRTOS_CLIGetParameter
\r
266 pcCommandString, /* The command string itself. */
\r
267 lParameterNumber, /* Return the next parameter. */
\r
268 &xParameterStringLength /* Store the parameter string length. */
\r
271 /* Sanity check something was returned. */
\r
272 configASSERT( pcParameter );
\r
274 /* Return the parameter string. */
\r
275 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
276 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
277 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
278 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
280 /* If this is the last of the three parameters then there are no more
\r
281 strings to return after this one. */
\r
282 if( lParameterNumber == 3L )
\r
284 /* If this is the last of the three parameters then there are no more
\r
285 strings to return after this one. */
\r
287 lParameterNumber = 0L;
\r
291 /* There are more parameters to return after this one. */
\r
293 lParameterNumber++;
\r
299 /*-----------------------------------------------------------*/
\r
301 static portBASE_TYPE prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
303 const char *pcParameter;
\r
304 portBASE_TYPE xParameterStringLength, xReturn;
\r
305 static portBASE_TYPE lParameterNumber = 0;
\r
307 /* Remove compile time warnings about unused parameters, and check the
\r
308 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
309 write buffer length is adequate, so does not check for buffer overflows. */
\r
310 ( void ) pcCommandString;
\r
311 ( void ) xWriteBufferLen;
\r
312 configASSERT( pcWriteBuffer );
\r
314 if( lParameterNumber == 0 )
\r
316 /* The first time the function is called after the command has been
\r
317 entered just a header string is returned. */
\r
318 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
320 /* Next time the function is called the first parameter will be echoed
\r
322 lParameterNumber = 1L;
\r
324 /* There is more data to be returned as no parameters have been echoed
\r
330 /* Obtain the parameter string. */
\r
331 pcParameter = FreeRTOS_CLIGetParameter
\r
333 pcCommandString, /* The command string itself. */
\r
334 lParameterNumber, /* Return the next parameter. */
\r
335 &xParameterStringLength /* Store the parameter string length. */
\r
338 if( pcParameter != NULL )
\r
340 /* Return the parameter string. */
\r
341 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
342 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
343 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
344 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
346 /* There might be more parameters to return after this one. */
\r
348 lParameterNumber++;
\r
352 /* No more parameters were found. Make sure the write buffer does
\r
353 not contain a valid string. */
\r
354 pcWriteBuffer[ 0 ] = 0x00;
\r
356 /* No more data to return. */
\r
359 /* Start over the next time this command is executed. */
\r
360 lParameterNumber = 0;
\r
366 /*-----------------------------------------------------------*/
\r
368 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
370 static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
372 const char *pcParameter;
\r
373 portBASE_TYPE lParameterStringLength;
\r
375 /* Remove compile time warnings about unused parameters, and check the
\r
376 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
377 write buffer length is adequate, so does not check for buffer overflows. */
\r
378 ( void ) pcCommandString;
\r
379 ( void ) xWriteBufferLen;
\r
380 configASSERT( pcWriteBuffer );
\r
382 /* Obtain the parameter string. */
\r
383 pcParameter = FreeRTOS_CLIGetParameter
\r
385 pcCommandString, /* The command string itself. */
\r
386 1, /* Return the first parameter. */
\r
387 &lParameterStringLength /* Store the parameter string length. */
\r
390 /* Sanity check something was returned. */
\r
391 configASSERT( pcParameter );
\r
393 /* There are only two valid parameter values. */
\r
394 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
396 /* Start or restart the trace. */
\r
401 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
403 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
405 /* End the trace, if one is running. */
\r
407 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
411 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
414 /* There is no more data to return after this single string, so return
\r
419 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r