OpenCores
URL https://opencores.org/ocsvn/hpdmc/hpdmc/trunk

Subversion Repositories hpdmc

[/] [hpdmc/] [trunk/] [hpdmc_ddr32/] [rtl/] [hpdmc_ctlif.v] - Blame information for rev 21

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 lekernel
/*
2
 * Milkymist VJ SoC
3
 * Copyright (C) 2007, 2008, 2009 Sebastien Bourdeauducq
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, version 3 of the License.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
 
18
module hpdmc_ctlif #(
19
        parameter csr_addr = 4'h0
20
) (
21
        input sys_clk,
22
        input sys_rst,
23
 
24
        input [13:0] csr_a,
25
        input csr_we,
26
        input [31:0] csr_di,
27
        output reg [31:0] csr_do,
28
 
29
        output reg bypass,
30
        output reg sdram_rst,
31
 
32
        output reg sdram_cke,
33
        output reg sdram_cs_n,
34
        output reg sdram_we_n,
35
        output reg sdram_cas_n,
36
        output reg sdram_ras_n,
37
        output reg [12:0] sdram_adr,
38
        output reg [1:0] sdram_ba,
39
 
40
        /* Clocks we must wait following a PRECHARGE command (usually tRP). */
41
        output reg [2:0] tim_rp,
42
        /* Clocks we must wait following an ACTIVATE command (usually tRCD). */
43
        output reg [2:0] tim_rcd,
44
        /* CAS latency, 0 = 2 */
45
        output reg tim_cas,
46
        /* Auto-refresh period (usually tREFI). */
47
        output reg [10:0] tim_refi,
48
        /* Clocks we must wait following an AUTO REFRESH command (usually tRFC). */
49
        output reg [3:0] tim_rfc,
50
        /* Clocks we must wait following the last word written to the SDRAM (usually tWR). */
51
        output reg [1:0] tim_wr,
52
 
53
        output reg idelay_rst,
54
        output reg idelay_ce,
55
        output reg idelay_inc,
56
 
57
        output reg dqs_psen,
58
        output reg dqs_psincdec,
59
        input dqs_psdone,
60
 
61
        input [1:0] pll_stat
62
);
63
 
64
reg psready;
65
always @(posedge sys_clk) begin
66
        if(dqs_psdone)
67
                psready <= 1'b1;
68
        else if(dqs_psen)
69
                psready <= 1'b0;
70
end
71
 
72
wire csr_selected = csr_a[13:10] == csr_addr;
73
 
74
/* Double-latching on pll_stat (asynchronous) */
75
reg [1:0] pll_stat1;
76
reg [1:0] pll_stat2;
77
always @(posedge sys_clk) begin
78
        pll_stat1 <= pll_stat;
79
        pll_stat2 <= pll_stat1;
80
end
81
 
82
always @(posedge sys_clk) begin
83
        if(sys_rst) begin
84
                csr_do <= 32'd0;
85
 
86
                bypass <= 1'b1;
87
                sdram_rst <= 1'b1;
88
 
89
                sdram_cke <= 1'b0;
90
                sdram_adr <= 13'd0;
91
                sdram_ba <= 2'd0;
92
 
93
                tim_rp <= 3'd2;
94
                tim_rcd <= 3'd2;
95
                tim_cas <= 1'b0;
96
                tim_refi <= 11'd740;
97
                tim_rfc <= 4'd8;
98
                tim_wr <= 2'd2;
99
        end else begin
100
                sdram_cs_n <= 1'b1;
101
                sdram_we_n <= 1'b1;
102
                sdram_cas_n <= 1'b1;
103
                sdram_ras_n <= 1'b1;
104
 
105
                idelay_rst <= 1'b0;
106
                idelay_ce <= 1'b0;
107
                idelay_inc <= 1'b0;
108
 
109
                dqs_psen <= 1'b0;
110
                dqs_psincdec <= 1'b0;
111
 
112
                csr_do <= 32'd0;
113
                if(csr_selected) begin
114
                        if(csr_we) begin
115
                                case(csr_a[1:0])
116
                                        2'b00: begin
117
                                                bypass <= csr_di[0];
118
                                                sdram_rst <= csr_di[1];
119
                                                sdram_cke <= csr_di[2];
120
                                        end
121
                                        2'b01: begin
122
                                                sdram_cs_n <= ~csr_di[0];
123
                                                sdram_we_n <= ~csr_di[1];
124
                                                sdram_cas_n <= ~csr_di[2];
125
                                                sdram_ras_n <= ~csr_di[3];
126
                                                sdram_adr <= csr_di[16:4];
127
                                                sdram_ba <= csr_di[18:17];
128
                                        end
129
                                        2'b10: begin
130
                                                tim_rp <= csr_di[2:0];
131
                                                tim_rcd <= csr_di[5:3];
132
                                                tim_cas <= csr_di[6];
133
                                                tim_refi <= csr_di[17:7];
134
                                                tim_rfc <= csr_di[21:18];
135
                                                tim_wr <= csr_di[23:22];
136
                                        end
137
                                        2'b11: begin
138
                                                idelay_rst <= csr_di[0];
139
                                                idelay_ce <= csr_di[1];
140
                                                idelay_inc <= csr_di[2];
141
 
142
                                                dqs_psen <= csr_di[3];
143
                                                dqs_psincdec <= csr_di[4];
144
                                        end
145
                                endcase
146
                        end
147
                        case(csr_a[1:0])
148
                                2'b00: csr_do <= {sdram_cke, sdram_rst, bypass};
149
                                2'b01: csr_do <= {sdram_ba, sdram_adr, 4'h0};
150
                                2'b10: csr_do <= {tim_wr, tim_rfc, tim_refi, tim_cas, tim_rcd, tim_rp};
151
                                2'b11: csr_do <= {pll_stat2, psready, 5'd0};
152
                        endcase
153
                end
154
        end
155
end
156
 
157
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.