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

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [axi4_stream_lib/] [src/] [axis_gear_box.sv] - Blame information for rev 45

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

Line No. Rev Author Line
1 40 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2017 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_gear_box
30
  #(
31 41 qaztronic
    IN_N = 2, // data bus width in bytes. axis_in.
32
    OUT_N = 2, // data bus width in bytes. axis_out.
33
    IN_W = 16, // width in bits
34
    OUT_W = 14, // width in bits
35
    U = 1, // TUSER width
36 40 qaztronic
    USE_TSTRB = 0, // set to 1 to enable, 0 to disable
37
    USE_TKEEP = 0, // set to 1 to enable, 0 to disable
38 41 qaztronic
    ANTECEDENT = 7, // in:out ratio (ANTECEDENT:CONSEQUENT)
39 40 qaztronic
    CONSEQUENT = 8
40
  )
41
  (
42
    axis_if axis_in,
43
    axis_if axis_out,
44
    input   aclk,
45
    input   aresetn
46
  );
47
 
48
  // --------------------------------------------------------------------
49
  //
50 41 qaztronic
  localparam B_W = IN_W*ANTECEDENT;
51
  localparam UB_W = $clog2(B_W);
52
  localparam UB_A = $clog2(ANTECEDENT);
53
  localparam UB_C = $clog2(CONSEQUENT);
54
 
55
// --------------------------------------------------------------------
56
// synthesis translate_off
57
  initial
58
  begin
59
    a_consequent: assert(B_W % CONSEQUENT == 0) else $fatal;
60
    a_in_w: assert(B_W % IN_W == 0) else $fatal;
61
    a_out_w: assert(B_W % OUT_W == 0) else $fatal;
62
  end
63
// synthesis translate_on
64
// --------------------------------------------------------------------
65 40 qaztronic
 
66 41 qaztronic
  // --------------------------------------------------------------------
67
  //
68
  reg [UB_W:0] wr_index;
69
  reg [UB_A:0] wr_select;
70
  wire wr_en = axis_in.tvalid & axis_in.tready & aresetn;
71
  wire wr_end = wr_en & (wr_index == B_W - IN_W);
72
  wire [UB_W:0] wr_next_index = wr_end ? 0 : wr_index + IN_W;
73
 
74
  always_ff @(posedge aclk)
75
    if(~aresetn)
76
      wr_index <= 0;
77
    else if(wr_en)
78
      wr_index <= wr_next_index;
79
 
80
  always_ff @(posedge aclk)
81
    if(~aresetn)
82
      wr_select <= 0;
83
    else if(wr_en)
84
      wr_select <= wr_end ? 0 : wr_select + 1;
85
 
86
  // --------------------------------------------------------------------
87
  //
88
  reg [UB_W:0] rd_index;
89
  reg [UB_C:0] rd_select;
90
  wire rd_en = axis_out.tvalid & axis_out.tready;
91
  wire rd_end = rd_en & (rd_index == B_W - OUT_W);
92
  wire [UB_W:0] rd_next_index = rd_end ? 0 : rd_index + OUT_W;
93
 
94
  always_ff @(posedge aclk)
95
    if(~aresetn)
96
      rd_index <= 0;
97
    else if(rd_en)
98
      rd_index <= rd_next_index;
99
 
100
  always_ff @(posedge aclk)
101
    if(~aresetn)
102
      rd_select <= 0;
103
    else if(rd_en)
104
      rd_select <= rd_end ? 0 : rd_select + 1;
105
 
106
  // --------------------------------------------------------------------
107
  //
108
  reg [B_W:0] buffer;
109
  genvar j;
110
 
111
  generate
112
  begin: buffer_gen
113
    for(j = 0; j < B_W/IN_W; j++)
114
      always_ff @(posedge aclk)
115
        if(wr_en & (wr_select == j))
116
          buffer[j*IN_W +: IN_W] <= axis_in.tdata[IN_W-1:0];
117
  end
118
  endgenerate
119
 
120
  // --------------------------------------------------------------------
121
  //
122
  // localparam C_DO = B_W/OUT_W;
123
  localparam MC_DO = 2**$clog2(CONSEQUENT); // max count
124
  wire [OUT_W-1:0] data_in[MC_DO-1:0];
125
  wire [OUT_W-1:0] data_out;
126
 
127
  generate
128
  begin: data_out_gen
129
    for(j = 0; j < CONSEQUENT; j++)
130
      assign data_in[j] = buffer[j*OUT_W +: OUT_W];
131
    if(MC_DO > CONSEQUENT)
132
      for(j = CONSEQUENT; j < MC_DO; j++)
133
        assign data_in[j] = 0;
134
  end
135
  endgenerate
136
 
137
  // --------------------------------------------------------------------
138
  //
139
  recursive_mux #(.A($clog2(CONSEQUENT)), .W(OUT_W))
140
    recursive_mux_i(.select(rd_select), .*);
141
 
142
  //---------------------------------------------------
143
  //  state machine binary definitions
144
  enum reg [1:0]
145
    {
146
      SAME      = 2'b01,
147
      WR_LAPPED = 2'b10
148
    } state, next_state;
149 40 qaztronic
 
150 41 qaztronic
  //---------------------------------------------------
151
  //  state machine flop
152
  always_ff @(posedge aclk)
153
    if(~aresetn)
154
      state <= SAME;
155
    else
156
      state <= next_state;
157
 
158
  //---------------------------------------------------
159
  //  state machine
160
  always_comb
161
    case(state)
162
      SAME:          if(wr_end & ~rd_end)
163
                       next_state <= WR_LAPPED;
164
                     else
165
                       next_state <= SAME;
166
 
167
      WR_LAPPED:     if(rd_end & ~wr_end)
168
                       next_state <= SAME;
169
                     else
170
                       next_state <= WR_LAPPED;
171
 
172
      default:       next_state <= SAME;
173
    endcase
174
 
175
  // --------------------------------------------------------------------
176
  //
177
  wire empty = (state == SAME) ? rd_next_index > wr_index : 0;
178
  wire full = (state == SAME) ? 0 : wr_next_index > rd_index;
179
  assign axis_in.tready = ~full;
180
  assign axis_out.tvalid = ~empty;
181
  assign axis_out.tdata = data_out;
182
 
183 40 qaztronic
// --------------------------------------------------------------------
184
//
185
endmodule
186
 
187
 

powered by: WebSVN 2.1.0

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