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 * Registers the CLI commands defined within this file with the FreeRTOS+CLI
\r
123 * command line interface.
\r
125 void vRegisterSampleCLICommands( void );
\r
128 * Implements the "trace start" and "trace stop" commands;
\r
130 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
131 static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
134 /* Structure that defines the "run-time-stats" command line command. This
\r
135 generates a table that shows how much run time each task has */
\r
136 static const CLI_Command_Definition_t xRunTimeStats =
\r
138 "run-time-stats", /* The command string to type. */
\r
139 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
140 prvRunTimeStatsCommand, /* The function to run. */
\r
141 0 /* No parameters are expected. */
\r
144 /* Structure that defines the "task-stats" command line command. This generates
\r
145 a table that gives information on each task in the system. */
\r
146 static const CLI_Command_Definition_t xTaskStats =
\r
148 "task-stats", /* The command string to type. */
\r
149 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
150 prvTaskStatsCommand, /* The function to run. */
\r
151 0 /* No parameters are expected. */
\r
154 /* Structure that defines the "echo_3_parameters" command line command. This
\r
155 takes exactly three parameters that the command simply echos back one at a
\r
157 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
159 "echo-3-parameters",
\r
160 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
161 prvThreeParameterEchoCommand, /* The function to run. */
\r
162 3 /* Three parameters are expected, which can take any value. */
\r
165 /* Structure that defines the "echo_parameters" command line command. This
\r
166 takes a variable number of parameters that the command simply echos back one at
\r
168 static const CLI_Command_Definition_t xParameterEcho =
\r
171 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
172 prvParameterEchoCommand, /* The function to run. */
\r
173 -1 /* The user can enter any number of commands. */
\r
176 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
177 /* Structure that defines the "trace" command line command. This takes a single
\r
178 parameter, which can be either "start" or "stop". */
\r
179 static const CLI_Command_Definition_t xStartStopTrace =
\r
182 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
183 prvStartStopTraceCommand, /* The function to run. */
\r
184 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
186 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
188 /*-----------------------------------------------------------*/
\r
190 void vRegisterSampleCLICommands( void )
\r
192 /* Register all the command line commands defined immediately above. */
\r
193 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
194 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
195 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
196 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
198 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
200 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
204 /*-----------------------------------------------------------*/
\r
206 static portBASE_TYPE prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
208 const char *const pcHeader = "Task State Priority Stack #\r\n************************************************\r\n";
\r
210 /* Remove compile time warnings about unused parameters, and check the
\r
211 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
212 write buffer length is adequate, so does not check for buffer overflows. */
\r
213 ( void ) pcCommandString;
\r
214 ( void ) xWriteBufferLen;
\r
215 configASSERT( pcWriteBuffer );
\r
217 /* Generate a table of task stats. */
\r
218 strcpy( pcWriteBuffer, pcHeader );
\r
219 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
221 /* There is no more data to return after this single string, so return
\r
225 /*-----------------------------------------------------------*/
\r
227 static portBASE_TYPE prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
229 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
231 /* Remove compile time warnings about unused parameters, and check the
\r
232 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
233 write buffer length is adequate, so does not check for buffer overflows. */
\r
234 ( void ) pcCommandString;
\r
235 ( void ) xWriteBufferLen;
\r
236 configASSERT( pcWriteBuffer );
\r
238 /* Generate a table of task stats. */
\r
239 strcpy( pcWriteBuffer, pcHeader );
\r
240 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
242 /* There is no more data to return after this single string, so return
\r
246 /*-----------------------------------------------------------*/
\r
248 static portBASE_TYPE prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
250 const char *pcParameter;
\r
251 portBASE_TYPE xParameterStringLength, xReturn;
\r
252 static portBASE_TYPE lParameterNumber = 0;
\r
254 /* Remove compile time warnings about unused parameters, and check the
\r
255 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
256 write buffer length is adequate, so does not check for buffer overflows. */
\r
257 ( void ) pcCommandString;
\r
258 ( void ) xWriteBufferLen;
\r
259 configASSERT( pcWriteBuffer );
\r
261 if( lParameterNumber == 0 )
\r
263 /* The first time the function is called after the command has been
\r
264 entered just a header string is returned. */
\r
265 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
267 /* Next time the function is called the first parameter will be echoed
\r
269 lParameterNumber = 1L;
\r
271 /* There is more data to be returned as no parameters have been echoed
\r
277 /* Obtain the parameter string. */
\r
278 pcParameter = FreeRTOS_CLIGetParameter
\r
280 pcCommandString, /* The command string itself. */
\r
281 lParameterNumber, /* Return the next parameter. */
\r
282 &xParameterStringLength /* Store the parameter string length. */
\r
285 /* Sanity check something was returned. */
\r
286 configASSERT( pcParameter );
\r
288 /* Return the parameter string. */
\r
289 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
290 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
291 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
292 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
294 /* If this is the last of the three parameters then there are no more
\r
295 strings to return after this one. */
\r
296 if( lParameterNumber == 3L )
\r
298 /* If this is the last of the three parameters then there are no more
\r
299 strings to return after this one. */
\r
301 lParameterNumber = 0L;
\r
305 /* There are more parameters to return after this one. */
\r
307 lParameterNumber++;
\r
313 /*-----------------------------------------------------------*/
\r
315 static portBASE_TYPE prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
317 const char *pcParameter;
\r
318 portBASE_TYPE xParameterStringLength, xReturn;
\r
319 static portBASE_TYPE lParameterNumber = 0;
\r
321 /* Remove compile time warnings about unused parameters, and check the
\r
322 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
323 write buffer length is adequate, so does not check for buffer overflows. */
\r
324 ( void ) pcCommandString;
\r
325 ( void ) xWriteBufferLen;
\r
326 configASSERT( pcWriteBuffer );
\r
328 if( lParameterNumber == 0 )
\r
330 /* The first time the function is called after the command has been
\r
331 entered just a header string is returned. */
\r
332 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
334 /* Next time the function is called the first parameter will be echoed
\r
336 lParameterNumber = 1L;
\r
338 /* There is more data to be returned as no parameters have been echoed
\r
344 /* Obtain the parameter string. */
\r
345 pcParameter = FreeRTOS_CLIGetParameter
\r
347 pcCommandString, /* The command string itself. */
\r
348 lParameterNumber, /* Return the next parameter. */
\r
349 &xParameterStringLength /* Store the parameter string length. */
\r
352 if( pcParameter != NULL )
\r
354 /* Return the parameter string. */
\r
355 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
356 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
357 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
358 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
360 /* There might be more parameters to return after this one. */
\r
362 lParameterNumber++;
\r
366 /* No more parameters were found. Make sure the write buffer does
\r
367 not contain a valid string. */
\r
368 pcWriteBuffer[ 0 ] = 0x00;
\r
370 /* No more data to return. */
\r
373 /* Start over the next time this command is executed. */
\r
374 lParameterNumber = 0;
\r
380 /*-----------------------------------------------------------*/
\r
382 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
384 static portBASE_TYPE prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
387 portBASE_TYPE lParameterStringLength;
\r
389 /* Remove compile time warnings about unused parameters, and check the
\r
390 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
391 write buffer length is adequate, so does not check for buffer overflows. */
\r
392 ( void ) pcCommandString;
\r
393 ( void ) xWriteBufferLen;
\r
394 configASSERT( pcWriteBuffer );
\r
396 /* Obtain the parameter string. */
\r
397 pcParameter = FreeRTOS_CLIGetParameter
\r
399 pcCommandString, /* The command string itself. */
\r
400 1, /* Return the first parameter. */
\r
401 &lParameterStringLength /* Store the parameter string length. */
\r
404 /* Sanity check something was returned. */
\r
405 configASSERT( pcParameter );
\r
407 /* There are only two valid parameter values. */
\r
408 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
410 /* Start or restart the trace. */
\r
415 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
417 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
419 /* End the trace, if one is running. */
\r
421 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
425 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
428 /* There is no more data to return after this single string, so return
\r
433 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r