1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
package Top where
import FIFOF
import GetPut
import Uart
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] #-}
clockFreqHz :: Integer
clockFreqHz = 12_000_000
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 / 2)
rules
-- "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
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
uart.rxPin bit
tx = uart.txPin
-- Onboard LEDs
ledR_N = uart.txPin
ledG_N = bitState
-- RGB LED driver
ledRed_N = 1
ledGrn_N = 1
ledBlu_N = 1
-- LEDs and buttons (PMOD 2)
led1 = 0
led2 = 0
led3 = 0
led4 = 0
led5 = 0
btn1 1 = lastByte := 0x40
btn1 0 = return ()
btn2 b = btn2State := b
btn3 b = btn3State := b
{-# verilog mkTop #-}
{-# properties mkTop = { RSTN = BTN_N } #-}
-- vim: set ft=haskell :
|