aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent2ec6d7d09e2cd6c08686aae9427b46a217972675 (diff)
Not yet working UART...
Diffstat (limited to 'src')
-rw-r--r--src/Top.bs111
-rw-r--r--src/icebreaker.pcf54
2 files changed, 122 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 } #-}
diff --git a/src/icebreaker.pcf b/src/icebreaker.pcf
new file mode 100644
index 0000000..1164c98
--- /dev/null
+++ b/src/icebreaker.pcf
@@ -0,0 +1,54 @@
+# 12 MHz clock
+set_io -nowarn CLK 35
+
+# RS232
+set_io -nowarn RX 6
+set_io -nowarn TX 9
+
+# LEDs and Button
+set_io -nowarn BTN_N 10
+set_io -nowarn LEDR_N 11
+set_io -nowarn LEDG_N 37
+
+# RGB LED Driver
+set_io -nowarn LED_RED_N 39
+set_io -nowarn LED_GRN_N 40
+set_io -nowarn LED_BLU_N 41
+
+# SPI Flash
+set_io -nowarn FLASH_SCK 15
+set_io -nowarn FLASH_SSB 16
+set_io -nowarn FLASH_IO0 14
+set_io -nowarn FLASH_IO1 17
+set_io -nowarn FLASH_IO2 12
+set_io -nowarn FLASH_IO3 13
+
+# PMOD 1A
+set_io -nowarn P1A1 4
+set_io -nowarn P1A2 2
+set_io -nowarn P1A3 47
+set_io -nowarn P1A4 45
+set_io -nowarn P1A7 3
+set_io -nowarn P1A8 48
+set_io -nowarn P1A9 46
+set_io -nowarn P1A10 44
+
+# PMOD 1B
+set_io -nowarn P1B1 43
+set_io -nowarn P1B2 38
+set_io -nowarn P1B3 34
+set_io -nowarn P1B4 31
+set_io -nowarn P1B7 42
+set_io -nowarn P1B8 36
+set_io -nowarn P1B9 32
+set_io -nowarn P1B10 28
+
+# LEDs and Buttons (PMOD 2)
+set_io -nowarn LED1 26
+set_io -nowarn LED2 27
+set_io -nowarn LED3 25
+set_io -nowarn LED4 23
+set_io -nowarn LED5 21
+set_io -nowarn BTN1 20
+set_io -nowarn BTN2 19
+set_io -nowarn BTN3 18