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));
|
||||
|
||||
WRITE_PERI_REG(UART_CONF0(uart_no), UartDev.exist_parity
|
||||
| UartDev.parity
|
||||
| (UartDev.stop_bits << UART_STOP_BIT_NUM_S)
|
||||
| (UartDev.data_bits << UART_BIT_NUM_S));
|
||||
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 & UART_PARITY_M) <<UART_PARITY_S )
|
||||
| ((UartDev.stop_bits & UART_STOP_BIT_NUM) << UART_STOP_BIT_NUM_S)
|
||||
| ((UartDev.data_bits & UART_BIT_NUM) << UART_BIT_NUM_S));
|
||||
|
||||
|
||||
//clear rx and tx fifo,not ready
|
||||
|
|
|
@ -17,20 +17,20 @@ typedef enum {
|
|||
} UartBitsNum4Char;
|
||||
|
||||
typedef enum {
|
||||
ONE_STOP_BIT = 0,
|
||||
ONE_HALF_STOP_BIT = BIT2,
|
||||
TWO_STOP_BIT = BIT2
|
||||
ONE_STOP_BIT = 0x1,
|
||||
ONE_HALF_STOP_BIT = 0x2,
|
||||
TWO_STOP_BIT = 0x3
|
||||
} UartStopBitsNum;
|
||||
|
||||
typedef enum {
|
||||
NONE_BITS = 0,
|
||||
ODD_BITS = 0,
|
||||
EVEN_BITS = BIT4
|
||||
NONE_BITS = 0x2,
|
||||
ODD_BITS = 1,
|
||||
EVEN_BITS = 0
|
||||
} UartParityMode;
|
||||
|
||||
typedef enum {
|
||||
STICK_PARITY_DIS = 0,
|
||||
STICK_PARITY_EN = BIT3 | BIT5
|
||||
STICK_PARITY_EN = 1
|
||||
} UartExistParity;
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -79,6 +79,12 @@
|
|||
#define UART_RXFIFO_CNT_S 0
|
||||
|
||||
#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
|
||||
#define UART_DTR_INV (BIT(24))
|
||||
#define UART_RTS_INV (BIT(23))
|
||||
#define UART_TXD_INV (BIT(22))
|
||||
#define UART_DSR_INV (BIT(21))
|
||||
#define UART_CTS_INV (BIT(20))
|
||||
#define UART_RXD_INV (BIT(19))
|
||||
#define UART_TXFIFO_RST (BIT(18))
|
||||
#define UART_RXFIFO_RST (BIT(17))
|
||||
#define UART_IRDA_EN (BIT(16))
|
||||
|
@ -97,7 +103,11 @@
|
|||
#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_RX_TOUT_EN (BIT(31))
|
||||
|
|
|
@ -160,6 +160,12 @@ static const LUA_REG_TYPE uart_map[] = {
|
|||
{ LSTRKEY( "write" ), LFUNCVAL( uart_write ) },
|
||||
{ LSTRKEY( "on" ), LFUNCVAL( uart_on ) },
|
||||
{ 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 }
|
||||
};
|
||||
|
||||
|
|
|
@ -222,8 +222,8 @@ uint32_t platform_uart_setup( unsigned id, uint32_t baud, int databits, int pari
|
|||
|
||||
switch (stopbits)
|
||||
{
|
||||
case PLATFORM_UART_STOPBITS_1:
|
||||
UartDev.stop_bits = ONE_STOP_BIT;
|
||||
case PLATFORM_UART_STOPBITS_1_5:
|
||||
UartDev.stop_bits = ONE_HALF_STOP_BIT;
|
||||
break;
|
||||
case PLATFORM_UART_STOPBITS_2:
|
||||
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:
|
||||
UartDev.parity = EVEN_BITS;
|
||||
UartDev.exist_parity = STICK_PARITY_EN;
|
||||
break;
|
||||
case PLATFORM_UART_PARITY_ODD:
|
||||
UartDev.parity = ODD_BITS;
|
||||
UartDev.exist_parity = STICK_PARITY_EN;
|
||||
break;
|
||||
default:
|
||||
UartDev.parity = NONE_BITS;
|
||||
UartDev.exist_parity = STICK_PARITY_DIS;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -119,19 +119,19 @@ int platform_spi_transaction( uint8_t id, uint8_t cmd_bitlen, spi_data_type cmd_
|
|||
// Parity
|
||||
enum
|
||||
{
|
||||
PLATFORM_UART_PARITY_EVEN,
|
||||
PLATFORM_UART_PARITY_ODD,
|
||||
PLATFORM_UART_PARITY_NONE,
|
||||
PLATFORM_UART_PARITY_MARK,
|
||||
PLATFORM_UART_PARITY_SPACE
|
||||
PLATFORM_UART_PARITY_NONE = 0,
|
||||
PLATFORM_UART_PARITY_EVEN = 1,
|
||||
PLATFORM_UART_PARITY_ODD = 2,
|
||||
PLATFORM_UART_PARITY_MARK = 3,
|
||||
PLATFORM_UART_PARITY_SPACE = 4
|
||||
};
|
||||
|
||||
// Stop bits
|
||||
enum
|
||||
{
|
||||
PLATFORM_UART_STOPBITS_1,
|
||||
PLATFORM_UART_STOPBITS_1_5,
|
||||
PLATFORM_UART_STOPBITS_2
|
||||
PLATFORM_UART_STOPBITS_1 = 1,
|
||||
PLATFORM_UART_STOPBITS_2 = 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 )
|
||||
|
|
Loading…
Reference in New Issue