-
Notifications
You must be signed in to change notification settings - Fork 55
/
cdbus.v
305 lines (253 loc) · 6.45 KB
/
cdbus.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
/*
* This Source Code Form is subject to the terms of the Mozilla
* Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
* Notice: The scope granted to MPL excludes the ASIC industry.
*
* Copyright (c) 2017 DUKELEC, All rights reserved.
*
* Author: Duke Fong <[email protected]>
*
* This file is the top module of CDBUS IP.
*/
module cdbus
#(
parameter DIV_LS = 346, // default: 115200 bps for 40MHz clk
parameter DIV_HS = 346
)(
input clk,
input reset_n,
input chip_select, // reduce ram_rx power consumption
output irq,
input [4:0] csr_address,
input csr_read,
output [7:0] csr_readdata,
input csr_write,
input [7:0] csr_writedata,
input rx,
output tx,
output tx_en
);
wire full_duplex;
wire break_sync;
wire arbitration;
wire not_drop;
wire user_crc;
wire tx_invert;
wire tx_push_pull;
wire [7:0] idle_wait_len;
wire [9:0] tx_permit_len;
wire [9:0] max_idle_len;
wire [1:0] tx_pre_len;
wire [7:0] filter;
wire [7:0] filter_m0;
wire [7:0] filter_m1;
wire [15:0] div_ls;
wire [15:0] div_hs;
wire [7:0] rx_ram_rd_addr;
wire rx_ram_rd_done;
wire rx_clean_all;
wire [7:0] rx_ram_rd_byte;
wire [7:0] rx_ram_rd_flags;
wire rx_error;
wire rx_ram_lost;
wire rx_break;
wire rx_pending;
wire bus_idle;
wire tx_ram_wr_en;
wire [7:0] tx_ram_wr_addr;
wire tx_ram_switch;
wire tx_abort;
wire has_break;
wire ack_break;
wire tx_pending;
wire cd;
wire tx_err;
wire [7:0] rx_ram_wr_byte;
wire [7:0] rx_ram_wr_addr;
wire rx_ram_wr_en;
wire rx_ram_switch;
wire [7:0] rx_ram_wr_flags;
wire [7:0] tx_ram_rd_byte;
wire [7:0] tx_ram_rd_addr;
wire tx_ram_rd_en;
wire tx_ram_rd_done;
wire [7:0] des_data;
wire [15:0] des_crc_data;
wire des_data_clk;
wire force_wait_idle;
wire [7:0] ser_data;
wire ser_has_data;
wire ser_ack_data;
wire ser_is_crc_byte;
wire ser_is_last_byte;
wire [15:0] ser_crc_data;
reg [1:0] rx_d;
always @(posedge clk)
rx_d <= {rx_d[0], rx};
wire tx_d;
wire tx_en_d;
wire tx_may_invert = tx_invert ? ~tx_d : tx_d;
assign tx_en = (reset_n && tx_push_pull) ? tx_en_d : 1'bz;
assign tx = (reset_n && (tx_push_pull || !tx_may_invert)) ? tx_may_invert : 1'bz;
cd_csr #(
.DIV_LS(DIV_LS),
.DIV_HS(DIV_HS)
) cd_csr_m(
.clk(clk),
.reset_n(reset_n),
.irq(irq),
`ifdef INT_FLAG_SNAPSHOT
.int_flag_update(~chip_select),
`endif
.csr_address(csr_address),
.csr_read(csr_read),
.csr_readdata(csr_readdata),
.csr_write(csr_write),
.csr_writedata(csr_writedata),
.full_duplex(full_duplex),
.break_sync(break_sync),
.arbitration(arbitration),
.not_drop(not_drop),
.user_crc(user_crc),
.tx_invert(tx_invert),
.tx_push_pull(tx_push_pull),
.idle_wait_len(idle_wait_len),
.tx_permit_len(tx_permit_len),
.max_idle_len(max_idle_len),
.tx_pre_len(tx_pre_len),
.filter(filter),
.filter_m0(filter_m0),
.filter_m1(filter_m1),
.div_ls(div_ls),
.div_hs(div_hs),
.rx_ram_rd_addr(rx_ram_rd_addr),
.rx_ram_rd_done(rx_ram_rd_done),
.rx_clean_all(rx_clean_all),
.rx_ram_rd_byte(rx_ram_rd_byte),
.rx_ram_rd_flags(rx_ram_rd_flags),
.rx_error(rx_error),
.rx_ram_lost(rx_ram_lost),
.rx_break(rx_break),
.rx_pending(rx_pending),
.bus_idle(bus_idle),
.tx_ram_wr_en(tx_ram_wr_en),
.tx_ram_wr_addr(tx_ram_wr_addr),
.tx_ram_switch(tx_ram_switch),
.tx_abort(tx_abort),
.has_break(has_break),
.ack_break(ack_break),
.tx_pending(tx_pending),
.cd(cd),
.tx_err(tx_err)
);
cd_rx_ram cd_rx_ram_m(
.clk(clk),
.reset_n(reset_n),
.rd_byte(rx_ram_rd_byte),
.rd_addr(rx_ram_rd_addr),
.rd_en(chip_select),
.rd_done(rx_ram_rd_done),
.rd_done_all(rx_clean_all),
.unread(rx_pending),
.wr_byte(rx_ram_wr_byte),
.wr_addr(rx_ram_wr_addr),
.wr_en(rx_ram_wr_en),
.switch(rx_ram_switch),
.wr_flags(rx_ram_wr_flags),
.rd_flags(rx_ram_rd_flags),
.switch_fail(rx_ram_lost)
);
cd_tx_ram cd_tx_ram_m(
.clk(clk),
.reset_n(reset_n),
.rd_byte(tx_ram_rd_byte),
.rd_addr(tx_ram_rd_addr),
.rd_en(tx_ram_rd_en),
.rd_done(tx_ram_rd_done),
.unread(tx_pending),
.wr_byte(csr_writedata),
.wr_addr(tx_ram_wr_addr),
.wr_en(tx_ram_wr_en),
.switch(tx_ram_switch)
);
cd_rx_bytes cd_rx_bytes_m(
.clk(clk),
.reset_n(reset_n),
.filter(filter),
.filter_m0(filter_m0),
.filter_m1(filter_m1),
.user_crc(user_crc),
.not_drop(not_drop),
.abort(rx_clean_all),
.error(rx_error),
.des_bus_idle(bus_idle),
.des_data(des_data),
.des_crc_data(des_crc_data),
.des_data_clk(des_data_clk),
.des_force_wait_idle(force_wait_idle),
.ram_wr_byte(rx_ram_wr_byte),
.ram_wr_addr(rx_ram_wr_addr),
.ram_wr_en(rx_ram_wr_en),
.ram_wr_flags(rx_ram_wr_flags),
.ram_switch(rx_ram_switch)
);
cd_rx_des cd_rx_des_m(
.clk(clk),
.reset_n(reset_n),
.div_ls(div_ls),
.div_hs(div_hs),
.idle_wait_len(idle_wait_len),
.bus_idle(bus_idle),
.rx_break(rx_break),
.force_wait_idle(force_wait_idle),
.rx(rx_d[1]),
.data(des_data),
.crc_data(des_crc_data),
.data_clk(des_data_clk)
);
cd_tx_bytes cd_tx_bytes_m(
.clk(clk),
.reset_n(reset_n),
.user_crc(user_crc),
.abort(tx_abort || tx_err),
.data(ser_data),
.has_data(ser_has_data),
.ack_data(ser_ack_data),
.is_crc_byte(ser_is_crc_byte),
.is_last_byte(ser_is_last_byte),
.crc_data(ser_crc_data),
.ram_unread(tx_pending),
.ram_rd_byte(tx_ram_rd_byte),
.ram_rd_addr(tx_ram_rd_addr),
.ram_rd_en(tx_ram_rd_en),
.ram_rd_done(tx_ram_rd_done)
);
cd_tx_ser cd_tx_ser_m(
.clk(clk),
.reset_n(reset_n),
.data(ser_data),
.has_data(ser_has_data),
.ack_data(ser_ack_data),
.is_crc_byte(ser_is_crc_byte),
.is_last_byte(ser_is_last_byte),
.crc_data(ser_crc_data),
.has_break(has_break),
.ack_break(ack_break),
.bus_idle(bus_idle),
.div_ls(div_ls),
.div_hs(div_hs),
.tx_permit_len(tx_permit_len),
.max_idle_len(max_idle_len),
.tx_pre_len(tx_pre_len),
.full_duplex(full_duplex),
.break_sync(break_sync),
.arbitration(arbitration),
.abort(tx_abort),
.cd(cd),
.err(tx_err),
.rx(rx_d[1]),
.tx(tx_d),
.tx_en(tx_en_d)
);
endmodule