这是我的代码:
define.v
`ifndef DEFINE_V
`define DEFINE_V
// define data path width
`define DP_WIDTH 32
// define operation code width
`define OPCODE_WIDTH 6
parameter[`OPCODE_WIDTH - 1:0] OP_ADD = 6'b00_0001; // add operation
parameter[`OPCODE_WIDTH - 1:0] OP_SUB = 6'b00_0002; // sub op
parameter[`OPCODE_WIDTH - 1:0] OP_JMP = 6'b00_0003; // jump op
`endif
A.v
`include "define.v"
module modA(
input in,
input[`OPCODE_WIDTH - 1:0] op,
output out
);
always @(*)
begin
// use parameter in case statement
case(op)
OP_ADD : // do something
OP_SUB : // do something
OP_JMP : // do something
endcase
end
endmodule
A_test.v
`include "define.v"
module Atest;
reg in;
wire out;
reg[`OPCODE_WIDTH - 1:0] op;
modA(
.in(in),
.op(op),
.out(out)
);
initial
begin
#200 op = OP_ADD;
#200 op = OP_SUB;
#200 op = OP_JMP;
end
endmodule
当我使用ISE 14.5 / ISim检查语法时,它已声明<SIZE>
已声明。似乎包括警卫不起作用。在Verilog中包含参数定义文件的正确方法是什么?