summaryrefslogtreecommitdiff
path: root/rtl/dma_axi32/dma_axi32_core0_ch_wr_slicer.v
blob: 318e44cf32d1f75c293c2e71912bce134b6b279f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
// verilator lint_off WIDTHEXPAND
// verilator lint_off WIDTHTRUNC
/////////////////////////////////////////////////////////////////////
////                                                             ////
////  Author: Eyal Hochberg                                      ////
////          eyal@provartec.com                                 ////
////                                                             ////
////  Downloaded from: http://www.opencores.org                  ////
/////////////////////////////////////////////////////////////////////
////                                                             ////
//// Copyright (C) 2010 Provartec LTD                            ////
//// www.provartec.com                                           ////
//// info@provartec.com                                          ////
////                                                             ////
//// This source file may be used and distributed without        ////
//// restriction provided that this copyright statement is not   ////
//// removed from the file and that any derivative work contains ////
//// the original copyright notice and the associated disclaimer.////
////                                                             ////
//// This source file is free software; you can redistribute it  ////
//// and/or modify it under the terms of the GNU Lesser General  ////
//// Public License as published by the Free Software Foundation.////
////                                                             ////
//// This source is distributed in the hope that it will be      ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied  ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR     ////
//// PURPOSE.  See the GNU Lesser General Public License for more////
//// details. http://www.gnu.org/licenses/lgpl.html              ////
////                                                             ////
/////////////////////////////////////////////////////////////////////
//---------------------------------------------------------
//-- File generated by RobustVerilog parser
//-- Version: 1.0
//-- Invoked Fri Mar 25 23:34:54 2011
//--
//-- Source file: dma_ch_wr_slicer.v
//---------------------------------------------------------


  
module  dma_axi32_core0_ch_wr_slicer (clk,reset,ch_update,rd_clr_line,fifo_wr,fifo_wdata,fifo_wsize,wr_align,wr_ptr,rd_incr,end_swap,slice_wr,slice_wr_fifo,slice_wr_ptr,slice_bsel,slice_wdata,slice_wsize);

   input               clk;
   input               reset;

   input               ch_update;
   input               rd_clr_line;
   
   input               fifo_wr;
   input [32-1:0]      fifo_wdata;
   input [3-1:0]      fifo_wsize;
   input [2-1:0]      wr_align;
   input [5-1:0]      wr_ptr;
   input               rd_incr;
   input [1:0]               end_swap;
   
   output               slice_wr;
   output               slice_wr_fifo;
   output [5-1:0]     slice_wr_ptr;
   output [4-1:0]     slice_bsel;
   output [32-1:0]     slice_wdata;
   output [3-1:0]     slice_wsize;
   

   
   reg [3-1:0]           line_remain;                  
   wire [3-1:0]       join_wsize;
   wire [3-1:0]       append_wsize;
   wire [3-1:0]       direct_wsize;
   reg                   append;
   reg [3-1:0]           next_size;
   
   reg [32-1:0]           align_wdata;
   reg [32-1:0]           align_wdata_d;
   wire [2-1:0]       wr_align_valid;
   reg [32-1:0]           next_wdata;
   wire [4-1:0]       bsel_dec;
   reg [4-1:0]           bsel_shift;

   wire               next_wr;
   
   wire               slice_wr_pre;
   wire [5-1:0]       slice_wr_ptr_pre;
   wire [4-1:0]       slice_bsel_pre;
   wire [4-1:0]       slice_bsel_swap;
   wire [32-1:0]       slice_wdata_pre;
   reg [32-1:0]           slice_wdata_pre_d;
   wire [32-1:0]       slice_wdata_swap;
   wire [3-1:0]       slice_wsize_pre;

   wire               slice_wr;
   wire               slice_wr_fifo;
   reg [5-1:0]           slice_wr_ptr;
   reg [4-1:0]           slice_bsel;
   reg [32-1:0]           slice_wdata;
   reg [3-1:0]           slice_wsize;


   always @(posedge clk or posedge reset)
     if (reset)
       line_remain <= 3'd4;
     else if (ch_update |  rd_clr_line)
       line_remain <= 3'd4;
     else if (slice_wr_pre & (line_remain == slice_wsize_pre))
       line_remain <= 3'd4;
     else if (slice_wr_pre)
       line_remain <= line_remain - slice_wsize_pre;
   
   assign               join_wsize = next_size + fifo_wsize;

   prgen_min2 #(3) min2_append(
                     .a(join_wsize),
                     .b(3'd4),
                     .min(append_wsize)
                     );
   
   prgen_min2 #(3) min2_direct(
                     .a(line_remain),
                     .b(fifo_wsize),
                     .min(direct_wsize)
                     );
   
   
   always @(posedge clk or posedge reset)
     if (reset)
       append  <= 1'b0;
     else if (next_wr)
       append  <= 1'b0;
     else if (fifo_wr & (slice_wsize_pre == join_wsize))
       append  <= 1'b0;
     else if (fifo_wr)
       append  <= 1'b1;

   
   always @(posedge clk or posedge reset)
     if (reset)
       next_size  <= {3{1'b0}};
     else if (next_wr)
       next_size  <= {3{1'b0}};
     else if (fifo_wr & append)
       next_size  <= join_wsize - append_wsize;
     else if (fifo_wr)
       next_size  <= join_wsize - direct_wsize;

   
   //WDATA
   always @(posedge clk or posedge reset)
     if (reset)
       align_wdata_d <= {32{1'b0}};
     else if (fifo_wr)
       align_wdata_d <= align_wdata;

   
   assign               wr_align_valid = 
                  rd_incr ? wr_align : 
                  wr_align - wr_ptr[2-1:0];

   //always @(/*AUTOSENSE*/) - no AUTOSENSE because of fifo_wr
   always @(fifo_wdata or wr_align_valid or fifo_wr)
     begin
    case (wr_align_valid[2-1:0])
      2'd0 : align_wdata = fifo_wdata;
      2'd1 : align_wdata = {fifo_wdata[7:0],  fifo_wdata[31:8]};
      2'd2 : align_wdata = {fifo_wdata[15:0], fifo_wdata[31:16]};
      2'd3 : align_wdata = {fifo_wdata[23:0], fifo_wdata[31:24]};
    endcase
     end


   always @(/*AUTOSENSE*/align_wdata or align_wdata_d or next_size)
     begin
    case (next_size[2-1:0])
      2'd0 : next_wdata = align_wdata_d;
      2'd1 : next_wdata = {align_wdata[31:8],  align_wdata_d[7:0]};
      2'd2 : next_wdata = {align_wdata[31:16], align_wdata_d[15:0]};
      2'd3 : next_wdata = {align_wdata[31:24], align_wdata_d[23:0]};
    endcase
     end

   
   //BSEL
   assign bsel_dec = 
      slice_wsize == 4'd1 ? 4'b0001 :
      slice_wsize == 4'd2 ? 4'b0011 :
      slice_wsize == 4'd3 ? 4'b0111 :
      slice_wsize == 4'd4 ? 4'b1111 :
             {4{1'b0}};

   
   always @(/*AUTOSENSE*/bsel_dec or wr_ptr)
     begin
    case (wr_ptr[2-1:0])
      2'd0 : bsel_shift = bsel_dec;
      2'd1 : bsel_shift = {bsel_dec[2:0], 1'b0};
      2'd2 : bsel_shift = {bsel_dec[1:0], 2'b0};
      2'd3 : bsel_shift = {bsel_dec[0],   3'b0};
    endcase
     end


   //CMD
   assign next_wr             = (~fifo_wr) & (|next_size);
   
   assign slice_wr_pre        = fifo_wr | next_wr;
      
   assign slice_wsize_pre     =  
      next_wr ? next_size    : 
      append  ? append_wsize : direct_wsize;
    
   assign slice_wr_ptr_pre    = wr_ptr;

   assign slice_wdata_pre     = append ? next_wdata : align_wdata;

   assign slice_bsel_pre      = bsel_shift;
   

   prgen_delay #(1) delay_wr0(.clk(clk), .reset(reset), .din(slice_wr_pre), .dout(slice_wr));
   prgen_delay #(1) delay_wr(.clk(clk), .reset(reset), .din(slice_wr), .dout(slice_wr_fifo));

   
   always @(posedge clk or posedge reset)
     if (reset)
       begin
      slice_wsize       <= {3{1'b0}};
      slice_wdata_pre_d <= {32{1'b0}};
       end
     else if (slice_wr_pre)
       begin
      slice_wsize       <= slice_wsize_pre;
      slice_wdata_pre_d <= slice_wdata_pre;
       end

   
   prgen_swap32 swap32(
               .end_swap(end_swap),
               .data_in(slice_wdata_pre_d),
               .data_out(slice_wdata_swap),
               .bsel_in(slice_bsel_pre),
               .bsel_out(slice_bsel_swap)
               );
   
   always @(posedge clk or posedge reset)
     if (reset)
       begin
      slice_wdata   <= {32{1'b0}};
      slice_wr_ptr  <= {5{1'b0}};
      slice_bsel    <= {4{1'b0}};
       end
     else if (slice_wr)
       begin
      slice_wdata   <= slice_wdata_swap;
      slice_wr_ptr  <= slice_wr_ptr_pre;
      slice_bsel    <= slice_bsel_swap;
       end
   
endmodule



   


// verilator lint_on WIDTHEXPAND
// verilator lint_on WIDTHTRUNC