2 FreeRTOS V8.1.1 - Copyright (C) 2014 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
28 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
29 >>! obliged to provide the source code for proprietary components !<<
\r
30 >>! outside of the FreeRTOS kernel. !<<
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Standard includes. */
\r
71 /* FreeRTOS includes. */
\r
72 #include "FreeRTOS.h"
\r
76 /* Common demo includes. */
\r
79 /* Example includes. */
\r
80 #include "FreeRTOS_CLI.h"
\r
81 #include "UARTCommandConsole.h"
\r
83 /* Dimensions the buffer into which input characters are placed. */
\r
84 #define cmdMAX_INPUT_SIZE 50
\r
86 /* The maximum time in ticks to wait for the UART access mutex. */
\r
87 #define cmdMAX_MUTEX_WAIT ( 200 / portTICK_PERIOD_MS )
\r
89 /*-----------------------------------------------------------*/
\r
92 * The task that implements the command console processing.
\r
94 static void prvUARTCommandConsoleTask( void *pvParameters );
\r
96 /*-----------------------------------------------------------*/
\r
98 /* Const messages output by the command console. */
\r
99 static const char * const pcWelcomeMessage = "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
\r
100 static const char * const pcEndOfOutputMessage = "\r\n[Press ENTER to execute the previous command again]\r\n>";
\r
101 static const char * const pcNewLine = "\r\n";
\r
103 /*-----------------------------------------------------------*/
\r
105 void vUARTCommandConsoleStart( uint16_t usStackSize, unsigned portBASE_TYPE uxPriority )
\r
107 /* Create that task that handles the console itself. */
\r
108 xTaskCreate( prvUARTCommandConsoleTask, /* The task that implements the command console. */
\r
109 "CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
\r
110 usStackSize, /* The size of the stack allocated to the task. */
\r
111 NULL, /* The parameter is not used, so NULL is passed. */
\r
112 uxPriority, /* The priority allocated to the task. */
\r
113 NULL ); /* A handle is not required, so just pass NULL. */
\r
115 /*-----------------------------------------------------------*/
\r
117 static void prvUARTCommandConsoleTask( void *pvParameters )
\r
119 char cRxedChar, cInputIndex = 0, *pcOutputString;
\r
120 static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
\r
121 portBASE_TYPE xReturned;
\r
123 ( void ) pvParameters;
\r
125 /* Obtain the address of the output buffer. Note there is no mutual
\r
126 exclusion on this buffer as it is assumed only one command console
\r
127 interface will be used at any one time. */
\r
128 pcOutputString = FreeRTOS_CLIGetOutputBuffer();
\r
130 /* Send the welcome message. */
\r
131 vSerialPutString( NULL, ( const signed char * ) pcWelcomeMessage, strlen( ( char * ) pcWelcomeMessage ) );
\r
135 /* Only interested in reading one character at a time. */
\r
136 while( xSerialGetChar( NULL, ( signed char * ) &cRxedChar, portMAX_DELAY ) == pdFALSE );
\r
138 /* Echo the character back. */
\r
139 xSerialPutChar( NULL, cRxedChar, portMAX_DELAY );
\r
141 /* Was it the end of the line? */
\r
142 if( cRxedChar == '\n' || cRxedChar == '\r' )
\r
144 /* Just to space the output from the input. */
\r
145 vSerialPutString( NULL, ( const signed char * ) pcNewLine, strlen( ( char * ) pcNewLine ) );
\r
147 /* See if the command is empty, indicating that the last command is
\r
148 to be executed again. */
\r
149 if( cInputIndex == 0 )
\r
151 /* Copy the last command back into the input string. */
\r
152 strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
\r
155 /* Pass the received command to the command interpreter. The
\r
156 command interpreter is called repeatedly until it returns pdFALSE
\r
157 (indicating there is no more output) as it might generate more than
\r
161 /* Get the next output string from the command interpreter. */
\r
162 xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
\r
164 /* Write the generated string to the UART. */
\r
165 vSerialPutString( NULL, ( const signed char * ) pcOutputString, strlen( ( char * ) pcOutputString ) );
\r
167 } while( xReturned != pdFALSE );
\r
169 /* All the strings generated by the input command have been sent.
\r
170 Clear the input string ready to receive the next command. Remember
\r
171 the command that was just processed first in case it is to be
\r
172 processed again. */
\r
173 strcpy( ( char * ) cLastInputString, ( char * ) cInputString );
\r
175 memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
\r
176 vSerialPutString( NULL, ( const signed char * ) pcEndOfOutputMessage, strlen( ( char * ) pcEndOfOutputMessage ) );
\r
180 if( cRxedChar == '\r' )
\r
182 /* Ignore the character. */
\r
184 else if( cRxedChar == '\b' )
\r
186 /* Backspace was pressed. Erase the last character in the
\r
187 string - if any. */
\r
188 if( cInputIndex > 0 )
\r
191 cInputString[ cInputIndex ] = '\0';
\r
196 /* A character was entered. Add it to the string
\r
197 entered so far. When a \n is entered the complete
\r
198 string will be passed to the command interpreter. */
\r
199 if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
\r
201 if( cInputIndex < cmdMAX_INPUT_SIZE )
\r
203 cInputString[ cInputIndex ] = cRxedChar;
\r
211 /*-----------------------------------------------------------*/
\r