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

Subversion Repositories crcahb

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

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

Line No. Rev Author Line
1 2 julioameri
module crc_datapath
2
(
3
 //OUTPUTS
4
 output [31:0] crc_out,
5
 output [ 1:0] size_out,
6
 output [ 7:0] crc_idr_out,
7
 output [31:0] crc_poly_out,
8
 output [31:0] crc_init_out,
9
 //INPUTS
10
 input [31:0] bus_wr, //Write data Bus
11
 input [ 1:0] rev_in_type, //select type of reversion of bus
12
 input rev_out_type,
13
 input buffer_en,
14
 input byte_en,
15
 input crc_init_en,
16
 input crc_out_en,
17
 input crc_idr_en,
18
 input crc_poly_en,
19
 input buffer_rst,
20
 input bypass_byte0,
21
 input bypass_size,
22
 input [1:0] byte_sel,
23
 input [1:0] size_in,
24
 input clear_crc_init_sel,
25
 input set_crc_init_sel,
26
 input [1:0] crc_poly_size,
27
 input clk,
28
 input rst_n
29
);
30
 
31
//Reset definitions
32
localparam RESET_BUFFER       = 32'hffffffff;
33
localparam RESET_BYTE         = 32'hffffffff;
34
localparam RESET_BF_SIZE      = 2'b10;
35
localparam RESET_SIZE         = 2'b10;
36
localparam RESET_CRC_INIT_SEL = 1'b0;
37
localparam RESET_CRC_INIT     = 32'hffffffff;
38
localparam RESET_CRC_OUT      = 32'h0;
39
localparam RESET_CRC_IDR      = 8'h0;
40
localparam RESET_CRC_POLY     = 32'h04c11db7;
41
 
42
//Parameters definitions
43
localparam BYTE_0 = 2'b00;
44
localparam BYTE_1 = 2'b01;
45
localparam BYTE_2 = 2'b10;
46
localparam BYTE_3 = 2'b11;
47
 
48
localparam POLY_SIZE_32 = 2'b00;
49
localparam POLY_SIZE_16 = 2'b01;
50
localparam POLY_SIZE_8  = 2'b10;
51
localparam POLY_SIZE_7  = 2'b11;
52
 
53
//Flops Definition
54
reg [31:0] buffer_ff;
55
reg [31:0] byte_ff;
56
reg [31:0] crc_init_ff;
57
reg [31:0] crc_out_ff;
58
reg [31:0] crc_poly_ff;
59
reg [ 7:0] crc_idr_ff;
60
reg [ 1:0] bf_size_ff;
61
reg [ 1:0] size_ff;
62
reg crc_init_sel_ff;
63
 
64
//internal signals definition
65
reg [7:0] crc_data_in;
66
reg crc_poly_size_7;
67
reg crc_poly_size_8;
68
reg crc_poly_size_16;
69
reg crc_poly_size_32;
70
wire [31:0] bus_reversed;
71
wire [31:0] crc_init_mux;
72
wire [31:0] crc_unit_out;
73
wire [31:0] crc_poly_size_in;
74
wire [31:0] crc_out_rev;
75
wire [ 7:0] byte0_in;
76
wire [ 7:0] byte1_in;
77
wire [ 7:0] byte2_in;
78
wire [ 7:0] byte3_in;
79
wire [ 7:0] byte0_mux_out;
80
 
81
//Instantiatin of bit_reversed module 
82
//to perform reversion fuctionality according with rev_type bits
83
bit_reversal
84
#(
85
 .DATA_SIZE ( 32 )
86
)REV_IN
87
(
88
 .data_out ( bus_reversed    ),
89
 .data_in  ( bus_wr          ),
90
 .rev_type ( rev_in_type     )
91
);
92
 
93
//Definition of Registers buffer_ff and byte_ff
94
always @(posedge clk)
95
 begin
96
  if(!rst_n)
97
   begin
98
    buffer_ff  <= RESET_BUFFER;
99
    byte_ff    <= RESET_BYTE;
100
   end
101
  else
102
   begin
103
    if(buffer_en)
104
     buffer_ff <= bus_reversed;
105
    //else
106
    // if(buffer_rst)
107
    //  buffer_ff <= RESET_BUFFER;
108
 
109
    if(byte_en)
110
     byte_ff <= buffer_ff;
111
   end
112
 end
113
 
114
//Definition of Registers bf_size_ff and size_ff
115
always @(posedge clk)
116
 begin
117
  if(!rst_n)
118
   begin
119
    bf_size_ff <= RESET_BF_SIZE;
120
    size_ff    <= RESET_SIZE;
121
   end
122
  else
123
   begin
124
    if(buffer_en)
125
     bf_size_ff <= size_in;
126
    else
127
     if(buffer_rst)
128
      bf_size_ff <= RESET_BF_SIZE;
129
 
130
    if(byte_en)
131
     size_ff <= bf_size_ff;
132
   end
133
 end
134
 
135
//Mux to bypass size_ff
136
//This informatin is used by FSM to decide the size of the current operatin  
137
assign size_out = (bypass_size) ? bf_size_ff : size_ff;
138
 
139
assign byte0_in = byte_ff[ 7: 0];
140
assign byte1_in = byte_ff[15: 8];
141
assign byte2_in = byte_ff[23:16];
142
assign byte3_in = byte_ff[31:24];
143
 
144
//Mux to bypass byte0_ff
145
assign byte0_mux_out = (bypass_byte0) ? buffer_ff[7:0] : byte0_in;
146
 
147
//Mux to select input of CRC Unit
148
//TODO:AVALIAR A INFLUENCIA DA CODIFICACAO DA FSM NO SINAL BYTE_SEL 
149
always @(*)
150
 begin
151
  crc_data_in = 32'h0;
152
  case(byte_sel)
153
   BYTE_0: crc_data_in = byte0_mux_out;
154
   BYTE_1: crc_data_in = byte1_in;
155
   BYTE_2: crc_data_in = byte2_in;
156
   BYTE_3: crc_data_in = byte3_in;
157
   default:crc_data_in = 32'h0;
158
  endcase
159
 end
160
 
161
//Definition of Register crc_init_sel_ff
162
//This is a set/clear flop where the clear wins set
163
//This flop controls when the CRC operation is chained (crc_init_sel_ff = 1) or not
164
//In the chained operatin the current crc calculation depends of the previous crc calculated
165
//in the unchained operatin the current crc calculation depends of value of crc_init register
166
always @(posedge clk)
167
 begin
168
  if(!rst_n)
169
   crc_init_sel_ff <= RESET_CRC_INIT_SEL;
170
  else
171
   begin
172
    if(clear_crc_init_sel)
173
     crc_init_sel_ff <= 1'b0;
174
    else
175
     if(set_crc_init_sel)
176
      crc_init_sel_ff <= 1'b1;
177
   end
178
 end
179
 
180
//This register contains the init value used in non chained operatin of crc
181
assign crc_init_out = crc_init_ff;
182
always @(posedge clk)
183
 begin
184
  if(!rst_n)
185
   crc_init_ff <= RESET_CRC_INIT;
186
  else
187
   if(crc_init_en)
188
    crc_init_ff <= bus_wr;
189
         else
190
           if(buffer_rst)
191
                         crc_init_ff <= RESET_CRC_INIT;
192
 end
193
 
194
//This register contains the final value of crc
195
always @(posedge clk)
196
 begin
197
  if(!rst_n)
198
   crc_out_ff <= RESET_CRC_OUT;
199
  else
200
   if(crc_out_en)
201
    crc_out_ff <= crc_unit_out;
202
 end
203
 
204
//this is a general purpouse register
205
//see the spec for more details
206
assign crc_idr_out = crc_idr_ff;
207
always @(posedge clk)
208
 begin
209
  if(!rst_n)
210
   crc_idr_ff <= RESET_CRC_IDR;
211
  else
212
   if(crc_idr_en)
213
    crc_idr_ff <= bus_wr[7:0];
214
 end
215
 
216
//This register contains the polynomial coefficients to crc calculation
217
assign crc_poly_out = crc_poly_ff;
218
always @(posedge clk)
219
 begin
220
  if(!rst_n)
221
   crc_poly_ff <= RESET_CRC_POLY;
222
  else
223
   if(crc_poly_en)
224
    crc_poly_ff <= bus_wr;
225
 end
226
 
227
//Mux that define the type of operation (chained or not)    
228
assign crc_init_mux = (crc_init_sel_ff) ? crc_out_ff : crc_init_ff;
229
 
230
//Decoding of crc_poly_sizesignal
231
always @(*)
232
 begin
233
  crc_poly_size_7  = 1'b0;
234
  crc_poly_size_8  = 1'b0;
235
  crc_poly_size_16 = 1'b0;
236
  crc_poly_size_32 = 1'b0;
237
  case(crc_poly_size)
238
   POLY_SIZE_7 : crc_poly_size_7  = 1'b1;
239
   POLY_SIZE_8 : crc_poly_size_8  = 1'b1;
240
   POLY_SIZE_16: crc_poly_size_16 = 1'b1;
241
   POLY_SIZE_32: crc_poly_size_32 = 1'b1;
242
  endcase
243
 end
244
 
245
//This signal define the configurability of the CRC Unit
246
//In this case, the size of the polynomial can be: 7, 8, 16 or 32
247
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};
248
 
249
//Instanciation of CRC Unit
250
//The module is configured to calculate CRC of 32 bits for 8 bits of data in parallel
251
crc_parallel
252
#(
253
 .CRC_SIZE   ( 32 ),
254
 .FRAME_SIZE ( 8  )
255
)CRC_UNIT
256
(
257
 .crc_out       ( crc_unit_out     ),
258
 .data_in       ( crc_data_in      ),
259
 .crc_init      ( crc_init_mux     ),
260
 .crc_poly      ( crc_poly_ff      ),
261
 .crc_poly_size ( crc_poly_size_in )
262
);
263
 
264
//crc_out_rev[31:0] = crc_out_ff[0:31]
265
generate
266
 genvar i;
267
 for(i = 0; i < 32; i = i + 1)
268
  assign crc_out_rev[i] = crc_out_ff[31 - i];
269
endgenerate
270
 
271
assign crc_out = (rev_out_type) ? crc_out_rev : crc_out_ff;
272
 
273
endmodule

powered by: WebSVN 2.1.0

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