aboutsummaryrefslogtreecommitdiff
path: root/fpga/src/Top.bs
blob: 7740c4b250f80c2d608998a23f619f9874f0e718 (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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
-- | The top-level module, for both simulation and the iCEBreaker.
package Top where

import Connectable
import CPU
import GetPut
import TriState
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 :: Inout (Bit 1) {-# prefix = "P1B1" #-}
  hyperBus_DQ1 :: Inout (Bit 1) {-# prefix = "P1B2" #-}
  hyperBus_DQ2 :: Inout (Bit 1) {-# prefix = "P1B3" #-}
  hyperBus_DQ3 :: Inout (Bit 1) {-# prefix = "P1B4" #-}
  hyperBus_DQ7 :: Inout (Bit 1) {-# prefix = "P1B7" #-}
  hyperBus_DQ6 :: Inout (Bit 1) {-# prefix = "P1B8" #-}
  hyperBus_DQ5 :: Inout (Bit 1) {-# prefix = "P1B9" #-}
  hyperBus_DQ4 :: Inout (Bit 1) {-# prefix = "P1B10" #-}
  -- LEDs and buttons (PMOD 2)
  led1 :: Bit 1 {-# always_ready, result = P2_7 #-}
  led2 :: Bit 1 {-# always_ready, result = P2_1 #-}
  led3 :: Bit 1 {-# always_ready, result = P2_2 #-}
  led4 :: Bit 1 {-# always_ready, result = P2_8 #-}
  led5 :: Bit 1 {-# always_ready, result = P2_3 #-}
  btn1 :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_9] #-}
  btn2 :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_4] #-}
  btn3 :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_10] #-}

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

    hyperBus_data0 <- mkTriState True 1
    hyperBus_data1 <- mkTriState True 1
    hyperBus_data2 <- mkTriState True 1
    hyperBus_data3 <- mkTriState True 1
    hyperBus_data4 <- mkTriState True 1
    hyperBus_data5 <- mkTriState True 1
    hyperBus_data6 <- mkTriState True 1
    hyperBus_data7 <- mkTriState True 1

    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
      -- HyperBus 2 (PMOD 1B)
      hyperBus_DQ0 = hyperBus_data0.io
      hyperBus_DQ1 = hyperBus_data1.io
      hyperBus_DQ2 = hyperBus_data2.io
      hyperBus_DQ3 = hyperBus_data3.io
      hyperBus_DQ4 = hyperBus_data4.io
      hyperBus_DQ5 = hyperBus_data5.io
      hyperBus_DQ6 = hyperBus_data6.io
      hyperBus_DQ7 = hyperBus_data7.io
      -- 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 :