Merge pull request #855 from devsaurus/dev-uart
UART: fix parity and stopbit generation
This commit is contained in:
commit
0069f002a8
|
@ -60,10 +60,10 @@ uart_config(uint8 uart_no)
|
||||||
|
|
||||||
uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));
|
uart_div_modify(uart_no, UART_CLK_FREQ / (UartDev.baut_rate));
|
||||||
|
|
||||||
WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity
|
WRITE_PERI_REG(UART_CONF0(uart_no), ((UartDev.exist_parity & UART_PARITY_EN_M) << UART_PARITY_EN_S) //SET BIT AND PARITY MODE
|
||||||
| UartDev.parity
|
| ((UartDev.parity & UART_PARITY_M) <<UART_PARITY_S )
|
||||||
| (UartDev.stop_bits << UART_STOP_BIT_NUM_S)
|
| ((UartDev.stop_bits & UART_STOP_BIT_NUM) << UART_STOP_BIT_NUM_S)
|
||||||
| (UartDev.data_bits << UART_BIT_NUM_S));
|
| ((UartDev.data_bits & UART_BIT_NUM) << UART_BIT_NUM_S));
|
||||||
|
|
||||||
|
|
||||||
//clear rx and tx fifo,not ready
|
//clear rx and tx fifo,not ready
|
||||||
|
|
|
@ -17,20 +17,20 @@ typedef enum {
|
||||||
} UartBitsNum4Char;
|
} UartBitsNum4Char;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ONE_STOP_BIT = 0,
|
ONE_STOP_BIT = 0x1,
|
||||||
ONE_HALF_STOP_BIT = BIT2,
|
ONE_HALF_STOP_BIT = 0x2,
|
||||||
TWO_STOP_BIT = BIT2
|
TWO_STOP_BIT = 0x3
|
||||||
} UartStopBitsNum;
|
} UartStopBitsNum;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
NONE_BITS = 0,
|
NONE_BITS = 0x2,
|
||||||
ODD_BITS = 0,
|
ODD_BITS = 1,
|
||||||
EVEN_BITS = BIT4
|
EVEN_BITS = 0
|
||||||
} UartParityMode;
|
} UartParityMode;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
STICK_PARITY_DIS = 0,
|
STICK_PARITY_DIS = 0,
|
||||||
STICK_PARITY_EN = BIT3 | BIT5
|
STICK_PARITY_EN = 1
|
||||||
} UartExistParity;
|
} UartExistParity;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -78,26 +78,36 @@
|
||||||
#define UART_RXFIFO_CNT 0x000000FF
|
#define UART_RXFIFO_CNT 0x000000FF
|
||||||
#define UART_RXFIFO_CNT_S 0
|
#define UART_RXFIFO_CNT_S 0
|
||||||
|
|
||||||
#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
|
#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
|
||||||
#define UART_TXFIFO_RST (BIT(18))
|
#define UART_DTR_INV (BIT(24))
|
||||||
#define UART_RXFIFO_RST (BIT(17))
|
#define UART_RTS_INV (BIT(23))
|
||||||
#define UART_IRDA_EN (BIT(16))
|
#define UART_TXD_INV (BIT(22))
|
||||||
#define UART_TX_FLOW_EN (BIT(15))
|
#define UART_DSR_INV (BIT(21))
|
||||||
#define UART_LOOPBACK (BIT(14))
|
#define UART_CTS_INV (BIT(20))
|
||||||
#define UART_IRDA_RX_INV (BIT(13))
|
#define UART_RXD_INV (BIT(19))
|
||||||
#define UART_IRDA_TX_INV (BIT(12))
|
#define UART_TXFIFO_RST (BIT(18))
|
||||||
#define UART_IRDA_WCTL (BIT(11))
|
#define UART_RXFIFO_RST (BIT(17))
|
||||||
#define UART_IRDA_TX_EN (BIT(10))
|
#define UART_IRDA_EN (BIT(16))
|
||||||
#define UART_IRDA_DPLX (BIT(9))
|
#define UART_TX_FLOW_EN (BIT(15))
|
||||||
#define UART_TXD_BRK (BIT(8))
|
#define UART_LOOPBACK (BIT(14))
|
||||||
#define UART_SW_DTR (BIT(7))
|
#define UART_IRDA_RX_INV (BIT(13))
|
||||||
#define UART_SW_RTS (BIT(6))
|
#define UART_IRDA_TX_INV (BIT(12))
|
||||||
#define UART_STOP_BIT_NUM 0x00000003
|
#define UART_IRDA_WCTL (BIT(11))
|
||||||
#define UART_STOP_BIT_NUM_S 4
|
#define UART_IRDA_TX_EN (BIT(10))
|
||||||
#define UART_BIT_NUM 0x00000003
|
#define UART_IRDA_DPLX (BIT(9))
|
||||||
#define UART_BIT_NUM_S 2
|
#define UART_TXD_BRK (BIT(8))
|
||||||
#define UART_PARITY_EN (BIT(1))
|
#define UART_SW_DTR (BIT(7))
|
||||||
#define UART_PARITY (BIT(0))
|
#define UART_SW_RTS (BIT(6))
|
||||||
|
#define UART_STOP_BIT_NUM 0x00000003
|
||||||
|
#define UART_STOP_BIT_NUM_S 4
|
||||||
|
#define UART_BIT_NUM 0x00000003
|
||||||
|
#define UART_BIT_NUM_S 2
|
||||||
|
#define UART_PARITY_EN (BIT(1))
|
||||||
|
#define UART_PARITY_EN_M 0x00000001
|
||||||
|
#define UART_PARITY_EN_S 1
|
||||||
|
#define UART_PARITY (BIT(0))
|
||||||
|
#define UART_PARITY_M 0x00000001
|
||||||
|
#define UART_PARITY_S 0
|
||||||
|
|
||||||
#define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24)
|
#define UART_CONF1( i ) (REG_UART_BASE( i ) + 0x24)
|
||||||
#define UART_RX_TOUT_EN (BIT(31))
|
#define UART_RX_TOUT_EN (BIT(31))
|
||||||
|
|
|
@ -156,10 +156,16 @@ static int uart_write( lua_State* L )
|
||||||
|
|
||||||
// Module function map
|
// Module function map
|
||||||
static const LUA_REG_TYPE uart_map[] = {
|
static const LUA_REG_TYPE uart_map[] = {
|
||||||
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
|
{ LSTRKEY( "setup" ), LFUNCVAL( uart_setup ) },
|
||||||
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
|
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
|
||||||
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
|
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
|
||||||
{ LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) },
|
{ LSTRKEY( "alt" ), LFUNCVAL( uart_alt ) },
|
||||||
|
{ LSTRKEY( "STOPBITS_1" ), LNUMVAL( PLATFORM_UART_STOPBITS_1 ) },
|
||||||
|
{ LSTRKEY( "STOPBITS_1_5" ), LNUMVAL( PLATFORM_UART_STOPBITS_1_5 ) },
|
||||||
|
{ LSTRKEY( "STOPBITS_2" ), LNUMVAL( PLATFORM_UART_STOPBITS_2 ) },
|
||||||
|
{ LSTRKEY( "PARITY_NONE" ), LNUMVAL( PLATFORM_UART_PARITY_NONE ) },
|
||||||
|
{ LSTRKEY( "PARITY_EVEN" ), LNUMVAL( PLATFORM_UART_PARITY_EVEN ) },
|
||||||
|
{ LSTRKEY( "PARITY_ODD" ), LNUMVAL( PLATFORM_UART_PARITY_ODD ) },
|
||||||
{ LNILKEY, LNILVAL }
|
{ LNILKEY, LNILVAL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -222,8 +222,8 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari
|
||||||
|
|
||||||
switch (stopbits)
|
switch (stopbits)
|
||||||
{
|
{
|
||||||
case PLATFORM_UART_STOPBITS_1:
|
case PLATFORM_UART_STOPBITS_1_5:
|
||||||
UartDev.stop_bits = ONE_STOP_BIT;
|
UartDev.stop_bits = ONE_HALF_STOP_BIT;
|
||||||
break;
|
break;
|
||||||
case PLATFORM_UART_STOPBITS_2:
|
case PLATFORM_UART_STOPBITS_2:
|
||||||
UartDev.stop_bits = TWO_STOP_BIT;
|
UartDev.stop_bits = TWO_STOP_BIT;
|
||||||
|
@ -237,12 +237,15 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari
|
||||||
{
|
{
|
||||||
case PLATFORM_UART_PARITY_EVEN:
|
case PLATFORM_UART_PARITY_EVEN:
|
||||||
UartDev.parity = EVEN_BITS;
|
UartDev.parity = EVEN_BITS;
|
||||||
|
UartDev.exist_parity = STICK_PARITY_EN;
|
||||||
break;
|
break;
|
||||||
case PLATFORM_UART_PARITY_ODD:
|
case PLATFORM_UART_PARITY_ODD:
|
||||||
UartDev.parity = ODD_BITS;
|
UartDev.parity = ODD_BITS;
|
||||||
|
UartDev.exist_parity = STICK_PARITY_EN;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
UartDev.parity = NONE_BITS;
|
UartDev.parity = NONE_BITS;
|
||||||
|
UartDev.exist_parity = STICK_PARITY_DIS;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -119,19 +119,19 @@ int platform_spi_transaction( uint8_t id, uint8_t cmd_bitlen, spi_data_type cmd_
|
||||||
// Parity
|
// Parity
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PLATFORM_UART_PARITY_EVEN,
|
PLATFORM_UART_PARITY_NONE = 0,
|
||||||
PLATFORM_UART_PARITY_ODD,
|
PLATFORM_UART_PARITY_EVEN = 1,
|
||||||
PLATFORM_UART_PARITY_NONE,
|
PLATFORM_UART_PARITY_ODD = 2,
|
||||||
PLATFORM_UART_PARITY_MARK,
|
PLATFORM_UART_PARITY_MARK = 3,
|
||||||
PLATFORM_UART_PARITY_SPACE
|
PLATFORM_UART_PARITY_SPACE = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
// Stop bits
|
// Stop bits
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PLATFORM_UART_STOPBITS_1,
|
PLATFORM_UART_STOPBITS_1 = 1,
|
||||||
PLATFORM_UART_STOPBITS_1_5,
|
PLATFORM_UART_STOPBITS_2 = 2,
|
||||||
PLATFORM_UART_STOPBITS_2
|
PLATFORM_UART_STOPBITS_1_5 = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flow control types (this is a bit mask, one can specify PLATFORM_UART_FLOW_RTS | PLATFORM_UART_FLOW_CTS )
|
// Flow control types (this is a bit mask, one can specify PLATFORM_UART_FLOW_RTS | PLATFORM_UART_FLOW_CTS )
|
||||||
|
|
Loading…
Reference in New Issue