aboutsummaryrefslogtreecommitdiff
path: root/src/Top.bs
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-05-05 17:20:00 -0500
committerNathan Ringo <nathan@remexre.com>2024-05-05 17:20:00 -0500
commit0874c7f1852145c3ae62f1e28dc10c0c89d78b45 (patch)
tree0717d0293a78510ac62ea7f463da4ef6d54229cb /src/Top.bs
parent2ec6d7d09e2cd6c08686aae9427b46a217972675 (diff)
Not yet working UART...
Diffstat (limited to 'src/Top.bs')
-rw-r--r--src/Top.bs111
1 files changed, 68 insertions, 43 deletions
diff --git a/src/Top.bs b/src/Top.bs
index 6dee830..61bdc86 100644
--- a/src/Top.bs
+++ b/src/Top.bs
@@ -1,53 +1,78 @@
package Top where
-mkTop :: Module Empty
-mkTop =
- module
- deepThought :: DeepThought_IFC <- mkDeepThought
-
- rules
- "rl_ask": when True ==> do
- $display "Asking the Ultimate Question of Life, The Universe and Everything"
- deepThought.whatIsTheAnswer
+import GetPut
+import RS232
- "rl_print_answer": when True ==> do
- x <- deepThought.getAnswer
- $display "Deep Thought says: Hello, World! The answer is %0d." x
- $finish
+interface Top =
+ -- RS232
+ rx :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [RX] #-}
+ tx :: Bit 1 {-# always_ready, result = TX #-}
+ -- Onboard LEDs
+ ledR_N :: Bit 1 {-# always_ready, result = LEDR_N #-}
+ ledG_N :: Bit 1 {-# always_ready, result = LEDG_N #-}
+ -- RGB LED driver
+ ledRed_N :: Bit 1 {-# always_ready, result = LED_RED_N #-}
+ ledGrn_N :: Bit 1 {-# always_ready, result = LED_GRN_N #-}
+ ledBlu_N :: Bit 1 {-# always_ready, result = LED_BLU_N #-}
+ -- LEDs and buttons (PMOD 2)
+ led1 :: Bit 1 {-# always_ready, result = LED1 #-}
+ led2 :: Bit 1 {-# always_ready, result = LED2 #-}
+ led3 :: Bit 1 {-# always_ready, result = LED3 #-}
+ led4 :: Bit 1 {-# always_ready, result = LED4 #-}
+ led5 :: Bit 1 {-# always_ready, result = LED5 #-}
+ btn1 :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [BTN1] #-}
+ btn2 :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [BTN2] #-}
+ btn3 :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [BTN3] #-}
-interface DeepThought_IFC =
- whatIsTheAnswer :: Action
- getAnswer :: ActionValue (Int 32)
+clockFreqHz :: Integer
+clockFreqHz = 12_000_000
-data State_DT = IDLE | THINKING | ANSWER_READY
- deriving (Eq, Bits, FShow)
-
-mkDeepThought :: Module DeepThought_IFC
-mkDeepThought =
+mkTop :: Module Top
+mkTop =
module
- rg_state_dt :: Reg State_DT <- mkReg IDLE
- rg_half_millenia :: Reg (Bit 4) <- mkReg 0
+ let uartBaud :: Integer
+ uartBaud = 115200
+ uartDivider :: Integer
+ uartDivider = clockFreqHz / uartBaud
+ uart :: UART 8 <- mkUART 8 NONE STOP_1 (fromInteger uartDivider)
- let millenia = rg_half_millenia [3:1]
- let half_millenium = rg_half_millenia [0:0]
+ clkState :: Reg (Bit 32) <- mkReg 0
+ btn1State :: Reg (Bit 1) <- mkReg 0
+ btn2State :: Reg (Bit 1) <- mkReg 0
+ btn3State :: Reg (Bit 1) <- mkReg 0
+ led4State :: Reg (Bit 1) <- mkReg 0
+ led5State :: Reg (Bit 1) <- mkReg 0
rules
- "rl_think": when (rg_state_dt == THINKING) ==> do
- $write " DeepThought: ... thinking ... (%0d" millenia
- if (half_millenium == 1) then $write ".5" else noAction
- $display " million years)"
-
- if (rg_half_millenia == 15) then
- rg_state_dt := ANSWER_READY
- else
- rg_half_millenia := rg_half_millenia + 1
-
- interface
- whatIsTheAnswer = rg_state_dt := THINKING
- when (rg_state_dt == IDLE)
+ "echo": when (clkState == 0) ==> do
+ led4State := led4State + 1
+ uart.rx.put 0x7e
+ "increment_clock": when True ==> do
+ if clkState == fromInteger (clockFreqHz / 10) then do
+ clkState := 0
+ led5State := led5State + 1
+ else
+ clkState := clkState + 1
- getAnswer = do
- rg_state_dt := IDLE
- rg_half_millenia := 0
- return 42
- when (rg_state_dt == ANSWER_READY)
+ interface Top
+ -- RS232
+ rx = uart.rs232.sin
+ tx = uart.rs232.sout
+ -- Onboard LEDs
+ ledR_N = 1
+ ledG_N = 1
+ -- RGB LED driver
+ ledRed_N = 1
+ ledGrn_N = 1
+ ledBlu_N = 1
+ -- LEDs and buttons (PMOD 2)
+ led1 = btn1State
+ led2 = btn2State
+ led3 = btn3State
+ led4 = led4State
+ led5 = led5State
+ btn1 x = btn1State := x
+ btn2 x = btn2State := x
+ btn3 x = btn3State := x
+{-# verilog mkTop #-}
+{-# properties mkTop = { RSTN = BTN_N } #-}