DATA
バス幅がパラメーターとして各インスタンスに渡され、パラメーターに従ってデザインが再構成されるメモリ モジュールを作成するにはどうすればよいですか? たとえば、バイトアドレス指定可能なメモリがあり、DATA-IN
バス幅が 32 ビット (各サイクルで 4 バイトが書き込まれる) で、DATA-OUT
16 ビット (各サイクルで 2 バイトが読み取られる) であると仮定します。他のインスタンスDATA-IN
は 64 ビットで、DATA-OUT
16 ビットです。そのようなすべてのインスタンスで、私のデザインは機能するはずです。
私が試したのは、設計パラメーター (たとえばDATA-IN
32 ビット) に従って書き込みポインター値を生成することです。書き込みポインターは、書き込み中にサイクルごとに 4 増加します。64 ビットの場合、インクリメントは 8 などになります。
問題は次のとおりです。インスタンスに渡されたパラメーターに従って、4、8、または 16 バイトを 1 サイクルで書き込む方法を教えてください。
//Something as following I want to implement. This memory instance can be considered as internal memory of FIFO having different datawidth for reading and writing in case you think of an application of such memory
module mem#(parameter DIN=16, parameter DOUT=8, parameter ADDR=4,parameter BYTE=8)
(
input [DIN-1:0] din,
output [DOUT-1:0] dout,
input wen,ren,clk
);
localparam DEPTH = (1<<ADDR);
reg [BYTE-1:0] mem [0:DEPTH-1];
reg wpointer=5'b00000;
reg rpointer=5'b00000;
reg [BYTE-1:0] tmp [0:DIN/BYTE-1];
function [ADDR:0] ptr;
input [4:0] index;
integer i;
begin
for(i=0;i<DIN/BYTE;i=i+1) begin
mem[index] = din[(BYTE*(i+1)-1):BYTE*(i)]; // something like this I want to implement, I know this line is not allowed in verilog, but is there any alternative to this?
index=index+1;
end
ptr=index;
end
endfunction
always @(posedge clk) begin
if(wen==1)
wpointer <= wptr(wpointer);
end
always @(posedge clk) begin
if(ren==1)
rpointer <= ptr(rpointer);
end
endmodule