1
0
mirror of https://github.com/aolofsson/oh.git synced 2025-01-17 20:02:53 +08:00
oh/memory/hdl/memory_sp.v

56 lines
1.3 KiB
Coq
Raw Normal View History

/*###########################################################################
# Function: Single port memory wrapper
2015-04-18 16:11:21 -04:00
# To run without hardware platform dependancy use:
# `define TARGET_CLEAN"
############################################################################
*/
module memory_sp(/*AUTOARG*/
2015-04-21 17:10:22 -04:00
// Outputs
dout,
// Inputs
2015-04-21 17:10:22 -04:00
clk, en, wen, addr, din
);
parameter AW = 14;
parameter DW = 32;
parameter WED = DW/8; //one write enable per byte
parameter MD = 1<<AW;//memory depth
2015-04-18 16:11:21 -04:00
//write-port
input clk; //clock
2015-04-18 16:11:21 -04:00
input en; //memory access
input [WED-1:0] wen; //write enable vector
input [AW-1:0] addr;//address
input [DW-1:0] din; //data input
2015-04-21 17:10:22 -04:00
output [DW-1:0] dout;//data output
2015-04-18 16:11:21 -04:00
reg [DW-1:0] ram [MD-1:0];
2015-04-18 16:11:21 -04:00
reg [DW-1:0] rd_data;
2015-04-21 17:10:22 -04:00
reg [DW-1:0] dout;
//read port
always @ (posedge clk)
if(en)
2015-04-18 16:11:21 -04:00
dout[DW-1:0] <= ram[addr[AW-1:0]];
//write port
generate
genvar i;
2015-04-18 16:11:21 -04:00
for (i = 0; i < WED; i = i+1) begin: gen_ram
always @(posedge clk)
begin
2015-04-21 17:10:22 -04:00
if (wen[i] & en)
2015-04-18 16:11:21 -04:00
ram[addr[AW-1:0]][(i+1)*8-1:i*8] <= din[(i+1)*8-1:i*8];
end
end
endgenerate
endmodule // memory_dp