-
Notifications
You must be signed in to change notification settings - Fork 1
/
GPIOController.v
92 lines (81 loc) · 1.7 KB
/
GPIOController.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module GPIOPin(
inout data, // GPIO data
input rw, // Read=0/Write=1
input en, // Enable Data Access
input sel, // Data=0/Mode=1
input clk, // Clock
inout pin
);
reg pin_mode = 0; // 0=output 1=input
reg pin_data = 0;
reg buffer;
always@ (posedge clk)
begin
if (en && rw)
begin
if (sel == 0) pin_data <= data;
else pin_mode <= data;
end
end
always@ (posedge clk)
begin
if (en && !rw)
begin
if (sel == 0) buffer <= pin;
else buffer <= pin;
end
end
assign pin = pin_mode ? 1'bz : pin_data;
assign data = (en && !rw) ? buffer : 1'bz;
endmodule
module GPIOController(
input [31:0] addr,
inout [31:0] data,
input [1:0] size,
input rw,
input clk,
inout [31:0] gpio
);
parameter ADDR = 32'h8000_0000;
parameter SIZE = 8;
wire enable = (addr >= ADDR) && (addr < (ADDR + SIZE)) && (addr[1:0] == 0);
wire select = ((addr - ADDR) & 4) == 4;
`ifdef ALTERA_RESERVED_QIS
`define declare_pin(I) GPIOPin ( .data(data[I]), .rw(rw), .en(enable), .sel(select), .clk(clk), .pin(gpio[I]) )
`else
`define declare_pin(I) GPIOPin pin_``I ( .data(data[I]), .rw(rw), .en(enable), .sel(select), .clk(clk), .pin(gpio[I]) )
`endif
`declare_pin(0);
`declare_pin(1);
`declare_pin(2);
`declare_pin(3);
`declare_pin(4);
`declare_pin(5);
`declare_pin(6);
`declare_pin(7);
`declare_pin(8);
`declare_pin(9);
`declare_pin(10);
`declare_pin(11);
`declare_pin(12);
`declare_pin(13);
`declare_pin(14);
`declare_pin(15);
/*`declare_pin(16);
`declare_pin(17);
`declare_pin(18);
`declare_pin(19);
`declare_pin(20);
`declare_pin(21);
`declare_pin(22);
`declare_pin(23);
`declare_pin(24);
`declare_pin(25);
`declare_pin(26);
`declare_pin(27);
`declare_pin(28);
`declare_pin(29);
`declare_pin(30);
`declare_pin(31);*/
`undef declare_pin
endmodule