Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
0069f002
Commit
0069f002
authored
Dec 22, 2015
by
Terry Ellison
Browse files
Merge pull request #855 from devsaurus/dev-uart
UART: fix parity and stopbit generation
parents
e45d7904
6cbe716d
Changes
6
Hide whitespace changes
Inline
Side-by-side
app/driver/uart.c
View file @
0069f002
...
...
@@ -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
...
...
app/include/driver/uart.h
View file @
0069f002
...
...
@@ -17,20 +17,20 @@ typedef enum {
}
UartBitsNum4Char
;
typedef
enum
{
ONE_STOP_BIT
=
0
,
ONE_HALF_STOP_BIT
=
BIT
2
,
TWO_STOP_BIT
=
BIT2
ONE_STOP_BIT
=
0
x1
,
ONE_HALF_STOP_BIT
=
0x
2
,
TWO_STOP_BIT
=
0x3
}
UartStopBitsNum
;
typedef
enum
{
NONE_BITS
=
0
,
ODD_BITS
=
0
,
EVEN_BITS
=
BIT4
NONE_BITS
=
0
x2
,
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
{
...
...
app/include/driver/uart_register.h
View file @
0069f002
...
...
@@ -78,26 +78,36 @@
#define UART_RXFIFO_CNT 0x000000FF
#define UART_RXFIFO_CNT_S 0
#define UART_CONF0( i ) (REG_UART_BASE( i ) + 0x20)
#define UART_TXFIFO_RST (BIT(18))
#define UART_RXFIFO_RST (BIT(17))
#define UART_IRDA_EN (BIT(16))
#define UART_TX_FLOW_EN (BIT(15))
#define UART_LOOPBACK (BIT(14))
#define UART_IRDA_RX_INV (BIT(13))
#define UART_IRDA_TX_INV (BIT(12))
#define UART_IRDA_WCTL (BIT(11))
#define UART_IRDA_TX_EN (BIT(10))
#define UART_IRDA_DPLX (BIT(9))
#define UART_TXD_BRK (BIT(8))
#define UART_SW_DTR (BIT(7))
#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 (BIT(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))
#define UART_TX_FLOW_EN (BIT(15))
#define UART_LOOPBACK (BIT(14))
#define UART_IRDA_RX_INV (BIT(13))
#define UART_IRDA_TX_INV (BIT(12))
#define UART_IRDA_WCTL (BIT(11))
#define UART_IRDA_TX_EN (BIT(10))
#define UART_IRDA_DPLX (BIT(9))
#define UART_TXD_BRK (BIT(8))
#define UART_SW_DTR (BIT(7))
#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_RX_TOUT_EN (BIT(31))
...
...
app/modules/uart.c
View file @
0069f002
...
...
@@ -156,10 +156,16 @@ static int uart_write( lua_State* L )
// Module function map
static
const
LUA_REG_TYPE
uart_map
[]
=
{
{
LSTRKEY
(
"setup"
),
LFUNCVAL
(
uart_setup
)
},
{
LSTRKEY
(
"write"
),
LFUNCVAL
(
uart_write
)
},
{
LSTRKEY
(
"on"
),
LFUNCVAL
(
uart_on
)
},
{
LSTRKEY
(
"alt"
),
LFUNCVAL
(
uart_alt
)
},
{
LSTRKEY
(
"setup"
),
LFUNCVAL
(
uart_setup
)
},
{
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
}
};
...
...
app/platform/platform.c
View file @
0069f002
...
...
@@ -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
;
}
...
...
app/platform/platform.h
View file @
0069f002
...
...
@@ -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 )
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment