Subversion Repositories ngs

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 lvd 1
// part of NeoGS project (c) 2007-2008 NedoPC
2
//
3
// mem512b is 512 bytes synchronous memory, which maps directly to the EAB memory block of ACEX1K.
4
// rdaddr is read address, dataout is the data read. Data is read with 1-clock latency, i.e. it
5
//  appears after the positive clock edge, which locked rdaddr.
6
// wraddr is write address, datain is data to be written. we enables write to memory: when it
7
//  locks as being 1 at positive clock edge, data contained at datain is written to wraddr location.
8
//
9
// clk     __/``\__/``\__/``\__/``\__/``
10
// rdaddr     |addr1|addr2|
11
// dataout          |data1|data2|
12
// wraddr           |addr3|addr4|
13
// datain           |data3|data4|
14
// we      _________/```````````\_______
15
//
16
// data1 is the data read from addr1, data2 is read from addr2
17
// data3 is written to addr3, data4 is written to addr4
18
//
19
// simultaneous write and read to the same memory address lead to undefined read data.
20
 
21
module mem512b(
22
 
23
        rdaddr, // read address
24
        wraddr, // write address
25
 
26
        datain,  // write data
27
        dataout, // read data
28
 
29
        we, // write enable
30
 
31
        clk
32
);
33
 
34
        input [8:0] rdaddr;
35
        input [8:0] wraddr;
36
 
37
        input      [7:0] datain;
38
        output reg [7:0] dataout;
39
 
40
        input we;
41
 
42
        input clk;
43
 
44
 
45
        reg [7:0] mem[0:511]; // memory block
46
 
47
 
48
 
49
        always @(posedge clk)
50
        begin
51
                dataout <= mem[rdaddr]; // reading data
52
 
53
                if( we ) // writing data
54
                begin
55
                        mem[wraddr] <= datain;
56
                end
57
        end
58
 
59
 
60
endmodule
61