2 FreeRTOS V8.1.0 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
6 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
8 ***************************************************************************
\r
10 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
11 * Complete, revised, and edited pdf reference manuals are also *
\r
14 * Purchasing FreeRTOS documentation will not only help you, by *
\r
15 * ensuring you get running as quickly as possible and with an *
\r
16 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
17 * the FreeRTOS project to continue with its mission of providing *
\r
18 * professional grade, cross platform, de facto standard solutions *
\r
19 * for microcontrollers - completely free of charge! *
\r
21 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
23 * Thank you for using FreeRTOS, and thank you for your support! *
\r
25 ***************************************************************************
\r
28 This file is part of the FreeRTOS distribution.
\r
30 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
31 the terms of the GNU General Public License (version 2) as published by the
\r
32 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
34 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
35 distribute a combined work that includes FreeRTOS without being obliged to
\r
36 provide the source code for proprietary components outside of the FreeRTOS
\r
39 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
40 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
41 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
42 details. You should have received a copy of the GNU General Public License
\r
43 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
44 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
45 writing to Real Time Engineers Ltd., contact details for whom are available
\r
46 on the FreeRTOS WEB site.
\r
50 ***************************************************************************
\r
52 * Having a problem? Start by reading the FAQ "My application does *
\r
53 * not run, what could be wrong?" *
\r
55 * http://www.FreeRTOS.org/FAQHelp.html *
\r
57 ***************************************************************************
\r
60 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
61 license and Real Time Engineers Ltd. contact details.
\r
63 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
64 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
65 fully thread aware and reentrant UDP/IP stack.
\r
67 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
68 Integrity Systems, who sell the code with commercial support,
\r
69 indemnification and middleware, under the OpenRTOS brand.
\r
71 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
72 engineered and independently SIL3 certified version for use in safety and
\r
73 mission critical applications that require provable dependability.
\r
76 /******************************************************************************
\r
78 * See the following URL for information on the commands defined in this file:
\r
79 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
81 ******************************************************************************/
\r
84 /* FreeRTOS includes. */
\r
85 #include "FreeRTOS.h"
\r
88 /* Standard includes. */
\r
93 /* FreeRTOS+CLI includes. */
\r
94 #include "FreeRTOS_CLI.h"
\r
96 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
97 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
102 * Implements the run-time-stats command.
\r
104 static portBASE_TYPE prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
107 * Implements the task-stats command.
\r
109 static portBASE_TYPE prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
112 * Implements the echo-three-parameters command.
\r
114 static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
117 * Implements the echo-parameters command.
\r
119 static portBASE_TYPE prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\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
380 const char *pcParameter;
\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