Skip to content

Commit 673c5c5

Browse files
committed
zephyr: device: uart: wip add ring size parameters
Add ring size parameters to the UartIrq type. These will later be used to migrate the interface to an async interface (not rust asyc). Signed-off-by: David Brown <[email protected]>
1 parent 0899f67 commit 673c5c5

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

zephyr/src/device/uart.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ impl Uart {
121121
UartAsync::new(self)
122122
}
123123

124-
/// Convert into an IRQ one.
125-
pub unsafe fn into_irq(self) -> Result<UartIrq> {
124+
/// Convert into an IRQ one. The parameters `WS` and `RS` set the size of the rings for write
125+
/// and read respectively.
126+
pub unsafe fn into_irq<const WS: usize, const RS: usize>(self) -> Result<UartIrq<WS, RS>> {
126127
UartIrq::new(self)
127128
}
128129
}

zephyr/src/device/uart/irq.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,26 @@ impl WriteSlice {
5656
}
5757
}
5858

59-
/// This is the irq-driven interface.
60-
pub struct UartIrq {
59+
/// An interface to the UART, that uses the "legacy" IRQ API.
60+
///
61+
/// The interface is parameterized by two value, `WS` is the number of elements in the write ring,
62+
/// and `RS` is the number of elements in the read ring. Each direction will have two rings, one
63+
/// for pending operations, and the other for completed operations. Setting these to 2 is
64+
/// sufficient to avoid stalling writes or dropping reads, but requires the application attend to
65+
/// the buffers.
66+
pub struct UartIrq<const WS: usize, const RS: usize> {
6167
/// Interior wrapped device, to be able to hand out lifetime managed references to it.
6268
uart: Uart,
6369
/// Critical section protected data.
6470
data: Arc<IrqOuterData>,
6571
}
6672

6773
// UartIrq is also Send, !Sync, for the same reasons as for Uart.
68-
unsafe impl Send for UartIrq {}
74+
unsafe impl<const WS: usize, const RS: usize> Send for UartIrq<WS, RS> {}
6975

70-
impl UartIrq {
76+
impl<const WS: usize, const RS: usize> UartIrq<WS, RS> {
7177
/// Convert uart into irq driven one.
72-
pub unsafe fn new(uart: Uart) -> Result<UartIrq> {
78+
pub unsafe fn new(uart: Uart) -> Result<Self> {
7379
let data = Arc::new(IrqOuterData {
7480
read_sem: Semaphore::new(0, 1)?,
7581
write_sem: Semaphore::new(0, 1)?,

0 commit comments

Comments
 (0)