如何在 verilog 任务中处理双向引脚(inout)
How to handle bidirectional pin (inout) in a verilog task
我想在我的controller.Here代码中使用双向数据总线
module controller ( clk, data_out);
// Port Declaration
input clk;
inout [7:0] data_out;
reg [7:0] a;
reg [7:0] b;
wire [7:0] c;
// data should write to data_out (data_out act as output)
task write;
input c;
begin
assign data_out = a;
data_out <= c;
end
endtask
// data should read from data_out (data_out act as input)
task read;
output b;
begin
assign data_out = 8'bz;
b <= data_out;
end
endtask
endmodule
当我编译这个时,我收到一条错误消息
LHS in procedural continuous assignment may not be a net: data_out.
说 assign data_out = a;
和 assign data_out = 8'bz;
有错误
我知道分配应该在 always 或 initial 块中完成,但在使用这些块的任务中是 useless/give eroor
那么,我们如何才能在任务中改变总线的方向??
您不应该在 initial 和 always 块中使用 assign。我不明白为什么您一定要在任务中使用它?
只需单独使用分配。为双向端口赋值需要一个标志来指定应该执行什么操作——读或写。语法如下:
assign bidir_port = [flag] ? a : 1'bz;
我想在我的controller.Here代码中使用双向数据总线
module controller ( clk, data_out);
// Port Declaration
input clk;
inout [7:0] data_out;
reg [7:0] a;
reg [7:0] b;
wire [7:0] c;
// data should write to data_out (data_out act as output)
task write;
input c;
begin
assign data_out = a;
data_out <= c;
end
endtask
// data should read from data_out (data_out act as input)
task read;
output b;
begin
assign data_out = 8'bz;
b <= data_out;
end
endtask
endmodule
当我编译这个时,我收到一条错误消息
LHS in procedural continuous assignment may not be a net: data_out.
说 assign data_out = a;
和 assign data_out = 8'bz;
有错误
我知道分配应该在 always 或 initial 块中完成,但在使用这些块的任务中是 useless/give eroor
那么,我们如何才能在任务中改变总线的方向??
您不应该在 initial 和 always 块中使用 assign。我不明白为什么您一定要在任务中使用它? 只需单独使用分配。为双向端口赋值需要一个标志来指定应该执行什么操作——读或写。语法如下:
assign bidir_port = [flag] ? a : 1'bz;