fix: enable the serial to retrieve the keys that consists of several characters, e.g., arrow keys (#1)
minor: mmodify out-dated comment minor: format code format code and fix a bug of uart driver in m0 minor: format code fix the problem that shell cannot read arrow keys correctly Co-authored-by: yuansm <yuanshumin@sjtu.edu.cn> Co-authored-by: trenne <trennewen@sjtu.edu.cn> Reviewed-on: https://git.trustie.net/gujinyu/xiuos/pulls/1
This commit is contained in:
parent
bc91fb23ee
commit
5c9255d38e
|
@ -79,20 +79,11 @@ void UARTlInitialize(void) {
|
||||||
UART_STARTTX = 1;
|
UART_STARTTX = 1;
|
||||||
UART_STARTRX = 1;
|
UART_STARTRX = 1;
|
||||||
UART_RXDRDY = 0;
|
UART_RXDRDY = 0;
|
||||||
|
UART_TXDRDY = 1;
|
||||||
/* Enable the uart interrupt in NVIC */
|
/* Enable the uart interrupt in NVIC */
|
||||||
HWREG(g_pulEnRegs[(18 - 16) / 32]) = 1 << ((18 - 16) & 31);
|
HWREG(g_pulEnRegs[(18 - 16) / 32]) = 1 << ((18 - 16) & 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SerialGetcNoBlock(void) {
|
|
||||||
char ch;
|
|
||||||
if (UART_RXDRDY) {
|
|
||||||
ch = UART_RXD;
|
|
||||||
UART_RXDRDY = 0;
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
|
void UARTConfigSetExpClk(unsigned long ulBase, unsigned long ulUARTClk,
|
||||||
unsigned long ulBaud, unsigned long ulConfig)
|
unsigned long ulBaud, unsigned long ulConfig)
|
||||||
{
|
{
|
||||||
|
@ -106,22 +97,34 @@ tBoolean UARTCharsAvail(unsigned long ulBase)
|
||||||
|
|
||||||
long UARTCharGetNonBlocking(unsigned long ulBase)
|
long UARTCharGetNonBlocking(unsigned long ulBase)
|
||||||
{
|
{
|
||||||
return SerialGetcNoBlock();
|
char ch;
|
||||||
|
|
||||||
|
if (UART_RXDRDY) {
|
||||||
|
UART_RXDRDY = 0;
|
||||||
|
ch = UART_RXD;
|
||||||
|
return ch;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
long UARTCharGet(unsigned long ulBase)
|
long UARTCharGet(unsigned long ulBase)
|
||||||
{
|
{
|
||||||
|
char ch;
|
||||||
|
|
||||||
while (!UART_RXDRDY);
|
while (!UART_RXDRDY);
|
||||||
char ch = UART_RXD;
|
|
||||||
UART_RXDRDY = 0;
|
UART_RXDRDY = 0;
|
||||||
|
ch = UART_RXD;
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
tBoolean UARTCharPutNonBlocking(unsigned long ulBase, unsigned char ucData)
|
tBoolean UARTCharPutNonBlocking(unsigned long ulBase, unsigned char ucData)
|
||||||
{
|
{
|
||||||
UART_TXDRDY = 0;
|
if (UART_TXDRDY) {
|
||||||
UART_TXD = ucData;
|
UART_TXDRDY = 0;
|
||||||
return 1;
|
UART_TXD = ucData;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UARTCharPut(unsigned long ulBase, unsigned char ucData)
|
void UARTCharPut(unsigned long ulBase, unsigned char ucData)
|
||||||
|
@ -148,6 +151,6 @@ unsigned long UARTIntStatus(unsigned long ulBase, tBoolean bMasked)
|
||||||
|
|
||||||
void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags)
|
void UARTIntClear(unsigned long ulBase, unsigned long ulIntFlags)
|
||||||
{
|
{
|
||||||
ulIntFlags &= 0xFFFFFFFB;
|
|
||||||
UART_INTENCLR = ulIntFlags;
|
UART_INTENCLR = ulIntFlags;
|
||||||
|
UART_INTENSET = ulIntFlags;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ extern "C" {
|
||||||
|
|
||||||
#define SERIAL_DMA_RX 0x01
|
#define SERIAL_DMA_RX 0x01
|
||||||
#define SERIAL_DMA_TX 0x02
|
#define SERIAL_DMA_TX 0x02
|
||||||
|
#define KEY_LENGTH 8
|
||||||
|
|
||||||
struct SerialTx
|
struct SerialTx
|
||||||
{
|
{
|
||||||
|
|
|
@ -122,30 +122,41 @@ static inline int SerialDevIntRead(struct SerialHardwareDevice *serial_dev, stru
|
||||||
NULL_PARAM_CHECK(serial_dev);
|
NULL_PARAM_CHECK(serial_dev);
|
||||||
NULL_PARAM_CHECK(read_param);
|
NULL_PARAM_CHECK(read_param);
|
||||||
|
|
||||||
|
int char_num = 0;
|
||||||
struct SerialHwDevDone *hwdev_done = serial_dev->hwdev_done;
|
struct SerialHwDevDone *hwdev_done = serial_dev->hwdev_done;
|
||||||
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data;
|
struct SerialCfgParam *serial_cfg = (struct SerialCfgParam *)serial_dev->private_data;
|
||||||
uint8 *read_data = (uint8 *)read_param->buffer;
|
uint8 *read_data = (uint8 *)read_param->buffer;
|
||||||
x_size_t read_length = read_param->size;
|
x_size_t read_length = read_param->size;
|
||||||
|
|
||||||
|
int start_pointer, end_pointer;
|
||||||
|
int i;
|
||||||
|
|
||||||
while (read_length)
|
while (read_length)
|
||||||
{
|
{
|
||||||
uint8 get_char;
|
|
||||||
x_base lock;
|
x_base lock;
|
||||||
|
|
||||||
|
start_pointer = serial_dev->serial_fifo.serial_rx->serial_recv_num;
|
||||||
|
end_pointer = serial_dev->serial_fifo.serial_rx->serial_send_num;
|
||||||
lock = CriticalAreaLock();
|
lock = CriticalAreaLock();
|
||||||
|
|
||||||
if (serial_dev->serial_fifo.serial_rx->serial_recv_num == serial_dev->serial_fifo.serial_rx->serial_send_num) {
|
if (start_pointer == end_pointer) {
|
||||||
if (RET_FALSE == serial_dev->serial_fifo.serial_rx->serial_rx_full) {
|
if (RET_FALSE == serial_dev->serial_fifo.serial_rx->serial_rx_full) {
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get_char = serial_dev->serial_fifo.serial_rx->serial_rx_buffer[serial_dev->serial_fifo.serial_rx->serial_recv_num];
|
/* Read all the chars from the serial_rx_buffer */
|
||||||
serial_dev->serial_fifo.serial_rx->serial_recv_num += 1;
|
while (start_pointer != end_pointer)
|
||||||
if (serial_dev->serial_fifo.serial_rx->serial_recv_num >= serial_cfg->data_cfg.serial_buffer_size) {
|
{
|
||||||
serial_dev->serial_fifo.serial_rx->serial_recv_num = 0;
|
read_data[char_num] = serial_dev->serial_fifo.serial_rx->serial_rx_buffer[start_pointer];
|
||||||
|
start_pointer += 1;
|
||||||
|
if (start_pointer >= serial_cfg->data_cfg.serial_buffer_size) {
|
||||||
|
start_pointer = 0;
|
||||||
|
}
|
||||||
|
char_num = char_num + 1;
|
||||||
}
|
}
|
||||||
|
read_data[char_num]='\0';
|
||||||
|
|
||||||
if (RET_TRUE == serial_dev->serial_fifo.serial_rx->serial_rx_full) {
|
if (RET_TRUE == serial_dev->serial_fifo.serial_rx->serial_rx_full) {
|
||||||
serial_dev->serial_fifo.serial_rx->serial_rx_full = RET_FALSE;
|
serial_dev->serial_fifo.serial_rx->serial_rx_full = RET_FALSE;
|
||||||
|
@ -153,10 +164,9 @@ static inline int SerialDevIntRead(struct SerialHardwareDevice *serial_dev, stru
|
||||||
|
|
||||||
CriticalAreaUnLock(lock);
|
CriticalAreaUnLock(lock);
|
||||||
|
|
||||||
*read_data = get_char;
|
|
||||||
read_data++;
|
|
||||||
read_length--;
|
read_length--;
|
||||||
read_param->read_length++;
|
read_param->read_length += char_num;
|
||||||
|
serial_dev->serial_fifo.serial_rx->serial_recv_num = start_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return EOK;
|
return EOK;
|
||||||
|
|
|
@ -1645,14 +1645,21 @@ void shellTask(void *param)
|
||||||
{
|
{
|
||||||
// KPrintf("this is in 1733");
|
// KPrintf("this is in 1733");
|
||||||
Shell *shell = (Shell *)param;
|
Shell *shell = (Shell *)param;
|
||||||
char data;
|
|
||||||
|
/* One input key from the the keyboard/uart may consist of mutliple characters (e.g., arrow keys). */
|
||||||
|
char data[KEY_LENGTH];
|
||||||
|
int i;
|
||||||
|
int data_len;
|
||||||
|
|
||||||
while(RET_TRUE)
|
while(RET_TRUE)
|
||||||
{
|
{
|
||||||
if (shell->read && shell->read(&data) == 0)
|
if (shell->read && shell->read(data) == 0) {
|
||||||
{
|
|
||||||
// KPrintf("in 1741 the char is: '%c' and ascii code is %d.\n\n",data,data);
|
// KPrintf("in 1741 the char is: '%c' and ascii code is %d.\n\n",data,data);
|
||||||
// KPrintf("the buffer is:'%s'\n\n",shell->parser.);
|
// KPrintf("the buffer is:'%s'\n\n",shell->parser.);
|
||||||
shellHandler(shell, data);
|
data_len = strlen(data);
|
||||||
|
for (i = 0; i < data_len; i++) {
|
||||||
|
shellHandler(shell, data[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,6 +256,7 @@ typedef struct
|
||||||
|
|
||||||
#define shellSetPath(_shell, _path) (_shell)->info.path = _path
|
#define shellSetPath(_shell, _path) (_shell)->info.path = _path
|
||||||
#define shellGetPath(_shell) ((_shell)->info.path)
|
#define shellGetPath(_shell) ((_shell)->info.path)
|
||||||
|
#define KEY_LENGTH 8
|
||||||
|
|
||||||
void shellInit(Shell *shell, char *buffer, unsigned short size);
|
void shellInit(Shell *shell, char *buffer, unsigned short size);
|
||||||
unsigned short shellWriteString(Shell *shell, const char *string);
|
unsigned short shellWriteString(Shell *shell, const char *string);
|
||||||
|
|
Loading…
Reference in New Issue