OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [rtl/] [src_noc/] [traffic_gen_top.sv] - Blame information for rev 48

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
`timescale  1ns/1ps
2
 
3
module  traffic_gen_top
4
                import pronoc_pkg::*;
5
        #(
6
                parameter MAX_RATIO = 1000,
7
                parameter ENDP_ID   = 10
8
        )
9
        (
10
 
11
                //noc port
12
                chan_in,
13
                chan_out,
14
 
15
                //input
16
                ratio,// real injection ratio  = (MAX_RATIO/100)*ratio
17
                pck_size_in,
18
                current_e_addr,
19
                dest_e_addr,
20
                pck_class_in,
21
                start,
22
                stop,
23
                report,
24
                init_weight,
25
                start_delay,
26
 
27
                //output
28
                pck_number,
29
                sent_done, // tail flit has been sent
30
                hdr_flit_sent,
31
                update, // update the noc_analayzer
32
                src_e_addr,
33
                flit_out_class,
34
                flit_out_wr,
35
                flit_in_wr,
36
 
37
                distance,
38
                pck_class_out,
39
                time_stamp_h2h,
40
                time_stamp_h2t,
41
                pck_size_o,
42
 
43
                reset,
44
                clk
45
 
46
        );
47
 
48
        localparam
49
                RATIOw= $clog2(MAX_RATIO);
50
 
51
        //      Vw =    $clog2(V);
52
 
53
        input   smartflit_chanel_t      chan_in;
54
        output  smartflit_chanel_t      chan_out;
55
 
56
 
57
 
58
 
59
        localparam
60
                PCK_CNTw = log2(MAX_PCK_NUM+1),
61
                CLK_CNTw = log2(MAX_SIM_CLKs+1),
62
                PCK_SIZw = log2(MAX_PCK_SIZ+1),
63
                AVG_PCK_SIZw = log2(10*MAX_PCK_SIZ+1),
64
                /* verilator lint_off WIDTH */
65
                DISTw = (TOPOLOGY=="FATTREE" || TOPOLOGY=="TREE" ) ? log2(2*L+1): log2(NR+1),
66
                W=WEIGHTw,
67
                PORT_B = (TOPOLOGY!="FMESH")?  LB :
68
                (ENDP_ID < NE_MESH_TORI)? LB :B; // in FMESH, the buffer size of endpoints connected to edge routers non-local ports are B not LB
69
                /* verilator lint_on WIDTH */
70
        input reset, clk;
71
        input  [RATIOw-1                :0] ratio;
72
        input                               start,stop;
73
        output                              update;
74
        output [CLK_CNTw-1              :0] time_stamp_h2h,time_stamp_h2t;
75
        output [DISTw-1                 :0] distance;
76
        output [Cw-1                    :0] pck_class_out;
77
 
78
        // the current endpoint address
79
        input  [EAw-1                   :0] current_e_addr;
80
        // the destination endpoint address
81
        input  [EAw-1                   :0] dest_e_addr;
82
 
83
        output [PCK_CNTw-1              :0] pck_number;
84
        input  [PCK_SIZw-1              :0] pck_size_in;
85
 
86
        output reg sent_done;
87
        output reg hdr_flit_sent;
88
        input  [Cw-1                    :0] pck_class_in;
89
        input  [W-1                     :0] init_weight;
90
 
91
        input                               report;
92
        input  [DELAYw-1                        :0] start_delay;
93
        // the received packet source endpoint address
94
        output [EAw-1        :   0]    src_e_addr;
95
        output [PCK_SIZw-1   :   0]    pck_size_o;
96
 
97
 
98
        logic  [Fw-1                   :0] flit_out;
99
        output  logic                       flit_out_wr;
100
        output  [Cw-1 : 0] flit_out_class;
101
        logic   [V-1                    :0] credit_in;
102
 
103
        logic   [Fw-1                   :0] flit_in;
104
        output logic                              flit_in_wr;
105
        logic  [V-1                :0] credit_out;
106
 
107
        // the connected router address
108
        wire  [RAw-1                   :0] current_r_addr;
109
 
110
 
111
        assign  chan_out.flit_chanel.flit = flit_out;
112
        assign  chan_out.flit_chanel.flit_wr = flit_out_wr;
113
        assign  chan_out.flit_chanel.credit = credit_out;
114
 
115
 
116
        assign flit_in   =  chan_in.flit_chanel.flit;
117
        assign flit_in_wr=  chan_in.flit_chanel.flit_wr;
118
        assign credit_in =  chan_in.flit_chanel.credit;
119
        assign current_r_addr = chan_in.ctrl_chanel.neighbors_r_addr;
120
 
121
        genvar i;
122
        generate
123
        for (i=0; i
124
                assign chan_out.ctrl_chanel.credit_init_val[i]= PORT_B;
125
        end
126
        endgenerate
127
 
128
        //old traffic.v file
129
 
130
        reg [2:0]   ps,ns;
131
        localparam IDEAL =3'b001, SENT =3'b010, WAIT=3'b100;
132
 
133
        reg                                 inject_en,cand_wr_vc_en,pck_rd;
134
        reg    [PCK_SIZw-1              :0] pck_size, pck_size_next;
135
        reg    [EAw-1                    :0] dest_e_addr_reg;
136
 
137
        // synopsys  translate_off
138
        // synthesis translate_off
139
 
140
        `ifdef MONITORE_PATH
141
 
142
 
143
                reg tt;
144
                always @(posedge clk) begin
145
                        if(reset)begin
146
                                tt<=1'b0;
147
                        end else begin
148
                                if(flit_out_wr && tt==1'b0 )begin
149
                                        $display( "%t: Injector: current_r_addr=%x,current_e_addr=%x,dest_e_addr=%x\n",$time, current_r_addr, current_e_addr, dest_e_addr);
150
                                        tt<=1'b1;
151
                                end
152
                        end
153
                end
154
        `endif
155
 
156
        // synthesis translate_on
157
        // synopsys  translate_on
158
 
159
 
160
 
161
 
162
 
163
 
164
        localparam
165
                HDR_DATA_w =  (MIN_PCK_SIZE==1)? CLK_CNTw : 0,
166
                HDR_Dw =  (MIN_PCK_SIZE==1)? CLK_CNTw : 1;
167
 
168
        wire [HDR_Dw-1 : 0] hdr_data_in,rd_hdr_data_out;
169
 
170
 
171
        `ifdef SYNC_RESET_MODE
172
                always @ (posedge clk )begin
173
                `else
174
                        always @ (posedge clk or posedge reset)begin
175
                        `endif
176
                        if(reset) begin
177
                                dest_e_addr_reg<={EAw{1'b0}};
178
                        end else begin
179
                                dest_e_addr_reg<=dest_e_addr;
180
                        end
181
                end
182
 
183
                wire    [DSTPw-1                :   0] destport;
184
                wire    [V-1                    :   0] ovc_wr_in;
185
                wire    [V-1                    :   0] full_vc,empty_vc,nearly_full_vc;
186
                reg     [V-1                    :   0] wr_vc,wr_vc_next;
187
                wire    [V-1                    :   0] cand_vc;
188
 
189
 
190
                wire    [CLK_CNTw-1             :   0] wr_timestamp,pck_timestamp;
191
                wire                                   hdr_flit,tail_flit;
192
                reg     [PCK_SIZw-1             :   0] flit_counter;
193
                reg                                    flit_cnt_rst,flit_cnt_inc;
194
                wire                                   rd_hdr_flg,rd_tail_flg;
195
                wire    [Cw-1   :   0] rd_class_hdr;
196
                //  wire    [P_1-1      :   0] rd_destport_hdr;
197
                wire    [EAw-1      :   0] rd_des_e_addr, rd_src_e_addr;
198
                reg     [CLK_CNTw-1             :   0] rsv_counter;
199
                reg     [CLK_CNTw-1             :   0] clk_counter;
200
                wire    [Vw-1                   :   0] rd_vc_bin;//,wr_vc_bin;
201
                reg     [CLK_CNTw-1             :   0] rsv_time_stamp[V-1:0];
202
                reg     [PCK_SIZw-1             :   0] rsv_pck_size    [V-1:0];
203
                wire    [V-1                    :   0] rd_vc;
204
                wire                                   wr_vc_is_full,wr_vc_avb,wr_vc_is_empty;
205
                reg     [V-1                    :   0] credit_out_next;
206
                reg     [EAw-1     :   0] rsv_pck_src_e_addr        [V-1:0];
207
                reg     [Cw-1                   :   0] rsv_pck_class_in     [V-1:0];
208
 
209
                wire [CLK_CNTw-1             :   0] hdr_flit_timestamp;
210
                wire pck_wr,buffer_full,pck_ready,valid_dst;
211
                wire [CLK_CNTw-1 : 0] rd_timestamp;
212
 
213
 
214
 
215
                logic [DELAYw-1 : 0] start_delay_counter,start_delay_counter_next;
216
                logic  start_en_next , start_en;
217
 
218
                register #(.W(1)) streg1 (.reset(reset),.clk(clk), .in(start_en_next), .out(start_en)   );
219
                register #(.W(DELAYw)) streg2 (.reset(reset),.clk(clk), .in(start_delay_counter_next), .out(start_delay_counter)        );
220
 
221
 
222
 
223
                always @(*) begin
224
                        start_en_next =start_en;
225
                        start_delay_counter_next= start_delay_counter;
226
                        if(start)       begin
227
                                start_en_next=1'b1;
228
                                start_delay_counter_next={DELAYw{1'b0}};
229
                        end else if(start_en && ~inject_en) begin
230
                                start_delay_counter_next= start_delay_counter + 1'b1;
231
                        end
232
                        if(stop) begin
233
                                start_en_next=1'b0;
234
                        end
235
                end//always
236
 
237
                wire start_injection = (start_delay_counter == start_delay);
238
 
239
 
240
 
241
 
242
                check_destination_addr #(
243
                                .TOPOLOGY(TOPOLOGY),
244
                                .T1(T1),
245
                                .T2(T2),
246
                                .T3(T3),
247
                                .EAw(EAw),
248
                                .SELF_LOOP_EN(SELF_LOOP_EN)
249
                        )
250
                        check_destination_addr(
251
                                .dest_e_addr(dest_e_addr),
252
                                .current_e_addr(current_e_addr),
253
                                .dest_is_valid(valid_dst)
254
                        );
255
 
256
 
257
                //assign hdr_flit_sent=pck_rd;
258
 
259
 
260
                injection_ratio_ctrl #
261
                        (
262
                                .MAX_PCK_SIZ(MAX_PCK_SIZ),
263
                                .MAX_RATIO(MAX_RATIO)
264
                        )
265
                        pck_inject_ratio_ctrl
266
                        (
267
                                .en(inject_en),
268
                                .pck_size_in(pck_size_in),
269
                                .clk(clk),
270
                                .reset(reset),
271
                                .freez(buffer_full),
272
                                .inject(pck_wr),
273
                                .ratio(ratio)
274
                        );
275
 
276
 
277
 
278
                output_vc_status #(
279
                                .CRDTw(CRDTw),
280
                                .V  (V),
281
                                .B  (PORT_B)
282
                        )
283
                        nic_ovc_status
284
                        (
285
                                .credit_init_val_in         ( chan_in.ctrl_chanel.credit_init_val),
286
                                .wr_in                      (ovc_wr_in),
287
                                .credit_in                  (credit_in),
288
                                .nearly_full_vc             (nearly_full_vc),
289
                                .full_vc                    (full_vc),
290
                                .empty_vc                   (empty_vc),
291
                                .cand_vc                    (cand_vc),
292
                                .cand_wr_vc_en              (cand_wr_vc_en),
293
                                .clk                        (clk),
294
                                .reset                      (reset)
295
                        );
296
 
297
 
298
 
299
                packet_gen #(
300
                                .P(MAX_P),
301
                                .T1(T1),
302
                                .T2(T2),
303
                                .T3(T3),
304
                                .RAw(RAw),
305
                                .EAw(EAw),
306
                                .TOPOLOGY(TOPOLOGY),
307
                                .DSTPw(DSTPw),
308
                                .ROUTE_NAME(ROUTE_NAME),
309
                                .ROUTE_TYPE(ROUTE_TYPE),
310
                                .MAX_PCK_NUM(MAX_PCK_NUM),
311
                                .MAX_SIM_CLKs(MAX_SIM_CLKs),
312
                                .TIMSTMP_FIFO_NUM(TIMSTMP_FIFO_NUM),
313
                                .MIN_PCK_SIZE(MIN_PCK_SIZE),
314
                                .MAX_PCK_SIZ(MAX_PCK_SIZ)
315
                        )
316
                        packet_buffer
317
                        (
318
                                .reset(reset),
319
                                .clk(clk),
320
                                .pck_wr(pck_wr),
321
                                .pck_rd(pck_rd),
322
                                .current_r_addr(current_r_addr),
323
                                .current_e_addr(current_e_addr),
324
                                .clk_counter(clk_counter+1'b1),//in case of zero load latency, the flit will be injected in the next clock cycle
325
                                .pck_number(pck_number),
326
                                .dest_e_addr(dest_e_addr_reg),
327
                                .pck_timestamp(pck_timestamp),
328
                                .buffer_full(buffer_full),
329
                                .pck_ready(pck_ready),
330
                                .valid_dst(valid_dst),
331
                                .destport(destport),
332
                                .pck_size_in(pck_size_in),
333
                                .pck_size_o(pck_size)
334
                        );
335
 
336
 
337
                assign wr_timestamp    =pck_timestamp;
338
 
339
                assign  update      = flit_in_wr & flit_in[Fw-2];
340
                assign  hdr_flit    = (flit_counter == 0);
341
                assign  tail_flit   = (flit_counter ==  pck_size-1'b1);
342
 
343
 
344
 
345
                assign  time_stamp_h2h  = hdr_flit_timestamp - rd_timestamp;
346
                assign  time_stamp_h2t  = clk_counter - rd_timestamp;
347
 
348
                wire [FPAYw-1    :   0] flit_out_pyload;
349
                wire [1         :   0] flit_out_hdr;
350
 
351
 
352
                wire [FPAYw-1    :   0] flit_out_header_pyload;
353
                wire [Fw-1      :   0] hdr_flit_out;
354
 
355
 
356
 
357
 
358
 
359
                assign hdr_data_in = (MIN_PCK_SIZE==1)? wr_timestamp[HDR_Dw-1 : 0]  : {HDR_Dw{1'b0}};
360
 
361
                header_flit_generator #(
362
                                .DATA_w(HDR_DATA_w)
363
                        )
364
                        the_header_flit_generator
365
                        (
366
                                .flit_out(hdr_flit_out),
367
                                .vc_num_in(wr_vc),
368
                                .class_in(pck_class_in),
369
                                .dest_e_addr_in(dest_e_addr_reg),
370
                                .src_e_addr_in(current_e_addr),
371
                                .weight_in(init_weight),
372
                                .destport_in(destport),
373
                                .data_in(hdr_data_in),
374
                                .be_in({BEw{1'b1}} )// Be is not used in simulation as we dont sent real data
375
                        );
376
 
377
        assign flit_out_class = pck_class_in;
378
 
379
                assign flit_out_hdr = {hdr_flit,tail_flit};
380
 
381
                assign flit_out_header_pyload = hdr_flit_out[FPAYw-1 : 0];
382
 
383
 
384
                /* verilator lint_off WIDTH */
385
                assign flit_out_pyload = (hdr_flit)  ?    flit_out_header_pyload :
386
 
387
                        (tail_flit) ?     wr_timestamp:
388
                        {pck_number,flit_counter};
389
                /* verilator lint_on WIDTH */
390
 
391
 
392
 
393
                assign flit_out = {flit_out_hdr, wr_vc, flit_out_pyload };
394
 
395
 
396
                //extract header flit info
397
 
398
 
399
 
400
                extract_header_flit_info #(
401
                                .DATA_w(HDR_DATA_w)
402
                        )
403
                        header_extractor
404
                        (
405
                                .flit_in(flit_in),
406
                                .flit_in_wr(flit_in_wr),
407
                                .class_o(rd_class_hdr),
408
                                .destport_o(),
409
                                .dest_e_addr_o(rd_des_e_addr),
410
                                .src_e_addr_o(rd_src_e_addr),
411
                                .vc_num_o(rd_vc),
412
                                .hdr_flit_wr_o( ),
413
                                .hdr_flg_o(rd_hdr_flg),
414
                                .tail_flg_o(rd_tail_flg),
415
                                .weight_o( ),
416
                                .be_o( ),
417
                                .data_o(rd_hdr_data_out)
418
                        );
419
 
420
 
421
                distance_gen #(
422
                                .TOPOLOGY(TOPOLOGY),
423
                                .T1(T1),
424
                                .T2(T2),
425
                                .T3(T3),
426
                                .EAw(EAw),
427
                                .DISTw(DISTw)
428
                        )
429
                        the_distance_gen
430
                        (
431
                                .src_e_addr(src_e_addr),
432
                                .dest_e_addr(current_e_addr),
433
                                .distance(distance)
434
                        );
435
 
436
 
437
        generate
438
        if(MIN_PCK_SIZE == 1) begin : sf_pck
439
                assign src_e_addr         = (rd_hdr_flg & rd_tail_flg)? rd_src_e_addr : rsv_pck_src_e_addr[rd_vc_bin];
440
                assign pck_class_out      = (rd_hdr_flg & rd_tail_flg)? rd_class_hdr : rsv_pck_class_in[rd_vc_bin];
441
                assign hdr_flit_timestamp = (rd_hdr_flg & rd_tail_flg)?  clk_counter : rsv_time_stamp[rd_vc_bin];
442
                assign rd_timestamp       =     (rd_hdr_flg & rd_tail_flg)? rd_hdr_data_out : flit_in[CLK_CNTw-1             :   0];
443
                assign pck_size_o         = (rd_hdr_flg & rd_tail_flg)? 1 : rsv_pck_size[rd_vc_bin];
444
        end else begin : no_sf_pck
445
                assign pck_size_o = rsv_pck_size[rd_vc_bin];
446
                assign src_e_addr            = rsv_pck_src_e_addr[rd_vc_bin];
447
                assign pck_class_out    = rsv_pck_class_in[rd_vc_bin];
448
                assign hdr_flit_timestamp = rsv_time_stamp[rd_vc_bin];
449
                assign rd_timestamp=flit_in[CLK_CNTw-1 :   0];
450
        end
451
 
452
 
453
                if(V==1) begin : v1
454
                assign rd_vc_bin=1'b0;
455
        // assign wr_vc_bin=1'b0;
456
        end else begin :vother
457
 
458
                one_hot_to_bin #( .ONE_HOT_WIDTH (V)) conv1
459
                (
460
                        .one_hot_code   (rd_vc),
461
                        .bin_code       (rd_vc_bin)
462
                );
463
        /*
464
    one_hot_to_bin #( .ONE_HOT_WIDTH (V)) conv2
465
    (
466
        .one_hot_code   (wr_vc),
467
        .bin_code       (wr_vc_bin)
468
    );
469
         */
470
        end
471
        endgenerate
472
 
473
 
474
        assign  ovc_wr_in   = (flit_out_wr ) ?      wr_vc : {V{1'b0}};
475
 
476
        /* verilator lint_off WIDTH */
477
        assign  wr_vc_is_full           = (SSA_EN=="NO")?  | ( full_vc & wr_vc)  : | (nearly_full_vc & wr_vc);
478
    /* verilator lint_on WIDTH */
479
 
480
 
481
        generate
482
        /* verilator lint_off WIDTH */
483
                if(VC_REALLOCATION_TYPE ==  "NONATOMIC") begin : nanatom_b
484
                        /* verilator lint_on WIDTH */
485
                        assign wr_vc_avb    =  ~wr_vc_is_full;
486
                end else begin : atomic_b
487
                        assign wr_vc_is_empty   =  | ( empty_vc & wr_vc);
488
                        assign wr_vc_avb        =  wr_vc_is_empty;
489
                end
490
        endgenerate
491
 
492
        reg not_yet_sent_aflit_next,not_yet_sent_aflit;
493
 
494
        always @(*)begin
495
                wr_vc_next          = wr_vc;
496
                cand_wr_vc_en       = 1'b0;
497
                flit_out_wr         = 1'b0;
498
                flit_cnt_inc        = 1'b0;
499
                flit_cnt_rst        = 1'b0;
500
                credit_out_next     = {V{1'd0}};
501
                sent_done           = 1'b0;
502
                pck_rd              = 1'b0;
503
                hdr_flit_sent       =1'b0;
504
                ns                  = ps;
505
                pck_rd              =1'b0;
506
 
507
 
508
                not_yet_sent_aflit_next =not_yet_sent_aflit;
509
                case (ps)
510
                        IDEAL: begin
511
                                if(pck_ready ) begin
512
                                        if(wr_vc_avb && valid_dst)begin
513
 
514
                                                hdr_flit_sent=1'b1;
515
                                                flit_out_wr     = 1'b1;//sending header flit
516
                                                not_yet_sent_aflit_next = 1'b0;
517
                                                flit_cnt_inc = 1'b1;
518
                                                if (MIN_PCK_SIZE>1 || flit_out_hdr!=2'b11) begin
519
                                                        ns              = SENT;
520
                                                end else begin
521
                                                        pck_rd=1'b1;
522
                                                        flit_cnt_rst   = 1'b1;
523
                                                        sent_done       =1'b1;
524
                                                        cand_wr_vc_en   =1'b1;
525
                                                        if(cand_vc>0) begin
526
                                                                wr_vc_next  = cand_vc;
527
                                                        end  else ns = WAIT;
528
                                                end  //else
529
                                        end//wr_vc
530
                                end
531
 
532
                        end //IDEAL
533
                        SENT: begin
534
 
535
                                if(!wr_vc_is_full )begin
536
 
537
                                        flit_out_wr     = 1'b1;
538
                                        if(flit_counter  < pck_size-1) begin
539
                                                flit_cnt_inc = 1'b1;
540
                                        end else begin
541
                                                flit_cnt_rst   = 1'b1;
542
                                                sent_done       =1'b1;
543
                                                pck_rd=1'b1;
544
                                                cand_wr_vc_en   =1'b1;
545
                                                if(cand_vc>0) begin
546
                                                        wr_vc_next  = cand_vc;
547
                                                        ns          =IDEAL;
548
                                                end     else ns = WAIT;
549
                                        end//else
550
                                end // if wr_vc_is_full
551
                        end//SENT
552
                        WAIT:begin
553
 
554
                                cand_wr_vc_en   =1'b1;
555
                                if(cand_vc>0) begin
556
                                        wr_vc_next  = cand_vc;
557
                                        ns                  =IDEAL;
558
                                end
559
                        end
560
                        default: begin
561
                                ns                  =IDEAL;
562
                        end
563
                endcase
564
 
565
 
566
                // packet sink
567
                if(flit_in_wr) begin
568
                        credit_out_next = rd_vc;
569
                end else credit_out_next = {V{1'd0}};
570
        end
571
 
572
        always @ (*)begin
573
                pck_size_next    = pck_size;
574
                if((tail_flit & flit_out_wr ) || not_yet_sent_aflit) pck_size_next  = pck_size_in;
575
        end
576
 
577
        `ifdef SYNC_RESET_MODE
578
                always @ (posedge clk )begin
579
                `else
580
                        always @ (posedge clk or posedge reset)begin
581
                        `endif
582
                        if(reset) begin
583
                                inject_en       <= 1'b0;
584
                                ps              <= IDEAL;
585
                                wr_vc           <=1;
586
                                flit_counter    <= {PCK_SIZw{1'b0}};
587
                                credit_out      <= {V{1'd0}};
588
                                rsv_counter     <= 0;
589
                                clk_counter     <=  0;
590
                                //pck_size        <= 0;
591
                                not_yet_sent_aflit<=1'b1;
592
 
593
                        end else begin
594
                                //injection
595
                                not_yet_sent_aflit<=not_yet_sent_aflit_next;
596
                                inject_en <=  (start_injection |inject_en) & ~stop;
597
                                ps             <= ns;
598
                                clk_counter     <= clk_counter+1'b1;
599
                                wr_vc           <=wr_vc_next;
600
                                if (flit_cnt_rst)      flit_counter    <= {PCK_SIZw{1'b0}};
601
                                else if(flit_cnt_inc)   flit_counter    <= flit_counter + 1'b1;
602
                                credit_out      <= credit_out_next;
603
                                //pck_size  <= pck_size_next;
604
 
605
                                //sink
606
                                if(flit_in_wr) begin
607
                                        if (flit_in[Fw-1])begin //header flit
608
                                                rsv_pck_src_e_addr[rd_vc_bin]    <=  rd_src_e_addr;
609
                                                rsv_pck_class_in[rd_vc_bin]    <= rd_class_hdr;
610
                                                rsv_time_stamp[rd_vc_bin]   <= clk_counter;
611
                                                rsv_counter                 <= rsv_counter+1'b1;
612
                                                rsv_pck_size[rd_vc_bin] <=2;
613
                                                // distance        <= {{(32-8){1'b0}},flit_in[7:0]};
614
                                                `ifdef RSV_NOTIFICATION
615
                                                        // synopsys  translate_off
616
                                                        // synthesis translate_off
617
                                                        // last_pck_time<=$time;
618
                                                        $display ("total of %d pcks have been recived in core (%d)", rsv_counter,current_e_addr);
619
                                                        // synthesis translate_on
620
                                                        // synopsys  translate_on
621
                                                `endif
622
                                        end else begin
623
                                                 rsv_pck_size[rd_vc_bin] <=rsv_pck_size[rd_vc_bin]+1;
624
                                        end
625
                                end
626
                                // synopsys  translate_off
627
                                // synthesis translate_off
628
                                if(report) begin
629
                                        $display ("%t,\t total of %d pcks have been recived in core (%d)",$time ,rsv_counter,current_e_addr);
630
                                end
631
                                // synthesis translate_on
632
                                // synopsys  translate_on
633
 
634
 
635
 
636
 
637
 
638
                        end
639
                end//always
640
 
641
 
642
                // synopsys  translate_off
643
                // synthesis translate_off
644
 
645
                localparam NEw=log2(NE);
646
                wire [NEw-1: 0]  src_id,dst_id,current_id;
647
 
648
                endp_addr_decoder  #( .TOPOLOGY(TOPOLOGY), .T1(T1), .T2(T2), .T3(T3), .EAw(EAw),  .NE(NE)) decod1 ( .id(current_id), .code(current_e_addr));
649
                endp_addr_decoder  #( .TOPOLOGY(TOPOLOGY), .T1(T1), .T2(T2), .T3(T3), .EAw(EAw),  .NE(NE)) decod2 ( .id(dst_id), .code(rd_des_e_addr));
650
                endp_addr_decoder  #( .TOPOLOGY(TOPOLOGY), .T1(T1), .T2(T2), .T3(T3), .EAw(EAw),  .NE(NE)) decod3 ( .id(src_id), .code(rd_src_e_addr));
651
 
652
 
653
 
654
 
655
                always @(posedge clk) begin
656
                        if(flit_out_wr && hdr_flit && dest_e_addr_reg  == current_e_addr && SELF_LOOP_EN == "NO") begin
657
                                $display("%t: ERROR: The self-loop is not enabled in the router while a packet is injected to the NoC with identical source and destination address in endpoint (%h).: %m",$time, dest_e_addr );
658
                                $finish;
659
                        end
660
                        if(flit_in_wr && rd_hdr_flg && (rd_des_e_addr  != current_e_addr )) begin
661
                                $display("%t: ERROR: packet with destination %d (code %h) which is sent by source %d (code %h) has been recieved in wrong destination %d (code %h).  %m",$time,dst_id,rd_des_e_addr, src_id,rd_src_e_addr, current_id,current_e_addr);
662
                                $finish;
663
                        end
664
 
665
                        if(update) begin
666
                                if (hdr_flit_timestamp<= rd_timestamp) begin
667
                                        $display("%t: ERROR: In destination %d packt which is sent by source %d, the time when header flit is recived (%d) should be larger than the packet timestamp %d.  %m",$time, current_id ,src_e_addr, hdr_flit_timestamp, rd_timestamp);
668
                                        $finish;
669
                                end
670
                                if( clk_counter <= rd_timestamp) begin
671
                                        $display("%t: ERROR: ERROR: In destination %d packt which is sent by source %d,, the current time (%d) should be larger than the packet timestamp %d.  %m",$time, current_id ,src_e_addr, clk_counter, rd_timestamp);
672
                                        $finish;
673
                                end
674
                        end//update
675
                        if(tail_flit & flit_out_wr) begin
676
                                if(wr_timestamp > clk_counter) begin
677
                                        $display("%t: ERROR: In src %d, the current time (%d) should be larger than or equal to the packet timestamp %d.  %m",$time, current_id, clk_counter, wr_timestamp);
678
                                        $finish;
679
                                end
680
                        end
681
 
682
                end
683
                // synthesis translate_on
684
                // synopsys  translate_on
685
 
686
 
687
                `ifdef CHECK_PCKS_CONTENT
688
                        // synopsys  translate_off
689
                        // synthesis translate_off
690
 
691
                        wire     [PCK_SIZw-1             :   0] rsv_flit_counter;
692
                        reg      [PCK_SIZw-1             :   0] old_flit_counter    [V-1   :   0];
693
                        wire     [PCK_CNTw-1             :   0] rsv_pck_number;
694
                        reg      [PCK_CNTw-1             :   0] old_pck_number  [V-1   :   0];
695
 
696
                        wire [PCK_CNTw+PCK_SIZw-1 : 0] statistics;
697
                        generate
698
                                if(PCK_CNTw+PCK_SIZw > Fw) assign statistics = {{(PCK_CNTw+PCK_SIZw-Fw){1'b0}},flit_in};
699
                        else  assign statistics = flit_in[PCK_CNTw+PCK_SIZw-1   :   0];
700
                        assign {rsv_pck_number,rsv_flit_counter}=statistics;
701
 
702
                        endgenerate
703
 
704
 
705
 
706
                                integer ii;
707
                        `ifdef SYNC_RESET_MODE
708
                                always @ (posedge clk )begin
709
                                `else
710
                                        always @ (posedge clk or posedge reset)begin
711
                                        `endif
712
                                        if(reset) begin
713
                                                for(ii=0;ii
714
                                                        old_flit_counter[ii]<=0;
715
                                                end
716
                                        end else begin
717
                                                if(flit_in_wr)begin
718
                                                        if      ( flit_in[Fw-1:Fw-2]==2'b10)  begin
719
                                                                old_pck_number[rd_vc_bin]<=0;
720
                                                                old_flit_counter[rd_vc_bin]<=0;
721
                                                        end else if ( flit_in[Fw-1:Fw-2]==2'b00)begin
722
                                                                old_pck_number[rd_vc_bin]<=rsv_pck_number;
723
                                                                old_flit_counter[rd_vc_bin]<=rsv_flit_counter;
724
                                                        end
725
 
726
                                                end
727
 
728
                                        end
729
                                end
730
 
731
 
732
                                always @(posedge clk) begin
733
                                        if(flit_in_wr && (flit_in[Fw-1:Fw-2]==2'b00) && (~reset))begin
734
                                                if( old_flit_counter[rd_vc_bin]!=rsv_flit_counter-1) $display("%t: Error: missmatch flit counter in %m. Expected %d but recieved %d",$time,old_flit_counter[rd_vc_bin]+1,rsv_flit_counter);
735
                                                if( old_pck_number[rd_vc_bin]!=rsv_pck_number && old_pck_number[rd_vc_bin]!=0)   $display("%t: Error: missmatch pck number in %m. expected %d but recieved %d",$time,old_pck_number[rd_vc_bin],rsv_pck_number);
736
 
737
                                        end
738
 
739
                                end
740
                                // synthesis translate_on
741
                                // synopsys  translate_on
742
 
743
                        `endif
744
 
745
//                              `ifdef VERILATOR
746
//                                      logic  endp_is_active   /*verilator public_flat_rd*/ ;
747
//
748
//                                      always @ (*) begin
749
//                                              endp_is_active  = 1'b0;
750
//                                              if (chan_out.flit_chanel.flit_wr) endp_is_active=1'b1;
751
//                                              if (chan_out.flit_chanel.credit > {V{1'b0}} ) endp_is_active=1'b1;
752
//                                              if (chan_out.smart_chanel.requests > {SMART_NUM{1'b0}} ) endp_is_active=1'b1;
753
//                                      end
754
//                              `endif
755
 
756
 
757
endmodule
758
 
759
 
760
 
761
 
762
 
763
/*****************************
764
    injection_ratio_ctrl
765
 
766
*****************************/
767
module injection_ratio_ctrl #
768
        (
769
        parameter MAX_PCK_SIZ=10,
770
        parameter MAX_RATIO=100
771
)(
772
        en,
773
        pck_size_in, // average packet size in flit x10
774
        clk,
775
        reset,
776
        inject,// inject one packet
777
        freez,
778
        ratio // 0~100  flit injection ratio
779
);
780
 
781
 
782
        function integer log2;
783
        input integer number; begin
784
                log2=(number <=1) ? 1: 0;
785
                while(2**log2
786
                        log2=log2+1;
787
                end
788
        end
789
        endfunction // log2
790
 
791
 
792
        localparam PCK_SIZw= log2(MAX_PCK_SIZ);
793
 
794
 
795
        localparam CNTw    =   log2(MAX_RATIO);
796
        localparam STATE_INIT=   MAX_PCK_SIZ*MAX_RATIO;
797
        localparam STATEw    =   log2(MAX_PCK_SIZ*2*MAX_RATIO);
798
 
799
        input                       clk,reset,freez,en;
800
        output  reg                 inject;
801
        input   [CNTw-1     :   0]  ratio;
802
        input  [PCK_SIZw-1          :0] pck_size_in;
803
        reg    [PCK_SIZw-1          :0]pck_size;
804
 
805
        wire    [CNTw-1     :   0]  on_clks, off_clks;
806
        reg     [STATEw-1   :   0]  state,next_state;
807
        wire                        input_changed;
808
        reg     [CNTw-1     :   0]  ratio_old;
809
 
810
        always @(posedge clk ) ratio_old<=ratio;
811
 
812
        assign input_changed = (ratio_old!=ratio);
813
 
814
 
815
        assign on_clks = ratio;
816
        assign off_clks =MAX_RATIO-ratio;
817
 
818
        reg [PCK_SIZw-1 :0] flit_counter,next_flit_counter;
819
 
820
 
821
        reg sent,next_sent,next_inject;
822
 
823
 
824
 
825
        always @(*) begin
826
                next_state        =state;
827
                next_flit_counter =flit_counter;
828
                next_sent         =sent;
829
                if(en && ~freez ) begin
830
                        case(sent)
831
                                1'b1: begin
832
                                        /* verilator lint_off WIDTH */
833
                                        next_state          = state +  off_clks;
834
                                        /* verilator lint_on WIDTH */
835
                                        next_flit_counter = (flit_counter >= pck_size-1'b1) ? {PCK_SIZw{1'b0}} : flit_counter +1'b1;
836
                                        next_inject         = (flit_counter=={PCK_SIZw{1'b0}});
837
                                        if (next_flit_counter >= pck_size-1'b1) begin
838
                                                if( next_state  >= STATE_INIT ) next_sent =1'b0;
839
                                        end
840
                                end
841
                                1'b0:begin
842
                                        if( next_state  <  STATE_INIT ) next_sent  = 1'b1;
843
                                        next_inject= 1'b0;
844
                                        /* verilator lint_off WIDTH */
845
                                        next_state = state - on_clks;
846
                                        /* verilator lint_on WIDTH */
847
                                end
848
                        endcase
849
                end else begin
850
                        next_inject= 1'b0;
851
                end
852
        end
853
 
854
 
855
 
856
 
857
        `ifdef SYNC_RESET_MODE
858
                always @ (posedge clk )begin
859
                `else
860
                        always @ (posedge clk or posedge reset)begin
861
                        `endif
862
                        if( reset) begin
863
                                state       <=  STATE_INIT;
864
                                inject      <=  1'b0;
865
                                sent        <=  1'b1;
866
                                flit_counter<= 0;
867
                                pck_size<=2;
868
                        end else begin
869
                                if(input_changed)begin
870
                                        state       <=  STATE_INIT;
871
                                        inject      <=  1'b0;
872
                                        sent        <=  1'b1;
873
                                        flit_counter<= 0;
874
                                end
875
 
876
                                if(flit_counter=={PCK_SIZw{1'b0}}) pck_size<=pck_size_in;
877
                                state       <=  next_state;
878
                                if(ratio!={CNTw{1'b0}}) inject      <=  next_inject;
879
                                sent        <=  next_sent;
880
                                flit_counter<=  next_flit_counter;
881
 
882
                        end
883
                end
884
 
885
 
886
endmodule
887
 
888
 
889
 
890
 
891
/*************************************
892
       packet_buffer
893
**************************************/
894
 
895
 
896
module packet_gen #(
897
        parameter P = 5,
898
        parameter T1= 4,
899
        parameter T2= 4,
900
        parameter T3= 4,
901
        parameter RAw = 3,
902
        parameter EAw = 3,
903
        parameter TOPOLOGY  = "MESH",
904
        parameter DSTPw = 4,
905
        parameter ROUTE_NAME = "XY",
906
        parameter ROUTE_TYPE = "DETERMINISTIC",
907
        parameter MAX_PCK_NUM   = 10000,
908
        parameter MAX_SIM_CLKs  = 100000,
909
        parameter TIMSTMP_FIFO_NUM=16,
910
        parameter MIN_PCK_SIZE=2,
911
        parameter MAX_PCK_SIZ=100
912
 
913
)(
914
        clk_counter,
915
        pck_wr,
916
        pck_rd,
917
        current_r_addr,
918
        current_e_addr,
919
        pck_number,
920
        dest_e_addr,
921
        pck_timestamp,
922
        destport,
923
        buffer_full,
924
        pck_ready,
925
        valid_dst,
926
        pck_size_in,
927
        pck_size_o,
928
        clk,
929
        reset
930
);
931
 
932
 
933
        function integer log2;
934
        input integer number; begin
935
                log2=(number <=1) ? 1: 0;
936
                while(2**log2
937
                        log2=log2+1;
938
                end
939
        end
940
        endfunction // log2
941
 
942
        localparam
943
        PCK_CNTw    =   log2(MAX_PCK_NUM+1),
944
        CLK_CNTw    =   log2(MAX_SIM_CLKs+1),
945
        PCK_SIZw    =   log2(MAX_PCK_SIZ);
946
 
947
        input  reset,clk, pck_wr, pck_rd;
948
        input  [RAw-1  :0] current_r_addr;
949
        input  [EAw-1 : 0] current_e_addr;
950
        input  [CLK_CNTw-1 :0] clk_counter;
951
        input  [PCK_SIZw-1 :0] pck_size_in;
952
        input  [EAw-1  :0] dest_e_addr;
953
        input  valid_dst;
954
 
955
        output [PCK_CNTw-1 :0] pck_number;
956
        output [CLK_CNTw-1 :0] pck_timestamp;
957
        output [PCK_SIZw-1 :0] pck_size_o;
958
        output buffer_full,pck_ready;
959
 
960
        output [DSTPw-1    :0] destport;
961
        reg    [PCK_CNTw-1 :0] packet_counter;
962
        wire   buffer_empty;
963
 
964
        assign pck_ready = ~buffer_empty & valid_dst;
965
 
966
 
967
        conventional_routing #(
968
                .TOPOLOGY(TOPOLOGY),
969
                .ROUTE_NAME(ROUTE_NAME),
970
                .ROUTE_TYPE(ROUTE_TYPE),
971
                .T1(T1),
972
                .T2(T2),
973
                .T3(T3),
974
                .RAw(RAw),
975
                .EAw(EAw),
976
                .DSTPw(DSTPw),
977
                .LOCATED_IN_NI(1)
978
        )
979
        routing_module
980
        (
981
                .reset(reset),
982
                .clk(clk),
983
                .current_r_addr(current_r_addr),
984
                .dest_e_addr(dest_e_addr),
985
                .src_e_addr(current_e_addr),
986
                .destport(destport)
987
        );
988
 
989
        wire timestamp_fifo_nearly_full , timestamp_fifo_full;
990
        assign buffer_full = (MIN_PCK_SIZE==1) ? timestamp_fifo_nearly_full : timestamp_fifo_full;
991
 
992
 
993
        wire recieve_more_than_0;
994
        fwft_fifo_bram #(
995
                .DATA_WIDTH(CLK_CNTw+PCK_SIZw),
996
                .MAX_DEPTH(TIMSTMP_FIFO_NUM)
997
        )
998
        timestamp_fifo
999
        (
1000
                .din({pck_size_in,clk_counter}),
1001
                .wr_en(pck_wr),
1002
                .rd_en(pck_rd),
1003
                .dout({pck_size_o,pck_timestamp}),
1004
                .full(timestamp_fifo_full),
1005
                .nearly_full(timestamp_fifo_nearly_full),
1006
                .recieve_more_than_0(recieve_more_than_0),
1007
                .recieve_more_than_1(),
1008
                .reset(reset),
1009
                .clk(clk)
1010
        );
1011
 
1012
        assign buffer_empty = ~recieve_more_than_0;
1013
 
1014
                                /*
1015
 
1016
    bram_based_fifo #(
1017
        .Dw(CLK_CNTw),
1018
        .B(TIMSTMP_FIFO_NUM)
1019
    )
1020
    timestamp_fifo
1021
    (
1022
        .din(clk_counter),
1023
        .wr_en(pck_wr),
1024
        .rd_en(pck_rd),
1025
        .dout(pck_timestamp),
1026
        .full(timestamp_fifo_full),
1027
        .nearly_full(timestamp_fifo_nearly_full),
1028
        .empty(buffer_empty),
1029
        .reset(reset),
1030
        .clk(clk)
1031
    );
1032
                                 */
1033
 
1034
        `ifdef SYNC_RESET_MODE
1035
                always @ (posedge clk )begin
1036
                `else
1037
                        always @ (posedge clk or posedge reset)begin
1038
                        `endif
1039
                        if(reset) begin
1040
                                packet_counter <= {PCK_CNTw{1'b0}};
1041
 
1042
                        end else begin
1043
                                if(pck_rd) begin
1044
                                        packet_counter <= packet_counter+1'b1;
1045
 
1046
                                end
1047
                        end
1048
                end
1049
 
1050
                assign pck_number = packet_counter;
1051
 
1052
 
1053
endmodule
1054
 
1055
 
1056
 
1057
/********************
1058
 
1059
    distance_gen
1060
 
1061
********************/
1062
 
1063
module distance_gen #(
1064
        parameter TOPOLOGY  = "MESH",
1065
        parameter T1=4,
1066
        parameter T2=4,
1067
        parameter T3=4,
1068
        parameter EAw=2,
1069
        parameter DISTw=4
1070
 
1071
)(
1072
        src_e_addr,
1073
        dest_e_addr,
1074
        distance
1075
);
1076
 
1077
        input [EAw-1 : 0] src_e_addr;
1078
        input [EAw-1 : 0] dest_e_addr;
1079
        output [DISTw-1 : 0]   distance;
1080
 
1081
        generate
1082
        /* verilator lint_off WIDTH */
1083
        if (TOPOLOGY ==    "MESH" || TOPOLOGY ==  "TORUS" || TOPOLOGY == "RING" || TOPOLOGY == "LINE")begin : tori_noc
1084
        /* verilator lint_on WIDTH */
1085
 
1086
                mesh_torus_distance_gen #(
1087
                        .T1(T1),
1088
                        .T2(T2),
1089
                        .T3(T3),
1090
                        .TOPOLOGY(TOPOLOGY),
1091
                        .DISTw(DISTw),
1092
                        .EAw(EAw)
1093
                )
1094
                distance_gen
1095
                (
1096
                        .src_e_addr(src_e_addr),
1097
                        .dest_e_addr(dest_e_addr),
1098
                        .distance(distance)
1099
                );
1100
        /* verilator lint_off WIDTH */
1101
        end else if (TOPOLOGY ==    "FMESH") begin :fmesh
1102
        /* verilator lint_on WIDTH */
1103
                fmesh_distance_gen #(
1104
                        .T1(T1),
1105
                        .T2(T2),
1106
                        .T3(T3),
1107
                        .DISTw(DISTw),
1108
                        .EAw(EAw)
1109
                )
1110
                distance_gen
1111
                (
1112
                        .src_e_addr(src_e_addr),
1113
                        .dest_e_addr(dest_e_addr),
1114
                        .distance(distance)
1115
                );
1116
 
1117
        /* verilator lint_off WIDTH */
1118
        end else if (TOPOLOGY == "FATTREE" || TOPOLOGY == "TREE") begin : fat
1119
        /* verilator lint_on WIDTH */
1120
                fattree_distance_gen #(
1121
                        .K(T1),
1122
                        .L(T2)
1123
                )
1124
                distance_gen
1125
                (
1126
                        .src_addr_encoded(src_e_addr),
1127
                        .dest_addr_encoded(dest_e_addr),
1128
                        .distance(distance)
1129
                );
1130
        end else if (TOPOLOGY == "STAR") begin
1131
 
1132
                                assign distance =1 ;
1133
        end
1134
        endgenerate
1135
 
1136
endmodule
1137
 
1138
 
1139
 
1140
 
1141
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.