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
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
93 * The function that registers the commands that are defined within this file.
\r
95 void vRegisterSampleCLICommands( void );
\r
98 * Implements the task-stats command.
\r
100 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
103 * Implements the run-time-stats command.
\r
105 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
108 * Implements the echo-three-parameters command.
\r
110 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
113 * Implements the echo-parameters command.
\r
115 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
118 * Implements the "trace start" and "trace stop" commands;
\r
120 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
121 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
124 /* Structure that defines the "run-time-stats" command line command. This
\r
125 generates a table that shows how much run time each task has */
\r
126 static const CLI_Command_Definition_t xRunTimeStats =
\r
128 "run-time-stats", /* The command string to type. */
\r
129 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
130 prvRunTimeStatsCommand, /* The function to run. */
\r
131 0 /* No parameters are expected. */
\r
134 /* Structure that defines the "task-stats" command line command. This generates
\r
135 a table that gives information on each task in the system. */
\r
136 static const CLI_Command_Definition_t xTaskStats =
\r
138 "task-stats", /* The command string to type. */
\r
139 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
140 prvTaskStatsCommand, /* The function to run. */
\r
141 0 /* No parameters are expected. */
\r
144 /* Structure that defines the "echo_3_parameters" command line command. This
\r
145 takes exactly three parameters that the command simply echos back one at a
\r
147 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
149 "echo-3-parameters",
\r
150 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
151 prvThreeParameterEchoCommand, /* The function to run. */
\r
152 3 /* Three parameters are expected, which can take any value. */
\r
155 /* Structure that defines the "echo_parameters" command line command. This
\r
156 takes a variable number of parameters that the command simply echos back one at
\r
158 static const CLI_Command_Definition_t xParameterEcho =
\r
161 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
162 prvParameterEchoCommand, /* The function to run. */
\r
163 -1 /* The user can enter any number of commands. */
\r
166 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
167 /* Structure that defines the "trace" command line command. This takes a single
\r
168 parameter, which can be either "start" or "stop". */
\r
169 static const CLI_Command_Definition_t xStartStopTrace =
\r
172 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
173 prvStartStopTraceCommand, /* The function to run. */
\r
174 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
176 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
178 /*-----------------------------------------------------------*/
\r
180 void vRegisterSampleCLICommands( void )
\r
182 /* Register all the command line commands defined immediately above. */
\r
183 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
184 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
185 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
186 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
188 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
190 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
194 /*-----------------------------------------------------------*/
\r
196 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
198 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\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 /* Generate a table of task stats. */
\r
208 strcpy( pcWriteBuffer, pcHeader );
\r
209 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
211 /* There is no more data to return after this single string, so return
\r
215 /*-----------------------------------------------------------*/
\r
217 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
219 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
221 /* Remove compile time warnings about unused parameters, and check the
\r
222 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
223 write buffer length is adequate, so does not check for buffer overflows. */
\r
224 ( void ) pcCommandString;
\r
225 ( void ) xWriteBufferLen;
\r
226 configASSERT( pcWriteBuffer );
\r
228 /* Generate a table of task stats. */
\r
229 strcpy( pcWriteBuffer, pcHeader );
\r
230 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
232 /* There is no more data to return after this single string, so return
\r
236 /*-----------------------------------------------------------*/
\r
238 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
240 const char *pcParameter;
\r
241 BaseType_t xParameterStringLength, xReturn;
\r
242 static BaseType_t lParameterNumber = 0;
\r
244 /* Remove compile time warnings about unused parameters, and check the
\r
245 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
246 write buffer length is adequate, so does not check for buffer overflows. */
\r
247 ( void ) pcCommandString;
\r
248 ( void ) xWriteBufferLen;
\r
249 configASSERT( pcWriteBuffer );
\r
251 if( lParameterNumber == 0 )
\r
253 /* The first time the function is called after the command has been
\r
254 entered just a header string is returned. */
\r
255 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
257 /* Next time the function is called the first parameter will be echoed
\r
259 lParameterNumber = 1L;
\r
261 /* There is more data to be returned as no parameters have been echoed
\r
267 /* Obtain the parameter string. */
\r
268 pcParameter = FreeRTOS_CLIGetParameter
\r
270 pcCommandString, /* The command string itself. */
\r
271 lParameterNumber, /* Return the next parameter. */
\r
272 &xParameterStringLength /* Store the parameter string length. */
\r
275 /* Sanity check something was returned. */
\r
276 configASSERT( pcParameter );
\r
278 /* Return the parameter string. */
\r
279 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
280 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
281 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
282 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\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
286 if( lParameterNumber == 3L )
\r
288 /* If this is the last of the three parameters then there are no more
\r
289 strings to return after this one. */
\r
291 lParameterNumber = 0L;
\r
295 /* There are more parameters to return after this one. */
\r
297 lParameterNumber++;
\r
303 /*-----------------------------------------------------------*/
\r
305 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
307 const char *pcParameter;
\r
308 BaseType_t xParameterStringLength, xReturn;
\r
309 static BaseType_t lParameterNumber = 0;
\r
311 /* Remove compile time warnings about unused parameters, and check the
\r
312 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
313 write buffer length is adequate, so does not check for buffer overflows. */
\r
314 ( void ) pcCommandString;
\r
315 ( void ) xWriteBufferLen;
\r
316 configASSERT( pcWriteBuffer );
\r
318 if( lParameterNumber == 0 )
\r
320 /* The first time the function is called after the command has been
\r
321 entered just a header string is returned. */
\r
322 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
324 /* Next time the function is called the first parameter will be echoed
\r
326 lParameterNumber = 1L;
\r
328 /* There is more data to be returned as no parameters have been echoed
\r
334 /* Obtain the parameter string. */
\r
335 pcParameter = FreeRTOS_CLIGetParameter
\r
337 pcCommandString, /* The command string itself. */
\r
338 lParameterNumber, /* Return the next parameter. */
\r
339 &xParameterStringLength /* Store the parameter string length. */
\r
342 if( pcParameter != NULL )
\r
344 /* Return the parameter string. */
\r
345 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
346 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
347 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
348 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
350 /* There might be more parameters to return after this one. */
\r
352 lParameterNumber++;
\r
356 /* No more parameters were found. Make sure the write buffer does
\r
357 not contain a valid string. */
\r
358 pcWriteBuffer[ 0 ] = 0x00;
\r
360 /* No more data to return. */
\r
363 /* Start over the next time this command is executed. */
\r
364 lParameterNumber = 0;
\r
370 /*-----------------------------------------------------------*/
\r
372 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
374 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
376 const char *pcParameter;
\r
377 BaseType_t lParameterStringLength;
\r
379 /* Remove compile time warnings about unused parameters, and check the
\r
380 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
381 write buffer length is adequate, so does not check for buffer overflows. */
\r
382 ( void ) pcCommandString;
\r
383 ( void ) xWriteBufferLen;
\r
384 configASSERT( pcWriteBuffer );
\r
386 /* Obtain the parameter string. */
\r
387 pcParameter = FreeRTOS_CLIGetParameter
\r
389 pcCommandString, /* The command string itself. */
\r
390 1, /* Return the first parameter. */
\r
391 &lParameterStringLength /* Store the parameter string length. */
\r
394 /* Sanity check something was returned. */
\r
395 configASSERT( pcParameter );
\r
397 /* There are only two valid parameter values. */
\r
398 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
400 /* Start or restart the trace. */
\r
405 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
407 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
409 /* End the trace, if one is running. */
\r
411 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
415 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
418 /* There is no more data to return after this single string, so return
\r
423 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r