aboutsummaryrefslogtreecommitdiff
path: root/src/Uart.bs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-09-18 10:14:57 -0500
committerNathan Ringo <nathan@remexre.com>2024-09-18 10:14:57 -0500
commit46457cc330049bb38c0af9a3f671b33b8f534c55 (patch)
treef2852d85dceaf67e75bd7d5688f2d3a28b61bb71 /src/Uart.bs
parent03d5906c48812d6c03ab0483c502e5464eaa583b (diff)
Add the simulator.
Diffstat (limited to 'src/Uart.bs')
-rw-r--r--src/Uart.bs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Uart.bs b/src/Uart.bs
index adf77d4..f66970c 100644
--- a/src/Uart.bs
+++ b/src/Uart.bs
@@ -83,8 +83,12 @@ data RxState
| -- | In the 'Data _ n' state, the UART has received the start bit and 'n'
-- data bits, and is about to receive more data bits. 'Data _ n'
-- transitions to 'Data _ (n + 1)' by receiving a data bit. 'Data b 7'
- -- transitions to 'Idle' by receving the last data bit.
+ -- transitions to 'Stop' by receving the last data bit.
Data (Bit 8) (Bit 3)
+ | -- | In the 'Stop' state, the UART has received the start and data bits,
+ -- and is waiting for the stop bit (which is ignored). Transitions to
+ -- 'Idle'.
+ Stop
deriving (Bits)
-- | The RX side of the UART.
@@ -109,7 +113,7 @@ mkRxUart baudClock bufferSize =
rules
"uart_rx_idle": when Idle <- state ==>
if pin == 0 then do
- debugBit := 0
+ debugBit := pin
state := Data 0 0
else
state := Idle
@@ -117,10 +121,12 @@ mkRxUart baudClock bufferSize =
let newBits = pin ++ oldBits[6:0]
if n == 7 then do
fifo.enq newBits
- debugBit := 1
- state := Idle
+ state := Stop
else
state := Data newBits (n + 1)
+ "uart_rx_stop": when Stop <- state ==> do
+ debugBit := pin
+ state := Idle
interface RxUart
pin bit = pin := bit