2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
75 /******************************************************************************
\r
77 * See the following URL for information on the commands defined in this file:
\r
78 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
80 ******************************************************************************/
\r
83 /* FreeRTOS includes. */
\r
84 #include "FreeRTOS.h"
\r
87 /* Standard includes. */
\r
92 /* FreeRTOS+CLI includes. */
\r
93 #include "FreeRTOS_CLI.h"
\r
95 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
96 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
101 * Implements the run-time-stats command.
\r
103 static portBASE_TYPE prvTaskStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
\r
106 * Implements the task-stats command.
\r
108 static portBASE_TYPE prvRunTimeStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
\r
111 * Implements the echo-three-parameters command.
\r
113 static portBASE_TYPE prvThreeParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
\r
116 * Implements the echo-parameters command.
\r
118 static portBASE_TYPE prvParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
\r
121 * Implements the "trace start" and "trace stop" commands;
\r
123 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
124 static portBASE_TYPE prvStartStopTraceCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString );
\r
127 /* Structure that defines the "run-time-stats" command line command. This
\r
128 generates a table that shows how much run time each task has */
\r
129 static const CLI_Command_Definition_t xRunTimeStats =
\r
131 ( const int8_t * const ) "run-time-stats", /* The command string to type. */
\r
132 ( const int8_t * const ) "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
133 prvRunTimeStatsCommand, /* The function to run. */
\r
134 0 /* No parameters are expected. */
\r
137 /* Structure that defines the "task-stats" command line command. This generates
\r
138 a table that gives information on each task in the system. */
\r
139 static const CLI_Command_Definition_t xTaskStats =
\r
141 ( const int8_t * const ) "task-stats", /* The command string to type. */
\r
142 ( const int8_t * const ) "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
143 prvTaskStatsCommand, /* The function to run. */
\r
144 0 /* No parameters are expected. */
\r
147 /* Structure that defines the "echo_3_parameters" command line command. This
\r
148 takes exactly three parameters that the command simply echos back one at a
\r
150 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
152 ( const int8_t * const ) "echo-3-parameters",
\r
153 ( const int8_t * const ) "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
154 prvThreeParameterEchoCommand, /* The function to run. */
\r
155 3 /* Three parameters are expected, which can take any value. */
\r
158 /* Structure that defines the "echo_parameters" command line command. This
\r
159 takes a variable number of parameters that the command simply echos back one at
\r
161 static const CLI_Command_Definition_t xParameterEcho =
\r
163 ( const int8_t * const ) "echo-parameters",
\r
164 ( const int8_t * const ) "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
165 prvParameterEchoCommand, /* The function to run. */
\r
166 -1 /* The user can enter any number of commands. */
\r
169 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
170 /* Structure that defines the "trace" command line command. This takes a single
\r
171 parameter, which can be either "start" or "stop". */
\r
172 static const CLI_Command_Definition_t xStartStopTrace =
\r
174 ( const int8_t * const ) "trace",
\r
175 ( const int8_t * const ) "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
176 prvStartStopTraceCommand, /* The function to run. */
\r
177 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
179 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
181 /*-----------------------------------------------------------*/
\r
183 void vRegisterSampleCLICommands( void )
\r
185 /* Register all the command line commands defined immediately above. */
\r
186 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
187 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
188 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
189 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
191 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
193 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
197 /*-----------------------------------------------------------*/
\r
199 static portBASE_TYPE prvTaskStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
\r
201 const int8_t *const pcHeader = ( int8_t * ) "Task State Priority Stack #\r\n************************************************\r\n";
\r
203 /* Remove compile time warnings about unused parameters, and check the
\r
204 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
205 write buffer length is adequate, so does not check for buffer overflows. */
\r
206 ( void ) pcCommandString;
\r
207 ( void ) xWriteBufferLen;
\r
208 configASSERT( pcWriteBuffer );
\r
210 /* Generate a table of task stats. */
\r
211 strcpy( ( char * ) pcWriteBuffer, ( char * ) pcHeader );
\r
212 vTaskList( pcWriteBuffer + strlen( ( char * ) pcHeader ) );
\r
214 /* There is no more data to return after this single string, so return
\r
218 /*-----------------------------------------------------------*/
\r
220 static portBASE_TYPE prvRunTimeStatsCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
\r
222 const int8_t * const pcHeader = ( int8_t * ) "Task Abs Time % Time\r\n****************************************\r\n";
\r
224 /* Remove compile time warnings about unused parameters, and check the
\r
225 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
226 write buffer length is adequate, so does not check for buffer overflows. */
\r
227 ( void ) pcCommandString;
\r
228 ( void ) xWriteBufferLen;
\r
229 configASSERT( pcWriteBuffer );
\r
231 /* Generate a table of task stats. */
\r
232 strcpy( ( char * ) pcWriteBuffer, ( char * ) pcHeader );
\r
233 vTaskGetRunTimeStats( pcWriteBuffer + strlen( ( char * ) pcHeader ) );
\r
235 /* There is no more data to return after this single string, so return
\r
239 /*-----------------------------------------------------------*/
\r
241 static portBASE_TYPE prvThreeParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
\r
243 int8_t *pcParameter;
\r
244 portBASE_TYPE xParameterStringLength, xReturn;
\r
245 static portBASE_TYPE lParameterNumber = 0;
\r
247 /* Remove compile time warnings about unused parameters, and check the
\r
248 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
249 write buffer length is adequate, so does not check for buffer overflows. */
\r
250 ( void ) pcCommandString;
\r
251 ( void ) xWriteBufferLen;
\r
252 configASSERT( pcWriteBuffer );
\r
254 if( lParameterNumber == 0 )
\r
256 /* The first time the function is called after the command has been
\r
257 entered just a header string is returned. */
\r
258 sprintf( ( char * ) pcWriteBuffer, "The three parameters were:\r\n" );
\r
260 /* Next time the function is called the first parameter will be echoed
\r
262 lParameterNumber = 1L;
\r
264 /* There is more data to be returned as no parameters have been echoed
\r
270 /* Obtain the parameter string. */
\r
271 pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
\r
273 pcCommandString, /* The command string itself. */
\r
274 lParameterNumber, /* Return the next parameter. */
\r
275 &xParameterStringLength /* Store the parameter string length. */
\r
278 /* Sanity check something was returned. */
\r
279 configASSERT( pcParameter );
\r
281 /* Return the parameter string. */
\r
282 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
283 sprintf( ( char * ) pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
284 strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, xParameterStringLength );
\r
285 strncat( ( char * ) pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
287 /* If this is the last of the three parameters then there are no more
\r
288 strings to return after this one. */
\r
289 if( lParameterNumber == 3L )
\r
291 /* If this is the last of the three parameters then there are no more
\r
292 strings to return after this one. */
\r
294 lParameterNumber = 0L;
\r
298 /* There are more parameters to return after this one. */
\r
300 lParameterNumber++;
\r
306 /*-----------------------------------------------------------*/
\r
308 static portBASE_TYPE prvParameterEchoCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
\r
310 int8_t *pcParameter;
\r
311 portBASE_TYPE xParameterStringLength, xReturn;
\r
312 static portBASE_TYPE lParameterNumber = 0;
\r
314 /* Remove compile time warnings about unused parameters, and check the
\r
315 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
316 write buffer length is adequate, so does not check for buffer overflows. */
\r
317 ( void ) pcCommandString;
\r
318 ( void ) xWriteBufferLen;
\r
319 configASSERT( pcWriteBuffer );
\r
321 if( lParameterNumber == 0 )
\r
323 /* The first time the function is called after the command has been
\r
324 entered just a header string is returned. */
\r
325 sprintf( ( char * ) pcWriteBuffer, "The parameters were:\r\n" );
\r
327 /* Next time the function is called the first parameter will be echoed
\r
329 lParameterNumber = 1L;
\r
331 /* There is more data to be returned as no parameters have been echoed
\r
337 /* Obtain the parameter string. */
\r
338 pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
\r
340 pcCommandString, /* The command string itself. */
\r
341 lParameterNumber, /* Return the next parameter. */
\r
342 &xParameterStringLength /* Store the parameter string length. */
\r
345 if( pcParameter != NULL )
\r
347 /* Return the parameter string. */
\r
348 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
349 sprintf( ( char * ) pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
350 strncat( ( char * ) pcWriteBuffer, ( const char * ) pcParameter, xParameterStringLength );
\r
351 strncat( ( char * ) pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
353 /* There might be more parameters to return after this one. */
\r
355 lParameterNumber++;
\r
359 /* No more parameters were found. Make sure the write buffer does
\r
360 not contain a valid string. */
\r
361 pcWriteBuffer[ 0 ] = 0x00;
\r
363 /* No more data to return. */
\r
366 /* Start over the next time this command is executed. */
\r
367 lParameterNumber = 0;
\r
373 /*-----------------------------------------------------------*/
\r
375 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
377 static portBASE_TYPE prvStartStopTraceCommand( int8_t *pcWriteBuffer, size_t xWriteBufferLen, const int8_t *pcCommandString )
\r
379 int8_t *pcParameter;
\r
380 portBASE_TYPE lParameterStringLength;
\r
382 /* Remove compile time warnings about unused parameters, and check the
\r
383 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
384 write buffer length is adequate, so does not check for buffer overflows. */
\r
385 ( void ) pcCommandString;
\r
386 ( void ) xWriteBufferLen;
\r
387 configASSERT( pcWriteBuffer );
\r
389 /* Obtain the parameter string. */
\r
390 pcParameter = ( int8_t * ) FreeRTOS_CLIGetParameter
\r
392 pcCommandString, /* The command string itself. */
\r
393 1, /* Return the first parameter. */
\r
394 &lParameterStringLength /* Store the parameter string length. */
\r
397 /* Sanity check something was returned. */
\r
398 configASSERT( pcParameter );
\r
400 /* There are only two valid parameter values. */
\r
401 if( strncmp( ( const char * ) pcParameter, "start", strlen( "start" ) ) == 0 )
\r
403 /* Start or restart the trace. */
\r
408 sprintf( ( char * ) pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
410 else if( strncmp( ( const char * ) pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
412 /* End the trace, if one is running. */
\r
414 sprintf( ( char * ) pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
418 sprintf( ( char * ) pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
421 /* There is no more data to return after this single string, so return
\r
426 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r