- # Return state of input if ie
- with m.If(gpio_ie_list[gpio_addr] == 1):
- sync += csrbus.io.eq(gpio_i_list[gpio_addr])
- comb += wb_rd_data.eq(csrbus)
- # Return state of out if oe
- with m.Else():
- sync += csrbus.io.eq(gpio_o_list[gpio_addr])
- comb += wb_rd_data.eq(csrbus)
-
- # Combinatorial
- comb += gpio_oe_list[gpio_addr].eq(csrbus.oe)
- comb += gpio_ie_list[gpio_addr].eq(csrbus.ie)
- # Check to prevent output being set if GPIO configured as input
- # TODO: Is this necessary? PAD might deal with this
- # check GPIO is in output mode and NOT input (oe high, ie low)
- #with m.If(csrbus.oe & (~csrbus.ie)):
- with m.If(gpio_oe_list[gpio_addr] & (~gpio_ie_list[gpio_addr])):
- comb += gpio_o_list[gpio_addr].eq(csrbus.io)
- comb += puen_list[gpio_addr].eq(csrbus.puen)
- comb += pden_list[gpio_addr].eq(csrbus.pden)
- comb += bank_sel[gpio_addr].eq(csrbus.bank_sel)
+ comb += wb_rd_data.eq(csrbus)
+ with m.Else():
+ sync += new_transaction.eq(0)
+ # Update the state of "io" while no WB transactions
+ with m.If(gpio_oe_list[gpio_addr] & (~gpio_ie_list[gpio_addr])):
+ sync += csrbus.io.eq(gpio_o_list[gpio_addr])
+ with m.If(gpio_ie_list[gpio_addr] & (~gpio_oe_list[gpio_addr])):
+ sync += csrbus.io.eq(gpio_i_list[gpio_addr])
+ with m.Else():
+ sync += csrbus.io.eq(csrbus.io)
+
+ # Only update GPIOs config if a new transaction happened last cycle
+ # (read or write). Always lags from csrbus by 1 clk cycle, most
+ # sane way I could think of while using Record().
+ with m.If(new_transaction):
+ sync += gpio_oe_list[gpio_addr].eq(csrbus.oe)
+ sync += gpio_ie_list[gpio_addr].eq(csrbus.ie)
+ # Check to prevent output being set if GPIO configured as input
+ # TODO: Is this necessary? PAD might deal with this
+ # check GPIO is in output mode and NOT input (oe high, ie low)
+ with m.If(gpio_oe_list[gpio_addr] & (~gpio_ie_list[gpio_addr])):
+ sync += gpio_o_list[gpio_addr].eq(csrbus.io)
+ sync += puen_list[gpio_addr].eq(csrbus.puen)
+ sync += pden_list[gpio_addr].eq(csrbus.pden)
+ sync += bank_sel[gpio_addr].eq(csrbus.bank_sel)