将枚举转换为逻辑 [英] Casting enum to logic
问题描述
考虑以下模块声明:
module DFF(d, q, CLK, RESET);
parameter W = 2;
input [W-1:0] d;
input CLK;
input RESET;
output logic [W-1:0] q;
//....
endmodule
在 d 和 q 是枚举类型的情况下实例化它的正确方法是什么?这是我的枚举类型:
What is the proper way of instantiating it where d and q are of enum type? Here is my enum type:
typedef enum logic [1:0] {ENUM_IDLE = 0,
ENUM_S1 ,
ENUM_S2
} T_STATE;
我想为 T_STATE 变量类型实例化 DFF:
I would like to instantiate the DFF for a T_STATE variable type:
T_STATE d, q;
DFF dff_inst (.d(d), .q(q), .CLK(CLK), .RESET(RESET));
这会产生编译/枚举错误.我也试过不成功:
This generates compile/enumeration error. I have also unsuccessfully tried:
DFF dff_inst (.d(logic'(d)), .q(logic'(q)), .CLK(CLK), .RESET(RESET));
和
DFF dff_inst (.d(logic[1:0]'(d)), .q(logic[1:0]'(q)), .CLK(CLK), .RESET(RESET));
我想保持 DFF 定义不变,但将枚举类型转换为逻辑.
I would like to keep the DFF definition as is, but cast the enum type to logic.
这个,在 IEEE Std 1800-2012 中建议, 6.24.1, 也会产生精化错误:
This one, suggested in IEEE Std 1800-2012, 6.24.1, also generates an elaboration error:
typedef logic [$bits(T_STATE) - 1 : 0] T_STATE_LOGIC;
DFF dff_inst (.d(T_STATE_LOGIC'(d)), .q(T_STATE_LOGIC'(q)), .CLK(CLK), .RESET(RESET));
推荐答案
d
不需要强制转换.
我只能用 ModelSim 重现错误,我可以访问的所有其他模拟器都没有产生任何错误或警告并且模拟正确.
I could only reproduce the error with ModelSim, all the other simulators I have access to didn't generate any errors or warnings and simulated correctly.
对于 ModelSim,我发现这有效:
For ModelSim, I found that this worked:
DFF dff_inst (.q(q[1:0]), .*);
这奏效了:
DFF dff_inst (.q({q}), .*);
这篇关于将枚举转换为逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!