-
Notifications
You must be signed in to change notification settings - Fork 0
/
apb_slave.v
129 lines (114 loc) · 2.02 KB
/
apb_slave.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
`define WCYC 0
`define USE_POWER_PINS
module apb_memory (
`ifdef USE_POWER_PINS
vccd1,
vssd1,
`endif
pclk,
rst_n,
paddr,
wen,
ren,
pwdata,
prdata);
`ifdef USE_POWER_PINS
inout vccd1;
inout vssd1;
`endif
input pclk;
input rst_n;
input [3:0] paddr;
input wen;
input ren;
input [7:0] pwdata;
output [7:0] prdata;
`ifndef USE_RAM_MODEL
`ifdef MACRO_SYN
reg [7:0] mem[16];
reg [7:0] rdata;
reg write_data;
//assign prdata = ren ? mem[paddr] : 0;
assign prdata = rdata;
always @(posedge pclk or negedge rst_n) begin
if (!rst_n)
rdata = 0;
else if (ren)
rdata = mem[paddr];
end
always @(posedge pclk or negedge rst_n) begin
if (!rst_n)
write_data = 0;
else if (wen && !write_data) begin
write_data = 1;
mem[paddr] = pwdata;
end
else if (write_data && !wen) begin
write_data = 0;
end
end
`endif
`else
sky130_sram_16byte_1r1w u_ram
(.clk0(pclk),
.csb0(!wen),
.addr0(paddr),
.din0(pwdata),
.clk1(pclk),
.csb1(!ren),
.addr1(paddr),
.dout1(prdata)
);
`endif
endmodule
module apb_slave (
pclk,
rst_n,
paddr,
pwrite,
psel,
penable,
pwdata,
prdata,
pready);
input pclk;
input rst_n;
input reg [3:0] paddr;
input reg pwrite;
input reg psel;
input reg penable;
input reg [7:0] pwdata;
output reg [7:0] prdata;
output pready;
reg ren, wen, ready;
apb_memory u_mem (
.pclk(pclk),
.rst_n(rst_n),
.paddr(paddr),
.wen(wen),
.ren(ren),
.pwdata(pwdata),
.prdata(prdata)
);
assign wen = psel & penable & pwrite & ready;
assign ren = psel & penable & !pwrite;
assign #0 pready = ready;
reg [2:0] wcnt;
always @(posedge pclk or negedge rst_n) begin
if (!rst_n)
begin
ready = 1;
wcnt = `WCYC;
end
else if (psel && penable && (wcnt > 0))
begin
ready = 0;
wcnt = wcnt-1;
end
else
begin
ready = 1;
wcnt = `WCYC;
end
end
endmodule