Hello All,
I created payload by dynamic arrays in a packet class. Now I want to use these dynamically created payload bytes in CRC generation for polynomial x^16 + x^12 + x^5 + 1, for data width 8 bits.
Following is the code of CRC I am using:
function [15:0] cal_crc( byte payload);//[1:10]);
//int j;
//for ( integer j = 1; j <= 10 ; j++)
begin
bit [15:0] crc;
reg [7:0] d;
reg [15:0] c;
reg [15:0] newcrc;
d = payload;//[j];
c = crc;
newcrc[0] = d[4] ^ d[0] ^ c[8] ^ c[12];
newcrc[1] = d[5] ^ d[1] ^ c[9] ^ c[13];
newcrc[2] = d[6] ^ d[2] ^ c[10] ^ c[14];
newcrc[3] = d[7] ^ d[3] ^ c[11] ^ c[15];
newcrc[4] = d[4] ^ c[12];
newcrc[5] = d[5] ^ d[4] ^ d[0] ^ c[8] ^ c[12] ^ c[13];
newcrc[6] = d[6] ^ d[5] ^ d[1] ^ c[9] ^ c[13] ^ c[14];
newcrc[7] = d[7] ^ d[6] ^ d[2] ^ c[10] ^ c[14] ^ c[15];
newcrc[8] = d[7] ^ d[3] ^ c[0] ^ c[11] ^ c[15];
newcrc[9] = d[4] ^ c[1] ^ c[12];
newcrc[10] = d[5] ^ c[2] ^ c[13];
newcrc[11] = d[6] ^ c[3] ^ c[14];
newcrc[12] = d[7] ^ d[4] ^ d[0] ^ c[4] ^ c[8] ^ c[12] ^ c[15];
newcrc[13] = d[5] ^ d[1] ^ c[5] ^ c[9] ^ c[13];
newcrc[14] = d[6] ^ d[2] ^ c[6] ^ c[10] ^ c[14];
newcrc[15] = d[7] ^ d[3] ^ c[7] ^ c[11] ^ c[15];
$display("The value of CRC result newcrc = %h ",newcrc);
return newcrc;
end
endfunction : cal_crc
AND THIS IS HOW I GENERATED payload through dynamic array:-
class transaction extends uvm_sequence_item;//uvm_transaction; //uvm_sequence_item;
`uvm_object_utils(transaction)
rand bit [7:0] sync;
rand bit [15:0] sof;
rand bit [15:0] header;
rand bit[7:0] payload;
rand bit [15:0] crc;
rand bit [7:0] eof;
constraint data_size_c { payload.size inside { [1 : 10]};};
Can some one please help me that how shall I provide these payload bytes in the CRC function. As you can see in the cal_crc function, I tried to do it by passing argument by value. but its not working. Please help me with this. Its kinda urgent.
Any help is appreciated.
Thanks,
Swapnil