If I receive an enum:
my_cmd cmd = my_cmd'(value_from_bus);
How do I easily check that cmd
is a valid cmd?
typedef enum int {
ADD = 1,
SUBTRACT = 3,
MULTIPLY = 7
} my_cmd;
You can also use $cast
to check if it is valid, and copy at the same time.
So instead of doing: cmd = my_cmd'(value_from_bus);
, you can do this:
if ($cast(cmd, value_from_bus))
$display("Valid: %s", cmd.name());
else
$display("Invalid");
Example on EDA Playground
You can use enum's name() function:
if (cmd.name() == "")
$display("%0d is bad", cmd);
else
$display("%s:%0d is good", cmd.name(), cmd);
Example on EDA Playground
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With