Domanda

I'm trying to implement a Router.

In the test bench, I'm using a Class to represent a packet in SystemVerilog, which include integer variables and some routines.

Now I'm trying to convert a Packet object to a logic vector.

I tried using static and dynamic casting and it didn't work.

I also tried to convert the Packet data to a struct and then converting the struct to a logic vector, but when I need to convert the vector back to struct it failed.

this is the temporary struct:

typedef struct {
    integer data;
    integer address;
    integer source;
    integer counter;
    integer failure;
} Packed_packet;

this is the conversion i'm trying to do:

logic [$bits(Packed_packet)-1:0] i;
Packed_packet packet1;
Packed_packet packet2;

assign i = packet1;
assign packet2 = i;//fails

can you help me to deal with this?

È stato utile?

Soluzione

You should look at the streaming operator to convert members of a class to an integral variable (pack) and back (unpack). Assuming p has a handle to a class object with the same member names as your struct:

i = {>>{p.data,p.address,p.source,p.counter,p.failure}}; //pack
{>>{p.data,p.address,p.source,p.counter,p.failure}} = i; //unpack

The code that you showed should have failed in both directions. You cannot make an assignment between packed and unpacked types without a cast.

typedef logic [$bits(Packed_packet)-1:0] temp_t;
temp_t i;
Packed_packet packet1;
Packed_packet packet2;

assign i = temp_t'(packet1);
assign packet2 = Packed_packet'(i);

Altri suggerimenti

You should probably be using a packed struct to do what you want. This will pack all of the bits together as an integral type (see section 7.2.1 of the standard):

typedef struct packed {
  integer data;
  integer address;
  integer source;
  integer counter;
  integer failure;
} Packed_packet;

The title of your question implies that you are passing this packet of data to synthesized logic. Does the logic really expect 5 integers, or do each of these pieces of the packet have different bit lengths? If so, then packing 5 integers together will not do what you want. I am guessing you want something like this:

typedef struct packed {
  bit [15:0] data;
  bit [15:0] address;
  bit [3:0] source;
  bit [3:0] counter;
  bit failure;
} Packed_packet;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top