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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_stream_lib/] [src/] [axis_down_shift.sv] - Blame information for rev 49

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 49 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2019 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
// --------------------------------------------------------------------
29
module
30
  axis_down_shift_tuser_mux
31
  #(
32
    U = 1, // TUSER width
33
    logic [U-1:0] TUSER_MASK[3] = '{ {U{1'b0}},  // first
34
                                     {U{1'b0}},  // middle
35
                                     {U{1'b0}} } // last
36
  )
37
  (
38
    axis_if axis_in,
39
    axis_if axis_out,
40
    input   aclk,
41
    input   aresetn
42
  );
43
 
44
// --------------------------------------------------------------------
45
endmodule
46
 
47
// --------------------------------------------------------------------
48
module
49
  axis_down_shift
50
  #(
51
    N,     // axis_in tdata bus width in bytes
52
    S,     // tdata size divisor
53
    I = 1, // TID width
54
    D = 1, // TDEST width
55
    U = 1, // TUSER width
56
    logic [U-1:0] TUSER_MASK[3] = '{ {U{1'b0}},  // first
57
                                     {U{1'b0}},  // middle
58
                                     {U{1'b0}} } // last
59
  )
60
  (
61
    axis_if axis_in,
62
    axis_if axis_out,
63
    input   aclk,
64
    input   aresetn
65
  );
66
 
67
// --------------------------------------------------------------------
68
// synthesis translate_off
69
  initial
70
  begin
71
    assert(S > 1) else $fatal;
72
    assert(N % S == 0) else $fatal;
73
  end
74
// synthesis translate_on
75
// --------------------------------------------------------------------
76
 
77
  // --------------------------------------------------------------------
78
  localparam N_OUT = (N / S); // width of axis_out.tdata in bytes
79
  localparam W = N_OUT * 8;   // width of axis_out.tdata in bits
80
  localparam UB = (W*(S-1))-1;
81
 
82
  // --------------------------------------------------------------------
83
  axis_if #(.N(N_OUT), .I(I), .D(D), .U(U)) a_down(.*);
84
  wire almost_last;
85
 
86
  // --------------------------------------------------------------------
87
  enum reg [2:0]
88
    {
89
      FIRST   = 3'b001,
90
      MIDDLE  = 3'b010,
91
      LAST    = 3'b100
92
    } state, next_state;
93
 
94
  // --------------------------------------------------------------------
95
  always_ff @(posedge aclk)
96
    if(~aresetn)
97
      state <= FIRST;
98
    else
99
      state <= next_state;
100
 
101
  // --------------------------------------------------------------------
102
  always_comb
103
    case(state)
104
      FIRST:    if(axis_in.tvalid & a_down.tready)
105
                  if(almost_last)
106
                    next_state <= LAST;
107
                  else
108
                    next_state <= MIDDLE;
109
                else
110
                  next_state <= FIRST;
111
 
112
      MIDDLE:   if(almost_last & a_down.tready)
113
                  next_state <= LAST;
114
                else
115
                  next_state <= MIDDLE;
116
 
117
      LAST:     if(a_down.tready)
118
                  next_state <= FIRST;
119
                else
120
                  next_state <= LAST;
121
 
122
      default:  next_state <= FIRST;
123
    endcase
124
 
125
  // --------------------------------------------------------------------
126
  reg [$clog2(S)-1:0] index;
127
  assign almost_last = (index >= S - 2);
128
 
129
  always_ff @(posedge aclk)
130
    if(next_state == FIRST)
131
      index <= 0;
132
    else if(a_down.tready)
133
      index <= index + 1;
134
 
135
  // --------------------------------------------------------------------
136
  reg  [UB:0]  remainder;
137
  wire [W-1:0] tdata_pass  = axis_in.tdata[W-1:0];
138
  wire [W-1:0] tdata_shift = remainder[W-1:0];
139
 
140
  always_ff @(posedge aclk)
141
    if(state == FIRST)
142
      remainder <= axis_in.tdata[(N*8)-1:W];
143
    else if(a_down.tready)
144
      remainder <= { {W{1'b0}}, remainder[UB:W]};
145
 
146
  // --------------------------------------------------------------------
147
  reg [U-1:0] tuser;
148
 
149
    generate
150
      for(genvar j = 0; j < U; j++)
151
      begin: tuser_gen
152
        always_comb
153
          case(state)
154
            FIRST:    tuser[j] = TUSER_MASK[0][j] ? axis_in.tuser[j] : 0;
155
            MIDDLE:   tuser[j] = TUSER_MASK[1][j] ? axis_in.tuser[j] : 0;
156
            LAST:     tuser[j] = TUSER_MASK[2][j] ? axis_in.tuser[j] : 0;
157
            default:  tuser[j] = 0;
158
          endcase
159
      end
160
    endgenerate
161
 
162
  // --------------------------------------------------------------------
163
  assign axis_in.tready = (state == LAST) & (next_state != LAST);
164
  // assign a_down.tstrb  = axis_in.tstrb;
165
  // assign a_down.tkeep  = axis_in.tkeep;
166
  assign a_down.tid    = axis_in.tid;
167
  assign a_down.tdest  = axis_in.tdest;
168
  assign a_down.tvalid = axis_in.tvalid;
169
  assign a_down.tlast  = (state == LAST) ? axis_in.tlast : 0;
170
  assign a_down.tuser  = tuser;
171
  assign a_down.tdata  = (state == FIRST) ? tdata_pass : tdata_shift;
172
 
173
  // --------------------------------------------------------------------
174
  axis_register_slice #(.N(N_OUT), .I(I), .D(D), .U(U))
175
    slice_i(.axis_in(a_down), .*);
176
 
177
// --------------------------------------------------------------------
178
endmodule

powered by: WebSVN 2.1.0

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