-
Notifications
You must be signed in to change notification settings - Fork 0
/
s33_read_mem_reseed.sv
429 lines (399 loc) · 13.1 KB
/
s33_read_mem_reseed.sv
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
// vi:set ft=verilog ts=4 sw=4 expandtab ai si:
// [email protected] 20180821
`default_nettype none
`include "./s00_defines.sv"
// read to mem(seed) with 'all' 3 phase : SmpFwd, BiDir & Reseed
module ReadMemReseed3
import BwaMemDefines::*;
#(
parameter integer READ_LEN = 76,
// POW_W moved into package BwaMemDefines
// parameter POS_W = 8,
parameter integer OCC_AW = 40,
parameter logic [OCC_AW - 1 : 0] OCC_BASE = 40'h00_0000_0000, // must be align to 64G
parameter integer FILTER_GRP_SIZE = 2,
parameter integer BIDIREX_QU_AW = 8,
parameter integer RESEED_QU_AW = 6
)(
input wire clk, rst,
input wire Symbol read[0 : READ_LEN - 1],
input wire [RID_W - 1 : 0] read_id,
input wire start,
output logic finish,
output logic busy,
Axi4StreamIf.master m_axis_emout,
Axi4LiteIf.master m_axi_occlu,
input wire [KLS_W - 1 : 0] acc_cnt_in[0 : 3],
input wire [KLS_W - 1 : 0] pri_pos_in,
input wire [KLS_W - 1 : 0] bwt_len_in,
input wire bwt_params_valid,
input wire [POS_W - 1 : 0] min_mlen_in,
input wire min_mlen_valid,
input wire [POS_W - 1 : 0] rs_min_mlen_in,
input wire [KLS_W - 1 : 0] rs_max_intv_in,
input wire rs_params_valid,
input wire [POS_W - 1 : 0] sf_mlen_in,
input wire [KLS_W - 1 : 0] sf_max_intv_in,
input wire sf_params_valid
);
localparam GD_READ_LEN = READ_LEN + 2;
Symbol gd_read[0 : GD_READ_LEN - 1];
logic [POS_W - 1 : 0] pos;
wire [POS_W - 1 : 0] nxt_pos;
logic bex_start, bi_dir;
wire bex_finish, bex_busy;
// logic [POS_W - 1 : 0] default_min_mlen;
// logic [POW_W - 1 : 0] bex_min_mlen_in;
// wire bex_min_mlen_valid;
logic [KLS_W - 1 : 0] min_intv;
logic min_intv_valid;
logic fil1_start, fil1_stop;
wire fil1_finish, fil1_busy;
wire fil2_start, fil2_stop, fil2_finish, fil2_busy;
assign fil2_start = fil1_start;
assign fil2_stop = fil1_finish;
wire asm_last;
wire ReseedMem fifo_tdata;
wire fifo_tvalid;
wire fifo_ready;
logic [1:0] wait_cnt;
localparam logic [3:0] S_Idle = 4'd0;
localparam logic [3:0] S_SmpFwdSeeding = 4'd1;
localparam logic [3:0] S_SFWaitFilter = 4'd2;
localparam logic [3:0] S_BiDirSeeding = 4'd3;
localparam logic [3:0] S_BDWaitFilter = 4'd4;
localparam logic [3:0] S_WaitRsFifo = 4'd5;
localparam logic [3:0] S_CheckRsFifo = 4'd6;
localparam logic [3:0] S_Reseeding = 4'd7;
localparam logic [3:0] S_RSWaitFilter = 4'd8;
logic [3:0] state, nxt_sts;
always_ff @(posedge clk) begin : proc_state
if(rst) begin
state <= S_Idle;
end
else begin
state <= nxt_sts;
end
end
always_comb begin : proc_nxt_sts
nxt_sts = state;
case(state)
S_Idle : begin
if(start) begin
nxt_sts = S_SmpFwdSeeding;
end
end // S_Idle :
S_SmpFwdSeeding : begin
if(bex_finish && nxt_pos >= GD_READ_LEN) begin
nxt_sts = S_SFWaitFilter;
end
end // S_SmpFwdSeeding :
S_SFWaitFilter : begin
if(fil2_finish) begin
nxt_sts = S_BiDirSeeding;
end
end
S_BiDirSeeding : begin
if(bex_finish && nxt_pos >= GD_READ_LEN) begin
nxt_sts = S_BDWaitFilter;
end
end // S_BiDirSeeding :
S_BDWaitFilter : begin
if(fil2_finish) begin
nxt_sts = S_WaitRsFifo;
end
end
S_WaitRsFifo : begin
if(wait_cnt == 2'd2) begin
nxt_sts = S_CheckRsFifo;
end
end
S_CheckRsFifo : begin
if(fifo_tvalid) begin
nxt_sts = S_Reseeding;
end
else begin
nxt_sts = S_RSWaitFilter;
end
end // S_CheckRsFifo :
S_Reseeding : begin
if(bex_finish) begin
nxt_sts = S_CheckRsFifo;
end
end // S_Reseeding :
S_RSWaitFilter: begin
if(asm_last) begin
nxt_sts = S_Idle;
end
end
endcase
end
always_ff @(posedge clk) begin : proc_wait_cnt
if(rst) begin
wait_cnt <= 1'b0;
end
else if (state == S_BDWaitFilter && fil2_finish) begin
wait_cnt <= 1'b0;
end
else if (state == S_WaitRsFifo) begin
wait_cnt <= wait_cnt + 1'b1;
end
end
always_ff @(posedge clk) begin : proc_gd_read
if(rst) begin
gd_read <= '{GD_READ_LEN{sym_N}};
end
else if(state == S_Idle /*&& start*/) begin
gd_read[0] <= sym_N;
gd_read[1 : READ_LEN] <= read;
gd_read[READ_LEN + 1] <= sym_N;
end
end
logic [RID_W - 1 : 0] id;
always_ff @(posedge clk) begin : proc_id
if(rst) begin
id <= 1'b0;
end
else if(state == S_Idle /*&& start*/) begin
id <= read_id;
end
end
always_ff @(posedge clk) begin : proc_pos
if(rst) begin
pos <= '0;
end
else if(state == S_Idle /*&& start*/) begin
pos <= 1'b1;
end
else if(state == S_SmpFwdSeeding && bex_finish /*&& nxt_pos < GD_READ_LEN*/) begin
pos <= nxt_pos; // nxt_pos?? or next multple of 20 pos??
end
else if(state == S_SFWaitFilter /*&& fil2_finish*/) begin
pos <= 1'b1;
end
else if(state == S_BiDirSeeding && bex_finish /*&& nxt_pos < GD_READ_LEN*/) begin
pos <= nxt_pos;
end
else if(state == S_CheckRsFifo) begin
// if(fifo_tvalid /*nxt_sts == S_Reseeding*/) begin
pos <= POS_W'(((POS_W+1)'(fifo_tdata.i) + fifo_tdata.j + 1'b1) >> 1);
// end
//// else if(nxt_sts == S_WaitFilter) begin
//// pos <= '0;
//// end
end
end
always_ff @(posedge clk) begin : proc_bi_dir
if(rst) begin
bi_dir <= 1'b0;
end
else if(state == S_Idle /*&& start*/) begin
bi_dir <= 1'b0;
end
else if(state == S_SFWaitFilter /*&& fil2_finish*/) begin
bi_dir <= 1'b1;
end
end
always_ff @(posedge clk) begin : proc_bex_start
if(rst) begin
bex_start <= 1'b0;
end
else if(state == S_Idle && start) begin
bex_start <= 1'b1;
end
else if(state == S_SmpFwdSeeding && bex_finish && nxt_pos < GD_READ_LEN) begin
bex_start <= 1'b1;
end
else if(state == S_SFWaitFilter && fil2_finish) begin
bex_start <= 1'b1;
end
else if(state == S_BiDirSeeding && bex_finish && nxt_pos < GD_READ_LEN) begin
bex_start <= 1'b1;
end
else if(state == S_CheckRsFifo && fifo_tvalid) begin
bex_start <= 1'b1;
end
else begin
bex_start <= 1'b0;
end
end
always_ff @(posedge clk) begin : proc_min_intv;
if(rst) begin
min_intv <= '0;
end
else if(state == S_Idle /*&& start*/) begin
min_intv <= '0;
end
else if(state == S_CheckRsFifo /*&& fifo_tvalid*/) begin
min_intv <= fifo_tdata.s;
end
end
always_ff @(posedge clk) begin : proc_min_intv_valid
if(rst) begin
min_intv_valid <= 1'b0;
end
else if(state == S_Idle && start) begin
min_intv_valid <= 1'b1;
end
else if(state == S_CheckRsFifo && fifo_tvalid) begin
min_intv_valid <= 1'b1;
end
else begin
min_intv_valid <= 1'b0;
end
end
always_ff @(posedge clk) begin : proc_fil1_start
if(rst) begin
fil1_start <= 1'b0;
end
else if(state == S_Idle && start) begin
fil1_start <= 1'b1;
end
else if(state == S_SFWaitFilter && fil2_finish) begin
fil1_start <= 1'b1;
end
else if(state == S_BDWaitFilter && fil2_finish) begin
fil1_start <= 1'b1;
end
else begin
fil1_start <= 1'b0;
end
end
always_ff @(posedge clk) begin : proc_fil1_stop
if(rst) begin
fil1_stop <= 0;
end
else if(state == S_SmpFwdSeeding && bex_finish && nxt_pos >= GD_READ_LEN) begin
fil1_stop <= 1'b1;
end
else if(state == S_BiDirSeeding && bex_finish && nxt_pos >= GD_READ_LEN) begin
fil1_stop <= 1'b1;
end
else if(state == S_CheckRsFifo && !fifo_tvalid) begin
fil1_stop <= 1'b1;
end
else begin
fil1_stop <= 1'b0;
end
end
logic gen_last;
always_ff @(posedge clk) begin : proc_gen_last
if(rst) begin
gen_last <= 1'b0;
end
else if(state == S_Idle /*&& start*/) begin
gen_last <= 1'b0;
end
//else if(state == S_SFWaitFilter /*&& fil2_finish*/) begin
// gen_last <= 1'b0;
//end
else if(state == S_BDWaitFilter && fil2_finish) begin
gen_last <= 1'b1;
end
end
always_ff @(posedge clk) begin : proc_finish
if(rst) begin
finish <= 1'b0;
end
else if(state == S_RSWaitFilter && asm_last) begin
finish <= 1'b1;
end
else begin
finish <= 1'b0;
end
end
assign busy = state != S_Idle;
Axi4StreamIf #(.DW_BYTES($bits(WorkingMem)/8)) axis_em_to_fil1 (.clk(clk), .reset_n(~rst));
Axi4StreamIf #(.DW_BYTES($bits(WorkingMem)/8)) axis_fil1_to_fil2(.clk(clk), .reset_n(~rst));
Axi4StreamIf #(.DW_BYTES($bits(WorkingMem)/8)) axis_fil2_to_rs (.clk(clk), .reset_n(~rst));
Axi4StreamIf #(.DW_BYTES($bits(WorkingMem)/8)) axis_rs_to_fifo (.clk(clk), .reset_n(~rst));
Axi4StreamIf #(.DW_BYTES($bits(WorkingMem)/8)) axis_rs_to_asm (.clk(clk), .reset_n(~rst));
BiDirEmSeek3 #(
.GD_READ_LEN(GD_READ_LEN),
.OCC_AW(OCC_AW),
.OCC_BASE(OCC_BASE),
.BEX_QU_AW(BIDIREX_QU_AW)
) the_bex (
.clk (clk),
.rst (rst),
.gd_read (gd_read),
.pos_in (pos),
.bi_dir_in (bi_dir),
.start (bex_start),
.pos_out (nxt_pos),
.finish (bex_finish),
.busy (bex_busy),
.m_axis_emout (axis_em_to_fil1.master),
.m_axi_occlu (m_axi_occlu),
.acc_cnt_in (acc_cnt_in),
.pri_pos_in (pri_pos_in),
.bwt_len_in (bwt_len_in),
.bwt_params_valid(bwt_params_valid),
.min_mlen_in (min_mlen_in),
.min_mlen_valid (min_mlen_valid),
.min_intv_in (min_intv),
.min_intv_valid (min_intv_valid),
.sf_mlen_in (sf_mlen_in),
.sf_max_intv_in (sf_max_intv_in),
.sf_params_valid (sf_params_valid)
);
MemFilter1 #(.GRP_SIZE(FILTER_GRP_SIZE)) the_fil1 (
.clk (clk),
.rst (rst),
.start (fil1_start),
.stop (fil1_stop),
.finish (fil1_finish),
.busy (fil1_busy),
.s_axis_emin (axis_em_to_fil1.slave),
.m_axis_emout(axis_fil1_to_fil2.master)
);
MemFilter2 #(.GRP_SIZE(FILTER_GRP_SIZE)) the_fil2 (
.clk (clk),
.rst (rst),
.gen_last (gen_last),
.start (fil2_start),
.stop (fil2_stop),
.finish (fil2_finish),
.busy (fil2_busy),
.s_axis_emin (axis_fil1_to_fil2.slave),
.m_axis_emout(axis_fil2_to_rs.master)
);
wire rs_bypass = !(state == S_BiDirSeeding || state == S_BDWaitFilter);
ReseedFilter the_rsfil (
.clk (clk),
.rst (rst),
.rs_min_len (rs_min_mlen_in),
.rs_max_intv (rs_max_intv_in),
.rs_params_valid(rs_params_valid),
.bypass (rs_bypass),
.s_axis_emin (axis_fil2_to_rs.slave),
.m_axis_rsout (axis_rs_to_fifo.master),
.m_axis_emout (axis_rs_to_asm.master)
);
assign fifo_ready = state == S_CheckRsFifo;
wire [RESEED_QU_AW : 0] fifo_data_cnt;
wire WorkingMem rsfil_out = axis_rs_to_fifo.tdata;
wire ReseedMem rsfifo_in;
assign rsfifo_in.j = rsfil_out.j;
assign rsfifo_in.i = rsfil_out.i;
assign rsfifo_in.s = rsfil_out.s;
StreamFifo #(.DW($bits(ReseedMem)), .AW(RESEED_QU_AW)) reseedFifo (
.clk (clk),
.rst (rst),
.in_data (rsfifo_in),
.in_valid (axis_rs_to_fifo.tvalid),
.in_ready (axis_rs_to_fifo.tready),
.out_data (fifo_tdata),
.out_valid(fifo_tvalid),
.out_ready(fifo_ready),
.data_cnt (fifo_data_cnt)
);
assign asm_last = axis_rs_to_asm.tlast & axis_rs_to_asm.tready & axis_rs_to_asm.tvalid;
MemAssem the_assem (
.clk (clk),
.rst (rst),
.read_id (id),
.s_axis_emin (axis_rs_to_asm.slave),
.m_axis_emout(m_axis_emout)
);
endmodule