OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_stream_lib/] [src/] [axis_upsizer.sv] - Blame information for rev 31

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

Line No. Rev Author Line
1 31 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2015 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
module
29
  axis_upsizer
30
  #(
31
    N,              // data bus width in bytes
32
    I = 1,          // TID width
33
    D = 1,          // TDEST width
34
    U,              // TUSER width
35
    S,              // tdata size multiplier
36
    USE_TSTRB = 0,  //  set to 1 to enable, 0 to disable
37
    USE_TKEEP = 0,  //  set to 1 to enable, 0 to disable
38
    BYTES_PER_TUSER //  bytes per tuser bit. Set to 0 for transfer based.
39
  )
40
  (
41
    axis_if axis_in,
42
    axis_if axis_out,
43
    input   aclk,
44
    input   aresetn
45
  );
46
 
47
// --------------------------------------------------------------------
48
// synthesis translate_off
49
 
50
  initial
51
  begin
52
    a_multiplier: assert((S > 1) & (S % 2 == 0))else $fatal;
53
    a_tstrb_unsuported: assert(USE_TSTRB == 0) else $fatal;
54
    a_tkeep_unsuported: assert(USE_TKEEP == 0) else $fatal;
55
    a_bytes_per_tuser: assert((BYTES_PER_TUSER == 0) | (N % BYTES_PER_TUSER == 0)) else $fatal;
56
    a_tuser: assert((BYTES_PER_TUSER == 0) | (U % S == 0)) else $fatal;
57
  end
58
 
59
// synthesis translate_on
60
// --------------------------------------------------------------------
61
 
62
 
63
  // --------------------------------------------------------------------
64
  //
65
  localparam A = $clog2(S);
66
  localparam ED = 2 ** A;
67
 
68
 
69
  // --------------------------------------------------------------------
70
  //
71
  axis_if #(.N(N*S), .U(U*S)) axis_upsizer_bus(.*);
72
  wire last_word;
73
 
74
 
75
  //---------------------------------------------------
76
  //  state machine binary definitions
77
  enum reg [1:0]
78
    {
79
      GET_WORDS_IN  = 2'b01,
80
      WORD_OUT      = 2'b10
81
    } state, next_state;
82
 
83
 
84
  //---------------------------------------------------
85
  //  state machine flop
86
  always_ff @(posedge aclk)
87
    if(~aresetn)
88
      state <= GET_WORDS_IN;
89
    else
90
      state <= next_state;
91
 
92
 
93
  //---------------------------------------------------
94
  //  state machine
95
  always_comb
96
    case(state)
97
      GET_WORDS_IN:         if(axis_in.tvalid & last_word)
98
                              next_state <= WORD_OUT;
99
                            else
100
                              next_state <= GET_WORDS_IN;
101
 
102
      WORD_OUT:             if(axis_upsizer_bus.tready)
103
                              next_state <= GET_WORDS_IN;
104
                            else
105
                              next_state <= WORD_OUT;
106
 
107
      default:              next_state <= GET_WORDS_IN;
108
 
109
    endcase
110
 
111
 
112
  // --------------------------------------------------------------------
113
  //
114
  reg [A-1:0] index;
115
  wire roll_over = ~(index < S - 1) & axis_in.tready & axis_in.tvalid;
116
 
117
  always_ff @(posedge aclk)
118
    if(~aresetn | roll_over)
119
      index <= 0;
120
    else if(axis_in.tready & axis_in.tvalid)
121
      index <= index + 1;
122
 
123
 
124
  // --------------------------------------------------------------------
125
  //
126
  wire [ED-1:0] encoded;
127
  assign last_word = encoded[S-1];
128
 
129
  one_hot_encoder #(A)
130
    one_hot_encoder_i(index, encoded);
131
 
132
 
133
  // --------------------------------------------------------------------
134
  //
135
  reg tlast_in[S];
136
  reg [U-1:0] tuser_in[S];
137
  reg [(8*N)-1:0] tdata_in[S];
138
  wire [S-1:0] tlast_out_w;
139
  wire [(U*S)-1:0] tuser_out_w;
140
  wire [(8*N*S)-1:0] tdata_out_w;
141
  genvar j;
142
 
143
  generate
144
    for(j = 0; j < S; j++)
145
    begin: tdata_gen
146
      always_ff @(posedge aclk)
147
        if(encoded[j] & axis_in.tready & axis_in.tvalid)
148
        begin
149
          tdata_in[j] <= axis_in.tdata;
150
          tuser_in[j] <= axis_in.tuser;
151
          tlast_in[j] <= axis_in.tlast;
152
        end
153
 
154
      assign tlast_out_w[j]             = tlast_in[j];
155
      assign tuser_out_w[j*U +: U]      = tuser_in[j];
156
      assign tdata_out_w[j*N*8 +: N*8]  = tdata_in[j];
157
    end
158
  endgenerate
159
 
160
 
161
  // --------------------------------------------------------------------
162
  //
163
  assign axis_in.tready = (state == GET_WORDS_IN) | (next_state == GET_WORDS_IN);
164
  assign axis_upsizer_bus.tvalid  = (state == WORD_OUT);
165
  assign axis_upsizer_bus.tdata = tdata_out_w;
166
  assign axis_upsizer_bus.tuser = tuser_out_w;
167
  assign axis_upsizer_bus.tlast = tlast_out_w[S-1];
168
 
169
 
170
  // --------------------------------------------------------------------
171
  //
172
  axis_register_slice #(.N(N*S), .U(U*S))
173
    axis_register_slice_i(.axis_in(axis_upsizer_bus), .*);
174
 
175
 
176
// --------------------------------------------------------------------
177
//
178
endmodule
179
 
180
 

powered by: WebSVN 2.1.0

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