SummerCart64/fw/rtl/cpu/cpu_gpio.sv

43 lines
1.0 KiB
Systemverilog
Raw Normal View History

2021-08-12 21:07:47 +02:00
module cpu_gpio (
2021-08-20 19:51:55 +02:00
if_system.sys sys,
2021-08-15 21:49:02 +02:00
if_cpu_bus bus,
2021-08-12 21:07:47 +02:00
input [7:0] gpio_i,
2021-08-20 19:51:55 +02:00
output [7:0] gpio_o,
output [7:0] gpio_oe
2021-08-12 21:07:47 +02:00
);
2021-08-20 19:51:55 +02:00
logic [1:0][7:0] gpio_i_ff;
logic [7:0] gpio_o_value;
logic [7:0] gpio_oe_value;
always_ff @(posedge sys.clk) begin
bus.ack <= 1'b0;
if (bus.request) begin
bus.ack <= 1'b1;
end
end
2021-08-12 21:07:47 +02:00
2021-08-15 21:49:02 +02:00
always_comb begin
bus.rdata = 32'd0;
if (bus.ack) begin
2021-08-20 19:51:55 +02:00
bus.rdata = {8'd0, gpio_oe_value, gpio_i_ff[1], gpio_o_value};
2021-08-15 21:49:02 +02:00
end
end
2021-08-12 21:07:47 +02:00
2021-08-20 19:51:55 +02:00
always_ff @(posedge sys.clk) begin
gpio_i_ff <= {gpio_i_ff[0], gpio_i};
2021-08-12 21:07:47 +02:00
gpio_o <= gpio_o_value;
gpio_oe <= gpio_oe_value;
2021-08-20 19:51:55 +02:00
if (sys.reset) begin
2021-08-12 21:07:47 +02:00
gpio_o_value <= 8'd0;
gpio_oe_value <= 8'd0;
2021-08-15 21:49:02 +02:00
end else if (bus.request) begin
if (bus.wmask[0]) gpio_o_value <= bus.wdata[7:0];
if (bus.wmask[2]) gpio_oe_value <= bus.wdata[23:16];
2021-08-12 21:07:47 +02:00
end
end
endmodule