aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--src/Top.bs26
-rw-r--r--src/TopSim.bs11
-rw-r--r--src/Uart.bs39
4 files changed, 38 insertions, 39 deletions
diff --git a/Makefile b/Makefile
index a7752ba..4eeeae1 100644
--- a/Makefile
+++ b/Makefile
@@ -35,6 +35,7 @@ tmp/$(TOPMODULE).v: tmp/$(TOPFILE).bo
tmp/%.bo:
@mkdir -p $(dir $@)
bsc -verilog $(BSC_COMP_FLAGS) $<
+# Hack around not having precise dependency information for Bluespec files.
.PHONY: tmp/$(TOPFILE).bo
tmp/depends.mk:
diff --git a/src/Top.bs b/src/Top.bs
index dfe98a5..ab2823f 100644
--- a/src/Top.bs
+++ b/src/Top.bs
@@ -32,27 +32,32 @@ mkTop :: Module Top
mkTop =
module
bitState :: Reg (Bit 1) <- mkReg 0
+ btn2State :: Reg (Bit 1) <- mkReg 0
+ btn3State :: Reg (Bit 1) <- mkReg 0
uart <- mkUart (clockFreqHz / 9600)
lastByte :: Reg (Bit 8) <- mkReg 0x21
- tick <- mkDivider (clockFreqHz)
+ tick <- mkDivider (clockFreqHz / 2)
rules
- "tick": when tick.clk ==> do
- uart.send.put lastByte
- "recv": when tick.clk ==> do
+ -- "tick": when tick.clk ==> do
+ -- uart.send.put lastByte
+ "debugPin": when True ==> bitState := uart.debugPin
+ "recv": when True ==> do
byte <- uart.recv.get
- lastByte := byte
+ -- lastByte := byte
+ uart.send.put byte
+ -- "inc": when tick.clk, btn2State == 1 ==> lastByte := lastByte + 1
+ -- "dec": when tick.clk, btn3State == 1 ==> lastByte := lastByte - 1
interface Top
-- RS232
rx bit = do
- bitState := bit
uart.rxPin bit
tx = uart.txPin
-- Onboard LEDs
ledR_N = uart.txPin
- ledG_N = uart.debugBit
+ ledG_N = bitState
-- RGB LED driver
ledRed_N = 1
ledGrn_N = 1
@@ -63,9 +68,10 @@ mkTop =
led3 = 0
led4 = 0
led5 = 0
- btn1 _ = return ()
- btn2 _ = return ()
- btn3 _ = return ()
+ btn1 1 = lastByte := 0x40
+ btn1 0 = return ()
+ btn2 b = btn2State := b
+ btn3 b = btn3State := b
{-# verilog mkTop #-}
{-# properties mkTop = { RSTN = BTN_N } #-}
diff --git a/src/TopSim.bs b/src/TopSim.bs
index 93fef14..0b77d3b 100644
--- a/src/TopSim.bs
+++ b/src/TopSim.bs
@@ -12,12 +12,9 @@ mkTopSim =
uart <- mkUart 1
rules
- when True ==> do
- timer := timer + 1
- when (timer == 0x00) ==> uart.send.put 0x81
- when (timer == 0x01) ==> uart.send.put 0x18
- when (timer == 0x02) ==> uart.send.put 0x81
- when (timer == 0x40) ==> do
- $finish
+ when True ==> timer := timer + 1
+ when True ==> uart.rxPin (1 - uart.txPin)
+ when (timer == 0x00) ==> uart.send.put 0x6a
+ when (timer == 0x40) ==> $finish
-- vim: set ft=haskell :
diff --git a/src/Uart.bs b/src/Uart.bs
index d79f246..47d32e0 100644
--- a/src/Uart.bs
+++ b/src/Uart.bs
@@ -75,8 +75,8 @@ mkTxUart baudClock bufferSize =
-- | The state of the RX side of the UART.
data RxState
- = -- | The UART is not currently receiving anything. May transition to
- -- 'Data 0 0' when the start bit is received.
+ = -- | The initial state of the UART, and the state after receiving the stop
+ -- bit. May transition to 'Data 0 0' when the start bit is received.
Idle
| -- | 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'
@@ -96,7 +96,7 @@ interface RxUart =
-- | Reads a byte from the UART's receive buffer.
recv :: Get (Bit 8)
- debugBit :: Bit 1
+ debugPin :: Bit 1
mkRxUart :: Clock -> Integer -> Module RxUart
mkRxUart baudClock bufferSize =
@@ -104,32 +104,26 @@ mkRxUart baudClock bufferSize =
fifo :: FIFOF (Bit 8) <- mkGSizedFIFOF True False bufferSize
state :: Reg RxState <- mkReg Idle
pin :: Wire (Bit 1) <- mkWire
- debugBit :: Reg (Bit 1) <- mkReg 1
+ debugPin :: Wire (Bit 1) <- mkWire
rules
"uart_rx": when baudClock.clk
rules
- "uart_rx_idle": when Idle <- state ==>
- if pin == 0 then do
- debugBit := pin
- state := Data 0 0
- else
- state := Idle
- "uart_rx_data": when Data oldBits n <- state ==> do
- let newBits = pin ++ oldBits[6:0]
- if n == 7 then do
- fifo.enq newBits
- state := Stop
- else
- state := Data newBits (n + 1)
- "uart_rx_stop": when Stop <- state ==> do
- debugBit := pin
+ "uart_rx_idle_to_start": when Idle <- state, pin == 0 ==> do
+ state := Data 0 0
+ "uart_rx_data_to_data": when Data bits n <- state, n < 7 ==> do
+ state := Data (bits[6:0] ++ pin) (n + 1)
+ "uart_rx_data_to_stop": when Data bits 7 <- state ==> do
+ fifo.enq (bits[6:0] ++ pin)
+ state := Stop
+ "uart_rx_stop": when Stop <- state, pin == 1 ==> do
state := Idle
+ "debugPin": when True ==> debugPin := if fifo.notEmpty then 1 else 0
interface RxUart
pin bit = pin := bit
recv = toGet fifo
- debugBit = debugBit
+ debugPin = debugPin
-- | An 8n1 UART.
interface Uart =
@@ -142,7 +136,8 @@ interface Uart =
recv :: Get (Bit 8)
-- | Writes a byte to the UART's transmit buffer.
send :: Put (Bit 8)
- debugBit :: Bit 1
+
+ debugPin :: Bit 1
mkUart :: Integer -> Module Uart
mkUart baudDivisor =
@@ -156,6 +151,6 @@ mkUart baudDivisor =
txPin = tx.pin
recv = rx.recv
send = tx.send
- debugBit = rx.debugBit
+ debugPin = rx.debugPin
-- vim: set ft=haskell :