2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /******************************************************************************
\r
98 * See the following URL for information on the commands defined in this file:
\r
99 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
101 ******************************************************************************/
\r
104 /* FreeRTOS includes. */
\r
105 #include "FreeRTOS.h"
\r
108 /* Standard includes. */
\r
109 #include <stdint.h>
\r
111 #include <stdlib.h>
\r
113 /* FreeRTOS+CLI includes. */
\r
114 #include "FreeRTOS_CLI.h"
\r
116 #ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
\r
117 #define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
\r
122 * Implements the run-time-stats command.
\r
124 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
127 * Implements the task-stats command.
\r
129 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
132 * Implements the echo-three-parameters command.
\r
134 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
137 * Implements the echo-parameters command.
\r
139 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
142 * Implements the "trace start" and "trace stop" commands;
\r
144 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
145 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
148 /* Structure that defines the "run-time-stats" command line command. This
\r
149 generates a table that shows how much run time each task has */
\r
150 static const CLI_Command_Definition_t xRunTimeStats =
\r
152 "run-time-stats", /* The command string to type. */
\r
153 "\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
\r
154 prvRunTimeStatsCommand, /* The function to run. */
\r
155 0 /* No parameters are expected. */
\r
158 /* Structure that defines the "task-stats" command line command. This generates
\r
159 a table that gives information on each task in the system. */
\r
160 static const CLI_Command_Definition_t xTaskStats =
\r
162 "task-stats", /* The command string to type. */
\r
163 "\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
\r
164 prvTaskStatsCommand, /* The function to run. */
\r
165 0 /* No parameters are expected. */
\r
168 /* Structure that defines the "echo_3_parameters" command line command. This
\r
169 takes exactly three parameters that the command simply echos back one at a
\r
171 static const CLI_Command_Definition_t xThreeParameterEcho =
\r
173 "echo-3-parameters",
\r
174 "\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
\r
175 prvThreeParameterEchoCommand, /* The function to run. */
\r
176 3 /* Three parameters are expected, which can take any value. */
\r
179 /* Structure that defines the "echo_parameters" command line command. This
\r
180 takes a variable number of parameters that the command simply echos back one at
\r
182 static const CLI_Command_Definition_t xParameterEcho =
\r
185 "\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
\r
186 prvParameterEchoCommand, /* The function to run. */
\r
187 -1 /* The user can enter any number of commands. */
\r
190 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
191 /* Structure that defines the "trace" command line command. This takes a single
\r
192 parameter, which can be either "start" or "stop". */
\r
193 static const CLI_Command_Definition_t xStartStopTrace =
\r
196 "\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
\r
197 prvStartStopTraceCommand, /* The function to run. */
\r
198 1 /* One parameter is expected. Valid values are "start" and "stop". */
\r
200 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r
202 /*-----------------------------------------------------------*/
\r
204 void vRegisterSampleCLICommands( void )
\r
206 /* Register all the command line commands defined immediately above. */
\r
207 FreeRTOS_CLIRegisterCommand( &xTaskStats );
\r
208 FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
\r
209 FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
\r
210 FreeRTOS_CLIRegisterCommand( &xParameterEcho );
\r
212 #if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
\r
214 FreeRTOS_CLIRegisterCommand( & xStartStopTrace );
\r
218 /*-----------------------------------------------------------*/
\r
220 static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
222 const char *const pcHeader = "Task State Priority Stack #\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( pcWriteBuffer, pcHeader );
\r
233 vTaskList( pcWriteBuffer + strlen( pcHeader ) );
\r
235 /* There is no more data to return after this single string, so return
\r
239 /*-----------------------------------------------------------*/
\r
241 static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
243 const char * const pcHeader = "Task Abs Time % Time\r\n****************************************\r\n";
\r
245 /* Remove compile time warnings about unused parameters, and check the
\r
246 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
247 write buffer length is adequate, so does not check for buffer overflows. */
\r
248 ( void ) pcCommandString;
\r
249 ( void ) xWriteBufferLen;
\r
250 configASSERT( pcWriteBuffer );
\r
252 /* Generate a table of task stats. */
\r
253 strcpy( pcWriteBuffer, pcHeader );
\r
254 vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
\r
256 /* There is no more data to return after this single string, so return
\r
260 /*-----------------------------------------------------------*/
\r
262 static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
264 const char *pcParameter;
\r
265 BaseType_t xParameterStringLength, xReturn;
\r
266 static BaseType_t lParameterNumber = 0;
\r
268 /* Remove compile time warnings about unused parameters, and check the
\r
269 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
270 write buffer length is adequate, so does not check for buffer overflows. */
\r
271 ( void ) pcCommandString;
\r
272 ( void ) xWriteBufferLen;
\r
273 configASSERT( pcWriteBuffer );
\r
275 if( lParameterNumber == 0 )
\r
277 /* The first time the function is called after the command has been
\r
278 entered just a header string is returned. */
\r
279 sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
\r
281 /* Next time the function is called the first parameter will be echoed
\r
283 lParameterNumber = 1L;
\r
285 /* There is more data to be returned as no parameters have been echoed
\r
291 /* Obtain the parameter string. */
\r
292 pcParameter = FreeRTOS_CLIGetParameter
\r
294 pcCommandString, /* The command string itself. */
\r
295 lParameterNumber, /* Return the next parameter. */
\r
296 &xParameterStringLength /* Store the parameter string length. */
\r
299 /* Sanity check something was returned. */
\r
300 configASSERT( pcParameter );
\r
302 /* Return the parameter string. */
\r
303 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
304 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
305 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
306 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
308 /* If this is the last of the three parameters then there are no more
\r
309 strings to return after this one. */
\r
310 if( lParameterNumber == 3L )
\r
312 /* If this is the last of the three parameters then there are no more
\r
313 strings to return after this one. */
\r
315 lParameterNumber = 0L;
\r
319 /* There are more parameters to return after this one. */
\r
321 lParameterNumber++;
\r
327 /*-----------------------------------------------------------*/
\r
329 static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
331 const char *pcParameter;
\r
332 BaseType_t xParameterStringLength, xReturn;
\r
333 static BaseType_t lParameterNumber = 0;
\r
335 /* Remove compile time warnings about unused parameters, and check the
\r
336 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
337 write buffer length is adequate, so does not check for buffer overflows. */
\r
338 ( void ) pcCommandString;
\r
339 ( void ) xWriteBufferLen;
\r
340 configASSERT( pcWriteBuffer );
\r
342 if( lParameterNumber == 0 )
\r
344 /* The first time the function is called after the command has been
\r
345 entered just a header string is returned. */
\r
346 sprintf( pcWriteBuffer, "The parameters were:\r\n" );
\r
348 /* Next time the function is called the first parameter will be echoed
\r
350 lParameterNumber = 1L;
\r
352 /* There is more data to be returned as no parameters have been echoed
\r
358 /* Obtain the parameter string. */
\r
359 pcParameter = FreeRTOS_CLIGetParameter
\r
361 pcCommandString, /* The command string itself. */
\r
362 lParameterNumber, /* Return the next parameter. */
\r
363 &xParameterStringLength /* Store the parameter string length. */
\r
366 if( pcParameter != NULL )
\r
368 /* Return the parameter string. */
\r
369 memset( pcWriteBuffer, 0x00, xWriteBufferLen );
\r
370 sprintf( pcWriteBuffer, "%d: ", ( int ) lParameterNumber );
\r
371 strncat( pcWriteBuffer, pcParameter, xParameterStringLength );
\r
372 strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
\r
374 /* There might be more parameters to return after this one. */
\r
376 lParameterNumber++;
\r
380 /* No more parameters were found. Make sure the write buffer does
\r
381 not contain a valid string. */
\r
382 pcWriteBuffer[ 0 ] = 0x00;
\r
384 /* No more data to return. */
\r
387 /* Start over the next time this command is executed. */
\r
388 lParameterNumber = 0;
\r
394 /*-----------------------------------------------------------*/
\r
396 #if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
\r
398 static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
400 const char *pcParameter;
\r
401 BaseType_t lParameterStringLength;
\r
403 /* Remove compile time warnings about unused parameters, and check the
\r
404 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
405 write buffer length is adequate, so does not check for buffer overflows. */
\r
406 ( void ) pcCommandString;
\r
407 ( void ) xWriteBufferLen;
\r
408 configASSERT( pcWriteBuffer );
\r
410 /* Obtain the parameter string. */
\r
411 pcParameter = FreeRTOS_CLIGetParameter
\r
413 pcCommandString, /* The command string itself. */
\r
414 1, /* Return the first parameter. */
\r
415 &lParameterStringLength /* Store the parameter string length. */
\r
418 /* Sanity check something was returned. */
\r
419 configASSERT( pcParameter );
\r
421 /* There are only two valid parameter values. */
\r
422 if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
\r
424 /* Start or restart the trace. */
\r
429 sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
\r
431 else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
\r
433 /* End the trace, if one is running. */
\r
435 sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
\r
439 sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
\r
442 /* There is no more data to return after this single string, so return
\r
447 #endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
\r