2 FreeRTOS V9.0.0 - Copyright (C) 2016 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 BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
101 * Implements the task-stats command.
\r
103 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
106 * Implements the echo-three-parameters command.
\r
108 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
111 * Implements the echo-parameters command.
\r
113 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
116 * Implements the "trace start" and "trace stop" commands;
\r
118 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
119 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
122 /* Structure that defines the "run-time-stats" command line command. This
\r
123 generates a table that shows how much run time each task has */
\r
124 static const CLI_Command_Definition_t xRunTimeStats =
\r
126 "run-time-stats", /* The command string to type. */
\r
127 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
128 prvRunTimeStatsCommand, /* The function to run. */
\r
129 0 /* No parameters are expected. */
\r
132 /* Structure that defines the "task-stats" command line command. This generates
\r
133 a table that gives information on each task in the system. */
\r
134 static const CLI_Command_Definition_t xTaskStats =
\r
136 "task-stats", /* The command string to type. */
\r
137 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
138 prvTaskStatsCommand, /* The function to run. */
\r
139 0 /* No parameters are expected. */
\r
142 /* Structure that defines the "echo_3_parameters" command line command. This
\r
143 takes exactly three parameters that the command simply echos back one at a
\r
145 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
147 "echo-3-parameters",
\r
148 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
149 prvThreeParameterEchoCommand, /* The function to run. */
\r
150 3 /* Three parameters are expected, which can take any value. */
\r
153 /* Structure that defines the "echo_parameters" command line command. This
\r
154 takes a variable number of parameters that the command simply echos back one at
\r
156 static const CLI_Command_Definition_t xParameterEcho =
\r
159 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
160 prvParameterEchoCommand, /* The function to run. */
\r
161 -1 /* The user can enter any number of commands. */
\r
164 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
165 /* Structure that defines the "trace" command line command. This takes a single
\r
166 parameter, which can be either "start" or "stop". */
\r
167 static const CLI_Command_Definition_t xStartStopTrace =
\r
170 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
171 prvStartStopTraceCommand, /* The function to run. */
\r
172 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
174 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
176 /*-----------------------------------------------------------*/
\r
178 void vRegisterSampleCLICommands( void )
\r
180 /* Register all the command line commands defined immediately above. */
\r
181 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
182 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
183 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
184 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
186 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
188 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
192 /*-----------------------------------------------------------*/
\r
194 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
196 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
198 /* Remove compile time warnings about unused parameters, and check the
\r
199 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
200 write buffer length is adequate, so does not check for buffer overflows. */
\r
201 ( void ) pcCommandString;
\r
202 ( void ) xWriteBufferLen;
\r
203 configASSERT( pcWriteBuffer );
\r
205 /* Generate a table of task stats. */
\r
206 strcpy( pcWriteBuffer, pcHeader );
\r
207 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
209 /* There is no more data to return after this single string, so return
\r
213 /*-----------------------------------------------------------*/
\r
215 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
217 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
219 /* Remove compile time warnings about unused parameters, and check the
\r
220 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
221 write buffer length is adequate, so does not check for buffer overflows. */
\r
222 ( void ) pcCommandString;
\r
223 ( void ) xWriteBufferLen;
\r
224 configASSERT( pcWriteBuffer );
\r
226 /* Generate a table of task stats. */
\r
227 strcpy( pcWriteBuffer, pcHeader );
\r
228 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
230 /* There is no more data to return after this single string, so return
\r
234 /*-----------------------------------------------------------*/
\r
236 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
238 const char *pcParameter;
\r
239 BaseType_t xParameterStringLength, xReturn;
\r
240 static BaseType_t lParameterNumber = 0;
\r
242 /* Remove compile time warnings about unused parameters, and check the
\r
243 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
244 write buffer length is adequate, so does not check for buffer overflows. */
\r
245 ( void ) pcCommandString;
\r
246 ( void ) xWriteBufferLen;
\r
247 configASSERT( pcWriteBuffer );
\r
249 if( lParameterNumber == 0 )
\r
251 /* The first time the function is called after the command has been
\r
252 entered just a header string is returned. */
\r
253 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
255 /* Next time the function is called the first parameter will be echoed
\r
257 lParameterNumber = 1L;
\r
259 /* There is more data to be returned as no parameters have been echoed
\r
265 /* Obtain the parameter string. */
\r
266 pcParameter = FreeRTOS_CLIGetParameter
\r
268 pcCommandString, /* The command string itself. */
\r
269 lParameterNumber, /* Return the next parameter. */
\r
270 &xParameterStringLength /* Store the parameter string length. */
\r
273 /* Sanity check something was returned. */
\r
274 configASSERT( pcParameter );
\r
276 /* Return the parameter string. */
\r
277 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
278 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
279 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
280 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\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
284 if( lParameterNumber == 3L )
\r
286 /* If this is the last of the three parameters then there are no more
\r
287 strings to return after this one. */
\r
289 lParameterNumber = 0L;
\r
293 /* There are more parameters to return after this one. */
\r
295 lParameterNumber++;
\r
301 /*-----------------------------------------------------------*/
\r
303 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
305 const char *pcParameter;
\r
306 BaseType_t xParameterStringLength, xReturn;
\r
307 static BaseType_t lParameterNumber = 0;
\r
309 /* Remove compile time warnings about unused parameters, and check the
\r
310 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
311 write buffer length is adequate, so does not check for buffer overflows. */
\r
312 ( void ) pcCommandString;
\r
313 ( void ) xWriteBufferLen;
\r
314 configASSERT( pcWriteBuffer );
\r
316 if( lParameterNumber == 0 )
\r
318 /* The first time the function is called after the command has been
\r
319 entered just a header string is returned. */
\r
320 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
322 /* Next time the function is called the first parameter will be echoed
\r
324 lParameterNumber = 1L;
\r
326 /* There is more data to be returned as no parameters have been echoed
\r
332 /* Obtain the parameter string. */
\r
333 pcParameter = FreeRTOS_CLIGetParameter
\r
335 pcCommandString, /* The command string itself. */
\r
336 lParameterNumber, /* Return the next parameter. */
\r
337 &xParameterStringLength /* Store the parameter string length. */
\r
340 if( pcParameter != NULL )
\r
342 /* Return the parameter string. */
\r
343 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
344 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
345 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
346 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
348 /* There might be more parameters to return after this one. */
\r
350 lParameterNumber++;
\r
354 /* No more parameters were found. Make sure the write buffer does
\r
355 not contain a valid string. */
\r
356 pcWriteBuffer[ 0 ] = 0x00;
\r
358 /* No more data to return. */
\r
361 /* Start over the next time this command is executed. */
\r
362 lParameterNumber = 0;
\r
368 /*-----------------------------------------------------------*/
\r
370 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
372 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
374 const char *pcParameter;
\r
375 BaseType_t lParameterStringLength;
\r
377 /* Remove compile time warnings about unused parameters, and check the
\r
378 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
379 write buffer length is adequate, so does not check for buffer overflows. */
\r
380 ( void ) pcCommandString;
\r
381 ( void ) xWriteBufferLen;
\r
382 configASSERT( pcWriteBuffer );
\r
384 /* Obtain the parameter string. */
\r
385 pcParameter = FreeRTOS_CLIGetParameter
\r
387 pcCommandString, /* The command string itself. */
\r
388 1, /* Return the first parameter. */
\r
389 &lParameterStringLength /* Store the parameter string length. */
\r
392 /* Sanity check something was returned. */
\r
393 configASSERT( pcParameter );
\r
395 /* There are only two valid parameter values. */
\r
396 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
398 /* Start or restart the trace. */
\r
403 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
405 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
407 /* End the trace, if one is running. */
\r
409 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
413 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
416 /* There is no more data to return after this single string, so return
\r
421 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r