|
楼主 |
发表于 2011-11-16 05:16:08
|
显示全部楼层
回复 4# pwb1118
楼上的能指教一下么,我用双口RAM做了个乒乓结构,写入是没问题,但是我想实现在写A的时候读B该怎么操作呢?
module ram ( clk, rst_n, idin, dout_a, dout_b);
input clk;
input rst_n;
input [7:0] idin;
output [7:0] dout_a, dout_b;
reg rd_a, rd_b;
reg wr_a, wr_b;
reg [4:0] addr_a, addr_b;
reg [7:0] data_a, data_b;
wire a ,b;
assign a = addr_a == 'b1_1111 ? 1 : 0;
assign b = addr_b == 'b1_1111 ? 1 : 0;
always @ (posedge clk or negedge rst_n)
if (!rst_n)
begin
wr_a <= 1'b1; //A的写使能
wr_b <= 1'b0; //B的写使能
rd_a <= 1'b0; //A的读使能
rd_b <= 1'b1; //B的读使能
end
else if (a)
begin
wr_a <= 1'b0;
wr_b <= 1'b1;
rd_a <= 1'b1;
rd_b <= 1'b0;
end
else if (b)
begin
wr_a <= 1'b1;
wr_b <= 1'b0;
rd_a <= 1'b0;
rd_b <= 1'b1;
end
always @ (posedge clk or negedge rst_n)
if (!rst_n)
begin
data_a <= 'b0;
addr_a <= 'b0;
data_b <= 'b0;
addr_b <= 'b0;
end
else if (wr_a) // 这里想在写A的时候同时读B,不知道该怎么写了
begin
data_a <= idin;
addr_a <= addr_a + 1'b1;
end
else if (wr_b) // write. b read a
begin
data_b <= idin;
addr_b <= addr_b + 1'b1;
end
dualram ram (
// input
.address_a(addr_a),
.address_b(addr_b),
.clock(clk),
.data_a(data_a),
.data_b(data_b),
.rden_a(rd_a),
.rden_b(rd_b),
.wren_a(wr_a),
.wren_b(wr_b),
//output
.q_a(dout_a),
.q_b(dout_b)
);
endmodule |
|