/*-----------------------------------------------------------*/\r
\r
/* Const messages output by the command console. */\r
-static const uint8_t * const pcWelcomeMessage = ( uint8_t * ) "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";\r
+static const uint8_t * const pcWelcomeMessage = ( uint8_t * ) "\r\n\r\nFreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";\r
static const uint8_t * const pcEndOfOutputMessage = ( uint8_t * ) "\r\n[Press ENTER to execute the previous command again]\r\n>";\r
static const uint8_t * const pcNewLine = ( uint8_t * ) "\r\n";\r
\r
interface will be used at any one time. */\r
pcOutputString = FreeRTOS_CLIGetOutputBuffer();\r
\r
- /* Initialise the UART. */\r
- MSS_UART_init( pxUART, MSS_UART_115200_BAUD, MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT );\r
-\r
/* Send the welcome message. */\r
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcWelcomeMessage );\r
\r
cRxedChar = 0;\r
\r
/* Only interested in reading one character at a time. */\r
- MSS_UART_get_rx( pxUART, &cRxedChar, sizeof( cRxedChar ) );\r
-\r
- /* Echo the character back. */\r
- MSS_UART_polled_tx( pxUART, &cRxedChar, sizeof( cRxedChar ) );\r
-\r
- /* Was it the end of the line? */\r
- if( cRxedChar == '\n' || cRxedChar == '\r' )\r
+ if( MSS_UART_get_rx( pxUART, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) ) > 0 )\r
{\r
- /* Just to space the output from the input. */\r
- MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );\r
+ /* Echo the character back. */\r
+ MSS_UART_polled_tx( pxUART, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) );\r
\r
- /* See if the command is empty, indicating that the last command is\r
- to be executed again. */\r
- if( cInputIndex == 0 )\r
+ /* Was it the end of the line? */\r
+ if( cRxedChar == '\n' || cRxedChar == '\r' )\r
{\r
- /* Copy the last command back into the input string. */\r
- strcpy( ( char * ) cInputString, ( char * ) cLastInputString );\r
- }\r
+ /* Just to space the output from the input. */\r
+ MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );\r
\r
- /* Pass the received command to the command interpreter. The\r
- command interpreter is called repeatedly until it returns pdFALSE\r
- (indicating there is no more output) as it might generate more than\r
- one string. */\r
- do\r
- {\r
- /* Get the next output string from the command interpreter. */\r
- xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );\r
+ /* See if the command is empty, indicating that the last command is\r
+ to be executed again. */\r
+ if( cInputIndex == 0 )\r
+ {\r
+ /* Copy the last command back into the input string. */\r
+ strcpy( ( char * ) cInputString, ( char * ) cLastInputString );\r
+ }\r
\r
- /* Write the generated string to the UART. */\r
- MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );\r
- vTaskDelay( 1 );\r
+ /* Pass the received command to the command interpreter. The\r
+ command interpreter is called repeatedly until it returns pdFALSE\r
+ (indicating there is no more output) as it might generate more than\r
+ one string. */\r
+ do\r
+ {\r
+ /* Get the next output string from the command interpreter. */\r
+ xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );\r
\r
- } while( xReturned != pdFALSE );\r
+ /* Write the generated string to the UART. */\r
+ MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );\r
+ vTaskDelay( 1 );\r
\r
- /* All the strings generated by the input command have been sent.\r
- Clear the input string ready to receive the next command. Remember\r
- the command that was just processed first in case it is to be\r
- processed again. */\r
- strcpy( ( char * ) cLastInputString, ( char * ) cInputString );\r
- cInputIndex = 0;\r
- memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );\r
+ } while( xReturned != pdFALSE );\r
\r
- MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcEndOfOutputMessage );\r
- }\r
- else\r
- {\r
- if( cRxedChar == '\r' )\r
- {\r
- /* Ignore the character. */\r
+ /* All the strings generated by the input command have been sent.\r
+ Clear the input string ready to receive the next command. Remember\r
+ the command that was just processed first in case it is to be\r
+ processed again. */\r
+ strcpy( ( char * ) cLastInputString, ( char * ) cInputString );\r
+ cInputIndex = 0;\r
+ memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );\r
+\r
+ MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcEndOfOutputMessage );\r
}\r
- else if( cRxedChar == '\b' )\r
+ else\r
{\r
- /* Backspace was pressed. Erase the last character in the\r
- string - if any. */\r
- if( cInputIndex > 0 )\r
+ if( cRxedChar == '\r' )\r
{\r
- cInputIndex--;\r
- cInputString[ cInputIndex ] = '\0';\r
+ /* Ignore the character. */\r
}\r
- }\r
- else\r
- {\r
- /* A character was entered. Add it to the string\r
- entered so far. When a \n is entered the complete\r
- string will be passed to the command interpreter. */\r
- if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )\r
+ else if( cRxedChar == '\b' )\r
+ {\r
+ /* Backspace was pressed. Erase the last character in the\r
+ string - if any. */\r
+ if( cInputIndex > 0 )\r
+ {\r
+ cInputIndex--;\r
+ cInputString[ cInputIndex ] = '\0';\r
+ }\r
+ }\r
+ else\r
{\r
- if( cInputIndex < cmdMAX_INPUT_SIZE )\r
+ /* A character was entered. Add it to the string\r
+ entered so far. When a \n is entered the complete\r
+ string will be passed to the command interpreter. */\r
+ if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )\r
{\r
- cInputString[ cInputIndex ] = cRxedChar;\r
- cInputIndex++;\r
+ if( cInputIndex < cmdMAX_INPUT_SIZE )\r
+ {\r
+ cInputString[ cInputIndex ] = cRxedChar;\r
+ cInputIndex++;\r
+ }\r
}\r
}\r
}\r