简体   繁体   English

SystemVerilog值不在typedef枚举内

[英]SystemVerilog Values not inside a typedef enum

I can't figure out where I am going wrong. 我不知道哪里出了问题。 I have a command structure (actually around 100 commands) defined in a similar manner as follows. 我有一个命令结构(实际上是大约100个命令),其定义方式如下。

    typedef enum bit [15:0] { 
     CMD_1A           = 16'h1000,
     CMD_1B           = 16'h1100,
     CMD_1C           = 16'h1110,
     CMD_2A           = 16'h2000,
     CMD_2B           = 16'h2100,
     CMD_2C           = 16'h2200,
     CMD_2D           = 16'h2300,
     CMD_3A           = 16'h3000,
     CMD_4A           = 16'h4000,
     CMD_4B           = 16'h4010
      } command_type_e;

     rand command_type_e cmd_type;

Around the first # (1, 2, 3 or 4) I have a class which breaks out format. 在第一个#(1、2、3或4)周围,我有一个分解格式的类。 These commands have common parts while other command sections are unique. 这些命令具有相同的部分,而其他命令部分则是唯一的。 This is easy enough to control since all the valid values are defined in this typedef. 这很容易控制,因为所有有效值都在此typedef中定义。

After checking valid commands defined in the list I want to check is all the undefined values so I can see how my command controller handles them and if these invalid messages get discarded correctly. 在检查了列表中定义的有效命令后,我要检查的是所有未定义的值,这样我就可以看到命令控制器如何处理它们以及这些无效消息是否被正确丢弃。

I tried to create an invalid group and constrain it to be not inside the valid types but this doesn't work. 我试图创建一个无效的组并将其限制为不在有效类型之内,但这不起作用。

    rand bit [15:0] inv_cmd_type;
    constraint not_in_range {!(inv_cmd_type inside {command_type_e});}

I tried a couple other ways without much success. 我尝试了其他几种方法,但收效甚微。 I can put in specific values but that is a mess especially since that list would have to be tracked every time a new command is created. 我可以输入特定的值,但这很麻烦,因为每次创建新命令时都必须跟踪该列表。

Thoughts on how to define all the items not in that list? 关于如何定义不在该列表中的所有项目的想法?

Thanks! 谢谢!

You can create a list of all literals inside the enum using the pattern described in section 6.19.5.7 Using enumerated type methods of the 2012 LRM. 您可以使用6.19.5.7节中所述的模式创建枚举内所有文字的列表,该模式使用2012 LRM的枚举类型方法。 Adapted to your case (and fixed formatting): 适应您的情况(和固定格式):

command_type_e cmd = cmd.first;
command_type_e all_cmds[$];
forever begin
  all_cmds.push_back(cmd);
  if (cmd == cmd.last())
    break;
  cmd = cmd.next();
end

Based on this list, it's trivial to create a constraint. 根据此列表,创建约束很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM