Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1029 chrv 1
`include "../include/tune.v"
2
 
3
module drammem(
4
        input   [9:0] ma,
5
        inout [15:0] d,
6
        input ras_n,
7
        input ucas_n,
8
        input lcas_n,
9
        input we_n
10
);
11
 
12
        parameter _verbose_ = 1;
13
        parameter _add_to_addr_ = 0;
14
        parameter _filter_out_ = 32'h91;
15
 
16
        reg [15:0] array [0:32767]; // 9..0 RAS addr and 14:10=>4:0 CAS addr, total 65536 bytes, or 2 modules - 131072 bytes
17
        reg [15:0] dout;
18
 
19
        reg [14:0] addr;
20
 
21
        wire cas_n;
22
 
23
        wire idle;
24
 
25
        reg was_ras;
26
        reg was_cas;
27
        reg ready;
28
 
29
 
30
 
31
 
32
 
33
        always @(negedge ras_n)
34
                addr[9:0] <= ma[9:0];
35
 
36
        assign cas_n = ucas_n & lcas_n;
37
        always @(negedge cas_n)
38
        begin
39
                addr[14:10] <= ma[4:0];
40
        end
41
 
42
        always @(posedge cas_n, negedge cas_n)
43
                ready <= ~cas_n; // to introduce delta-cycle in ready to allow capturing of CAS address before proceeding data
44
 
45
 
46
        assign idle = ras_n & cas_n;
47
 
48
        always @(negedge ras_n, posedge idle)
49
        begin
50
                if( idle )
51
                        was_ras <= 1'b0;
52
                else // negedge ras_n
53
                        was_ras <= 1'b1;
54
        end
55
 
56
        always @(negedge cas_n, posedge idle)
57
        begin
58
                if( idle )
59
                        was_cas <= 1'b0;
60
                else
61
                        if( was_ras )
62
                                was_cas <= 1'b1;
63
        end
64
 
65
 
66
 
67
 
68
 
69
        assign d = dout;
70
 
71
        always @*
72
        begin
73
                if( ready && was_ras && was_cas && we_n && (~idle) ) // idle here is to prevent races at the end of all previous signals, which cause redundant read at the end of write
74
                begin
75
                        dout = array[addr];
76
`ifdef DRAMMEM_VERBOSE
77
                        if( _verbose_ == 1 )
78
                        begin
79
                                if( addr != _filter_out_ )
80
                                        $display("DRAM read at %t: ($%h)=>$%h",$time,addr*2+_add_to_addr_,dout);
81
                        end
82
`endif
83
                end
84
                else
85
                begin
86
                        dout = 16'hZZZZ;
87
                end
88
        end
89
 
90
 
91
        always @*
92
                if( ready && was_ras && was_cas && (~we_n) && (~idle) )
93
                begin
94
                        if( ~ucas_n )
95
                                array[addr][15:8] = d[15:8];
96
 
97
                        if( ~lcas_n )
98
                                array[addr][7:0] = d[7:0];
99
 
100
`ifdef DRAMMEM_VERBOSE
101
                        if( _verbose_ == 1 )
102
                        begin
103
                                if( addr != _filter_out_ )
104
                                        $display("DRAM written at %t: ($%h)<=$%h.$%h",$time,addr*2+_add_to_addr_,ucas_n?8'hXX:d[15:8],lcas_n?8'hXX:d[7:0]);
105
                        end
106
`endif
107
                end
108
 
109
 
110
 
111
 
112
endmodule
113