Jump to content

Help in providing dynamic array elements to a CRC generation function?


Recommended Posts

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++)


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); //result);

return newcrc; //result;


endfunction : cal_crc

AND THIS IS HOW I GENERATED payload through dynamic array:-

class transaction extends uvm_sequence_item;//uvm_transaction; //uvm_sequence_item;


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.



Link to comment
Share on other sites

You can use TLM.Can you explain where you want to use cal_crc in your environment?

According to what I understand,the flow could be like this:-

Your model for cal_crc can make a TLM port which will be connected to monitor (port-import connection).

Now, whatever payload you are driving to DUT, will also be visible to monitor_cb (interface connections) and can be extracted from there.

Now though monitor - model TLM port connections you can pass that payload to your cal_crc model.

Additionally, score boarding can be done by making TLM port connections between model and scoreboard.



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...