Hi, I’ve got a situation where I need to convert a bit into an enum. I’m looking at a code example from a book.
In class command_monitor, there is this line that tries to take op (bit[2:0]) and pass it’s value to an enumerated type (cmd.op):
cmd.op = op2enum(op);
VCS simulator has no idea what op2enum() is, so I’ve tried other things:
cmd.op = operation_t’(op);
$cast(cmd.op, op);
So far nothing works, those casting attempts get me a message:
Error-[IATC] Illegal argument to $cast
/apps/vcsmx/etc/uvm-1.2/src/tlm1/uvm_analysis_port.svh, 74
Illegal or unsupported arguments to $cast.
Source info: $cast(obj, t)
Does anybody know to get the value of op into the enumerated type? Thanks!
package tinyalu_pkg;
import uvm_pkg::*;
`include "uvm_macros.svh"
typedef enum bit[2:0] {no_op = 3'b000,
add_op = 3'b001,
and_op = 3'b010,
xor_op = 3'b011,
mul_op = 3'b100,
rst_op = 3'b111} operation_t;
typedef struct {
byte unsigned A;
byte unsigned B;
operation_t op;
} command_s;
endpackage : tinyalu_pkg
class command_monitor extends uvm_component;
`uvm_component_utils(command_monitor);
**uvm_analysis_port #(command_s) ap;**
virtual tinyalu_bfm bfm;
function new (string name, uvm_component parent);
super.new(name, parent);
endfunction : new
function void build_phase(uvm_phase phase);
if(!uvm_config_db #(virtual tinyalu_bfm)::get(null, "*","bfm", bfm)) $fatal("Failed to get BFM");
bfm.command_monitor_h = this;
ap = new("ap", this);
endfunction : build_phase
function void write_to_monitor(byte A, byte B, bit[2:0] op);
command_s cmd;
cmd.A = A;
cmd.B = B;
cmd.op = op2enum(op); <- CASTING HAPPENS HERE
`uvm_info("blah", $psprintf("COMMAND MONITOR: A:0x%2h B:0x%2h op: %s", A, B, cmd.op.name()), UVM_NONE);
ap.write(cmd);
endfunction : write_to_monitor
endclass : command_monitor