-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpio.v
63 lines (52 loc) · 974 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
`default_nettype none
module gpio #(parameter BASE_ADDR = 16'h0430)
(
input wire i_clk,
input wire i_rst,
input wire i_we,
input wire [15:0] i_addr,
input wire[15:0] i_data,
output reg [15:0] o_data,
input wire [15:0] i_gp,
output reg [15:0] o_gp
);
always @(posedge i_clk)
begin
if(!i_rst)
begin
case (i_addr)
BASE_ADDR: // GPIO data
begin
if(i_we)
begin
o_gp <= i_data;
end
else
begin
o_data <= i_gp;
end
end
BASE_ADDR + 1: // Output toggle
begin
if(i_we)
begin
o_gp <= o_gp ^ i_data;
end
else
begin
o_data <= i_gp;
end
end
default:
begin
o_data <= 0;
end
endcase
end
else
begin
o_gp <= 0;
o_data <= 0;
end
end
endmodule