Reputation: 445
I have an queue, which I want to init with the binary value. What is the best way to do that?
logic serial_frame[$];
// Want to init with 0010_0000_1000_0
Upvotes: 0
Views: 377
Reputation: 42698
There are a couple of ways to do this.
Array Concatenation: { list of values for each queue element }
serial_frame = {0,0,1,0, 0,0,0,0, 1,0,0,0, 0}; // first element is serial_frame[0]
Bit-stream cast: uses a type to reformat source to target type
typedef logic bitstream_t[$];
serial_frame = bitstream_t'(13'b0010_0000_1000_0);
The MSB of the source becomes serial_frame[0]. The size of the target must be adjustable to the size of the target. (not a problem with 1-bit queue, but would be an error if you had a queue of 8-bit bytes)
Streaming operator (unpack). You can chose the order of the stream
{>>{serial_frame}} = 13'b0010_0000_1000_0; // same ordering as bit-stream cast
{<<{serial_frame}} = 13'b0010_0000_1000_0; // reverse ordering - LSB is serial_frame[0];
The streaming operator is probably the easiest for your situation, but be aware that for other target types, it left-justifies data unlike normal assignments which right-justifies data. It also 0-pads data when the source size is smaller than the target.
See sections 10.10 Unpacked array concatenation, 6.24.3 Bit-stream casting, and 11.4.14 Streaming operators (pack/unpack) in the IEEE 1800-2017 SystemVerilog LRM.
Upvotes: 1