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 GetPut
import RS232
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
let uartBaud :: Integer
uartBaud = 115200
uartDivider :: Integer
uartDivider = clockFreqHz / uartBaud
uart :: UART 8 <- mkUART 8 NONE STOP_1 (fromInteger uartDivider)
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
"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
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 } #-}
|