From 3e654efa5678193a5577329598b9314b4bcd6307 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Fri, 10 May 2013 18:47:43 +0000 Subject: [PATCH] SmartFusion2 CLI working with polled UART, about to convert to interrupt driven UART. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1890 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../RTOSDemo/FreeRTOSConfig.h | 8 +- .../Full-Demo/File-releated-CLI-commands.c | 3 +- .../RTOSDemo/Full-Demo/File-system-demo.c | 5 +- .../RTOSDemo/Full-Demo/UARTCommandConsole.c | 120 +++++++++--------- .../RTOSDemo/Full-Demo/main_full.c | 4 +- .../RTOSDemo/main.c | 5 + .../RTOSDemo/printf-stdarg.c | 11 +- 7 files changed, 81 insertions(+), 75 deletions(-) diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/FreeRTOSConfig.h b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/FreeRTOSConfig.h index 53e139a62..4b5ec8214 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/FreeRTOSConfig.h @@ -98,8 +98,12 @@ #include 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 diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-releated-CLI-commands.c b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-releated-CLI-commands.c index 87960c4d4..5e7b7a3f7 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-releated-CLI-commands.c +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-releated-CLI-commands.c @@ -80,6 +80,7 @@ #include #include #include +#include /* 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 ); } diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-system-demo.c b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-system-demo.c index 8dd6f0b27..d7ee184f1 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-system-demo.c +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/File-system-demo.c @@ -79,6 +79,7 @@ /* Standard includes. */ #include +#include /* 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. */ diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c index 571238e64..a3e5b8961 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/UARTCommandConsole.c @@ -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++; + } } } } diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/main_full.c b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/main_full.c index 05a923a66..1444238f0 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/main_full.c +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/Full-Demo/main_full.c @@ -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 ); /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/main.c b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/main.c index e96a299f3..d846b6a38 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/main.c +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/main.c @@ -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 ); } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/printf-stdarg.c b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/printf-stdarg.c index 9bfc45a5c..559fd6851 100644 --- a/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/printf-stdarg.c +++ b/FreeRTOS/Demo/CORTEX_M2S050_Starter_Kit_SoftConsole/RTOSDemo/printf-stdarg.c @@ -24,22 +24,19 @@ replace outbyte(c) by your own function call. */ - -#define putchar(c) c - +#include "FreeRTOS.h" #include +#include 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 ) ); } } -- 2.39.5