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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [system/] [wb_xs6_ddr3_bridge.v] - Blame information for rev 15

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

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Wishbone Slave to Xilinx Spartan-6 MCB (DDR3 controller)    //
4
//  Bridge                                                      //
5
//                                                              //
6
//  This file is part of the Amber project                      //
7
//  http://www.opencores.org/project,amber                      //
8
//                                                              //
9
//  Description                                                 //
10
//  Converts wishbone read and write accesses to the signalling //
11
//  used by the Xilinx DDR3 Controller in Spartan-6 FPGAs.      //
12
//                                                              //
13
//  The MCB is configured with a single 128-bit port.           //
14
//                                                              //
15
//  Author(s):                                                  //
16
//      - Conor Santifort, csantifort.amber@gmail.com           //
17
//                                                              //
18
//////////////////////////////////////////////////////////////////
19
//                                                              //
20
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
21
//                                                              //
22
// This source file may be used and distributed without         //
23
// restriction provided that this copyright statement is not    //
24
// removed from the file and that any derivative work contains  //
25
// the original copyright notice and the associated disclaimer. //
26
//                                                              //
27
// This source file is free software; you can redistribute it   //
28
// and/or modify it under the terms of the GNU Lesser General   //
29
// Public License as published by the Free Software Foundation; //
30
// either version 2.1 of the License, or (at your option) any   //
31
// later version.                                               //
32
//                                                              //
33
// This source is distributed in the hope that it will be       //
34
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
35
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
36
// PURPOSE.  See the GNU Lesser General Public License for more //
37
// details.                                                     //
38
//                                                              //
39
// You should have received a copy of the GNU Lesser General    //
40
// Public License along with this source; if not, download it   //
41
// from http://www.opencores.org/lgpl.shtml                     //
42
//                                                              //
43
//////////////////////////////////////////////////////////////////
44
 
45
 
46
module wb_xs6_ddr3_bridge
47
(
48
input                          i_clk,
49
 
50 11 csantifort
input                          i_mem_ctrl,  // 0=128MB, 1=32MB
51
 
52 2 csantifort
// Wishbone Bus
53
input       [31:0]             i_wb_adr,
54
input       [3:0]              i_wb_sel,
55
input                          i_wb_we,
56
output reg  [31:0]             o_wb_dat         = 'd0,
57
input       [31:0]             i_wb_dat,
58
input                          i_wb_cyc,
59
input                          i_wb_stb,
60
output                         o_wb_ack,
61
output                         o_wb_err,
62
 
63 15 csantifort
output                         o_cmd_en,                // Command Enable
64 2 csantifort
output reg [2:0]               o_cmd_instr      = 'd0,  // write = 000, read = 001
65
output reg [29:0]              o_cmd_byte_addr  = 'd0,  // Memory address
66
input                          i_cmd_full,              // DDR3 I/F Command FIFO is full
67
 
68
input                          i_wr_full,               // DDR3 I/F Write Data FIFO is full
69 15 csantifort
output                         o_wr_en,                 // Write data enable
70 2 csantifort
output reg [15:0]              o_wr_mask        = 'd0,  // 1 bit per byte
71
output reg [127:0]             o_wr_data        = 'd0,  // 16 bytes write data
72
input      [127:0]             i_rd_data,               // 16 bytes of read data
73
input                          i_rd_empty               // low when read data is valid
74
 
75
);
76
 
77
wire            start_write;
78
wire            start_read;
79
reg             start_write_d1;
80
reg             start_read_d1;
81
reg             start_read_hold = 'd0;
82 11 csantifort
reg  [29:0]     wb_adr_d1;
83 2 csantifort
wire            ddr3_busy;
84
reg             read_ack = 'd0;
85
reg             read_ready = 1'd1;
86 15 csantifort
reg             cmd_en_r = 'd0;
87
reg             wr_en_r = 'd0;
88 2 csantifort
 
89
assign start_write = i_wb_stb && i_wb_we && !start_read_d1;
90
assign start_read  = i_wb_stb && !i_wb_we && read_ready;
91 15 csantifort
assign ddr3_busy   = i_cmd_full;// || i_wr_full;
92 2 csantifort
 
93
assign o_wb_err    = 'd0;
94
 
95
// ------------------------------------------------------
96
// Outputs
97
// ------------------------------------------------------
98
 
99
// Command FIFO
100
always @( posedge i_clk )
101 15 csantifort
    if ( !ddr3_busy )
102
        begin
103
        o_cmd_byte_addr  <= {wb_adr_d1[29:4], 4'd0};
104
        cmd_en_r         <= ( start_write_d1 || start_read_d1 );
105
        o_cmd_instr      <= start_write_d1 ? 3'd0 : 3'd1;
106
        end
107 2 csantifort
 
108 15 csantifort
assign o_cmd_en = cmd_en_r && !i_cmd_full;
109 2 csantifort
 
110
// ------------------------------------------------------
111
// Write
112
// ------------------------------------------------------
113
always @( posedge i_clk )
114 15 csantifort
    if ( !ddr3_busy )
115
        begin
116
        wr_en_r    <= start_write;
117
 
118
        o_wr_mask  <= i_wb_adr[3:2] == 2'd0 ? { 12'hfff, ~i_wb_sel          } :
119
                      i_wb_adr[3:2] == 2'd1 ? { 8'hff,   ~i_wb_sel, 4'hf    } :
120
                      i_wb_adr[3:2] == 2'd2 ? { 4'hf,    ~i_wb_sel, 8'hff   } :
121
                                              {          ~i_wb_sel, 12'hfff } ;
122
 
123
        o_wr_data  <= {4{i_wb_dat}};
124
        end
125 2 csantifort
 
126 15 csantifort
assign o_wr_en = wr_en_r && !i_cmd_full;
127
 
128 2 csantifort
// ------------------------------------------------------
129
// Read
130
// ------------------------------------------------------
131
always @( posedge i_clk )
132
    begin
133
    if ( read_ack )
134
        read_ready <= 1'd1;
135
    else if ( start_read )
136
        read_ready <= 1'd0;
137
 
138 15 csantifort
    if ( !ddr3_busy )
139
        begin
140
        start_write_d1  <= start_write;
141
        start_read_d1   <= start_read;
142
        wb_adr_d1       <= i_mem_ctrl ? {5'd0, i_wb_adr[24:0]} : i_wb_adr[29:0];
143
        end
144
 
145 2 csantifort
    if ( start_read  )
146
        start_read_hold <= 1'd1;
147
    else if ( read_ack )
148
        start_read_hold <= 1'd0;
149
 
150
    if ( i_rd_empty == 1'd0 && start_read_hold )
151
        begin
152
        o_wb_dat  <= i_wb_adr[3:2] == 2'd0 ? i_rd_data[ 31: 0] :
153
                     i_wb_adr[3:2] == 2'd1 ? i_rd_data[ 63:32] :
154
                     i_wb_adr[3:2] == 2'd2 ? i_rd_data[ 95:64] :
155
                                             i_rd_data[127:96] ;
156
        read_ack  <= 1'd1;
157
        end
158
    else
159
        read_ack  <= 1'd0;
160
    end
161
 
162 15 csantifort
assign o_wb_ack = i_wb_stb && ( start_write || read_ack ) && !i_cmd_full;
163 2 csantifort
 
164
 
165
endmodule
166
 

powered by: WebSVN 2.1.0

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