-
Notifications
You must be signed in to change notification settings - Fork 1
/
crc_ci.v
152 lines (136 loc) · 2.72 KB
/
crc_ci.v
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
module crc_ci (
input clk,
input reset,
input [4:0] enable,
input load,
input [63:0] i_data,
output reg [31:0] crc_o,
output reg done
);
reg [31:0] crc_mem[0:255]; //CRC TABLE
reg [31:0] crc_o_next;
reg [7:0] bytedata;
reg evaluate;
reg [2:0] counter;
reg [2:0] counter_next;
initial begin
$readmemh("CRC.hex", crc_mem);
end
always @(posedge clk) begin
if(reset) begin
crc_o <= 32'h4E08BFB4;
end
else begin
crc_o <= crc_o_next;
end
end
always @(crc_o or load or evaluate or i_data or bytedata) begin
crc_o_next = crc_o;
if(load) begin
crc_o_next = i_data;
end
else if(evaluate) begin
crc_o_next = ( { crc_o[23:0], 8'h0 } ^ crc_mem[ crc_o[31:24] ^ bytedata ] );
end
end
always @(posedge clk) begin
if(reset) begin
counter <= 3'b000;
end
else begin
counter <= counter_next;
end
end
always @(counter or enable or i_data) begin
counter_next = 3'b000;
bytedata = 8'h0;
evaluate = 1'b0;
done = 1'b1;
case(counter)
3'b000 : begin
if(enable[0]) begin
bytedata = i_data[7:0];
evaluate = 1'b1;
if(enable[1]) begin
counter_next = 3'b001;
done = 1'b0;
end
else begin
done = 1'b1;
end
end
end
3'b001 : begin
if(enable[1]) begin
bytedata = i_data[15:8];
evaluate = 1'b1;
if(enable[2]) begin
counter_next = 3'b010;
done = 1'b0;
end
else begin
done = 1'b1;
end
end
end
3'b010 : begin
if(enable[2]) begin
bytedata = i_data[23:16];
evaluate = 1'b1;
if(enable[3]) begin
counter_next = 3'b011;
done = 1'b0;
end
else begin
done = 1'b1;
end
end
end
3'b011 : begin
if(enable[3]) begin
bytedata = i_data[31:24];
evaluate = 1'b1;
if(enable[4]) begin
counter_next = 3'b100;
done =1'b0;
end
else begin
done = 1'b1;
end
end
end
3'b100 : begin
if(enable[4]) begin
bytedata = i_data[39:32];
evaluate = 1'b1;
counter_next = 3'b101;
done =1'b0;
end
end
3'b101 : begin
if(enable[4]) begin
bytedata = i_data[47:40];
evaluate = 1'b1;
counter_next = 3'b110;
done =1'b0;
end
end
3'b110 : begin
if(enable[4]) begin
bytedata = i_data[55:48];
evaluate = 1'b1;
counter_next = 3'b111;
done =1'b0;
end
end
3'b111 : begin
if(enable[4]) begin
bytedata = i_data[63:56];
evaluate = 1'b1;
counter_next = 3'b000;
done = 1'b1;
end
end
endcase
end
endmodule