blob: 2a58a838b81f10d6bd0d223d76766d23480ef0c0 (
plain)
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
|
-- | The top-level module for simulation.
package TopSim where
-- import Numini
import GetPut
import I2C
mkTopSim :: Module Empty
mkTopSim = module
{-
ch559_uart_rx <- mkWire
inkplate_uart_rx <- mkWire
usb_uart_rx <- mkWire
hyperbus_rwds_in <- mkWire
hyperbus_dq_in <- mkWire
i2c_scl_in <- mkWire
i2c_sda_in <- mkWire
numini <- mkNumini ch559_uart_rx inkplate_uart_rx usb_uart_rx
hyperbus_rwds_in hyperbus_dq_in i2c_scl_in i2c_sda_in
-}
txSCL <- mkReg 0
txSDA <- mkReg 0
rxSCL <- mkReg 1
rxSDA <- mkReg 1
i2c <- mkI2C rxSCL rxSDA
rules
when True ==> txSCL := i2c.txSCL
when True ==> txSDA := i2c.txSDA
-- Provide commands.
state :: Reg (Bit 4) <- mkReg 0
rules
when state == 0, i2c.statusRegGet.ready ==> do
i2c.addrRegPut (0x20 ++ (0 :: Bit 1))
i2c.dataRegPut 0x01
i2c.statusRegPut (i2c.statusRegGet { ready = False })
state := 1
when state == 1 ==> do
i2c.addrRegPut (0x20 ++ (0 :: Bit 1))
i2c.dataRegPut 0x02
state := 2
when state == 2, i2c.statusRegGet.ready ==> do
i2c.statusRegPut (i2c.statusRegGet { ready = False })
state := 3
{-
when state == 3 ==> do
i2c.addrRegPut (0x20 ++ (0 :: Bit 1))
i2c.dataRegPut 0x03
state := 4
when state == 4, i2c.statusRegGet.ready ==> do
i2c.statusRegPut (i2c.statusRegGet { ready = False })
state := 5
when state == 5 ==> do
i2c.addrRegPut (0x20 ++ (0 :: Bit 1))
i2c.dataRegPut 0x12
state := 6
when state == 6, i2c.statusRegGet.busIdle ==> do
i2c.statusRegPut (i2c.statusRegGet { ready = False })
state := 7
when state == 7 ==> do
i2c.addrRegPut (0x20 ++ (0 :: Bit 1))
i2c.dataRegPut 0xaa
state := 8
when state == 8, i2c.statusRegGet.ready ==> do
i2c.statusRegPut (i2c.statusRegGet { ready = False })
state := 9
when state == 9 ==> do
i2c.addrRegPut (0x20 ++ (0 :: Bit 1))
i2c.dataRegPut 0xaa
state := 10
when state == 10, i2c.statusRegGet.ready ==> do
i2c.statusRegPut (i2c.statusRegGet { ready = False })
state := 11
-}
timer :: Reg (Bit 16) <- mkReg 0
rules
"t0022": when (timer == 0x0022) ==> rxSDA := 0
"t0026": when (timer == 0x0026) ==> rxSDA := 1
"t0046": when (timer == 0x0046) ==> rxSDA := 0
"t004a": when (timer == 0x004a) ==> rxSDA := 1
"t006a": when (timer == 0x006a) ==> rxSDA := 0
"t006e": when (timer == 0x006e) ==> rxSDA := 1
"t008e": when (timer == 0x008e) ==> rxSDA := 0
"t0092": when (timer == 0x0092) ==> rxSDA := 1
"advance timer": when True ==> timer := timer + 1
"finish": when (timer == 0x01ff) ==> $finish
-- vim: set ft=haskell :
|