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

Subversion Repositories sdr_ctrl

[/] [sdr_ctrl/] [trunk/] [rtl/] [core/] [sdrc_bs_convert.v] - Blame information for rev 47

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

Line No. Rev Author Line
1 3 dinesha
/*********************************************************************
2
 
3
  SDRAM Controller buswidth converter
4
 
5
  This file is part of the sdram controller project
6
  http://www.opencores.org/cores/sdr_ctrl/
7
 
8
  Description: SDRAM Controller Buswidth converter
9
 
10
  This module does write/read data transalation between
11
     application data to SDRAM bus width
12
 
13
  To Do:
14
    nothing
15
 
16
  Author(s):
17
      - Dinesh Annayya, dinesha@opencores.org
18 44 dinesha
  Version  :  0.0  - 8th Jan 2012 - Initial structure
19
              0.2 - 2nd Feb 2012
20
                 Improved the command pipe structure to accept up-to 4 command of different bank.
21 47 dinesha
              0.3 - 6th Feb 2012
22
                 Bug fix on read valid generation
23 3 dinesha
 
24
 
25
 
26
 Copyright (C) 2000 Authors and OPENCORES.ORG
27
 
28
 This source file may be used and distributed without
29
 restriction provided that this copyright statement is not
30
 removed from the file and that any derivative work contains
31
 the original copyright notice and the associated disclaimer.
32
 
33
 This source file is free software; you can redistribute it
34
 and/or modify it under the terms of the GNU Lesser General
35
 Public License as published by the Free Software Foundation;
36
 either version 2.1 of the License, or (at your option) any
37
later version.
38
 
39
 This source is distributed in the hope that it will be
40
 useful, but WITHOUT ANY WARRANTY; without even the implied
41
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
42
 PURPOSE.  See the GNU Lesser General Public License for more
43
 details.
44
 
45
 You should have received a copy of the GNU Lesser General
46
 Public License along with this source; if not, download it
47
 from http://www.opencores.org/lgpl.shtml
48
 
49
*******************************************************************/
50
 
51 37 dinesha
`include "sdrc_define.v"
52 3 dinesha
module sdrc_bs_convert (
53 45 dinesha
                    clk                 ,
54
                    reset_n             ,
55
                    sdr_width           ,
56 3 dinesha
 
57 44 dinesha
        /* Control Signal from xfr ctrl */
58 45 dinesha
                    x2a_rdstart         ,
59
                    x2a_wrstart         ,
60
                    x2a_rdlast          ,
61
                    x2a_wrlast          ,
62
                    x2a_rddt            ,
63
                    x2a_rdok            ,
64
                    a2x_wrdt            ,
65
                    a2x_wren_n          ,
66
                    x2a_wrnext          ,
67 44 dinesha
 
68 45 dinesha
   /*  Control Signal from/to to application i/f  */
69
                    app_wr_data         ,
70
                    app_wr_en_n         ,
71
                    app_wr_next         ,
72
                    app_last_wr         ,
73
                    app_rd_data         ,
74
                    app_rd_valid        ,
75
                    app_last_rd
76
                );
77 44 dinesha
 
78
 
79 3 dinesha
parameter  APP_AW   = 30;  // Application Address Width
80
parameter  APP_DW   = 32;  // Application Data Width 
81
parameter  APP_BW   = 4;   // Application Byte Width
82
parameter  APP_RW   = 9;   // Application Request Width
83
 
84
parameter  SDR_DW   = 16;  // SDR Data Width 
85
parameter  SDR_BW   = 2;   // SDR Byte Width
86
 
87 45 dinesha
input                    clk              ;
88
input                    reset_n          ;
89
input [1:0]              sdr_width        ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
90 3 dinesha
 
91 45 dinesha
/* Control Signal from xfr ctrl Read Transaction*/
92
input                    x2a_rdstart      ; // read start indication
93
input                    x2a_rdlast       ; //  read last burst access
94
input [SDR_DW-1:0]       x2a_rddt         ;
95
input                    x2a_rdok         ;
96 44 dinesha
 
97 45 dinesha
/* Control Signal from xfr ctrl Write Transaction*/
98
input                    x2a_wrstart      ; // writ start indication
99
input                    x2a_wrlast       ; // write last transfer
100
input                    x2a_wrnext       ;
101
output [SDR_DW-1:0]      a2x_wrdt         ;
102
output [SDR_BW-1:0]      a2x_wren_n       ;
103 44 dinesha
 
104 45 dinesha
// Application Write Transaction
105
input  [APP_DW-1:0]      app_wr_data      ;
106
input  [APP_BW-1:0]      app_wr_en_n      ;
107
output                   app_wr_next      ;
108
output                   app_last_wr      ; // Indicate last Write Transfer for a given burst size
109 44 dinesha
 
110 45 dinesha
// Application Read Transaction
111
output [APP_DW-1:0]      app_rd_data      ;
112
output                   app_rd_valid     ;
113
output                   app_last_rd      ; // Indicate last Read Transfer for a given burst size
114 44 dinesha
 
115 45 dinesha
//----------------------------------------------
116
// Local Decleration
117
// ----------------------------------------
118 3 dinesha
 
119 45 dinesha
reg [APP_DW-1:0]         app_rd_data      ;
120
reg                      app_rd_valid     ;
121
reg [SDR_DW-1:0]         a2x_wrdt         ;
122
reg [SDR_BW-1:0]         a2x_wren_n       ;
123
reg                      app_wr_next      ;
124 3 dinesha
 
125 45 dinesha
reg [23:0]               saved_rd_data    ;
126
reg [1:0]                rd_xfr_count     ;
127
reg [1:0]                wr_xfr_count     ;
128 3 dinesha
 
129
 
130 45 dinesha
assign  app_last_wr = x2a_wrlast;
131
assign  app_last_rd = x2a_rdlast;
132 3 dinesha
 
133
always @(*) begin
134 16 dinesha
        if(sdr_width == 2'b00) // 32 Bit SDR Mode
135 3 dinesha
          begin
136 45 dinesha
            a2x_wrdt             = app_wr_data;
137
            a2x_wren_n           = app_wr_en_n;
138
            app_wr_next          = x2a_wrnext;
139
            app_rd_data          = x2a_rddt;
140
            app_rd_valid         = x2a_rdok;
141 3 dinesha
          end
142 16 dinesha
        else if(sdr_width == 2'b01) // 16 Bit SDR Mode
143
        begin
144 3 dinesha
           // Changed the address and length to match the 16 bit SDR Mode
145 45 dinesha
            app_wr_next          = (x2a_wrnext & wr_xfr_count[0]);
146 47 dinesha
            app_rd_valid         = (x2a_rdok & rd_xfr_count[0]);
147 16 dinesha
            if(wr_xfr_count[0] == 1'b1)
148 3 dinesha
              begin
149 45 dinesha
                a2x_wren_n      = app_wr_en_n[3:2];
150
                a2x_wrdt        = app_wr_data[31:16];
151 3 dinesha
              end
152
            else
153
              begin
154 45 dinesha
                a2x_wren_n      = app_wr_en_n[1:0];
155
                a2x_wrdt        = app_wr_data[15:0];
156 3 dinesha
              end
157
 
158 45 dinesha
            app_rd_data = {x2a_rddt,saved_rd_data[15:0]};
159 16 dinesha
        end else  // 8 Bit SDR Mode
160
        begin
161
           // Changed the address and length to match the 16 bit SDR Mode
162 45 dinesha
            app_wr_next         = (x2a_wrnext & (wr_xfr_count[1:0]== 2'b11));
163 47 dinesha
            app_rd_valid        = (x2a_rdok &   (rd_xfr_count[1:0]== 2'b11));
164 44 dinesha
            if(wr_xfr_count[1:0] == 2'b11)
165 3 dinesha
            begin
166 45 dinesha
                a2x_wren_n      = app_wr_en_n[3];
167
                a2x_wrdt        = app_wr_data[31:24];
168 3 dinesha
            end
169 16 dinesha
            else if(wr_xfr_count[1:0] == 2'b10)
170 3 dinesha
            begin
171 45 dinesha
                a2x_wren_n      = app_wr_en_n[2];
172
                a2x_wrdt        = app_wr_data[23:16];
173 3 dinesha
            end
174 44 dinesha
            else if(wr_xfr_count[1:0] == 2'b01)
175 3 dinesha
            begin
176 45 dinesha
                a2x_wren_n      = app_wr_en_n[1];
177
                a2x_wrdt        = app_wr_data[15:8];
178 3 dinesha
            end
179 16 dinesha
            else begin
180 45 dinesha
                a2x_wren_n      = app_wr_en_n[0];
181
                a2x_wrdt        = app_wr_data[7:0];
182 16 dinesha
            end
183
 
184 45 dinesha
            app_rd_data         = {x2a_rddt,saved_rd_data[23:0]};
185 16 dinesha
          end
186
     end
187 3 dinesha
 
188
 
189
 
190
always @(posedge clk)
191
  begin
192
    if(!reset_n)
193
      begin
194 16 dinesha
        rd_xfr_count    <= 8'b0;
195
        wr_xfr_count    <= 8'b0;
196
        saved_rd_data   <= 24'h0;
197 3 dinesha
      end
198 16 dinesha
    else begin
199
 
200
        // During Write Phase
201 44 dinesha
        if(x2a_wrlast) begin
202
           wr_xfr_count    <= 0;
203 3 dinesha
        end
204 45 dinesha
        else if(x2a_wrnext) begin
205 44 dinesha
           wr_xfr_count <= wr_xfr_count + 1'b1;
206 3 dinesha
        end
207 16 dinesha
 
208
        // During Read Phase
209 44 dinesha
        if(x2a_rdlast) begin
210
           rd_xfr_count    <= 0;
211 16 dinesha
        end
212 45 dinesha
        else if(x2a_rdok) begin
213 44 dinesha
           rd_xfr_count   <= rd_xfr_count + 1'b1;
214
        end
215
 
216
        // Save Previous Data
217 45 dinesha
        if(x2a_rdok) begin
218 16 dinesha
           if(sdr_width == 2'b01) // 16 Bit SDR Mode
219 45 dinesha
              saved_rd_data[15:0]  <= x2a_rddt;
220 16 dinesha
            else begin// 8 bit SDR Mode - 
221 45 dinesha
               if(rd_xfr_count[1:0] == 2'b00)      saved_rd_data[7:0]   <= x2a_rddt[7:0];
222
               else if(rd_xfr_count[1:0] == 2'b01) saved_rd_data[15:8]  <= x2a_rddt[7:0];
223
               else if(rd_xfr_count[1:0] == 2'b10) saved_rd_data[23:16] <= x2a_rddt[7:0];
224 16 dinesha
            end
225
        end
226
    end
227
end
228
 
229 3 dinesha
endmodule // sdr_bs_convert

powered by: WebSVN 2.1.0

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