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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [fpga/] [mc/] [src/] [ram/] [ddr/] [ram.v] - Blame information for rev 288

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 219 hellwig
//
2
// ram_2.v -- main memory, using DDR SDRAM
3
//
4
 
5
 
6
module ram(ddr_clk_0, ddr_clk_90, ddr_clk_180,
7
           ddr_clk_270, ddr_clk_ok, clk, reset,
8
           en, wr, size, addr,
9
           data_in, data_out, wt,
10
           sdram_ck_p, sdram_ck_n, sdram_cke,
11
           sdram_cs_n, sdram_ras_n, sdram_cas_n,
12
           sdram_we_n, sdram_ba, sdram_a,
13
           sdram_udm, sdram_ldm,
14
           sdram_udqs, sdram_ldqs, sdram_dq);
15
    // internal interface signals
16
    input ddr_clk_0;
17
    input ddr_clk_90;
18
    input ddr_clk_180;
19
    input ddr_clk_270;
20
    input ddr_clk_ok;
21
    input clk;
22
    input reset;
23
    input en;
24
    input wr;
25
    input [1:0] size;
26
    input [25:0] addr;
27
    input [31:0] data_in;
28
    output reg [31:0] data_out;
29
    output wt;
30
    // DDR SDRAM interface signals
31
    output sdram_ck_p;
32
    output sdram_ck_n;
33
    output sdram_cke;
34
    output sdram_cs_n;
35
    output sdram_ras_n;
36
    output sdram_cas_n;
37
    output sdram_we_n;
38
    output [1:0] sdram_ba;
39
    output [12:0] sdram_a;
40
    output sdram_udm;
41
    output sdram_ldm;
42
    inout sdram_udqs;
43
    inout sdram_ldqs;
44
    inout [15:0] sdram_dq;
45
 
46
  wire [31:0] do;
47
  reg [31:0] di;
48
  reg [3:0] wb;
49
  wire ack;
50
 
51
  ddr_sdram ddr_sdram1(
52
    .sd_CK_P(sdram_ck_p),
53
    .sd_CK_N(sdram_ck_n),
54
    .sd_A_O(sdram_a[12:0]),
55
    .sd_BA_O(sdram_ba[1:0]),
56
    .sd_D_IO(sdram_dq[15:0]),
57
    .sd_RAS_O(sdram_ras_n),
58
    .sd_CAS_O(sdram_cas_n),
59
    .sd_WE_O(sdram_we_n),
60
    .sd_UDM_O(sdram_udm),
61
    .sd_LDM_O(sdram_ldm),
62
    .sd_UDQS_IO(sdram_udqs),
63
    .sd_LDQS_IO(sdram_ldqs),
64
    .sd_CS_O(sdram_cs_n),
65
    .sd_CKE_O(sdram_cke),
66
    .clk0(ddr_clk_0),
67
    .clk90(ddr_clk_90),
68
    .clk180(ddr_clk_180),
69
    .clk270(ddr_clk_270),
70
    .reset(~ddr_clk_ok),
71
    .wADR_I(addr[25:2]),
72
    .wSTB_I(en),
73
    .wWE_I(wr),
74
    .wWRB_I(wb[3:0]),
75
    .wDAT_I(di[31:0]),
76
    .wDAT_O(do[31:0]),
77
    .wACK_O(ack)
78
  );
79
 
80
  // read multiplexer
81
  always @(*) begin
82
    case (size[1:0])
83
      2'b00:
84
        // byte
85
        begin
86
          data_out[31:24] = 8'hxx;
87
          data_out[23:16] = 8'hxx;
88
          data_out[15: 8] = 8'hxx;
89
          if (addr[1] == 0) begin
90
            if (addr[0] == 0) begin
91
              data_out[ 7: 0] = do[31:24];
92
            end else begin
93
              data_out[ 7: 0] = do[23:16];
94
            end
95
          end else begin
96
            if (addr[0] == 0) begin
97
              data_out[ 7: 0] = do[15: 8];
98
            end else begin
99
              data_out[ 7: 0] = do[ 7: 0];
100
            end
101
          end
102
        end
103
      2'b01:
104
        // halfword
105
        begin
106
          data_out[31:24] = 8'hxx;
107
          data_out[23:16] = 8'hxx;
108
          if (addr[1] == 0) begin
109
            data_out[15: 8] = do[31:24];
110
            data_out[ 7: 0] = do[23:16];
111
          end else begin
112
            data_out[15: 8] = do[15: 8];
113
            data_out[ 7: 0] = do[ 7: 0];
114
          end
115
        end
116
      2'b10:
117
        // word
118
        begin
119
          data_out[31:24] = do[31:24];
120
          data_out[23:16] = do[23:16];
121
          data_out[15: 8] = do[15: 8];
122
          data_out[ 7: 0] = do[ 7: 0];
123
        end
124
      default:
125
        // illegal
126
        begin
127
          data_out[31:24] = 8'hxx;
128
          data_out[23:16] = 8'hxx;
129
          data_out[15: 8] = 8'hxx;
130
          data_out[ 7: 0] = 8'hxx;
131
        end
132
    endcase
133
  end
134
 
135
  // write multiplexer & data masks
136
  always @(*) begin
137
    case (size[1:0])
138
      2'b00:
139
        // byte
140
        begin
141
          di[31:24] = data_in[ 7: 0];
142
          di[23:16] = data_in[ 7: 0];
143
          di[15: 8] = data_in[ 7: 0];
144
          di[ 7: 0] = data_in[ 7: 0];
145
          wb[3] = ~addr[1] & ~addr[0];
146
          wb[2] = ~addr[1] &  addr[0];
147
          wb[1] =  addr[1] & ~addr[0];
148
          wb[0] =  addr[1] &  addr[0];
149
        end
150
      2'b01:
151
        // halfword
152
        begin
153
          di[31:24] = data_in[15: 8];
154
          di[23:16] = data_in[ 7: 0];
155
          di[15: 8] = data_in[15: 8];
156
          di[ 7: 0] = data_in[ 7: 0];
157
          wb[3] = ~addr[1];
158
          wb[2] = ~addr[1];
159
          wb[1] =  addr[1];
160
          wb[0] =  addr[1];
161
        end
162
      2'b10:
163
        // word
164
        begin
165
          di[31:24] = data_in[31:24];
166
          di[23:16] = data_in[23:16];
167
          di[15: 8] = data_in[15: 8];
168
          di[ 7: 0] = data_in[ 7: 0];
169
          wb[3] = 1'b1;
170
          wb[2] = 1'b1;
171
          wb[1] = 1'b1;
172
          wb[0] = 1'b1;
173
        end
174
      default:
175
        // illegal
176
        begin
177
          di[31:24] = 8'hxx;
178
          di[23:16] = 8'hxx;
179
          di[15: 8] = 8'hxx;
180
          di[ 7: 0] = 8'hxx;
181
          wb[3] = 1'b0;
182
          wb[2] = 1'b0;
183
          wb[1] = 1'b0;
184
          wb[0] = 1'b0;
185
        end
186
    endcase
187
  end
188
 
189
  assign wt = ~ack;
190
 
191
endmodule

powered by: WebSVN 2.1.0

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