使用单个 in/out 数据端口在 `Verilog` 中创建 `RAM` 芯片

Creating a `RAM` chip in `Verilog` with single in/out data port

我想在 verilog 中创建一个 RAM 芯片来学习 Verilog,像 RAMEEPROM 这样的现代芯片如何允许通过单个地址端口和单个数据端口。(数据端口是输入和输出端口) 我想在 Verilog 中做同样的事情,我想我需要 inout 类型,但我不知道它是如何工作的。 我 google 它,但我能找到的所有 RAM 示例都有一个单独的数据写入和数据读取端口。 由于 inout 类型要求两侧都连接到电线,我需要将一根电线从一侧连接到地址选择的 reg。(所以没有分配)。但我不知道该怎么做。

这是我试过但行不通的方法:

wire [7:0] a;
wire rw;// 0 if read, 1 if write
reg [7:0] mem [16];
initial begin
  if (rw == 1) begin
    #1 a = mem[0];// 0 would be the address wire, but excluding it for clarity
  end
  if (rw == 0) begin
    #1 mem[0] = a;// 0 would be the address wire, but excluding it for clarity
  end
end

有人能帮忙吗?

谢谢

all RAM examples I can find have a separate data write and data read port.

原因是两个事实的结合:

  1. 真正的双向数据总线需要三态驱动器。

  2. FPGA 或 ASIC 芯片不再具有片上三态驱动程序。

唯一可能存在双向数据的地方是 I/O,那里有三态焊盘。

因此在内部每个人都会使用两条数据总线,因为任何实际内存的核心都会有一个单独的读取数据和写入数据总线。然后在边缘(在焊盘处)它们将切换到双向模式。

要编写您自己的 Verilog 双向总线,您应该使用三态信号分配。大致如下:

inout[7:0] data_bus,

// This assignment is inside the memory model:
// Driving the read data out of the memory device
assign data_bus = mem_read ? mem_read_data : 8'hzz;


// This assignment is outside the memory model
// Driving the write data into the memory device
assign data_bus = mem_read ? 8'hzz : external_driver;