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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
-- | The top-level module, for both simulation and the iCEBreaker.
package Top where
import Connectable
import CPU
import GetPut
import Uart
-- | The interface to the iCEBreaker.
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 #-}
-- HyperBus 1 (PMOD 1A)
hyperBus_CS2_N :: Bit 1 {-# always_ready, result = P1A1 #-}
hyperBus_CS0_N :: Bit 1 {-# always_ready, result = P1A2 #-}
hyperBus_CK :: Bit 1 {-# always_ready, result = P1A3 #-}
hyperBus_CK_N :: Bit 1 {-# always_ready, result = P1A4 #-}
hyperBus_CS3_N :: Bit 1 {-# always_ready, result = P1A7 #-}
hyperBus_CS1_N :: Bit 1 {-# always_ready, result = P1A8 #-}
hyperBus_RESET_N :: Bit 1 {-# always_ready, result = P1A9 #-}
hyperBus_RWDS :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P1A10] #-}
-- HyperBus 2 (PMOD 1B)
-- hyperBus_DQ0_i :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P1B1] #-}
-- hyperBus_DQ0 :: Inout (Bit 1) {-# always_ready, result = P1B1 #-}
-- hyperBus_DQ1 :: Bit 1 {-# always_ready, result = P1B2 #-}
-- hyperBus_DQ2 :: Bit 1 {-# always_ready, result = P1B3 #-}
-- hyperBus_DQ3 :: Bit 1 {-# always_ready, result = P1B4 #-}
-- hyperBus_DQ7 :: Bit 1 {-# always_ready, result = P1B7 #-}
-- hyperBus_DQ6 :: Bit 1 {-# always_ready, result = P1B8 #-}
-- hyperBus_DQ5 :: Bit 1 {-# always_ready, result = P1B9 #-}
-- hyperBus_DQ4 :: Bit 1 {-# always_ready, result = P1B10 #-}
-- 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
cpu <- mkCPU
uart <- mkUart (clockFreqHz / 9600)
mkConnection cpu.uart_tx uart.send
mkConnection cpu.uart_rx uart.recv
interface Top
-- RS232
rx = uart.rxPin
tx = uart.txPin
-- Onboard LEDs
ledR_N = uart.txPin
ledG_N = 1
-- RGB LED driver
ledRed_N = 1
ledGrn_N = 1
ledBlu_N = 1
-- HyperBus 1 (PMOD 1A)
hyperBus_CS2_N = 1
hyperBus_CS0_N = 1
hyperBus_CK = 0
hyperBus_CK_N = 1
hyperBus_CS3_N = 1
hyperBus_CS1_N = 1
hyperBus_RESET_N = 1
hyperBus_RWDS _ = noAction
-- LEDs and buttons (PMOD 2)
led1 = 0
led2 = 0
led3 = 0
led4 = 0
led5 = 0
btn1 _ = noAction
btn2 _ = noAction
btn3 _ = noAction
{-# verilog mkTop #-}
{-# properties mkTop = { RSTN = BTN_N } #-}
mkTopSim :: Module Empty
mkTopSim =
module
cpu <- mkCPU
uart <- mkUart 1
mkConnection cpu.uart_tx uart.send
mkConnection cpu.uart_rx uart.recv
fakeUart <- mkUart 1
rules
when True ==> uart.rxPin fakeUart.txPin
timer :: Reg (Bit 8) <- mkReg 0
rules
when True ==> timer := timer + 1
when (timer == 0x00) ==> fakeUart.send.put 0x30
when (timer == 0x01) ==> fakeUart.send.put 0x30
when (timer == 0x02) ==> fakeUart.send.put 0x77
when (timer == 0x03) ==> fakeUart.send.put 0x31
when (timer == 0x04) ==> fakeUart.send.put 0x32
when (timer == 0x05) ==> fakeUart.send.put 0x33
when (timer == 0x06) ==> fakeUart.send.put 0x34
when (timer == 0x10) ==> fakeUart.send.put 0x30
when (timer == 0x11) ==> fakeUart.send.put 0x30
when (timer == 0x12) ==> fakeUart.send.put 0x72
when (timer == 0xff) ==> $finish
-- vim: set ft=haskell :
|