SmartFusion2 CLI working with polled UART, about to convert to interrupt driven UART.

pull/4/head
Richard Barry 12 years ago
parent 8732e8efc5
commit 5ff880fee8

@ -98,8 +98,12 @@
#include <stdint.h>
extern uint32_t SystemCoreClock;
/* Driver includes required for UART IO. */
#include "drivers/mss_uart/mss_uart.h"
extern const mss_uart_instance_t * const pxUART;
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
@ -150,7 +154,7 @@ are multiple command interpreters running at once (for example, one on a UART
and one on TCP/IP). This is done to prevent an output buffer being defined by
each implementation - which would waste RAM. In this case, there is only one
command interpreter running. */
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 128
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 2048
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS

@ -80,6 +80,7 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
@ -570,5 +571,5 @@ const char * pcAttrib;
/* Create a string that includes the file name, the file size and the
attributes string. */
sprintf( ( char * ) pcBuffer, "%s [%s] [size=%d]", pxFindStruct->filename, pcAttrib, pxFindStruct->filesize );
sprintf( ( char * ) pcBuffer, "%s [%s] [size=%d]", pxFindStruct->filename, pcAttrib, ( int ) pxFindStruct->filesize );
}

@ -79,6 +79,7 @@
/* Standard includes. */
#include <stdio.h>
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
@ -187,7 +188,7 @@ F_FILE *pxFile;
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
{
/* Generate a file name. */
sprintf( cFileName, "root%03d.txt", xFileNumber );
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and
the directory into which the file is being written. */
@ -229,7 +230,7 @@ F_FILE *pxFile;
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
{
/* Generate the file name. */
sprintf( cFileName, "root%03d.txt", xFileNumber );
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and
the directory from which the file is being read. */

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

@ -161,7 +161,7 @@ check timer, only two are used by the flash timers. */
standard demo flash timers. */
#define mainCHECK_LED ( 1 )
/* The size of the stack and the priority used by the UART CDC command console
/* The size of the stack and the priority used by the UART command console
task. */
#define mainUART_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )
#define mainUART_COMMAND_CONSOLE_TASK_PRIORITY ( tskIDLE_PRIORITY )
@ -178,7 +178,7 @@ static void prvCheckTimerCallback( xTimerHandle xTimer );
* defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.
*/
extern void vRegisterSampleCLICommands( void );
extern vRegisterFileSystemCLICommands( void );
extern void vRegisterFileSystemCLICommands( void );
/*-----------------------------------------------------------*/

@ -119,6 +119,8 @@ void vApplicationIdleHook( void );
void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );
void vApplicationTickHook( void );
/* The UART used for printf() and CLI IO. */
const mss_uart_instance_t * const pxUART = &g_mss_uart0;
/*-----------------------------------------------------------*/
/* See the documentation page for this demo on the FreeRTOS.org web site for
full information - including hardware setup requirements. */
@ -150,6 +152,9 @@ static void prvSetupHardware( void )
functions. The name ParTest is now somewhat obsolete - originally it
stood for PARallel port Test. */
vParTestInitialise();
/* Initialise the UART which is used for printf() and CLI IO. */
MSS_UART_init( pxUART, MSS_UART_115200_BAUD, MSS_UART_DATA_8_BITS | MSS_UART_NO_PARITY | MSS_UART_ONE_STOP_BIT );
}
/*-----------------------------------------------------------*/

@ -24,22 +24,19 @@
replace outbyte(c) by your own function call.
*/
#define putchar(c) c
#include "FreeRTOS.h"
#include <stdarg.h>
#include <stdint.h>
static void printchar(char **str, int c)
{
//extern int putchar(int c);
if (str) {
**str = (char)c;
++(*str);
}
else
{
(void)putchar(c);
{
MSS_UART_polled_tx( pxUART, ( uint8_t * ) &c, sizeof( uint8_t ) );
}
}

Loading…
Cancel
Save