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

Subversion Repositories crcahb

[/] [crcahb/] [trunk/] [rtl/] [crc_datapath.v] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 redbear
//////////////////////////////////////////////////////////////////
2
////
3
////
4
////    CRCAHB CORE BLOCK
5
////
6
////
7
////
8
//// This file is part of the APB to I2C project
9
////
10
//// http://www.opencores.org/cores/apbi2c/
11
////
12
////
13
////
14
//// Description
15
////
16
//// Implementation of APB IP core according to
17
////
18
//// crcahb IP core specification document.
19
////
20
////
21
////
22
//// To Do: Things are right here but always all block can suffer changes
23
////
24
////
25
////
26
////
27
////
28
//// Author(s): -  Julio Cesar 
29
////
30
///////////////////////////////////////////////////////////////// 
31
////
32
////
33
//// Copyright (C) 2009 Authors and OPENCORES.ORG
34
////
35
////
36
////
37
//// This source file may be used and distributed without
38
////
39
//// restriction provided that this copyright statement is not
40
////
41
//// removed from the file and that any derivative work contains
42
//// the original copyright notice and the associated disclaimer.
43
////
44
////
45
//// This source file is free software; you can redistribute it
46
////
47
//// and/or modify it under the terms of the GNU Lesser General
48
////
49
//// Public License as published by the Free Software Foundation;
50
//// either version 2.1 of the License, or (at your option) any
51
////
52
//// later version.
53
////
54
////
55
////
56
//// This source is distributed in the hope that it will be
57
////
58
//// useful, but WITHOUT ANY WARRANTY; without even the implied
59
////
60
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
61
////
62
//// PURPOSE. See the GNU Lesser General Public License for more
63
//// details.
64
////
65
////
66
////
67
//// You should have received a copy of the GNU Lesser General
68
////
69
//// Public License along with this source; if not, download it
70
////
71
//// from http://www.opencores.org/lgpl.shtml
72
////
73
////
74
///////////////////////////////////////////////////////////////////
75 2 julioameri
module crc_datapath
76
(
77
 //OUTPUTS
78
 output [31:0] crc_out,
79
 output [ 1:0] size_out,
80
 output [ 7:0] crc_idr_out,
81
 output [31:0] crc_poly_out,
82
 output [31:0] crc_init_out,
83
 //INPUTS
84
 input [31:0] bus_wr, //Write data Bus
85
 input [ 1:0] rev_in_type, //select type of reversion of bus
86
 input rev_out_type,
87
 input buffer_en,
88
 input byte_en,
89
 input crc_init_en,
90
 input crc_out_en,
91
 input crc_idr_en,
92
 input crc_poly_en,
93
 input buffer_rst,
94
 input bypass_byte0,
95
 input bypass_size,
96
 input [1:0] byte_sel,
97
 input [1:0] size_in,
98
 input clear_crc_init_sel,
99
 input set_crc_init_sel,
100
 input [1:0] crc_poly_size,
101
 input clk,
102
 input rst_n
103
);
104
 
105
//Reset definitions
106
localparam RESET_BUFFER       = 32'hffffffff;
107
localparam RESET_BYTE         = 32'hffffffff;
108
localparam RESET_BF_SIZE      = 2'b10;
109
localparam RESET_SIZE         = 2'b10;
110
localparam RESET_CRC_INIT_SEL = 1'b0;
111
localparam RESET_CRC_INIT     = 32'hffffffff;
112
localparam RESET_CRC_OUT      = 32'h0;
113
localparam RESET_CRC_IDR      = 8'h0;
114
localparam RESET_CRC_POLY     = 32'h04c11db7;
115
 
116
//Parameters definitions
117
localparam BYTE_0 = 2'b00;
118
localparam BYTE_1 = 2'b01;
119
localparam BYTE_2 = 2'b10;
120
localparam BYTE_3 = 2'b11;
121
 
122
localparam POLY_SIZE_32 = 2'b00;
123
localparam POLY_SIZE_16 = 2'b01;
124
localparam POLY_SIZE_8  = 2'b10;
125
localparam POLY_SIZE_7  = 2'b11;
126
 
127
//Flops Definition
128
reg [31:0] buffer_ff;
129
reg [31:0] byte_ff;
130
reg [31:0] crc_init_ff;
131
reg [31:0] crc_out_ff;
132
reg [31:0] crc_poly_ff;
133
reg [ 7:0] crc_idr_ff;
134
reg [ 1:0] bf_size_ff;
135
reg [ 1:0] size_ff;
136
reg crc_init_sel_ff;
137
 
138
//internal signals definition
139
reg [7:0] crc_data_in;
140
reg crc_poly_size_7;
141
reg crc_poly_size_8;
142
reg crc_poly_size_16;
143
reg crc_poly_size_32;
144
wire [31:0] bus_reversed;
145
wire [31:0] crc_init_mux;
146
wire [31:0] crc_unit_out;
147
wire [31:0] crc_poly_size_in;
148
wire [31:0] crc_out_rev;
149
wire [ 7:0] byte0_in;
150
wire [ 7:0] byte1_in;
151
wire [ 7:0] byte2_in;
152
wire [ 7:0] byte3_in;
153
wire [ 7:0] byte0_mux_out;
154
 
155
//Instantiatin of bit_reversed module 
156
//to perform reversion fuctionality according with rev_type bits
157
bit_reversal
158
#(
159
 .DATA_SIZE ( 32 )
160
)REV_IN
161
(
162
 .data_out ( bus_reversed    ),
163
 .data_in  ( bus_wr          ),
164
 .rev_type ( rev_in_type     )
165
);
166
 
167
//Definition of Registers buffer_ff and byte_ff
168
always @(posedge clk)
169
 begin
170
  if(!rst_n)
171
   begin
172
    buffer_ff  <= RESET_BUFFER;
173
    byte_ff    <= RESET_BYTE;
174
   end
175
  else
176
   begin
177
    if(buffer_en)
178
     buffer_ff <= bus_reversed;
179
    //else
180
    // if(buffer_rst)
181
    //  buffer_ff <= RESET_BUFFER;
182
 
183
    if(byte_en)
184
     byte_ff <= buffer_ff;
185
   end
186
 end
187
 
188
//Definition of Registers bf_size_ff and size_ff
189
always @(posedge clk)
190
 begin
191
  if(!rst_n)
192
   begin
193
    bf_size_ff <= RESET_BF_SIZE;
194
    size_ff    <= RESET_SIZE;
195
   end
196
  else
197
   begin
198
    if(buffer_en)
199
     bf_size_ff <= size_in;
200
    else
201
     if(buffer_rst)
202
      bf_size_ff <= RESET_BF_SIZE;
203
 
204
    if(byte_en)
205
     size_ff <= bf_size_ff;
206
   end
207
 end
208
 
209
//Mux to bypass size_ff
210
//This informatin is used by FSM to decide the size of the current operatin  
211
assign size_out = (bypass_size) ? bf_size_ff : size_ff;
212
 
213
assign byte0_in = byte_ff[ 7: 0];
214
assign byte1_in = byte_ff[15: 8];
215
assign byte2_in = byte_ff[23:16];
216
assign byte3_in = byte_ff[31:24];
217
 
218
//Mux to bypass byte0_ff
219
assign byte0_mux_out = (bypass_byte0) ? buffer_ff[7:0] : byte0_in;
220
 
221
//Mux to select input of CRC Unit
222
//TODO:AVALIAR A INFLUENCIA DA CODIFICACAO DA FSM NO SINAL BYTE_SEL 
223
always @(*)
224
 begin
225
  crc_data_in = 32'h0;
226
  case(byte_sel)
227
   BYTE_0: crc_data_in = byte0_mux_out;
228
   BYTE_1: crc_data_in = byte1_in;
229
   BYTE_2: crc_data_in = byte2_in;
230
   BYTE_3: crc_data_in = byte3_in;
231
   default:crc_data_in = 32'h0;
232
  endcase
233
 end
234
 
235
//Definition of Register crc_init_sel_ff
236
//This is a set/clear flop where the clear wins set
237
//This flop controls when the CRC operation is chained (crc_init_sel_ff = 1) or not
238
//In the chained operatin the current crc calculation depends of the previous crc calculated
239
//in the unchained operatin the current crc calculation depends of value of crc_init register
240
always @(posedge clk)
241
 begin
242
  if(!rst_n)
243
   crc_init_sel_ff <= RESET_CRC_INIT_SEL;
244
  else
245
   begin
246
    if(clear_crc_init_sel)
247
     crc_init_sel_ff <= 1'b0;
248
    else
249
     if(set_crc_init_sel)
250
      crc_init_sel_ff <= 1'b1;
251
   end
252
 end
253
 
254
//This register contains the init value used in non chained operatin of crc
255
assign crc_init_out = crc_init_ff;
256
always @(posedge clk)
257
 begin
258
  if(!rst_n)
259
   crc_init_ff <= RESET_CRC_INIT;
260
  else
261
   if(crc_init_en)
262
    crc_init_ff <= bus_wr;
263
         else
264
           if(buffer_rst)
265
                         crc_init_ff <= RESET_CRC_INIT;
266
 end
267
 
268
//This register contains the final value of crc
269
always @(posedge clk)
270
 begin
271
  if(!rst_n)
272
   crc_out_ff <= RESET_CRC_OUT;
273
  else
274
   if(crc_out_en)
275
    crc_out_ff <= crc_unit_out;
276
 end
277
 
278
//this is a general purpouse register
279
//see the spec for more details
280
assign crc_idr_out = crc_idr_ff;
281
always @(posedge clk)
282
 begin
283
  if(!rst_n)
284
   crc_idr_ff <= RESET_CRC_IDR;
285
  else
286
   if(crc_idr_en)
287
    crc_idr_ff <= bus_wr[7:0];
288
 end
289
 
290
//This register contains the polynomial coefficients to crc calculation
291
assign crc_poly_out = crc_poly_ff;
292
always @(posedge clk)
293
 begin
294
  if(!rst_n)
295
   crc_poly_ff <= RESET_CRC_POLY;
296
  else
297
   if(crc_poly_en)
298
    crc_poly_ff <= bus_wr;
299
 end
300
 
301
//Mux that define the type of operation (chained or not)    
302
assign crc_init_mux = (crc_init_sel_ff) ? crc_out_ff : crc_init_ff;
303
 
304
//Decoding of crc_poly_sizesignal
305
always @(*)
306
 begin
307
  crc_poly_size_7  = 1'b0;
308
  crc_poly_size_8  = 1'b0;
309
  crc_poly_size_16 = 1'b0;
310
  crc_poly_size_32 = 1'b0;
311
  case(crc_poly_size)
312
   POLY_SIZE_7 : crc_poly_size_7  = 1'b1;
313
   POLY_SIZE_8 : crc_poly_size_8  = 1'b1;
314
   POLY_SIZE_16: crc_poly_size_16 = 1'b1;
315
   POLY_SIZE_32: crc_poly_size_32 = 1'b1;
316
  endcase
317
 end
318
 
319
//This signal define the configurability of the CRC Unit
320
//In this case, the size of the polynomial can be: 7, 8, 16 or 32
321
assign crc_poly_size_in = {crc_poly_size_32, 15'h0, crc_poly_size_16, 7'h0, crc_poly_size_8, crc_poly_size_7, 6'h0};
322
 
323
//Instanciation of CRC Unit
324
//The module is configured to calculate CRC of 32 bits for 8 bits of data in parallel
325
crc_parallel
326
#(
327
 .CRC_SIZE   ( 32 ),
328
 .FRAME_SIZE ( 8  )
329
)CRC_UNIT
330
(
331
 .crc_out       ( crc_unit_out     ),
332
 .data_in       ( crc_data_in      ),
333
 .crc_init      ( crc_init_mux     ),
334
 .crc_poly      ( crc_poly_ff      ),
335
 .crc_poly_size ( crc_poly_size_in )
336
);
337
 
338
//crc_out_rev[31:0] = crc_out_ff[0:31]
339
generate
340
 genvar i;
341
 for(i = 0; i < 32; i = i + 1)
342
  assign crc_out_rev[i] = crc_out_ff[31 - i];
343
endgenerate
344
 
345
assign crc_out = (rev_out_type) ? crc_out_rev : crc_out_ff;
346
 
347
endmodule

powered by: WebSVN 2.1.0

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