2 FreeRTOS V8.0.1 - 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 !<<
\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
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
66 /******************************************************************************
\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
71 ******************************************************************************/
\r
74 /* FreeRTOS includes. */
\r
75 #include "FreeRTOS.h"
\r
78 /* Standard includes. */
\r
83 /* FreeRTOS+CLI includes. */
\r
84 #include "FreeRTOS_CLI.h"
\r
86 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
87 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
92 * Implements the run-time-stats command.
\r
94 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
97 * Implements the task-stats command.
\r
99 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
102 * Implements the echo-three-parameters command.
\r
104 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
107 * Implements the echo-parameters command.
\r
109 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
112 * Implements the "trace start" and "trace stop" commands;
\r
114 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
115 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
118 /* Structure that defines the "run-time-stats" command line command. This
\r
119 generates a table that shows how much run time each task has */
\r
120 static const CLI_Command_Definition_t xRunTimeStats =
\r
122 "run-time-stats", /* The command string to type. */
\r
123 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
124 prvRunTimeStatsCommand, /* The function to run. */
\r
125 0 /* No parameters are expected. */
\r
128 /* Structure that defines the "task-stats" command line command. This generates
\r
129 a table that gives information on each task in the system. */
\r
130 static const CLI_Command_Definition_t xTaskStats =
\r
132 "task-stats", /* The command string to type. */
\r
133 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
134 prvTaskStatsCommand, /* The function to run. */
\r
135 0 /* No parameters are expected. */
\r
138 /* Structure that defines the "echo_3_parameters" command line command. This
\r
139 takes exactly three parameters that the command simply echos back one at a
\r
141 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
143 "echo-3-parameters",
\r
144 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
145 prvThreeParameterEchoCommand, /* The function to run. */
\r
146 3 /* Three parameters are expected, which can take any value. */
\r
149 /* Structure that defines the "echo_parameters" command line command. This
\r
150 takes a variable number of parameters that the command simply echos back one at
\r
152 static const CLI_Command_Definition_t xParameterEcho =
\r
155 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
156 prvParameterEchoCommand, /* The function to run. */
\r
157 -1 /* The user can enter any number of commands. */
\r
160 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
161 /* Structure that defines the "trace" command line command. This takes a single
\r
162 parameter, which can be either "start" or "stop". */
\r
163 static const CLI_Command_Definition_t xStartStopTrace =
\r
166 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
167 prvStartStopTraceCommand, /* The function to run. */
\r
168 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
170 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
172 /*-----------------------------------------------------------*/
\r
174 void vRegisterSampleCLICommands( void )
\r
176 /* Register all the command line commands defined immediately above. */
\r
177 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
178 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
179 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
180 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
182 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
184 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
188 /*-----------------------------------------------------------*/
\r
190 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
192 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
194 /* Remove compile time warnings about unused parameters, and check the
\r
195 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
196 write buffer length is adequate, so does not check for buffer overflows. */
\r
197 ( void ) pcCommandString;
\r
198 ( void ) xWriteBufferLen;
\r
199 configASSERT( pcWriteBuffer );
\r
201 /* Generate a table of task stats. */
\r
202 strcpy( pcWriteBuffer, pcHeader );
\r
203 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
205 /* There is no more data to return after this single string, so return
\r
209 /*-----------------------------------------------------------*/
\r
211 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
213 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
215 /* Remove compile time warnings about unused parameters, and check the
\r
216 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
217 write buffer length is adequate, so does not check for buffer overflows. */
\r
218 ( void ) pcCommandString;
\r
219 ( void ) xWriteBufferLen;
\r
220 configASSERT( pcWriteBuffer );
\r
222 /* Generate a table of task stats. */
\r
223 strcpy( pcWriteBuffer, pcHeader );
\r
224 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
226 /* There is no more data to return after this single string, so return
\r
230 /*-----------------------------------------------------------*/
\r
232 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
234 const char *pcParameter;
\r
235 BaseType_t xParameterStringLength, xReturn;
\r
236 static BaseType_t lParameterNumber = 0;
\r
238 /* Remove compile time warnings about unused parameters, and check the
\r
239 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
240 write buffer length is adequate, so does not check for buffer overflows. */
\r
241 ( void ) pcCommandString;
\r
242 ( void ) xWriteBufferLen;
\r
243 configASSERT( pcWriteBuffer );
\r
245 if( lParameterNumber == 0 )
\r
247 /* The first time the function is called after the command has been
\r
248 entered just a header string is returned. */
\r
249 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
251 /* Next time the function is called the first parameter will be echoed
\r
253 lParameterNumber = 1L;
\r
255 /* There is more data to be returned as no parameters have been echoed
\r
261 /* Obtain the parameter string. */
\r
262 pcParameter = FreeRTOS_CLIGetParameter
\r
264 pcCommandString, /* The command string itself. */
\r
265 lParameterNumber, /* Return the next parameter. */
\r
266 &xParameterStringLength /* Store the parameter string length. */
\r
269 /* Sanity check something was returned. */
\r
270 configASSERT( pcParameter );
\r
272 /* Return the parameter string. */
\r
273 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
274 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
275 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
276 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
278 /* If this is the last of the three parameters then there are no more
\r
279 strings to return after this one. */
\r
280 if( lParameterNumber == 3L )
\r
282 /* If this is the last of the three parameters then there are no more
\r
283 strings to return after this one. */
\r
285 lParameterNumber = 0L;
\r
289 /* There are more parameters to return after this one. */
\r
291 lParameterNumber++;
\r
297 /*-----------------------------------------------------------*/
\r
299 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
301 const char *pcParameter;
\r
302 BaseType_t xParameterStringLength, xReturn;
\r
303 static BaseType_t lParameterNumber = 0;
\r
305 /* Remove compile time warnings about unused parameters, and check the
\r
306 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
307 write buffer length is adequate, so does not check for buffer overflows. */
\r
308 ( void ) pcCommandString;
\r
309 ( void ) xWriteBufferLen;
\r
310 configASSERT( pcWriteBuffer );
\r
312 if( lParameterNumber == 0 )
\r
314 /* The first time the function is called after the command has been
\r
315 entered just a header string is returned. */
\r
316 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
318 /* Next time the function is called the first parameter will be echoed
\r
320 lParameterNumber = 1L;
\r
322 /* There is more data to be returned as no parameters have been echoed
\r
328 /* Obtain the parameter string. */
\r
329 pcParameter = FreeRTOS_CLIGetParameter
\r
331 pcCommandString, /* The command string itself. */
\r
332 lParameterNumber, /* Return the next parameter. */
\r
333 &xParameterStringLength /* Store the parameter string length. */
\r
336 if( pcParameter != NULL )
\r
338 /* Return the parameter string. */
\r
339 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
340 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
341 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
342 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
344 /* There might be more parameters to return after this one. */
\r
346 lParameterNumber++;
\r
350 /* No more parameters were found. Make sure the write buffer does
\r
351 not contain a valid string. */
\r
352 pcWriteBuffer[ 0 ] = 0x00;
\r
354 /* No more data to return. */
\r
357 /* Start over the next time this command is executed. */
\r
358 lParameterNumber = 0;
\r
364 /*-----------------------------------------------------------*/
\r
366 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
368 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
370 const char *pcParameter;
\r
371 BaseType_t lParameterStringLength;
\r
373 /* Remove compile time warnings about unused parameters, and check the
\r
374 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
375 write buffer length is adequate, so does not check for buffer overflows. */
\r
376 ( void ) pcCommandString;
\r
377 ( void ) xWriteBufferLen;
\r
378 configASSERT( pcWriteBuffer );
\r
380 /* Obtain the parameter string. */
\r
381 pcParameter = FreeRTOS_CLIGetParameter
\r
383 pcCommandString, /* The command string itself. */
\r
384 1, /* Return the first parameter. */
\r
385 &lParameterStringLength /* Store the parameter string length. */
\r
388 /* Sanity check something was returned. */
\r
389 configASSERT( pcParameter );
\r
391 /* There are only two valid parameter values. */
\r
392 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
394 /* Start or restart the trace. */
\r
399 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
401 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
403 /* End the trace, if one is running. */
\r
405 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
409 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
412 /* There is no more data to return after this single string, so return
\r
417 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r