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_peripheral/] [ni/] [ni_master.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
//`define MONITOR_HDR_FLITS
2
//`define MONITOR_DAT_FLITS
3
 
4
/**********************************************************************
5
**      File:  ni.sv
6
**      Date:2017-06-04
7
**
8
**      Copyright (C) 2014-2017  Alireza Monemi
9
**
10
**      This file is part of ProNoC
11
**
12
**      ProNoC ( stands for Prototype Network-on-chip)  is free software:
13
**      you can redistribute it and/or modify it under the terms of the GNU
14
**      Lesser General Public License as published by the Free Software Foundation,
15
**      either version 2 of the License, or (at your option) any later version.
16
**
17
**      ProNoC is distributed in the hope that it will be useful, but WITHOUT
18
**      ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19
**      or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
20
**      Public License for more details.
21
**
22
**      You should have received a copy of the GNU Lesser General Public
23
**      License along with ProNoC. If not, see .
24
**
25
**
26
**      Description: multi-chanel DMA-based network interface for
27
**  handling packetizing/depacketizing data to/form NoC.
28
**  Can support CRC32
29
**
30
**
31
*******************************************************************/
32
 
33
 
34
// synthesis translate_off
35
`timescale 1ns / 1ps
36
// synthesis translate_on
37
 
38
module  ni_master
39
                import pronoc_pkg::*;
40
 
41
                #(
42
    parameter MAX_TRANSACTION_WIDTH=10, // Maximum transaction size will be 2 power of MAX_DMA_TRANSACTION_WIDTH words
43
    parameter MAX_BURST_SIZE =256, // in words
44
    parameter CRC_EN= "NO",// "YES","NO" if CRC is enable then the CRC32 of all packet data is calculated and sent via tail flit.
45
    parameter HDATA_PRECAPw=0,
46
    // The header Data pre capture width. It Will be enabled when it is larger than zero. The header data can optionally carry a short width Data. This data can be pre-captured (completely/partially)
47
    // by the NI before saving the packet in a memory buffer. This can give some hints to the software regarding the incoming
48
    // packet such as its type, or source port so the software can store the packet in its appropriate buffer.
49
 
50
    //wishbone port parameters
51
    parameter Dw            =   32,
52
    parameter S_Aw          =   7,
53
    parameter M_Aw          =   32,
54
    parameter TAGw          =   3,
55
    parameter SELw          =   4,
56
    parameter PCK_TYPE      =  "MULTI_FLIT"
57
)
58
(
59
    //general
60
    reset,
61
    clk,
62
 
63
    //noc interface
64
    current_r_addr,
65
    current_e_addr,
66
    chan_in,
67
    chan_out,
68
 
69
    //wishbone slave interface signals
70
    s_dat_i,
71
    s_sel_i,
72
    s_addr_i,
73
    s_cti_i,
74
    s_stb_i,
75
    s_cyc_i,
76
    s_we_i,
77
    s_dat_o,
78
    s_ack_o,
79
 
80
    //wishbone master rd interface signals
81
    m_send_sel_o,
82
    m_send_addr_o,
83
    m_send_cti_o,
84
    m_send_stb_o,
85
    m_send_cyc_o,
86
    m_send_we_o,
87
    m_send_dat_i,
88
    m_send_ack_i,
89
 
90
    //wishbone master wr interface signals
91
    m_receive_sel_o,
92
    m_receive_dat_o,
93
    m_receive_addr_o,
94
    m_receive_cti_o,
95
    m_receive_stb_o,
96
    m_receive_cyc_o,
97
    m_receive_we_o,
98
    m_receive_ack_i,
99
 
100
    //interrupt interface
101
    irq
102
 
103
);
104
 
105
 
106
 
107
 
108
 
109
    input reset,clk;
110
 
111
 
112
     // NOC interfaces
113
    input   [RAw-1   :   0]  current_r_addr;
114
    input   [EAw-1   :   0]  current_e_addr;
115
 
116
    input   smartflit_chanel_t  chan_in;
117
    output  smartflit_chanel_t  chan_out;
118
 
119
 
120
   //wishbone slave interface signals
121
    input   [Dw-1       :   0]      s_dat_i;
122
    input   [SELw-1     :   0]      s_sel_i;
123
    input   [S_Aw-1     :   0]      s_addr_i;
124
    input   [TAGw-1     :   0]      s_cti_i;
125
    input                           s_stb_i;
126
    input                           s_cyc_i;
127
    input                           s_we_i;
128
 
129
    output  reg    [Dw-1       :   0]  s_dat_o;
130
    output  reg                     s_ack_o;
131
 
132
    //wishbone read master interface signals
133
    output  [SELw-1          :   0] m_send_sel_o;
134
    output  [M_Aw-1          :   0] m_send_addr_o;
135
    output  [TAGw-1          :   0] m_send_cti_o;
136
    output                          m_send_stb_o;
137
    output                          m_send_cyc_o;
138
    output                          m_send_we_o;
139
    input   [Dw-1           :  0]   m_send_dat_i;
140
    input                           m_send_ack_i;
141
 
142
     //wishbone write master interface signals
143
    output  [SELw-1          :   0] m_receive_sel_o;
144
    output  [Dw-1            :   0] m_receive_dat_o;
145
    output  [M_Aw-1          :   0] m_receive_addr_o;
146
    output  [TAGw-1          :   0] m_receive_cti_o;
147
    output                          m_receive_stb_o;
148
    output                          m_receive_cyc_o;
149
    output                          m_receive_we_o;
150
    input                           m_receive_ack_i;
151
 
152
      //Interrupt  interface
153
    output                          irq;
154
 
155
    wire                            s_ack_o_next;
156
 
157
 
158
 
159
 
160
    logic  [Fw-1   :   0]  flit_out;
161
    logic                  flit_out_wr;
162
    logic   [V-1    :   0]  credit_in;
163
    logic   [Fw-1   :   0]  flit_in;
164
    logic                   flit_in_wr;
165
    logic  [V-1    :   0]  credit_out;
166
 
167
 
168
    assign      chan_out.flit_chanel.flit = flit_out;
169
    assign  chan_out.flit_chanel.flit_wr = flit_out_wr;
170
    assign  chan_out.flit_chanel.credit = credit_out;
171
 
172
 
173
    assign flit_in   =  chan_in.flit_chanel.flit;
174
    assign flit_in_wr=  chan_in.flit_chanel.flit_wr;
175
    assign credit_in =  chan_in.flit_chanel.credit;
176
 
177
    //old ni.v file
178
 
179
 
180
 
181
 
182
 
183
 
184
 
185
 
186
    localparam
187
        CTRL_FLGw=14,
188
        CHw=log2(V),
189
        BURST_SIZE_w= log2(MAX_BURST_SIZE+1),
190
        STATUS1w=  2 * CHw + 4;
191
 
192
/*   Wishbone bus slave address :
193
 
194
 VC specific registers
195
       address bits
196
 [4+Vw:4]      [3:0]
197
                1  :   CTRL_FLAGS    :  {invalid_send_req_err,burst_size_err_isr,send_data_size_err_isr,crc_miss_match_isr,rcive_buff_ovrflw_err_isr,got_packet_isr, packet_is_saved_isr, packet_is_sent_isr,got_any_errorint_en,got_packet_int_en, packet_is_saved_int_en, packet_is_sent_int_en,receive_is_busy, send_is_busy};
198
 
199
                2  :   SEND_DEST_WB_ADDR        // The destination router address
200
                3  :   SEND_POINTER_WB_ADDR,    // The address of data to be sent in byte
201
 Virtual        4  :   SEND_DATA_SIZE,          // The size of data to be sent in byte
202
 chanel        5  :   SEND_HDR_DATA            // The short width data that can be sent by header flit
203
 number
204
                8  :   RECEIVE_SRC_WB_ADDR       // The source router (the router which is sent this packet).
205
                9  :   RECEIVE_POINTER_WB_ADDR   // The address pointer of receiver memory in byte
206
                10 :   RECEIVE_DATA_SIZE_WB_ADDR // The size of received data in byte
207
                11 :   RECEIVE_MAX_BUFF_SIZ      // The receiver allocated buffer size in words. If the packet size is bigger than the buffer size the rest of it will be discarded
208
                12 :   RECEIVE_START_INDEX_WB_ADDR  // The received data is written on RECEIVE_POINTER_WB_ADDR + RECEIVE_START_INDEX_WB_ADDR. If the write address reach to the end of buffer pointer, it starts at the RECEIVE_POINTER_WB_ADDR.
209
                13 :   RECEIVE_CTRL_WB_ADDR      // The NI receiver control register
210
                14 :   RECEIVE_PRECAP_DATA_ADDR  // The port address to the header flit data which can be pre-captured before buffering the actual data.
211
 
212
 Shared registers for all VCs
213
    address bits
214
      [5:0]
215
       0:    STATUS_WB_ADDR     // status1:  {send_vc_enable_binary, receive_vc_enable_binary, any_err_isr_en,any_got_packet_isr_en,any_packet_is_saved_isr_en,any_packet_is_sent_isr_en}
216
       16:   BURST_SIZE_WB_ADDR  // The burst size in words
217
       32: reserved
218
 
219
*/
220
    localparam
221
        chanel_ADDRw= 4,
222
        chanel_REGw = 4,
223
        GENRL_ADRw=2;
224
 
225
    wire [CHw-1 :   0] vc_addr = s_addr_i [chanel_REGw+CHw-1    :       chanel_REGw];
226
    wire [GENRL_ADRw-1 :   0] genrl_reg_addr = s_addr_i [chanel_REGw+GENRL_ADRw-1  :   chanel_REGw];
227
    wire [chanel_ADDRw-1     :   0] vc_s_addr_i = s_addr_i [chanel_ADDRw-1: 0];
228
 
229
//general registers
230
    localparam [GENRL_ADRw-1  :   0]
231
        STATUS1_WB_ADDR  =   0,          // status1
232
      //  STATUS2_WB_ADDR  =   1,          // status2
233
     //   STATUS3_WB_ADDR  =   3,          // status3
234
        BURST_SIZE_WB_ADDR = 1;
235
 
236
 //Readonly registers per VC
237
    localparam [chanel_ADDRw-1  :   0]
238
        GENERAL_REGS_WB_ADDR=0,
239
        CTRL_FLAGS_WB_ADDR=1,
240
        RECEIVE_SRC_WB_ADDR =8,         // The source router (the router which is sent this packet).
241
        RECEIVE_DATA_SIZE_WB_ADDR = 10,  // The size of received data in byte
242
        RECEIVE_PRECAP_DATA_ADDR=14;
243
 
244
 
245
    localparam
246
        WORLD_SIZE = Dw/8,
247
        OFFSETw= log2(WORLD_SIZE),
248
        HDw = Fpay - (2*EAw) -  DSTPw - WEIGHTw,
249
        PRE_Dw = (HDATA_PRECAPw>0)? HDATA_PRECAPw : 1,
250
        MAX_PCK_SIZE_IN_BYTE = MAX_TRANSACTION_WIDTH + log2(Fpay/8),
251
        BEw = (BYTE_EN)? log2(Fpay/8) : 1;
252
 
253
 
254
 
255
    reg [BURST_SIZE_w-1  :   0] burst_size, burst_size_next,burst_counter,burst_counter_next;
256
    wire [V-1 :   0] receive_vc_is_busy, send_vc_is_busy;
257
    wire [V-1 :   0] receive_vc_enable,send_vc_enable,vc_state_reg_enable;
258
    wire [V-1 :   0] vc_burst_counter_ld, vc_burst_counter_dec;
259
    wire [V-1 :   0] vc_fifo_wr, vc_fifo_rd;
260
    wire [V-1 :   0] vc_fifo_full, vc_fifo_nearly_full, vc_fifo_empty;
261
    wire [V-1 :   0] send_vc_is_active,receive_vc_is_active;
262
    wire [CHw-1:  0] send_vc_enable_binary,receive_vc_enable_binary;
263
    wire  [SELw-1    :   0] vc_m_send_sel_o  [V-1 :   0];
264
    wire  [M_Aw-1    :   0] vc_m_send_addr_o [V-1 :   0];
265
    wire  [TAGw-1    :   0] vc_m_send_cti_o  [V-1 :   0];
266
    wire  [V-1 :   0] vc_m_send_stb_o;
267
    wire  [V-1 :   0] vc_m_send_cyc_o;
268
    wire  [V-1 :   0] vc_m_send_we_o;
269
    wire  [V-1 :   0] save_hdr_info;
270
    wire  [SELw-1    :   0] vc_m_receive_sel_o  [V-1 :   0];
271
    wire  [M_Aw-1    :   0] vc_m_receive_addr_o [V-1 :   0];
272
    wire  [TAGw-1    :   0] vc_m_receive_cti_o  [V-1 :   0];
273
    wire  [V-1 :   0] vc_m_receive_stb_o;
274
    wire  [V-1 :   0] vc_m_receive_cyc_o;
275
    wire  [V-1 :   0] vc_m_receive_we_o;
276
    wire  [MAX_PCK_SIZE_IN_BYTE-1    :   0] receive_dat_size_in_byte [V-1 :   0];
277
    wire  [V-1    :   0] send_vc_fsm_is_ideal,receive_vc_fsm_is_ideal;
278
    wire  [Dw-1   :   0] send_vc_pointer_addr [V-1   :  0];
279
    wire  [Dw-1   :   0] receive_vc_pointer_addr [V-1   :  0];
280
    wire  [V-1    :   0] receive_vc_got_packet,receive_vc_got_hdr_flit_at_head;
281
    wire [MAX_TRANSACTION_WIDTH-1    :   0] send_vc_data_size [V-1   :  0];
282
    wire [MAX_TRANSACTION_WIDTH-1    :   0] receive_vc_max_buff_siz [V-1   :  0];
283
    wire [MAX_TRANSACTION_WIDTH-1    :   0] receive_vc_start_index  [V-1   :  0];
284
    wire [OFFSETw-1 : 0] receive_vc_start_index_offset [V-1   :  0];
285
 
286
 
287
 
288
    wire [V-1   :  0]   send_vc_start, receive_vc_start;
289
    wire  received_flit_is_tail,received_flit_is_hdr;
290
    wire [EAw-1  :   0]  vc_dest_e_addr [V-1   :  0];
291
    wire [Cw-1   :   0]  vc_pck_class [V-1   :  0];
292
    wire [WEIGHTw-1 : 0] vc_weight [V-1:0];
293
    wire [BEw-1 : 0 ] vc_be_in  [V-1    :   0];
294
    wire [HDw-1 : 0] vc_hdr_data [V-1:0];
295
    wire [V-1    :   0]  send_vc_send_hdr,send_vc_send_tail;
296
    wire [V-1    :   0]  send_vc_done,receive_vc_done;
297
 
298
    wire [EAw-1   :   0]  dest_e_addr;
299
    wire [Cw-1   :   0]  pck_class;
300
    wire [BEw-1 : 0 ] be_in;
301
    wire send_hdr, send_tail;
302
    wire [Fw-1   :   0] hdr_flit_out;
303
    wire burst_counter_ld = | vc_burst_counter_ld;
304
    wire burst_counter_dec= | vc_burst_counter_dec;
305
    wire fifo_wr = | vc_fifo_wr;
306
    wire fifo_rd = | vc_fifo_rd;
307
 
308
 
309
 
310
 
311
 
312
    wire last_burst = (burst_counter == 1);
313
    wire burst_is_set =  (burst_size>0);
314
    wire [Cw-1   :   0] received_class_next;
315
    wire [EAw-1   :   0] received_src_e_addr_next;
316
    wire [BEw-1 : 0 ] received_be_next;
317
    wire [HDw-1 : 0 ] received_hdr_dat_next;
318
    wire [Fpay-1    :   0] tail_flit_out;
319
    reg [Cw-1  : 0] class_in [V-1    :   0];
320
    reg [EAw-1 : 0] src_e_addr [V-1    :   0];
321
    reg [HDw-1 : 0] rsv_hdr_dat [V-1 : 0];
322
    reg [BEw-1 : 0] receive_vc_be [V-1 : 0];
323
    wire [CTRL_FLGw-1 : 0] vc_ctrl_flags [V-1 : 0];
324
    reg [V-1    :   0] crc_miss_match;
325
 
326
    wire [V-1    :   0] burst_size_err,send_data_size_err,rcive_buff_ovrflw_err;
327
    wire [V-1    :   0] invalid_send_req_err;
328
 
329
    wire [V-1 : 0] vc_irq;
330
 
331
 
332
 
333
    wire  [STATUS1w-1  :0] status1;
334
   // wire  [STATUS2w-1  :0] status2;
335
  //  wire  [STATUS3w-1  :0] status3;
336
 
337
 
338
    wire [DSTPw-1 : 0] destport;
339
    wire [WEIGHTw-1 : 0] weight;
340
    wire [HDw-1 : 0 ] hdr_data;
341
 
342
    wire [V-1 :0] vc_any_err_isr        ;
343
    wire [V-1 :0] vc_got_packet_isr     ;
344
    wire [V-1 :0] vc_packet_is_saved_isr;
345
    wire [V-1 :0] vc_packet_is_sent_isr ;
346
    wire [PRE_Dw-1 : 0 ] recive_vc_precap_data [V-1 : 0];
347
    wire any_err_isr,any_got_packet_isr,any_packet_is_saved_isr,any_packet_is_sent_isr;
348
 
349
    assign any_err_isr = |  vc_any_err_isr         ;
350
    assign any_got_packet_isr = |  vc_got_packet_isr      ;
351
    assign any_packet_is_saved_isr = |  vc_packet_is_saved_isr;
352
    assign any_packet_is_sent_isr  = |  vc_packet_is_sent_isr;
353
  //  assign status1= {vc_got_error_isr, receive_vc_got_packet_isr, receive_vc_packet_is_saved_isr, send_vc_packet_is_sent_isr};
354
 //   assign status2= {vc_got_error_int_en, receive_vc_got_packet_int_en, receive_vc_packet_is_saved_int_en, send_vc_packet_is_sent_int_en};
355
    assign status1= {send_vc_enable_binary, receive_vc_enable_binary, any_err_isr,any_got_packet_isr,any_packet_is_saved_isr,any_packet_is_sent_isr};
356
 
357
 
358
    assign  irq =|vc_irq;
359
 
360
    wire [7: 0] temp;
361
    generate
362
    if (HDw >= 8) assign temp = rsv_hdr_dat [vc_addr][7:0];
363
    else assign temp = {{(8-HDw){1'b0}},rsv_hdr_dat [vc_addr]};
364
    endgenerate
365
 
366
 
367
    //read wb registers
368
    always @(*)begin
369
        s_dat_o ={Dw{1'b0}};
370
        case(vc_s_addr_i)
371
        GENERAL_REGS_WB_ADDR:begin // This is a general address. check the general address filed
372
            case(genrl_reg_addr)
373
            STATUS1_WB_ADDR: begin
374
                s_dat_o = {{(Dw-STATUS1w){1'b0}}, status1};
375
            end
376
            BURST_SIZE_WB_ADDR:begin
377
                s_dat_o = {{(Dw-BURST_SIZE_w){1'b0}}, burst_size};
378
            end
379
            default: begin
380
                s_dat_o ={Dw{1'b0}};
381
            end
382
            endcase
383
        end//0
384
 
385
        CTRL_FLAGS_WB_ADDR: begin
386
             s_dat_o[CTRL_FLGw-1     : 0] = vc_ctrl_flags[vc_addr];
387
        end
388
 
389
        RECEIVE_SRC_WB_ADDR: begin
390
 
391
            s_dat_o[EAw-1: 0]   =   src_e_addr[vc_addr];   // first&second bytes
392
            s_dat_o[Cw+15: 16]  =   class_in[vc_addr];  //third byte
393
            s_dat_o[31: 24] =       temp;   // 4th byte
394
        end
395
 
396
        RECEIVE_DATA_SIZE_WB_ADDR: begin
397
            s_dat_o   [MAX_PCK_SIZE_IN_BYTE-1    :   0] = receive_dat_size_in_byte[vc_addr];
398
        end
399
 
400
        RECEIVE_PRECAP_DATA_ADDR: begin
401
                s_dat_o[PRE_Dw-1 : 0 ] =  (HDATA_PRECAPw>0)? recive_vc_precap_data[vc_addr][PRE_Dw-1 : 0 ]: {{PRE_Dw{1'b0}}};
402
        end
403
        default: begin
404
             s_dat_o ={Dw{1'b0}};
405
        end
406
        endcase
407
    end
408
 
409
 
410
 
411
 
412
    //write wb registers
413
    always @ (*)begin
414
        burst_counter_next=burst_counter;
415
        burst_size_next= burst_size;
416
        if(burst_counter_ld)    burst_counter_next = burst_size;
417
        if(burst_counter_dec)   burst_counter_next= burst_counter- 1'b1;
418
 
419
        if((s_stb_i  &    s_we_i) && (vc_s_addr_i == GENERAL_REGS_WB_ADDR)) begin // This is a general address. check the general address filed
420
            case(genrl_reg_addr)
421
            BURST_SIZE_WB_ADDR: begin
422
                if (send_vc_is_busy == {V{1'b0}}) burst_size_next=s_dat_i [BURST_SIZE_w-1 : 0];
423
            end //BURST_SIZE_WB_ADDR
424
 
425
                    default begin
426
 
427
                    end
428
            endcase
429
        end//  if(s_stb_i  &    s_we_i)
430
 
431
    end
432
 
433
 
434
 
435
 
436
`ifdef SYNC_RESET_MODE
437
    always @ (posedge clk )begin
438
`else
439
    always @ (posedge clk or posedge reset)begin
440
`endif
441
 
442
 
443
 
444
        if(reset) begin
445
            burst_counter <= {BURST_SIZE_w{1'b0}};
446
            burst_size <= {BURST_SIZE_w{1'b1}};
447
            s_ack_o <= 1'b0;
448
 
449
 
450
        end else begin
451
            burst_counter<= burst_counter_next;
452
            burst_size <= burst_size_next;
453
            s_ack_o <= s_ack_o_next;
454
 
455
 
456
        end
457
    end
458
 
459
 
460
    bin_to_one_hot #(
461
        .BIN_WIDTH(CHw),
462
        .ONE_HOT_WIDTH(V)
463
   )
464
   convert
465
   (
466
        .bin_code(vc_addr),
467
        .one_hot_code(vc_state_reg_enable)
468
   );
469
 
470
    assign s_ack_o_next    =   s_stb_i & (~s_ack_o);
471
 
472
 
473
    genvar i;
474
    generate
475
 
476
     wire [V-1 : 0 ] precap_hdr_flit_wr;
477
     wire [HDATA_PRECAPw-1 : 0 ] precap_din;
478
     wire [V-1 : 0] precap_hdr_flit_rd = (fifo_rd & received_flit_is_hdr) ?  receive_vc_enable : {V{1'b0}};
479
     wire [HDATA_PRECAPw-1 : 0 ] precap_dout  [V-1 : 0] ;
480
     wire [V-1 : 0 ] precap_valid;
481
 
482
 
483
    //capture data before saving the actual flit in memory
484
    if(HDATA_PRECAPw > 0 ) begin : precap
485
 
486
 
487
       wire [EAw-1 : 0] src_endp_addr;
488
 
489
        extract_header_flit_info #(
490
            .DATA_w(HDATA_PRECAPw)
491
        )
492
        data_extractor
493
        (
494
            .flit_in(flit_in),
495
            .flit_in_wr(flit_in_wr),
496
            .src_e_addr_o(src_endp_addr ),
497
            .dest_e_addr_o( ),
498
            .destport_o( ),
499
            .class_o( ),
500
            .weight_o( ),
501
            .tail_flg_o( ),
502
            .hdr_flg_o( ),
503
            .vc_num_o( ),
504
            .be_o( ),
505
            .hdr_flit_wr_o(precap_hdr_flit_wr),
506
            .data_o(precap_din)
507
        );
508
 
509
 
510
//synthesis translate_off
511
//synopsys  translate_off
512
`ifdef MONITOR_HDR_FLITS
513
always @(posedge clk) begin
514
 
515
    if(precap_hdr_flit_wr)begin
516
        $display("%t: endp %d got a packet with port address %d from endp %d",$time,current_e_addr,precap_din,src_endp_addr);
517
    end
518
 
519
    if(send_hdr & flit_out_wr)begin
520
        $display("%t: endp %d sends a packet with port address %d to endp %d",$time,current_e_addr,hdr_data,dest_e_addr);
521
    end
522
 
523
 
524
end
525
`endif
526
 
527
`ifdef MONITOR_DAT_FLITS
528
    always @(posedge clk) begin
529
        if(flit_out_wr & ~send_hdr) begin
530
            $display("%t: endp %u V %u sends %h",$time,current_e_addr,  flit_out [Fpay+V-1 : Fpay],  flit_out [Fpay-1 : 0 ]);
531
        end
532
    end
533
`endif
534
 
535
//synopsys  translate_on
536
//synthesis translate_on
537
 
538
 
539
 
540
       for (i=0;i
541
 
542
          fwft_fifo #(
543
            .DATA_WIDTH(HDATA_PRECAPw),
544
            .MAX_DEPTH(LB/MIN_PCK_SIZE),//maximum packet number which can be stored in buffer
545
            .IGNORE_SAME_LOC_RD_WR_WARNING("YES")
546
          )
547
          precap_data_fifo
548
          (
549
            .din(precap_din),
550
            .wr_en(precap_hdr_flit_wr[i]),
551
            .rd_en(precap_hdr_flit_rd[i]),
552
            .dout(precap_dout[i]),
553
            .full( ),
554
            .nearly_full( ),
555
            .recieve_more_than_0(precap_valid[i] ),
556
            .recieve_more_than_1( ),
557
            .reset(reset),
558
            .clk(clk)
559
          );
560
 
561
          assign recive_vc_precap_data[i] = precap_dout[i];
562
 
563
        //synthesis translate_off
564
        //synopsys  translate_off
565
        always @(posedge clk)begin
566
             if(s_stb_i  &  ~s_we_i &  (vc_addr==i) & (vc_s_addr_i == RECEIVE_PRECAP_DATA_ADDR) )begin
567
                    if( precap_valid[i] == 1'b0) $display( "Warning: Reading invalid precap-data %m");
568
             end
569
        end
570
        //synopsys  translate_on
571
        //synthesis translate_on
572
 
573
 
574
        end
575
 
576
    end
577
 
578
 
579
 
580
 
581
 
582
 
583
 
584
    for (i=0;i
585
 
586
 
587
                assign chan_out.ctrl_chanel.credit_init_val[i]= LB;
588
 
589
 
590
 
591
 
592
        ni_vc_wb_slave_regs #(
593
            .MAX_TRANSACTION_WIDTH(MAX_TRANSACTION_WIDTH),
594
            .DEBUG_EN(DEBUG_EN),
595
            .EAw(EAw),
596
            .Fpay(Fpay),
597
            .DSTPw(DSTPw),
598
            .HDw(HDw),
599
            .CTRL_FLGw(CTRL_FLGw),
600
            .C(C),
601
            .Dw(Dw),
602
            .S_Aw(chanel_REGw),
603
            .WEIGHTw(WEIGHTw),
604
            .BYTE_EN(BYTE_EN)
605
 
606
        )
607
        wb_slave_registers
608
        (
609
//synthesis translate_off
610
//synopsys  translate_off
611
            .current_e_addr(current_e_addr),
612
//synopsys  translate_on
613
//synthesis translate_on
614
            .clk(clk),
615
            .reset(reset),
616
            .state_reg_enable(vc_state_reg_enable[i]),
617
            .send_fsm_is_ideal(send_vc_fsm_is_ideal[i]),
618
            .receive_fsm_is_ideal(receive_vc_fsm_is_ideal[i]),
619
            .send_pointer_addr(send_vc_pointer_addr[i]),
620
            .be_in(vc_be_in[i]),
621
            .receive_pointer_addr(receive_vc_pointer_addr[i]),
622
            .receive_start_index(receive_vc_start_index[i]),
623
            .receive_start_index_offset(receive_vc_start_index_offset[i]),
624
            .receive_done(receive_vc_done[i]),
625
            .send_done(send_vc_done[i]),
626
 
627
            .send_data_size(send_vc_data_size[i]),
628
            .receive_max_buff_siz(receive_vc_max_buff_siz[i]),
629
            .dest_e_addr(vc_dest_e_addr[i]),
630
            .pck_class(vc_pck_class[i]),
631
            .weight(vc_weight[i]),
632
            .hdr_data(vc_hdr_data[i]),
633
            .send_start(send_vc_start[i]),
634
            .receive_start(receive_vc_start[i]),
635
            .receive_vc_got_packet(receive_vc_got_packet[i]),
636
 
637
                .burst_size_err(burst_size_err[i]),
638
            .send_data_size_err(send_data_size_err[i]),
639
            .rcive_buff_ovrflw_err(rcive_buff_ovrflw_err[i]),
640
                .crc_miss_match_err( crc_miss_match[i]),
641
                .invalid_send_req_err(invalid_send_req_err[i]),
642
 
643
                .receive_vc_got_hdr_flit_at_head(receive_vc_got_hdr_flit_at_head[i]),
644
                .receive_is_busy(receive_vc_is_busy[i]),
645
                .send_is_busy(send_vc_is_busy[i]),
646
                .ctrl_flags(vc_ctrl_flags[i]),
647
 
648
                .any_err_isr          (vc_any_err_isr        [i]),
649
                .got_packet_isr       (vc_got_packet_isr     [i]),
650
                .packet_is_saved_isr  (vc_packet_is_saved_isr[i]),
651
                .packet_is_sent_isr   (vc_packet_is_sent_isr [i]),
652
 
653
 
654
                .irq(vc_irq[i]),
655
 
656
                .s_dat_i(s_dat_i),
657
            .s_addr_i(s_addr_i[chanel_REGw-1:0]),
658
            .s_stb_i(s_stb_i),
659
            .s_cyc_i(s_cyc_i),
660
            .s_we_i(s_we_i)
661
        );
662
 
663
 
664
        ni_vc_dma #(
665
            .CRC_EN(CRC_EN),
666
            .MAX_TRANSACTION_WIDTH(MAX_TRANSACTION_WIDTH),
667
            .Dw(Dw),
668
            .M_Aw(M_Aw),
669
            .TAGw(TAGw),
670
            .SELw(SELw),
671
            .Fpay(Fpay),
672
            .BYTE_EN(BYTE_EN)
673
        )
674
        vc_dma
675
        (
676
            .reset(reset),
677
            .clk(clk),
678
            .status(),
679
            //active-enable signals
680
            .send_enable(send_vc_enable[i]),
681
            .receive_enable(receive_vc_enable[i]),
682
            .send_is_busy(send_vc_is_busy[i]),
683
            .receive_is_busy(receive_vc_is_busy[i]),
684
            .send_is_active(send_vc_is_active[i]),
685
            .receive_is_active(receive_vc_is_active[i]),
686
            .burst_counter_ld(vc_burst_counter_ld[i]),
687
            .burst_counter_dec(vc_burst_counter_dec[i]),
688
            .burst_size_is_set(burst_is_set),
689
            .last_burst(last_burst),
690
            .send_hdr(send_vc_send_hdr[i]),
691
            .send_tail(send_vc_send_tail[i]),
692
            .receive_dat_size_in_byte(receive_dat_size_in_byte[i]),
693
            .receive_be(receive_vc_be[i]),
694
            .save_hdr_info(save_hdr_info[i]),
695
            .send_done(send_vc_done[i]),
696
            .receive_done(receive_vc_done[i]),
697
            .send_fsm_is_ideal(send_vc_fsm_is_ideal[i]),
698
            .receive_fsm_is_ideal(receive_vc_fsm_is_ideal[i]),
699
            .send_pointer_addr(send_vc_pointer_addr[i]),
700
            .receive_pointer_addr(receive_vc_pointer_addr[i]),
701
            .receive_start_index(receive_vc_start_index[i]),
702
            .receive_start_index_offset(receive_vc_start_index_offset[i]),
703
            .send_data_size(send_vc_data_size[i]),
704
            .receive_max_buff_siz(receive_vc_max_buff_siz[i]),
705
            .send_start(send_vc_start[i]),
706
            .receive_start(receive_vc_start[i]),
707
            .received_flit_is_tail(received_flit_is_tail),
708
            //fifo
709
            .send_fifo_wr(vc_fifo_wr[i]),
710
            .send_fifo_full(vc_fifo_full[i]),
711
            .send_fifo_nearly_full(vc_fifo_nearly_full[i]),
712
            .send_fifo_rd(credit_in[i]),
713
            .receive_fifo_empty(vc_fifo_empty[i]),
714
            .receive_fifo_rd(vc_fifo_rd[i]),
715
 
716
            //errors
717
            .burst_size_err(burst_size_err[i]),
718
            .send_data_size_err(send_data_size_err[i]),
719
            .rcive_buff_ovrflw_err(rcive_buff_ovrflw_err[i]),
720
            .invalid_send_req_err(invalid_send_req_err[i]),
721
            //
722
            .m_send_sel_o(vc_m_send_sel_o[i]),
723
            .m_send_addr_o(vc_m_send_addr_o[i]),
724
            .m_send_cti_o(vc_m_send_cti_o[i]),
725
            .m_send_stb_o(vc_m_send_stb_o[i]),
726
            .m_send_cyc_o(vc_m_send_cyc_o[i]),
727
            .m_send_we_o(vc_m_send_we_o[i]),
728
        //  .m_send_dat_i(m_send_dat_i),
729
            .m_send_ack_i(m_send_ack_i),
730
 
731
            .m_receive_sel_o(vc_m_receive_sel_o[i]),
732
        //  .m_receive_dat_o(vc_m_receive_dat_o[i]),
733
            .m_receive_addr_o(vc_m_receive_addr_o[i]),
734
            .m_receive_cti_o(vc_m_receive_cti_o[i]),
735
            .m_receive_stb_o(vc_m_receive_stb_o[i]),
736
            .m_receive_cyc_o(vc_m_receive_cyc_o[i]),
737
            .m_receive_we_o(vc_m_receive_we_o[i]),
738
            .m_receive_ack_i(m_receive_ack_i)
739
        );
740
 
741
`ifdef SYNC_RESET_MODE
742
    always @ (posedge clk )begin
743
`else
744
    always @ (posedge clk or posedge reset)begin
745
`endif
746
 
747
            if(reset) begin
748
                class_in[i]<= {Cw{1'b0}};
749
                src_e_addr[i]<= {EAw{1'b0}};
750
                rsv_hdr_dat[i]<={HDw{1'b0}};
751
                receive_vc_be[i] <= {BEw{1'b0}};
752
            end else if(save_hdr_info[i])begin
753
                class_in[i]<= received_class_next;
754
                src_e_addr[i]<= received_src_e_addr_next;
755
                rsv_hdr_dat[i]<=received_hdr_dat_next;
756
                receive_vc_be[i]<= received_be_next;
757
            end
758
        end//always
759
 
760
    end  // for loop vc_
761
 
762
/* verilator lint_off WIDTH */
763
    if(  CRC_EN == "YES") begin :crc_blk
764
/* verilator lint_on WIDTH */
765
 
766
      reg fifo_rd_delayed;
767
`ifdef SYNC_RESET_MODE
768
    always @ (posedge clk )begin
769
`else
770
    always @ (posedge clk or posedge reset)begin
771
`endif
772
        if(reset) fifo_rd_delayed <=1'b0;
773
        else fifo_rd_delayed <= fifo_rd;
774
      end
775
 
776
      wire send_crc_enable =  flit_out_wr & ~send_hdr &   ~send_tail;
777
      wire receive_crc_enable =  fifo_rd_delayed & ~ received_flit_is_tail & ~received_flit_is_hdr;
778
      wire [31:0]  send_crc_out,receive_crc_out;
779
 
780
        crc_32_multi_chanel #(
781
            .chanel(V)
782
        )
783
        send_crc
784
        (
785
            .reset(reset),
786
            .clk(clk),
787
            .crc_reset(send_hdr),
788
            .crc_enable(send_crc_enable),
789
            .chanel_in(send_vc_enable_binary),
790
            .data_in(m_send_dat_i [Fpay-1 : 0]),
791
            .crc_out(send_crc_out)
792
        );
793
 
794
        crc_32_multi_chanel #(
795
                .chanel(V)
796
        )
797
         receive_crc
798
         (
799
                .reset(reset),
800
                .clk(clk),
801
                .crc_reset(received_flit_is_hdr),
802
                .crc_enable(receive_crc_enable),
803
                .chanel_in(receive_vc_enable_binary),
804
                .data_in(m_receive_dat_o[Fpay-1 : 0]),
805
                .crc_out(receive_crc_out)
806
        );
807
 
808
        for (i=0;i
809
 
810
`ifdef SYNC_RESET_MODE
811
            always @ (posedge clk )begin
812
`else
813
            always @ (posedge clk or posedge reset)begin
814
`endif
815
 
816
                if(reset) begin
817
                    crc_miss_match[i] <= 1'b0;
818
                end else begin
819
                    if(receive_vc_enable_binary==i && received_flit_is_tail && m_receive_stb_o ) begin
820
                        crc_miss_match[i] <= receive_crc_out[31:0] != m_receive_dat_o[31 : 0];
821
                    end
822
                end
823
 
824
            end
825
        end//for
826
 
827
        assign tail_flit_out[31 : 0]  =  send_crc_out;
828
    end   else begin : no_crc
829
        assign tail_flit_out   =  m_send_dat_i [Fpay-1 : 0];
830
        //always @(*) crc_miss_match = {V{1'b0}};
831
        always @(posedge clk) crc_miss_match <= {V{1'b0}};
832
    end
833
 
834
 
835
    if(V> 1) begin : multi_chanel
836
 
837
        // round roubin arbiter
838
        bus_arbiter # (
839
            .M (V)
840
        )
841
        receive_arbiter
842
        (
843
            .request (receive_vc_is_active),
844
            .grant  (receive_vc_enable),
845
            .clk (clk),
846
            .reset (reset)
847
        );
848
 
849
        bus_arbiter # (
850
            .M (V)
851
        )
852
        send_arbiter
853
        (
854
            .request (send_vc_is_active),
855
            .grant  (send_vc_enable),
856
            .clk (clk),
857
            .reset (reset)
858
        );
859
 
860
 
861
        one_hot_to_bin #(
862
            .ONE_HOT_WIDTH(V),
863
            .BIN_WIDTH(CHw)
864
        )
865
        send_en_conv
866
        (
867
            .one_hot_code(send_vc_enable),
868
            .bin_code(send_vc_enable_binary)
869
        );
870
 
871
 
872
         one_hot_to_bin #(
873
            .ONE_HOT_WIDTH(V),
874
            .BIN_WIDTH(CHw)
875
        )
876
        receive_en_conv
877
        (
878
            .one_hot_code(receive_vc_enable),
879
            .bin_code(receive_vc_enable_binary)
880
        );
881
 
882
 
883
    end else begin : single_chanel // if we have just one chanel there is no need for arbitration
884
        assign receive_vc_enable =  receive_vc_is_active;
885
        assign send_vc_enable =  send_vc_is_active;
886
        assign send_vc_enable_binary = 1'b0;
887
        assign receive_vc_enable_binary = 1'b0;
888
    end
889
    endgenerate
890
 
891
 
892
 
893
    conventional_routing #(
894
        .TOPOLOGY(TOPOLOGY),
895
        .ROUTE_NAME(ROUTE_NAME),
896
        .ROUTE_TYPE(ROUTE_TYPE),
897
        .T1(T1),
898
        .T2(T2),
899
        .T3(T3),
900
        .RAw(RAw),
901
        .EAw(EAw),
902
        .DSTPw(DSTPw),
903
        .LOCATED_IN_NI(1)
904
    )
905
    route_compute
906
    (
907
        .reset(reset),
908
        .clk(clk),
909
        .current_r_addr(current_r_addr),
910
        .src_e_addr(current_e_addr),
911
        .dest_e_addr(dest_e_addr),
912
        .destport(destport)
913
    );
914
 
915
 
916
    header_flit_generator #(
917
         .DATA_w(HDw)
918
    )
919
    hdr_flit_gen
920
    (
921
        .flit_out(hdr_flit_out),
922
        .class_in(pck_class),
923
        .dest_e_addr_in(dest_e_addr),
924
        .src_e_addr_in(current_e_addr),
925
        .destport_in(destport),
926
        .vc_num_in(send_vc_enable),
927
        .weight_in(weight),
928
        .be_in(be_in),
929
        .data_in(hdr_data )
930
 
931
    );
932
 
933
  wire [V-1    :   0] wr_vc_send =  (fifo_wr) ? send_vc_enable : {V{1'b0}};
934
 
935
 
936
  ovc_status #(
937
    .V(V),
938
    .B(LB),
939
    .CRDTw(CRDTw)
940
  )
941
  the_ovc_status
942
  (
943
    .credit_init_val_in ( chan_in.ctrl_chanel.credit_init_val),
944
        .wr_in(wr_vc_send),
945
    .credit_in(credit_in),
946
    .full_vc(vc_fifo_full),
947
    .nearly_full_vc(vc_fifo_nearly_full),
948
    .empty_vc( ),
949
    .clk(clk),
950
    .reset(reset)
951
  );
952
 
953
    // header info mux
954
    assign dest_e_addr = vc_dest_e_addr[send_vc_enable_binary];
955
    assign pck_class  = vc_pck_class[send_vc_enable_binary];
956
    assign weight =   vc_weight[send_vc_enable_binary];
957
    assign hdr_data = vc_hdr_data [send_vc_enable_binary];
958
    assign send_hdr = send_vc_send_hdr[send_vc_enable_binary];
959
    assign send_tail = send_vc_send_tail[send_vc_enable_binary];
960
    assign be_in = vc_be_in[send_vc_enable_binary];
961
 
962
    //wb multiplexors
963
    assign m_send_sel_o  = vc_m_send_sel_o[send_vc_enable_binary];
964
    assign m_send_addr_o = vc_m_send_addr_o[send_vc_enable_binary];
965
    assign m_send_cti_o  = vc_m_send_cti_o[send_vc_enable_binary];
966
    assign m_send_stb_o  = vc_m_send_stb_o[send_vc_enable_binary];
967
    assign m_send_cyc_o  = vc_m_send_cyc_o[send_vc_enable_binary];
968
    assign m_send_we_o   = vc_m_send_we_o[send_vc_enable_binary];
969
 
970
    assign m_receive_sel_o = vc_m_receive_sel_o[receive_vc_enable_binary];
971
    assign m_receive_addr_o= vc_m_receive_addr_o[receive_vc_enable_binary];
972
    assign m_receive_cti_o = vc_m_receive_cti_o[receive_vc_enable_binary];
973
    assign m_receive_stb_o = vc_m_receive_stb_o[receive_vc_enable_binary];
974
    assign m_receive_cyc_o = vc_m_receive_cyc_o[receive_vc_enable_binary];
975
    assign m_receive_we_o  = vc_m_receive_we_o[receive_vc_enable_binary];
976
 
977
    wire [V-1    :   0]  flit_in_vc_num = flit_in [Fpay+V-1    :   Fpay];
978
    wire [V-1    :   0]  ififo_vc_not_empty;
979
    assign vc_fifo_empty = ~ ififo_vc_not_empty;
980
    assign receive_vc_got_packet = ififo_vc_not_empty;
981
    assign receive_vc_got_hdr_flit_at_head=  ififo_vc_not_empty & receive_vc_fsm_is_ideal;
982
 
983
 
984
 
985
 
986
    wire [Fw-1  :   0] fifo_dout;
987
 
988
    flit_buffer #(
989
        .V(V),
990
        .B(LB),
991
        .PCK_TYPE(PCK_TYPE),
992
        .Fw(Fw),
993
        .DEBUG_EN(DEBUG_EN),
994
        .SSA_EN("NO")
995
     )
996
     the_ififo
997
     (
998
        .din(flit_in),     // Data in
999
        .vc_num_wr(flit_in_vc_num),//write vertual chanel
1000
        .wr_en(flit_in_wr),   // Write enable
1001
        .vc_num_rd(receive_vc_enable),//read vertual chanel
1002
        .rd_en(fifo_rd),   // Read the next word
1003
        .dout(fifo_dout),    // Data out
1004
        .vc_not_empty(ififo_vc_not_empty),
1005
        .reset(reset),
1006
        .clk(clk),
1007
        .ssa_rd({V{1'b0}})
1008
    );
1009
 
1010
   extract_header_flit_info #(
1011
        .DATA_w (HDw)
1012
    )
1013
    extractor
1014
    (
1015
        .flit_in(fifo_dout),
1016
        .flit_in_wr(),
1017
        .class_o(received_class_next),
1018
        .destport_o(),
1019
        .dest_e_addr_o(),
1020
        .src_e_addr_o(received_src_e_addr_next),
1021
        .vc_num_o(),
1022
        .hdr_flit_wr_o( ),
1023
        .hdr_flg_o( ),
1024
        .tail_flg_o( ),
1025
        .weight_o(),
1026
        .be_o(received_be_next),
1027
        .data_o(received_hdr_dat_next)
1028
    );
1029
 
1030
 
1031
 
1032
  assign m_receive_dat_o = fifo_dout[Dw-1   :   0];
1033
  assign received_flit_is_tail = fifo_dout[Fw-2];
1034
  assign received_flit_is_hdr  = fifo_dout[Fw-1];
1035
//  assign any_vc_got_pck = |receive_vc_got_packet;
1036
 
1037
    localparam [1:0]
1038
        HDR_FLAG           =   2'b10,
1039
        BDY_FLAG            =   2'b00,
1040
        TAIL_FLAG          =   2'b01;
1041
 
1042
  assign credit_out = vc_fifo_rd;
1043
  assign flit_out_wr= fifo_wr;
1044
  assign flit_out [Fpay+V-1 : Fpay] = send_vc_enable;
1045
  assign flit_out [Fpay-1   : 0   ] = (send_hdr)?  hdr_flit_out [Fpay-1 : 0] :
1046
                                      (send_tail)? tail_flit_out :  m_send_dat_i [Fpay-1 : 0];
1047
  assign flit_out [Fw-1 : Fw-2] =   (send_hdr)?  HDR_FLAG :
1048
                                    (send_tail)?  TAIL_FLAG    : BDY_FLAG;
1049
endmodule
1050
 
1051
 
1052
 
1053
/******************
1054
*   ovc_status
1055
*******************/
1056
 
1057
 module ovc_status #(
1058
    parameter V     =   4,
1059
    parameter B =   16,
1060
    parameter CRDTw =4
1061
)
1062
(
1063
 
1064
        input   [V-1 : 0] [CRDTw-1 : 0 ] credit_init_val_in,
1065
        input   [V-1            :0] wr_in,
1066
    input   [V-1            :0] credit_in,
1067
    output  [V-1            :0] full_vc,
1068
    output  [V-1            :0] nearly_full_vc,
1069
    output  [V-1            :0] empty_vc,
1070
    input                       clk,
1071
    input                       reset
1072
);
1073
 
1074
 
1075
         function integer log2;
1076
         input integer number; begin
1077
                log2=(number <=1) ? 1: 0;
1078
                while(2**log2
1079
                        log2=log2+1;
1080
                end
1081
         end
1082
         endfunction // log2
1083
 
1084
 
1085
        localparam  DEPTH_WIDTH =   log2(B+1);
1086
 
1087
 
1088
         reg  [DEPTH_WIDTH-1 : 0] credit    [V-1 : 0];
1089
         wire  [V-1 : 0] cand_vc_next;
1090
 
1091
 
1092
         genvar i;
1093
         generate
1094
                for(i=0;i
1095
                `ifdef SYNC_RESET_MODE
1096
                        always @ (posedge clk )begin
1097
                `else
1098
                        always @ (posedge clk or posedge reset)begin
1099
                `endif
1100
                if(reset)begin
1101
                credit[i]<= credit_init_val_in[i][DEPTH_WIDTH-1:0];
1102
            end else begin
1103
                if(  wr_in[i]  && ~credit_in[i])   credit[i] <= credit[i]-1'b1;
1104
                if( ~wr_in[i]  &&  credit_in[i])   credit[i] <= credit[i]+1'b1;
1105
            end //reset
1106
            end//always
1107
 
1108
            assign  full_vc[i]   = (credit[i] == {DEPTH_WIDTH{1'b0}});
1109
            assign  nearly_full_vc[i]=  (credit[i] == 1) |  full_vc[i];
1110
            assign  empty_vc[i]  = (credit[i] == credit_init_val_in[i][DEPTH_WIDTH-1:0]);
1111
      end//for
1112
    endgenerate
1113
endmodule
1114
 
1115
 

powered by: WebSVN 2.1.0

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