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 45

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