diff options
Diffstat (limited to 'fpga/src/Top.bs')
-rw-r--r-- | fpga/src/Top.bs | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/fpga/src/Top.bs b/fpga/src/Top.bs index 67449bd..65baf8a 100644 --- a/fpga/src/Top.bs +++ b/fpga/src/Top.bs @@ -24,25 +24,25 @@ interface Top = 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 :: Inout (Bit 1) {-# prefix = "P1A10" #-} + hyperbus_rwds :: Inout (Bit 1) {-# prefix = 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" #-} + 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 #-} -- Serial buses (PMOD 2) ch559_uart_rx :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_1] #-} ch559_uart_tx :: Bit 1 {-# always_ready, result = P2_2 #-} inkplate_uart_rx :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_3] #-} inkplate_uart_tx :: Bit 1 {-# always_ready, result = P2_4 #-} - i2c_scl :: Bit 1 {-# always_ready, result = P2_7 #-} - i2c_sda :: Inout (Bit 1) {-# prefix = "P2_8" #-} - todo_btn :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_9] #-} - todo_led :: Bit 1 {-# always_ready, result = P2_10 #-} + todo_btn :: Bit 1 -> Action {-# always_enabled, always_ready, prefix = "", arg_names = [P2_7] #-} + todo_led :: Bit 1 {-# always_ready, result = P2_8 #-} + i2c_scl :: Inout (Bit 1) {-# prefix = P2_9 #-} + i2c_sda :: Inout (Bit 1) {-# prefix = P2_10 #-} clockFreqHz :: Integer clockFreqHz = 12_000_000 @@ -68,18 +68,21 @@ mkTop = module hyperbus_dq6 <- mkTriState hyperbus_dq_enable hyperbus_dq_out[6:6] hyperbus_dq7 <- mkTriState hyperbus_dq_enable hyperbus_dq_out[7:7] - -- Make a tristate for the I2C inout. + -- Make a tristate for the I2C inouts. Note that we never drive the line + -- high -- I2C uses a high-impedance state instead of high. + i2c_scl_enable <- mkReg False + i2c_scl <- mkTriState i2c_scl_enable 0 i2c_sda_enable <- mkReg False - i2c_sda_out <- mkReg 0 - i2c_sda <- mkTriState i2c_sda_enable i2c_sda_out + i2c_sda <- mkTriState i2c_sda_enable 0 -- Make wires for all the inout inputs. hyperbus_rwds_in :: Wire (Bit 1) <- mkWire hyperbus_dq_in :: Wire (Bit 8) <- mkWire + i2c_scl_in :: Wire (Bit 1) <- mkWire i2c_sda_in :: Wire (Bit 1) <- mkWire numini <- mkNumini ch559_uart_rx inkplate_uart_rx usb_uart_rx - hyperbus_rwds_in hyperbus_dq_in i2c_sda_in + hyperbus_rwds_in hyperbus_dq_in i2c_scl_in i2c_sda_in -- Wire up the tristates. rules @@ -110,14 +113,12 @@ mkTop = module ++ hyperbus_dq2._read ++ hyperbus_dq1._read ++ hyperbus_dq0._read + "update_i2c_scl_out": when True ==> do + i2c_scl_enable := unpack numini.i2c_scl_out + "update_i2c_scl_in": when True ==> do + i2c_scl_in := i2c_scl._read "update_i2c_sda_out": when True ==> do - case numini.i2c_sda_out of - Just bits -> do - i2c_sda_enable := True - i2c_sda_out := bits - Nothing -> do - i2c_sda_enable := False - i2c_sda_out := 0 + i2c_sda_enable := unpack numini.i2c_sda_out "update_i2c_sda_in": when True ==> do i2c_sda_in := i2c_sda._read @@ -155,10 +156,10 @@ mkTop = module ch559_uart_tx = numini.ch559_uart_tx inkplate_uart_rx bit = inkplate_uart_rx := bit inkplate_uart_tx = numini.inkplate_uart_tx - i2c_scl = numini.i2c_scl - i2c_sda = i2c_sda.io todo_btn _ = noAction todo_led = 0 + i2c_scl = i2c_scl.io + i2c_sda = i2c_sda.io {-# verilog mkTop #-} {-# properties mkTop = { RSTN = BTN_N } #-} |