-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathusb_ep_status.v
140 lines (125 loc) · 3.03 KB
/
usb_ep_status.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
129
130
131
132
133
134
135
136
137
138
139
140
/*
* usb_ep_status.v
*
* vim: ts=4 sw=4
*
* Copyright (C) 2019 Sylvain Munaut
* All rights reserved.
*
* LGPL v3+, see LICENSE.lgpl3
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
`default_nettype none
module usb_ep_status (
// Priority port
input wire [ 7:0] p_addr_0,
input wire p_read_0,
input wire p_zero_0,
input wire p_write_0,
input wire [15:0] p_din_0,
output reg [15:0] p_dout_3,
// Aux R/W port
input wire [ 7:0] s_addr_0,
input wire s_read_0,
input wire s_zero_0,
input wire s_write_0,
input wire [15:0] s_din_0,
output reg [15:0] s_dout_3,
output wire s_ready_0,
// Clock / Reset
input wire clk,
input wire rst
);
// Signals
wire s_ready_0_i;
reg [ 7:0] addr_1;
reg [15:0] din_1;
reg we_1;
reg p_read_1;
reg p_zero_1;
reg s_read_1;
reg s_zero_1;
wire [15:0] dout_2;
reg p_read_2;
reg p_zero_2;
reg s_read_2;
reg s_zero_2;
// "Arbitration"
assign s_ready_0_i = ~p_read_0 & ~p_write_0;
assign s_ready_0 = s_ready_0_i;
// Stage 1 : Address mux and Write delay
always @(posedge clk)
begin
addr_1 <= (p_read_0 | p_write_0) ? p_addr_0 : s_addr_0;
we_1 <= p_write_0 | (s_write_0 & s_ready_0_i);
din_1 <= p_write_0 ? p_din_0 : s_din_0;
p_read_1 <= p_read_0;
p_zero_1 <= p_zero_0;
s_read_1 <= s_read_0 & s_ready_0_i;
s_zero_1 <= s_zero_0 & s_ready_0_i;
end
// Stage 2 : Delays
always @(posedge clk)
begin
p_read_2 <= p_read_1 | p_zero_1;
p_zero_2 <= p_zero_1;
s_read_2 <= s_read_1 | s_zero_1;
s_zero_2 <= s_zero_1;
end
// Stage 3 : Output registers
always @(posedge clk)
if (p_read_2)
p_dout_3 <= p_zero_2 ? 16'h0000 : dout_2;
always @(posedge clk)
if (s_read_2)
s_dout_3 <= s_zero_2 ? 16'h0000 : dout_2;
// RAM element
`ifdef XXX
SB_RAM40_4K #(
`ifdef SIM
.INIT_FILE("usb_ep_status.hex"),
`endif
.WRITE_MODE(0),
.READ_MODE(0)
) ebr_I (
.RDATA(dout_2),
.RADDR({3'b000, addr_1}),
.RCLK(clk),
.RCLKE(1'b1),
.RE(1'b1),
.WDATA(din_1),
.WADDR({3'b000, addr_1}),
.MASK(16'h0000),
.WCLK(clk),
.WCLKE(we_1),
.WE(1'b1)
);
`else
reg [15:0] ram[0:255];
reg [15:0] ram_rd;
`ifdef SIM
initial
$readmemh("usb_ep_status.hex", ram);
`endif
always @(posedge clk)
begin
ram_rd <= ram[addr_1];
if (we_1)
ram[addr_1] <= din_1;
end
assign dout_2 = ram_rd;
`endif
endmodule // usb_ep_status