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

Subversion Repositories yifive

[/] [yifive/] [trunk/] [caravel_yifive/] [verilog/] [rtl/] [sdram_ctrl/] [src/] [core/] [sdrc_bs_convert.v] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 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
  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
              0.3 - 6th Feb 2012
22
                 Bug fix on read valid generation
23
 
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
`include "sdrc_define.v"
52
module sdrc_bs_convert (
53
                    clk                 ,
54
                    reset_n             ,
55
                    sdr_width           ,
56
 
57
        /* Control Signal from xfr ctrl */
58
                    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
 
68
   /*  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
 
78
 
79
parameter  APP_AW   = 30;  // Application Address Width
80
parameter  APP_DW   = 32;  // Application Data Width 
81
parameter  APP_BW   = 4;   // Application Byte Width
82
 
83
parameter  SDR_DW   = 16;  // SDR Data Width 
84
parameter  SDR_BW   = 2;   // SDR Byte Width
85
 
86
input                    clk              ;
87
input                    reset_n          ;
88
input [1:0]              sdr_width        ; // 2'b00 - 32 Bit SDR, 2'b01 - 16 Bit SDR, 2'b1x - 8 Bit
89
 
90
/* Control Signal from xfr ctrl Read Transaction*/
91
input                    x2a_rdstart      ; // read start indication
92
input                    x2a_rdlast       ; //  read last burst access
93
input [SDR_DW-1:0]       x2a_rddt         ;
94
input                    x2a_rdok         ;
95
 
96
/* Control Signal from xfr ctrl Write Transaction*/
97
input                    x2a_wrstart      ; // writ start indication
98
input                    x2a_wrlast       ; // write last transfer
99
input                    x2a_wrnext       ;
100
output [SDR_DW-1:0]      a2x_wrdt         ;
101
output [SDR_BW-1:0]      a2x_wren_n       ;
102
 
103
// Application Write Transaction
104
input  [APP_DW-1:0]      app_wr_data      ;
105
input  [APP_BW-1:0]      app_wr_en_n      ;
106
output                   app_wr_next      ;
107
output                   app_last_wr      ; // Indicate last Write Transfer for a given burst size
108
 
109
// Application Read Transaction
110
output [APP_DW-1:0]      app_rd_data      ;
111
output                   app_rd_valid     ;
112
output                   app_last_rd      ; // Indicate last Read Transfer for a given burst size
113
 
114
//----------------------------------------------
115
// Local Decleration
116
// ----------------------------------------
117
 
118
reg [APP_DW-1:0]         app_rd_data      ;
119
reg                      app_rd_valid     ;
120
reg [SDR_DW-1:0]         a2x_wrdt         ;
121
reg [SDR_BW-1:0]         a2x_wren_n       ;
122
reg                      app_wr_next      ;
123
 
124
reg [23:0]               saved_rd_data    ;
125
reg [1:0]                rd_xfr_count     ;
126
reg [1:0]                wr_xfr_count     ;
127
 
128
 
129
assign  app_last_wr = x2a_wrlast;
130
assign  app_last_rd = x2a_rdlast;
131
 
132
always @(*) begin
133
        if(sdr_width == 2'b00) // 32 Bit SDR Mode
134
          begin
135
            a2x_wrdt             = app_wr_data;
136
            a2x_wren_n           = app_wr_en_n;
137
            app_wr_next          = x2a_wrnext;
138
            app_rd_data          = x2a_rddt;
139
            app_rd_valid         = x2a_rdok;
140
          end
141
        else if(sdr_width == 2'b01) // 16 Bit SDR Mode
142
        begin
143
           // Changed the address and length to match the 16 bit SDR Mode
144
            app_wr_next          = (x2a_wrnext & wr_xfr_count[0]);
145
            app_rd_valid         = (x2a_rdok & rd_xfr_count[0]);
146
            if(wr_xfr_count[0] == 1'b1)
147
              begin
148
                a2x_wren_n      = app_wr_en_n[3:2];
149
                a2x_wrdt        = app_wr_data[31:16];
150
              end
151
            else
152
              begin
153
                a2x_wren_n      = app_wr_en_n[1:0];
154
                a2x_wrdt        = app_wr_data[15:0];
155
              end
156
 
157
            app_rd_data = {x2a_rddt,saved_rd_data[15:0]};
158
        end else  // 8 Bit SDR Mode
159
        begin
160
           // Changed the address and length to match the 16 bit SDR Mode
161
            app_wr_next         = (x2a_wrnext & (wr_xfr_count[1:0]== 2'b11));
162
            app_rd_valid        = (x2a_rdok &   (rd_xfr_count[1:0]== 2'b11));
163
            if(wr_xfr_count[1:0] == 2'b11)
164
            begin
165
                a2x_wren_n      = app_wr_en_n[3];
166
                a2x_wrdt        = app_wr_data[31:24];
167
            end
168
            else if(wr_xfr_count[1:0] == 2'b10)
169
            begin
170
                a2x_wren_n      = app_wr_en_n[2];
171
                a2x_wrdt        = app_wr_data[23:16];
172
            end
173
            else if(wr_xfr_count[1:0] == 2'b01)
174
            begin
175
                a2x_wren_n      = app_wr_en_n[1];
176
                a2x_wrdt        = app_wr_data[15:8];
177
            end
178
            else begin
179
                a2x_wren_n      = app_wr_en_n[0];
180
                a2x_wrdt        = app_wr_data[7:0];
181
            end
182
 
183
            app_rd_data         = {x2a_rddt,saved_rd_data[23:0]};
184
          end
185
     end
186
 
187
 
188
 
189
always @(posedge clk)
190
  begin
191
    if(!reset_n)
192
      begin
193
        rd_xfr_count    <= 8'b0;
194
        wr_xfr_count    <= 8'b0;
195
        saved_rd_data   <= 24'h0;
196
      end
197
    else begin
198
 
199
        // During Write Phase
200
        if(x2a_wrlast) begin
201
           wr_xfr_count    <= 0;
202
        end
203
        else if(x2a_wrnext) begin
204
           wr_xfr_count <= wr_xfr_count + 1'b1;
205
        end
206
 
207
        // During Read Phase
208
        if(x2a_rdlast) begin
209
           rd_xfr_count    <= 0;
210
        end
211
        else if(x2a_rdok) begin
212
           rd_xfr_count   <= rd_xfr_count + 1'b1;
213
        end
214
 
215
        // Save Previous Data
216
        if(x2a_rdok) begin
217
           if(sdr_width == 2'b01) // 16 Bit SDR Mode
218
              saved_rd_data[15:0]  <= x2a_rddt;
219
            else begin// 8 bit SDR Mode - 
220
               if(rd_xfr_count[1:0] == 2'b00)      saved_rd_data[7:0]   <= x2a_rddt[7:0];
221
               else if(rd_xfr_count[1:0] == 2'b01) saved_rd_data[15:8]  <= x2a_rddt[7:0];
222
               else if(rd_xfr_count[1:0] == 2'b10) saved_rd_data[23:16] <= x2a_rddt[7:0];
223
            end
224
        end
225
    end
226
end
227
 
228
endmodule // sdr_bs_convert

powered by: WebSVN 2.1.0

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