forked from anishathalye/notary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpio.v
41 lines (36 loc) · 977 Bytes
/
gpio.v
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
module gpio #(
parameter [31:0] ADDR = 32'hffff_ffff
) (
input clk,
input resetn,
input mem_valid,
input [31:0] mem_addr,
input [31:0] mem_wdata,
input [3:0] mem_wstrb,
output gpio_ready,
output gpio_sel,
output [31:0] gpio_rdata,
input [7:0] gpio_pin_in,
output [7:0] gpio_pin_out
);
// layout:
// ADDR -- GPIO write register
// +4 -- GPIO read register
wire reg_write_sel = mem_valid && (mem_addr == ADDR);
wire reg_read_sel = mem_valid && (mem_addr == (ADDR + 4));
assign gpio_sel = reg_read_sel || reg_write_sel;
// always ready, because we handle everything in a single cycle
assign gpio_ready = 1;
// read logic
assign gpio_rdata = {24'h0000_00, gpio_pin_in};
// write logic
reg [7:0] gpio_out;
always @(posedge clk) begin
if (!resetn) begin
gpio_out <= 8'h0;
end else if (reg_write_sel && mem_wstrb[0]) begin
gpio_out <= mem_wdata[7:0];
end
end
assign gpio_pin_out = gpio_out;
endmodule