mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
SmartFusion2 CLI working with polled UART, about to convert to interrupt driven UART.
This commit is contained in:
parent
8732e8efc5
commit
5ff880fee8
|
@ -98,8 +98,12 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
extern uint32_t SystemCoreClock;
|
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_PREEMPTION 1
|
||||||
#define configUSE_IDLE_HOOK 0
|
#define configUSE_IDLE_HOOK 1
|
||||||
#define configUSE_TICK_HOOK 0
|
#define configUSE_TICK_HOOK 0
|
||||||
#define configCPU_CLOCK_HZ ( SystemCoreClock )
|
#define configCPU_CLOCK_HZ ( SystemCoreClock )
|
||||||
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
|
#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
|
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
|
each implementation - which would waste RAM. In this case, there is only one
|
||||||
command interpreter running. */
|
command interpreter running. */
|
||||||
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 128
|
#define configCOMMAND_INT_MAX_OUTPUT_SIZE 2048
|
||||||
|
|
||||||
/* Cortex-M specific definitions. */
|
/* Cortex-M specific definitions. */
|
||||||
#ifdef __NVIC_PRIO_BITS
|
#ifdef __NVIC_PRIO_BITS
|
||||||
|
|
|
@ -80,6 +80,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* FreeRTOS+CLI includes. */
|
/* FreeRTOS+CLI includes. */
|
||||||
#include "FreeRTOS_CLI.h"
|
#include "FreeRTOS_CLI.h"
|
||||||
|
@ -570,5 +571,5 @@ const char * pcAttrib;
|
||||||
|
|
||||||
/* Create a string that includes the file name, the file size and the
|
/* Create a string that includes the file name, the file size and the
|
||||||
attributes string. */
|
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. */
|
/* Standard includes. */
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/* FreeRTOS includes. */
|
/* FreeRTOS includes. */
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
|
@ -187,7 +188,7 @@ F_FILE *pxFile;
|
||||||
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
|
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
|
||||||
{
|
{
|
||||||
/* Generate a file name. */
|
/* 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
|
/* Obtain the current working directory and print out the file name and
|
||||||
the directory into which the file is being written. */
|
the directory into which the file is being written. */
|
||||||
|
@ -229,7 +230,7 @@ F_FILE *pxFile;
|
||||||
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
|
for( xFileNumber = 1; xFileNumber <= fsROOT_FILES; xFileNumber++ )
|
||||||
{
|
{
|
||||||
/* Generate the file name. */
|
/* 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
|
/* Obtain the current working directory and print out the file name and
|
||||||
the directory from which the file is being read. */
|
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. */
|
/* 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 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";
|
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. */
|
interface will be used at any one time. */
|
||||||
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
|
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. */
|
/* Send the welcome message. */
|
||||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcWelcomeMessage );
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcWelcomeMessage );
|
||||||
|
|
||||||
|
@ -127,77 +124,78 @@ mss_uart_instance_t * const pxUART = &g_mss_uart0;
|
||||||
cRxedChar = 0;
|
cRxedChar = 0;
|
||||||
|
|
||||||
/* Only interested in reading one character at a time. */
|
/* Only interested in reading one character at a time. */
|
||||||
MSS_UART_get_rx( pxUART, &cRxedChar, sizeof( cRxedChar ) );
|
if( MSS_UART_get_rx( pxUART, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) ) > 0 )
|
||||||
|
|
||||||
/* Echo the character back. */
|
|
||||||
MSS_UART_polled_tx( pxUART, &cRxedChar, sizeof( cRxedChar ) );
|
|
||||||
|
|
||||||
/* Was it the end of the line? */
|
|
||||||
if( cRxedChar == '\n' || cRxedChar == '\r' )
|
|
||||||
{
|
{
|
||||||
/* Just to space the output from the input. */
|
/* Echo the character back. */
|
||||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );
|
MSS_UART_polled_tx( pxUART, ( uint8_t * ) &cRxedChar, sizeof( cRxedChar ) );
|
||||||
|
|
||||||
/* See if the command is empty, indicating that the last command is
|
/* Was it the end of the line? */
|
||||||
to be executed again. */
|
if( cRxedChar == '\n' || cRxedChar == '\r' )
|
||||||
if( cInputIndex == 0 )
|
|
||||||
{
|
{
|
||||||
/* Copy the last command back into the input string. */
|
/* Just to space the output from the input. */
|
||||||
strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcNewLine );
|
||||||
}
|
|
||||||
|
|
||||||
/* Pass the received command to the command interpreter. The
|
/* See if the command is empty, indicating that the last command is
|
||||||
command interpreter is called repeatedly until it returns pdFALSE
|
to be executed again. */
|
||||||
(indicating there is no more output) as it might generate more than
|
if( cInputIndex == 0 )
|
||||||
one string. */
|
|
||||||
do
|
|
||||||
{
|
|
||||||
/* Get the next output string from the command interpreter. */
|
|
||||||
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
|
|
||||||
|
|
||||||
/* Write the generated string to the UART. */
|
|
||||||
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );
|
|
||||||
vTaskDelay( 1 );
|
|
||||||
|
|
||||||
} while( xReturned != pdFALSE );
|
|
||||||
|
|
||||||
/* 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 == '\r' )
|
|
||||||
{
|
|
||||||
/* Ignore the character. */
|
|
||||||
}
|
|
||||||
else if( cRxedChar == '\b' )
|
|
||||||
{
|
|
||||||
/* Backspace was pressed. Erase the last character in the
|
|
||||||
string - if any. */
|
|
||||||
if( cInputIndex > 0 )
|
|
||||||
{
|
{
|
||||||
cInputIndex--;
|
/* Copy the last command back into the input string. */
|
||||||
cInputString[ cInputIndex ] = '\0';
|
strcpy( ( char * ) cInputString, ( char * ) cLastInputString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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 );
|
||||||
|
|
||||||
|
/* Write the generated string to the UART. */
|
||||||
|
MSS_UART_polled_tx_string( pxUART, ( uint8_t * ) pcOutputString );
|
||||||
|
vTaskDelay( 1 );
|
||||||
|
|
||||||
|
} while( xReturned != pdFALSE );
|
||||||
|
|
||||||
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
/* A character was entered. Add it to the string
|
if( cRxedChar == '\r' )
|
||||||
entered so far. When a \n is entered the complete
|
|
||||||
string will be passed to the command interpreter. */
|
|
||||||
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
|
|
||||||
{
|
{
|
||||||
if( cInputIndex < cmdMAX_INPUT_SIZE )
|
/* Ignore the character. */
|
||||||
|
}
|
||||||
|
else if( cRxedChar == '\b' )
|
||||||
|
{
|
||||||
|
/* Backspace was pressed. Erase the last character in the
|
||||||
|
string - if any. */
|
||||||
|
if( cInputIndex > 0 )
|
||||||
{
|
{
|
||||||
cInputString[ cInputIndex ] = cRxedChar;
|
cInputIndex--;
|
||||||
cInputIndex++;
|
cInputString[ cInputIndex ] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 <= '~' ) )
|
||||||
|
{
|
||||||
|
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. */
|
standard demo flash timers. */
|
||||||
#define mainCHECK_LED ( 1 )
|
#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. */
|
task. */
|
||||||
#define mainUART_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )
|
#define mainUART_COMMAND_CONSOLE_STACK_SIZE ( configMINIMAL_STACK_SIZE * 3 )
|
||||||
#define mainUART_COMMAND_CONSOLE_TASK_PRIORITY ( tskIDLE_PRIORITY )
|
#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.
|
* defined in CLI-Commands.c and File-Related-CLI-Command.c respectively.
|
||||||
*/
|
*/
|
||||||
extern void vRegisterSampleCLICommands( void );
|
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 vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName );
|
||||||
void vApplicationTickHook( void );
|
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
|
/* See the documentation page for this demo on the FreeRTOS.org web site for
|
||||||
full information - including hardware setup requirements. */
|
full information - including hardware setup requirements. */
|
||||||
|
@ -150,6 +152,9 @@ static void prvSetupHardware( void )
|
||||||
functions. The name ParTest is now somewhat obsolete - originally it
|
functions. The name ParTest is now somewhat obsolete - originally it
|
||||||
stood for PARallel port Test. */
|
stood for PARallel port Test. */
|
||||||
vParTestInitialise();
|
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.
|
replace outbyte(c) by your own function call.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
#include "FreeRTOS.h"
|
||||||
#define putchar(c) c
|
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
static void printchar(char **str, int c)
|
static void printchar(char **str, int c)
|
||||||
{
|
{
|
||||||
//extern int putchar(int c);
|
|
||||||
|
|
||||||
if (str) {
|
if (str) {
|
||||||
**str = (char)c;
|
**str = (char)c;
|
||||||
++(*str);
|
++(*str);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(void)putchar(c);
|
MSS_UART_polled_tx( pxUART, ( uint8_t * ) &c, sizeof( uint8_t ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue