I am trying to add 2 header bytes to payload bytes, in order to calculate the CRC which is based on the calculation of header and payload bytes and using polynomial (x^16 + x^12 + x^5 + x). I need to add the crc to the transaction packets.
The payload bytes are created by dynamic array method. When I try to add the 2 header bytes with dynamic array bytes for the calculation of CRC, it gives error. Can some one plz tell me how to add the 2 header bytes with payload bytes? plz find below the portion of code. Plz have a look at it and give me suggestion.
Dear sir,
I am getting following errors when I tried to add header bytes to the payload bytes in order to calculate CRC which is dependent on both header(2 bytes) and payload bytes.
Errors are:- Error: transaction.sv(30): Illegal operation on unpacked types
Error: transaction.sv(30): Cannot assign a packed type to an unpacked type.
So can you plz tell me how to defeat this error as I really need to add the header bytes to the payload bytes.
OK, so the statement N = n + payload; is giving you trouble?
Can you give an example of values for n and payload and what the result should be? Did you really mean mathematical “addition” or do you mean “concatenation”?
How do expect the statement for ( j = 0; j <= N ; j++) to loop since N is an array, not an integer? You have a return statement inside your loop so the loop only executes once. Where does data get its value?
Swapnil,
Based on your description it looks like you need to first put header as 2 elements in the new “N” array, followed by “payload”.
If so, try the following:
function [15:0] cal_crc;
int j;
bit [7:0]data;
bit [15:0] n;
bit [7:0] N[];
reg [15:0] newcrc;
n = header;
N = new [this.payload.size + 2]; // 2 more for header
N = { >> {n, payload} };
`uvm_info ("CVC-Dbg", $sformatf("header + payload: %p", N), UVM_MEDIUM);
for ( j = 0; j < N.size ; j++)
begin
i.e. use streaming operator >> - works fine for simple data types.
Hello Ajeetha Madam,
Thank you so much for your suggestion. It has helped in solving my problem. So I replaced data[j] with N[j] as an input byte to calculate the CRC. Thats correct, right?
Also I put return newcrc outside the for loop and not inside the for loop? Because it gives different crc values. So In order to calculate the crc value for each byte of N[j] , its better to put return newcrc outside the For loop, right? Please correct me if I am wrong.This is how I did it as shown below:-
function [15:0] cal_crc;
int j;
bit [7:0]data;
bit [15:0] n;
bit [7:0] N;
reg [15:0] newcrc;
I believe you want to do c = newcrc; each time through the loop. Otherwise c is always 0. There is no need to do N =new[…];. Anytime you assign an array to dynamic array, the dynamic array is automatically re-sized to fit. Also, it would really help to format your code to make it more readable