Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
dc334f87
Unverified
Commit
dc334f87
authored
Sep 18, 2020
by
Nathaniel Wesley Filardo
Committed by
GitHub
Sep 18, 2020
Browse files
uart: expose fifo depth counters (#3177)
parent
139af0cd
Changes
2
Show whitespace changes
Inline
Side-by-side
app/modules/uart.c
View file @
dc334f87
...
...
@@ -142,6 +142,27 @@ static int l_uart_write( lua_State* L )
return
0
;
}
#define DIR_RX 0
#define DIR_TX 1
static
int
l_uart_fifodepth
(
lua_State
*
L
)
{
int
id
=
luaL_optinteger
(
L
,
1
,
0
);
if
((
id
!=
0
)
&&
(
id
!=
1
))
return
luaL_argerror
(
L
,
1
,
"Bad UART id; must be 0 or 1"
);
int
dir
=
luaL_optinteger
(
L
,
2
,
0
);
if
((
dir
!=
DIR_RX
)
&&
(
dir
!=
DIR_TX
))
return
luaL_argerror
(
L
,
2
,
"Bad direction; must be DIR_RX or DIR_TX"
);
int
reg
=
READ_PERI_REG
(
UART_STATUS
(
id
));
int
rsh
=
reg
>>
((
dir
==
DIR_RX
)
?
UART_RXFIFO_CNT_S
:
UART_TXFIFO_CNT_S
);
int
rm
=
rsh
&
((
dir
==
DIR_RX
)
?
UART_RXFIFO_CNT
:
UART_TXFIFO_CNT
);
lua_pushinteger
(
L
,
rm
);
return
1
;
}
// Module function map
LROT_BEGIN
(
uart
,
NULL
,
0
)
LROT_FUNCENTRY
(
setup
,
l_uart_setup
)
...
...
@@ -149,12 +170,17 @@ LROT_BEGIN(uart, NULL, 0)
LROT_FUNCENTRY
(
write
,
l_uart_write
)
LROT_FUNCENTRY
(
on
,
l_uart_on
)
LROT_FUNCENTRY
(
alt
,
l_uart_alt
)
LROT_FUNCENTRY
(
fifodepth
,
l_uart_fifodepth
)
LROT_NUMENTRY
(
STOPBITS_1
,
PLATFORM_UART_STOPBITS_1
)
LROT_NUMENTRY
(
STOPBITS_1_5
,
PLATFORM_UART_STOPBITS_1_5
)
LROT_NUMENTRY
(
STOPBITS_2
,
PLATFORM_UART_STOPBITS_2
)
LROT_NUMENTRY
(
PARITY_NONE
,
PLATFORM_UART_PARITY_NONE
)
LROT_NUMENTRY
(
PARITY_EVEN
,
PLATFORM_UART_PARITY_EVEN
)
LROT_NUMENTRY
(
PARITY_ODD
,
PLATFORM_UART_PARITY_ODD
)
LROT_NUMENTRY
(
DIR_RX
,
DIR_RX
)
LROT_NUMENTRY
(
DIR_TX
,
DIR_TX
)
LROT_END
(
uart
,
NULL
,
0
)
...
...
docs/modules/uart.md
View file @
dc334f87
...
...
@@ -145,3 +145,17 @@ Write string or byte to the UART.
uart
.
write
(
0
,
"Hello, world\n"
)
```
## uart.fifodepth()
Report the depth, in bytes, of TX or RX hardware queues associated with the
UART.
#### Syntax
`uart.fifodepth(id, dir)`
#### Parameters
-
`id`
UART id (0 or 1).
-
`dir`
`uart.DIR_RX`
for the RX FIFO,
`uart.DIR_TX`
for TX FIFO.
#### Returns
The number of bytes in the selected FIFO.
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