这并不是要实际创建一个带有 inout 端口的 verilog 模块。我发现了很多关于这个的帖子。
我坚持的是,如果我有一个带有输入端口的黑盒模块,假设它的定义如下
module blackbox(inout a, in b, in c)
我想在不同的模块中实例化它
module myModule(input reg inReg, output wire outWire)
blackbox(outWire);
我如何还使用 inReg 驱动黑盒并在不同时间将其输出到 outWire 上?我不知道如何连接一个和断开另一个。这显然过于简单化了。我真正拥有的是下面,但它更复杂。
module sram_control(
input wire HCLK,
input wire [20:0] HADDR,
input wire HWRITE,
input wire [1:0] HTRANS,
input wire [7:0] HWDATA,
output reg [7:0] HRDATA
);
parameter IDLE_PHASE = 2'b00;
parameter WRITE_PHASE = 2'b01;
parameter READ_PHASE = 2'b10;
parameter IDLE = 2'b00;
parameter NONSEQ = 2'b10;
parameter READ = 1'b0;
parameter WRITE = 1'b1;
reg current_state, next_state;
wire CE, WE, OE;
reg [20:0] A;
wire [7:0] DQ;
reg [7:0] DQ_tmp1;
wire [7:0] DQ_tmp2;
async the_mem(.CE_b(CE), .WE_b(WE), .OE_b(OE), .A(A), .DQ(DQ));
always @(posedge HCLK) begin
if(current_state == IDLE_PHASE) begin
next_state <= HTRANS == NONSEQ? (HWRITE == WRITE? WRITE_PHASE : READ_PHASE) : IDLE_PHASE;
A <= HADDR;
end
else if(current_state != IDLE_PHASE) begin
if(HTRANS == NONSEQ) begin
if(HWRITE == WRITE) begin
next_state <= WRITE_PHASE;
end
else begin
next_state <= READ_PHASE;
end
end
else next_state <= IDLE_PHASE;
end
// we never get here
else next_state <= IDLE_PHASE;
end
always@(posedge HCLK) begin
if(current_state == READ_PHASE) HRDATA <= DQ;
end
assign CE = current_state != IDLE_PHASE? 1 : 0;
assign WE = current_state != IDLE && HWRITE == WRITE? 1 : 0;
assign OE = current_state != IDLE_PHASE? 1 : 0;
always@(posedge HCLK) current_state <= next_state;
endmodule
我需要一种在我想写入异步模块时将 HWDATA 分配给它的方法,并且当我想从异步中读取时,我需要一种将异步模块的输出分配给 HRDATA 的方法。