本帖最后由 hotpower 于 2023-9-21 11:19 编辑
/*-----------------------------------------------------------------------------------------------
HotCRC CRC8R_8C_00_00 FPGA模块 HotPower[url=home.php?mod=space&uid=516618]@163.com[/url] 2023-09-21 10:49:06
-----------------------------------------------------------------------------------------------*/
module CRC8R_8C(clk, rst, data, outcrc8)
input clk, rst;
input [7:0] data;
output reg[7:0] outcrc8;
reg [7:0] crc8;
task CRC8R_8C;
inout[7:0] crc8;
input[7:0] indata;
crc8 = CRC8R_8C_Table(crc8 ^ indata);
endtask
function [7:0] CRC8R_8C_Table;
input [7:0] data;
CRC8R_8C_Table = CRC8R_8C_Table0(data[1:0]) ^ CRC8R_8C_Table1(data[3:2]) ^ CRC8R_8C_Table2(data[5:4]) ^ CRC8R_8C_Table3(data[7:6]);
endfunction
function [7:0] CRC8R_8C_Table0;
input[1:0] data;
case(data)
2'b00: CRC8R_8C_Table0 = 8'h00; 2'b01: CRC8R_8C_Table0 = 8'h5E; 2'b10: CRC8R_8C_Table0 = 8'hBC; 2'b11: CRC8R_8C_Table0 = 8'hE2;
default: CRC8R_8C_Table0 = 8'h00;
endcase
endfunction
function [7:0] CRC8R_8C_Table1;
input[1:0] data;
case(data)
2'b00: CRC8R_8C_Table1 = 8'h00; 2'b01: CRC8R_8C_Table1 = 8'h61; 2'b10: CRC8R_8C_Table1 = 8'hC2; 2'b11: CRC8R_8C_Table1 = 8'hA3;
default: CRC8R_8C_Table1 = 8'h00;
endcase
endfunction
function [7:0] CRC8R_8C_Table2;
input[1:0] data;
case(data)
2'b00: CRC8R_8C_Table2 = 8'h00; 2'b01: CRC8R_8C_Table2 = 8'h9D; 2'b10: CRC8R_8C_Table2 = 8'h23; 2'b11: CRC8R_8C_Table2 = 8'hBE;
default: CRC8R_8C_Table2 = 8'h00;
endcase
endfunction
function [7:0] CRC8R_8C_Table3;
input[1:0] data;
case(data)
2'b00: CRC8R_8C_Table3 = 8'h00; 2'b01: CRC8R_8C_Table3 = 8'h46; 2'b10: CRC8R_8C_Table3 = 8'h8C; 2'b11: CRC8R_8C_Table3 = 8'hCA;
default: CRC8R_8C_Table3 = 8'h00;
endcase
endfunction
always @(posedge clk or negedge rst)
begin
if (!rst)
begin
crc8 <= 8'h00;
end
else
begin
CRC8R_8(crc8, data);
outcrc8 <= crc8;
crc8 <= crc8;
end
end
endmodule
|