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 11

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
output reg                     o_cmd_en         = 'd0,  // Command Enable
64
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
output reg                     o_wr_en          = 'd0,  // Write data enable
70
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
 
87
 
88
assign start_write = i_wb_stb && i_wb_we && !start_read_d1;
89
assign start_read  = i_wb_stb && !i_wb_we && read_ready;
90
assign ddr3_busy   = i_cmd_full || i_wr_full;
91
 
92
assign o_wb_err    = 'd0;
93
 
94
// ------------------------------------------------------
95
// Outputs
96
// ------------------------------------------------------
97
 
98
// Command FIFO
99
always @( posedge i_clk )
100
    begin
101
    o_cmd_byte_addr  <= {wb_adr_d1[29:4], 4'd0};
102
    o_cmd_en         <= !ddr3_busy && ( start_write_d1 || start_read_d1 );
103
    o_cmd_instr      <= start_write_d1 ? 3'd0 : 3'd1;
104
    end
105
 
106
 
107
// ------------------------------------------------------
108
// Write
109
// ------------------------------------------------------
110
always @( posedge i_clk )
111
    begin
112
    o_wr_en    <= start_write;
113
 
114
    o_wr_mask  <= i_wb_adr[3:2] == 2'd0 ? { 12'hfff, ~i_wb_sel          } :
115
                  i_wb_adr[3:2] == 2'd1 ? { 8'hff,   ~i_wb_sel, 4'hf    } :
116
                  i_wb_adr[3:2] == 2'd2 ? { 4'hf,    ~i_wb_sel, 8'hff   } :
117
                                          {          ~i_wb_sel, 12'hfff } ;
118
 
119
    o_wr_data  <= {4{i_wb_dat}};
120
    end
121
 
122
 
123
// ------------------------------------------------------
124
// Read
125
// ------------------------------------------------------
126
always @( posedge i_clk )
127
    begin
128
    if ( read_ack )
129
        read_ready <= 1'd1;
130
    else if ( start_read )
131
        read_ready <= 1'd0;
132
 
133
    start_write_d1  <= start_write;
134
    start_read_d1   <= start_read;
135 11 csantifort
    wb_adr_d1       <= i_mem_ctrl ? {5'd0, i_wb_adr[24:0]} : i_wb_adr[29:0];
136 2 csantifort
 
137
    if ( start_read  )
138
        start_read_hold <= 1'd1;
139
    else if ( read_ack )
140
        start_read_hold <= 1'd0;
141
 
142
    if ( i_rd_empty == 1'd0 && start_read_hold )
143
        begin
144
        o_wb_dat  <= i_wb_adr[3:2] == 2'd0 ? i_rd_data[ 31: 0] :
145
                     i_wb_adr[3:2] == 2'd1 ? i_rd_data[ 63:32] :
146
                     i_wb_adr[3:2] == 2'd2 ? i_rd_data[ 95:64] :
147
                                             i_rd_data[127:96] ;
148
        read_ack  <= 1'd1;
149
        end
150
    else
151
        read_ack  <= 1'd0;
152
    end
153
 
154
assign o_wb_ack = i_wb_stb && ( start_write || read_ack );
155
 
156
 
157
endmodule
158
 

powered by: WebSVN 2.1.0

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