typedef enum logic [2:0] {ALU_ADD = 3'b000, ALU_SUBTRACT = 3'b001, ALU_MULTIPLY = 3'b010} AluFunctionCode;
在我的alu模块中,我正在使用这样的类型:
module ArithmeticLogicUnit #(parameter N=8) (
input logic [N-1:0] operand_a, operand_b,
input AluFunctionCode function_code,
output logic [N-1:0] result
);
在我的测试板中,我正在实例化Alu,如下所示:
logic [7:0] a, b, result;
AluFunctionCode functionCode;
ArithmeticLogicUnit alu (.operand_a(a), .operand_b(b), .function_code(functionCode), .result(result));
如何定义枚举类型并将其包含在多个模块中?
做到这一点的好方法是创建一个
package
和
import
some_pkg
,例如,创建一个用这些内容来创建文件:
package some_pkg;
typedef enum logic [2:0] {
ALU_ADD = 3'b000,
ALU_SUBTRACT = 3'b001,
ALU_MULTIPLY = 3'b010
} AluFunctionCode;
endpackage
import
:
import some_pkg::*;
module ArithmeticLogicUnit #(parameter N=8) (
input logic [N-1:0] operand_a, operand_b,
input AluFunctionCode function_code,
output logic [N-1:0] result
);
endmodule
import
:
module tb;
import some_pkg::*;
logic [7:0] a, b, result;
AluFunctionCode functionCode;
ArithmeticLogicUnit alu (
.operand_a(a), .operand_b(b), .function_code(functionCode),
.result(result)
);
endmodule