-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemory_block.v
More file actions
34 lines (30 loc) · 891 Bytes
/
memory_block.v
File metadata and controls
34 lines (30 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
`ifndef __MEMORYBLOCK__
`define __MEMORYBLOCK__
module memory_block
#(
parameter DATA_WIDTH = 8
)
(
input wire clk, // clock
input wire ceb, // chip enable, if not enable, can't read from this memory
input wire web, // write/read, 0 for write, 1 for read
input wire write_en, // write enable
input wire [ 9: 0] A, // address
input wire [DATA_WIDTH-1: 0] D, // data write into memory
output reg [DATA_WIDTH-1: 0] Q // data read from memory
);
reg [ DATA_WIDTH-1:0] m_array[1023: 0]; // the memory is 816*32, each line in memory is 32 bits
//-----------------------------
// write data
always @(posedge clk) begin
if(~web & write_en & ~ceb)
m_array[A] <= D;
end
// read data
always @(posedge clk) begin
if(~ceb & web) begin
Q <= m_array[A];
end
end
endmodule
`endif