2 FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /******************************************************************************
\r
72 * See the following URL for information on the commands defined in this file:
\r
73 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
75 ******************************************************************************/
\r
78 /* FreeRTOS includes. */
\r
79 #include "FreeRTOS.h"
\r
82 /* Standard includes. */
\r
87 /* FreeRTOS+CLI includes. */
\r
88 #include "FreeRTOS_CLI.h"
\r
90 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
91 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
96 * Implements the run-time-stats command.
\r
98 static portBASE_TYPE prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
101 * Implements the task-stats command.
\r
103 static portBASE_TYPE prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
106 * Implements the echo-three-parameters command.
\r
108 static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
111 * Implements the echo-parameters command.
\r
113 static portBASE_TYPE prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
116 * Registers the CLI commands defined within this file with the FreeRTOS+CLI
\r
117 * command line interface.
\r
119 void vRegisterSampleCLICommands( void );
\r
122 * Implements the "trace start" and "trace stop" commands;
\r
124 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
125 static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
128 /* Structure that defines the "run-time-stats" command line command. This
\r
129 generates a table that shows how much run time each task has */
\r
130 static const CLI_Command_Definition_t xRunTimeStats =
\r
132 "run-time-stats", /* The command string to type. */
\r
133 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
134 prvRunTimeStatsCommand, /* The function to run. */
\r
135 0 /* No parameters are expected. */
\r
138 /* Structure that defines the "task-stats" command line command. This generates
\r
139 a table that gives information on each task in the system. */
\r
140 static const CLI_Command_Definition_t xTaskStats =
\r
142 "task-stats", /* The command string to type. */
\r
143 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
144 prvTaskStatsCommand, /* The function to run. */
\r
145 0 /* No parameters are expected. */
\r
148 /* Structure that defines the "echo_3_parameters" command line command. This
\r
149 takes exactly three parameters that the command simply echos back one at a
\r
151 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
153 "echo-3-parameters",
\r
154 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
155 prvThreeParameterEchoCommand, /* The function to run. */
\r
156 3 /* Three parameters are expected, which can take any value. */
\r
159 /* Structure that defines the "echo_parameters" command line command. This
\r
160 takes a variable number of parameters that the command simply echos back one at
\r
162 static const CLI_Command_Definition_t xParameterEcho =
\r
165 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
166 prvParameterEchoCommand, /* The function to run. */
\r
167 -1 /* The user can enter any number of commands. */
\r
170 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
171 /* Structure that defines the "trace" command line command. This takes a single
\r
172 parameter, which can be either "start" or "stop". */
\r
173 static const CLI_Command_Definition_t xStartStopTrace =
\r
176 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
177 prvStartStopTraceCommand, /* The function to run. */
\r
178 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
180 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
182 /*-----------------------------------------------------------*/
\r
184 void vRegisterSampleCLICommands( void )
\r
186 /* Register all the command line commands defined immediately above. */
\r
187 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
188 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
189 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
190 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
192 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
194 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
198 /*-----------------------------------------------------------*/
\r
200 static portBASE_TYPE prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
202 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
204 /* Remove compile time warnings about unused parameters, and check the
\r
205 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
206 write buffer length is adequate, so does not check for buffer overflows. */
\r
207 ( void ) pcCommandString;
\r
208 ( void ) xWriteBufferLen;
\r
209 configASSERT( pcWriteBuffer );
\r
211 /* Generate a table of task stats. */
\r
212 strcpy( pcWriteBuffer, pcHeader );
\r
213 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
215 /* There is no more data to return after this single string, so return
\r
219 /*-----------------------------------------------------------*/
\r
221 static portBASE_TYPE prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
223 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
225 /* Remove compile time warnings about unused parameters, and check the
\r
226 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
227 write buffer length is adequate, so does not check for buffer overflows. */
\r
228 ( void ) pcCommandString;
\r
229 ( void ) xWriteBufferLen;
\r
230 configASSERT( pcWriteBuffer );
\r
232 /* Generate a table of task stats. */
\r
233 strcpy( pcWriteBuffer, pcHeader );
\r
234 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
236 /* There is no more data to return after this single string, so return
\r
240 /*-----------------------------------------------------------*/
\r
242 static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
244 const char *pcParameter;
\r
245 portBASE_TYPE xParameterStringLength, xReturn;
\r
246 static portBASE_TYPE lParameterNumber = 0;
\r
248 /* Remove compile time warnings about unused parameters, and check the
\r
249 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
250 write buffer length is adequate, so does not check for buffer overflows. */
\r
251 ( void ) pcCommandString;
\r
252 ( void ) xWriteBufferLen;
\r
253 configASSERT( pcWriteBuffer );
\r
255 if( lParameterNumber == 0 )
\r
257 /* The first time the function is called after the command has been
\r
258 entered just a header string is returned. */
\r
259 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
261 /* Next time the function is called the first parameter will be echoed
\r
263 lParameterNumber = 1L;
\r
265 /* There is more data to be returned as no parameters have been echoed
\r
271 /* Obtain the parameter string. */
\r
272 pcParameter = FreeRTOS_CLIGetParameter
\r
274 pcCommandString, /* The command string itself. */
\r
275 lParameterNumber, /* Return the next parameter. */
\r
276 &xParameterStringLength /* Store the parameter string length. */
\r
279 /* Sanity check something was returned. */
\r
280 configASSERT( pcParameter );
\r
282 /* Return the parameter string. */
\r
283 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
284 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
285 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
286 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\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
290 if( lParameterNumber == 3L )
\r
292 /* If this is the last of the three parameters then there are no more
\r
293 strings to return after this one. */
\r
295 lParameterNumber = 0L;
\r
299 /* There are more parameters to return after this one. */
\r
301 lParameterNumber++;
\r
307 /*-----------------------------------------------------------*/
\r
309 static portBASE_TYPE prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
311 const char *pcParameter;
\r
312 portBASE_TYPE xParameterStringLength, xReturn;
\r
313 static portBASE_TYPE lParameterNumber = 0;
\r
315 /* Remove compile time warnings about unused parameters, and check the
\r
316 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
317 write buffer length is adequate, so does not check for buffer overflows. */
\r
318 ( void ) pcCommandString;
\r
319 ( void ) xWriteBufferLen;
\r
320 configASSERT( pcWriteBuffer );
\r
322 if( lParameterNumber == 0 )
\r
324 /* The first time the function is called after the command has been
\r
325 entered just a header string is returned. */
\r
326 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
328 /* Next time the function is called the first parameter will be echoed
\r
330 lParameterNumber = 1L;
\r
332 /* There is more data to be returned as no parameters have been echoed
\r
338 /* Obtain the parameter string. */
\r
339 pcParameter = FreeRTOS_CLIGetParameter
\r
341 pcCommandString, /* The command string itself. */
\r
342 lParameterNumber, /* Return the next parameter. */
\r
343 &xParameterStringLength /* Store the parameter string length. */
\r
346 if( pcParameter != NULL )
\r
348 /* Return the parameter string. */
\r
349 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
350 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
351 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
352 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
354 /* There might be more parameters to return after this one. */
\r
356 lParameterNumber++;
\r
360 /* No more parameters were found. Make sure the write buffer does
\r
361 not contain a valid string. */
\r
362 pcWriteBuffer[ 0 ] = 0x00;
\r
364 /* No more data to return. */
\r
367 /* Start over the next time this command is executed. */
\r
368 lParameterNumber = 0;
\r
374 /*-----------------------------------------------------------*/
\r
376 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
378 static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
381 portBASE_TYPE lParameterStringLength;
\r
383 /* Remove compile time warnings about unused parameters, and check the
\r
384 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
385 write buffer length is adequate, so does not check for buffer overflows. */
\r
386 ( void ) pcCommandString;
\r
387 ( void ) xWriteBufferLen;
\r
388 configASSERT( pcWriteBuffer );
\r
390 /* Obtain the parameter string. */
\r
391 pcParameter = FreeRTOS_CLIGetParameter
\r
393 pcCommandString, /* The command string itself. */
\r
394 1, /* Return the first parameter. */
\r
395 &lParameterStringLength /* Store the parameter string length. */
\r
398 /* Sanity check something was returned. */
\r
399 configASSERT( pcParameter );
\r
401 /* There are only two valid parameter values. */
\r
402 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
404 /* Start or restart the trace. */
\r
409 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
411 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
413 /* End the trace, if one is running. */
\r
415 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
419 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
422 /* There is no more data to return after this single string, so return
\r
427 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r