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

Subversion Repositories sdr_ctrl

[/] [sdr_ctrl/] [trunk/] [rtl/] [wb2sdrc/] [wb2sdrc.v] - Diff between revs 31 and 33

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 31 Rev 33
/*********************************************************************
/*********************************************************************
 
 
  This file is part of the sdram controller project
  This file is part of the sdram controller project
  http://www.opencores.org/cores/sdr_ctrl/
  http://www.opencores.org/cores/sdr_ctrl/
 
 
  Description: WISHBONE to SDRAM Controller Bus Transalator
  Description: WISHBONE to SDRAM Controller Bus Transalator
  This module translate the WISHBONE protocol to custom sdram controller i/f
     1. This module translate the WISHBONE protocol to custom sdram controller i/f
 
     2. Also Handle the clock domain change from Application layer to Sdram layer
 
 
  To Do:
  To Do:
    nothing
    nothing
 
 
  Author(s):  Dinesh Annayya, dinesha@opencores.org
  Author(s):  Dinesh Annayya, dinesha@opencores.org
 
 
 Copyright (C) 2000 Authors and OPENCORES.ORG
 Copyright (C) 2000 Authors and OPENCORES.ORG
 
 
 This source file may be used and distributed without
 This source file may be used and distributed without
 restriction provided that this copyright statement is not
 restriction provided that this copyright statement is not
 removed from the file and that any derivative work contains
 removed from the file and that any derivative work contains
 the original copyright notice and the associated disclaimer.
 the original copyright notice and the associated disclaimer.
 
 
 This source file is free software; you can redistribute it
 This source file is free software; you can redistribute it
 and/or modify it under the terms of the GNU Lesser General
 and/or modify it under the terms of the GNU Lesser General
 Public License as published by the Free Software Foundation;
 Public License as published by the Free Software Foundation;
 either version 2.1 of the License, or (at your option) any
 either version 2.1 of the License, or (at your option) any
later version.
later version.
 
 
 This source is distributed in the hope that it will be
 This source is distributed in the hope that it will be
 useful, but WITHOUT ANY WARRANTY; without even the implied
 useful, but WITHOUT ANY WARRANTY; without even the implied
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.  See the GNU Lesser General Public License for more
 PURPOSE.  See the GNU Lesser General Public License for more
 details.
 details.
 
 
 You should have received a copy of the GNU Lesser General
 You should have received a copy of the GNU Lesser General
 Public License along with this source; if not, download it
 Public License along with this source; if not, download it
 from http://www.opencores.org/lgpl.shtml
 from http://www.opencores.org/lgpl.shtml
 
 
*******************************************************************/
*******************************************************************/
 
 
 
 
module wb2sdrc (
module wb2sdrc (
      // WB bus
      // WB bus
      wb_rst_i           ,
                    wb_rst_i            ,
      wb_clk_i           ,
                    wb_clk_i            ,
 
 
      wb_stb_i           ,
                    wb_stb_i            ,
      wb_ack_o           ,
                    wb_ack_o            ,
      wb_addr_i          ,
                    wb_addr_i           ,
      wb_we_i            ,
                    wb_we_i             ,
      wb_dat_i           ,
                    wb_dat_i            ,
      wb_sel_i           ,
                    wb_sel_i            ,
      wb_dat_o           ,
                    wb_dat_o            ,
      wb_cyc_i           ,
                    wb_cyc_i            ,
      wb_cti_i           ,
                    wb_cti_i            ,
 
 
 
 
      //SDRAM Controller Hand-Shake Signal 
      //SDRAM Controller Hand-Shake Signal 
      sdram_clk          ,
                    sdram_clk           ,
      sdram_resetn       ,
                    sdram_resetn        ,
      sdr_req            ,
                    sdr_req             ,
      sdr_req_addr       ,
                    sdr_req_addr        ,
      sdr_req_len        ,
                    sdr_req_len         ,
      sdr_req_wr_n       ,
                    sdr_req_wr_n        ,
      sdr_req_ack        ,
                    sdr_req_ack         ,
      sdr_busy_n         ,
                    sdr_busy_n          ,
      sdr_wr_en_n        ,
                    sdr_wr_en_n         ,
      sdr_wr_next        ,
                    sdr_wr_next         ,
      sdr_rd_valid       ,
                    sdr_rd_valid        ,
      sdr_last_rd        ,
                    sdr_last_rd         ,
      sdr_wr_data        ,
                    sdr_wr_data         ,
      sdr_rd_data
                    sdr_rd_data
 
 
      );
      );
 
 
parameter      dw              = 32;  // data width
parameter      dw              = 32;  // data width
parameter      tw              = 8;   // tag id width
parameter      tw              = 8;   // tag id width
parameter      bl              = 9;   // burst_lenght_width 
parameter      bl              = 9;   // burst_lenght_width 
//--------------------------------------
//--------------------------------------
// Wish Bone Interface
// Wish Bone Interface
// -------------------------------------      
// -------------------------------------      
input           wb_rst_i           ;
input                   wb_rst_i           ;
input           wb_clk_i           ;
input                   wb_clk_i           ;
 
 
input           wb_stb_i           ;
input                   wb_stb_i           ;
output          wb_ack_o           ;
output                  wb_ack_o           ;
input [29:0]    wb_addr_i          ;
input [29:0]            wb_addr_i          ;
input           wb_we_i            ; // 1 - Write, 0 - Read
input                   wb_we_i            ; // 1 - Write , 0 - Read
input [dw-1:0]  wb_dat_i           ;
input [dw-1:0]          wb_dat_i           ;
input [dw/8-1:0]wb_sel_i           ; // Byte enable
input [dw/8-1:0]        wb_sel_i           ; // Byte enable
output [dw-1:0] wb_dat_o           ;
output [dw-1:0]         wb_dat_o           ;
input           wb_cyc_i           ;
input                   wb_cyc_i           ;
input  [2:0]    wb_cti_i           ;
input  [2:0]            wb_cti_i           ;
/***************************************************
/***************************************************
The Cycle Type Idenfier [CTI_IO()] Address Tag provides
The Cycle Type Idenfier [CTI_IO()] Address Tag provides
additional information about the current cycle.
additional information about the current cycle.
The MASTER sends this information to the SLAVE. The SLAVE can use this
The MASTER sends this information to the SLAVE. The SLAVE can use this
information to prepare the response for the next cycle.
information to prepare the response for the next cycle.
Table 4-2 Cycle Type Identifiers
Table 4-2 Cycle Type Identifiers
CTI_O(2:0) Description
CTI_O(2:0) Description
000 Classic cycle.
000 Classic cycle.
001 Constant address burst cycle
001 Constant address burst cycle
010 Incrementing burst cycle
010 Incrementing burst cycle
011 Reserved
011 Reserved
100 Reserved
100 Reserved
101 Reserved
101 Reserved
110 Reserved
110 Reserved
111 End-of-Burst
111 End-of-Burst
****************************************************/
****************************************************/
//--------------------------------------------
//--------------------------------------------
// SDRAM controller Interface 
// SDRAM controller Interface 
//--------------------------------------------
//--------------------------------------------
input                   sdram_clk           ; // sdram clock
input                   sdram_clk          ; // sdram clock
input                   sdram_resetn        ; // sdram reset
input                   sdram_resetn       ; // sdram reset
output                  sdr_req            ; // SDRAM request
output                  sdr_req            ; // SDRAM request
output [29:0]           sdr_req_addr       ; // SDRAM Request Address
output [29:0]           sdr_req_addr       ; // SDRAM Request Address
output [bl-1:0]         sdr_req_len        ;
output [bl-1:0]         sdr_req_len        ;
output                  sdr_req_wr_n       ; // 0 - Write, 1 -> Read
output                  sdr_req_wr_n       ; // 0 - Write, 1 -> Read
input                   sdr_req_ack        ; // SDRAM request Accepted
input                   sdr_req_ack        ; // SDRAM request Accepted
input                   sdr_busy_n         ; // 0 -> sdr busy
input                   sdr_busy_n         ; // 0 -> sdr busy
output [dw/8-1:0]       sdr_wr_en_n        ; // Active low sdr byte-wise write data valid
output [dw/8-1:0]       sdr_wr_en_n        ; // Active low sdr byte-wise write data valid
input                   sdr_wr_next        ; // Ready to accept the next write
input                   sdr_wr_next        ; // Ready to accept the next write
input                   sdr_rd_valid       ; // sdr read valid
input                   sdr_rd_valid       ; // sdr read valid
input                   sdr_last_rd        ; // Indicate last Read of Burst Transfer
input                   sdr_last_rd        ; // Indicate last Read of Burst Transfer
output [dw-1:0]         sdr_wr_data        ; // sdr write data
output [dw-1:0]         sdr_wr_data        ; // sdr write data
input  [dw-1:0]         sdr_rd_data        ; // sdr read data
input  [dw-1:0]         sdr_rd_data        ; // sdr read data
 
 
//----------------------------------------------------
//----------------------------------------------------
// Wire Decleration
// Wire Decleration
// ---------------------------------------------------
// ---------------------------------------------------
wire                    cmdfifo_full;
wire                    cmdfifo_full       ;
wire                    cmdfifo_empty;
wire                    cmdfifo_empty      ;
wire                    wrdatafifo_full;
wire                    wrdatafifo_full    ;
wire                    wrdatafifo_empty;
wire                    wrdatafifo_empty   ;
wire                    tagfifo_full;
wire                    tagfifo_full       ;
wire                    tagfifo_empty;
wire                    tagfifo_empty      ;
wire                    rddatafifo_empty;
wire                    rddatafifo_empty   ;
wire                    rddatafifo_full;
wire                    rddatafifo_full    ;
 
 
reg                     pending_read;
reg                     pending_read       ;
 
 
 
 
// Generate Address Enable only when internal fifo (Address + data are not full
//-----------------------------------------------------------------------------
 
// Ack Generaltion Logic
 
//  If Write Request - Acknowledge if the command and write FIFO are not full
 
//  If Read Request  - Generate the Acknowledgment once read fifo has data
 
//                     available
 
//-----------------------------------------------------------------------------
 
 
assign wb_ack_o = (wb_stb_i && wb_cyc_i && wb_we_i) ?  // Write Phase
assign wb_ack_o = (wb_stb_i && wb_cyc_i && wb_we_i) ?  // Write Phase
                          ((!cmdfifo_full) && (!wrdatafifo_full)) :
                          ((!cmdfifo_full) && (!wrdatafifo_full)) :
                  (wb_stb_i && wb_cyc_i && !wb_we_i) ? // Read Phase 
                  (wb_stb_i && wb_cyc_i && !wb_we_i) ? // Read Phase 
                           !rddatafifo_empty : 1'b0;
                           !rddatafifo_empty : 1'b0;
 
 
// Accept the cmdfifo only when burst start + address enable + address
//---------------------------------------------------------------------------
// valid is asserted
// Command FIFO Write Generation
wire           cmdfifo_wr   = (wb_stb_i && wb_cyc_i && wb_we_i) ? wb_ack_o :
//    If Write Request - Generate write, when Write fifo and command fifo is
                              (wb_stb_i && wb_cyc_i && !wb_we_i) ? !pending_read: 1'b0 ;
//                       not full
 
//    If Read Request - Generate write, when command fifo not full and there
 
//                      is no pending read request.
 
//---------------------------------------------------------------------------
 
wire           cmdfifo_wr   = (wb_stb_i && wb_cyc_i && wb_we_i && (!cmdfifo_full) ) ? wb_ack_o :
 
                              (wb_stb_i && wb_cyc_i && !wb_we_i && (!cmdfifo_full)) ? !pending_read: 1'b0 ;
 
 
 
//---------------------------------------------------------------------------
 
// command fifo read generation
 
//    Command FIFo read will be generated, whenever SDRAM Controller
 
//    Acknowldge the Request
 
//----------------------------------------------------------------------------
 
 
wire           cmdfifo_rd   = sdr_req_ack;
wire           cmdfifo_rd   = sdr_req_ack;
 
 
 
//---------------------------------------------------------------------------
 
// Application layer request is generated towards the controller, whenever
 
// Command FIFO is not full
 
// --------------------------------------------------------------------------
assign         sdr_req      = !cmdfifo_empty;
assign         sdr_req      = !cmdfifo_empty;
 
 
 
//----------------------------------------------------------------------------
 
// Since Burst length is not known at the start of the Burst, It's assumed as
 
// Single Cycle Burst. We need to improvise this ...
 
// --------------------------------------------------------------------------
wire [bl-1:0]  burst_length  = 1;  // 0 Mean 1 Transfer
wire [bl-1:0]  burst_length  = 1;  // 0 Mean 1 Transfer
 
 
 
//-----------------------------------------------------------------------------
 
// In Wish Bone Spec, For Read Request has to be acked along with data.
 
// We need to identify the pending read request.
 
// Once we accept the read request, we should not accept one more read
 
// request, untill we have transmitted the read data.
 
//  Pending Read will 
 
//     set - with Read Request 
 
//     reset - with Read Request + Ack
 
// ----------------------------------------------------------------------------
always @(posedge wb_rst_i or posedge wb_clk_i) begin
always @(posedge wb_rst_i or posedge wb_clk_i) begin
   if(wb_rst_i) begin
   if(wb_rst_i) begin
       pending_read <= 1'b0;
       pending_read <= 1'b0;
   end else begin
   end else begin
      pending_read <=  wb_stb_i & wb_cyc_i & !wb_we_i & !wb_ack_o;
      pending_read <=  wb_stb_i & wb_cyc_i & !wb_we_i & !wb_ack_o;
   end
   end
end
end
 
 
 
//---------------------------------------------------------------------
 
// Async Command FIFO. This block handle the clock domain change from
 
// Application layer to SDRAM Controller
 
// ------------------------------------------------------------------
   // Address + Burst Length + W/R Request 
   // Address + Burst Length + W/R Request 
    async_fifo #(.W(30+bl+1),.DP(4)) u_cmdfifo (
    async_fifo #(.W(30+bl+1),.DP(4)) u_cmdfifo (
     // Write Path Sys CLock Domain
     // Write Path Sys CLock Domain
          .wr_clk     (wb_clk_i),
          .wr_clk             (wb_clk_i           ),
          .wr_reset_n (!wb_rst_i),
          .wr_reset_n         (!wb_rst_i          ),
          .wr_en      (cmdfifo_wr),
          .wr_en              (cmdfifo_wr         ),
          .wr_data    ({burst_length,
          .wr_data            ({burst_length,
                        !wb_we_i,
                                !wb_we_i,
                       wb_addr_i}),
                                wb_addr_i}        ),
          .afull      (),
          .afull              (                   ),
          .full       (cmdfifo_full),
          .full               (cmdfifo_full       ),
 
 
     // Read Path, SDRAM clock domain
     // Read Path, SDRAM clock domain
          .rd_clk     (sdram_clk),
          .rd_clk             (sdram_clk          ),
          .rd_reset_n (sdram_resetn),
          .rd_reset_n         (sdram_resetn       ),
          .aempty     (),
          .aempty             (                   ),
          .empty      (cmdfifo_empty),
          .empty              (cmdfifo_empty      ),
          .rd_en      (cmdfifo_rd),
          .rd_en              (cmdfifo_rd         ),
          .rd_data    ({sdr_req_len,
          .rd_data            ({sdr_req_len,
                     sdr_req_wr_n,
                                sdr_req_wr_n,
                     sdr_req_addr})
                                sdr_req_addr}     )
     );
     );
 
 
// synopsys translate_off
// synopsys translate_off
always @(posedge wb_clk_i) begin
always @(posedge wb_clk_i) begin
  if (cmdfifo_full == 1'b1 && cmdfifo_wr == 1'b1)  begin
  if (cmdfifo_full == 1'b1 && cmdfifo_wr == 1'b1)  begin
     $display("ERROR:%m COMMAND FIFO WRITE OVERFLOW");
     $display("ERROR:%m COMMAND FIFO WRITE OVERFLOW");
  end
  end
end
end
// synopsys translate_off
// synopsys translate_off
always @(posedge sdram_clk) begin
always @(posedge sdram_clk) begin
   if (cmdfifo_empty == 1'b1 && cmdfifo_rd == 1'b1) begin
   if (cmdfifo_empty == 1'b1 && cmdfifo_rd == 1'b1) begin
      $display("ERROR:%m COMMAND FIFO READ OVERFLOW");
      $display("ERROR:%m COMMAND FIFO READ OVERFLOW");
   end
   end
end
end
// synopsys translate_on
// synopsys translate_on
 
 
 
//---------------------------------------------------------------------
 
// Write Data FIFO Write Generation, when ever Acked + Write Request
 
//   Note: Ack signal generation already taking account of FIFO full condition
 
// ---------------------------------------------------------------------
 
 
wire  wrdatafifo_wr  = wb_ack_o & wb_we_i ;
wire  wrdatafifo_wr  = wb_ack_o & wb_we_i ;
 
 
 
//------------------------------------------------------------------------
 
// Write Data FIFO Read Generation, When ever Next Write request generated
 
// from SDRAM Controller
 
// ------------------------------------------------------------------------
wire  wrdatafifo_rd  = sdr_wr_next;
wire  wrdatafifo_rd  = sdr_wr_next;
 
 
 
 
 
//------------------------------------------------------------------------
 
// Async Write Data FIFO
 
//    This block handle the clock domain change over + Write Data + Byte mask 
 
//    From Application layer to SDRAM controller layer
 
//------------------------------------------------------------------------
 
 
   // Write DATA + Data Mask FIFO
   // Write DATA + Data Mask FIFO
    async_fifo #(.W(dw+(dw/8)), .DP(16)) u_wrdatafifo (
    async_fifo #(.W(dw+(dw/8)), .DP(16)) u_wrdatafifo (
       // Write Path , System clock domain
       // Write Path , System clock domain
          .wr_clk     (wb_clk_i),
          .wr_clk             (wb_clk_i           ),
          .wr_reset_n (!wb_rst_i),
          .wr_reset_n         (!wb_rst_i          ),
          .wr_en   (wrdatafifo_wr),
          .wr_en              (wrdatafifo_wr      ),
          .wr_data ({~wb_sel_i,
          .wr_data            ({~wb_sel_i,
                     wb_dat_i}),
                                 wb_dat_i}        ),
          .afull    (),
          .afull              (                   ),
          .full     (wrdatafifo_full),
          .full               (wrdatafifo_full    ),
 
 
 
 
       // Read Path , SDRAM clock domain
       // Read Path , SDRAM clock domain
          .rd_clk     (sdram_clk),
          .rd_clk             (sdram_clk          ),
          .rd_reset_n (sdram_resetn),
          .rd_reset_n         (sdram_resetn       ),
          .aempty     (),
          .aempty             (                   ),
          .empty      (wrdatafifo_empty),
          .empty              (wrdatafifo_empty   ),
          .rd_en      (wrdatafifo_rd),
          .rd_en              (wrdatafifo_rd      ),
          .rd_data    ({sdr_wr_en_n,
          .rd_data            ({sdr_wr_en_n,
                        sdr_wr_data})
                                sdr_wr_data}      )
     );
     );
// synopsys translate_off
// synopsys translate_off
always @(posedge wb_clk_i) begin
always @(posedge wb_clk_i) begin
  if (wrdatafifo_full == 1'b1 && wrdatafifo_wr == 1'b1)  begin
  if (wrdatafifo_full == 1'b1 && wrdatafifo_wr == 1'b1)  begin
     $display("ERROR:%m WRITE DATA FIFO WRITE OVERFLOW");
     $display("ERROR:%m WRITE DATA FIFO WRITE OVERFLOW");
  end
  end
end
end
 
 
always @(posedge sdram_clk) begin
always @(posedge sdram_clk) begin
   if (wrdatafifo_empty == 1'b1 && wrdatafifo_rd == 1'b1) begin
   if (wrdatafifo_empty == 1'b1 && wrdatafifo_rd == 1'b1) begin
      $display("ERROR:%m WRITE DATA FIFO READ OVERFLOW");
      $display("ERROR:%m WRITE DATA FIFO READ OVERFLOW");
   end
   end
end
end
// synopsys translate_on
// synopsys translate_on
 
 
// -------------------------------------------------------------------
// -------------------------------------------------------------------
//  READ DATA FIFO
//  READ DATA FIFO
//  ------------------------------------------------------------------
//  ------------------------------------------------------------------
wire    rd_eop; // last read indication
wire    rd_eop; // last read indication
 
 
 
// Read FIFO write generation, when ever SDRAM controller issues the read
 
// valid signal
wire    rddatafifo_wr = sdr_rd_valid;
wire    rddatafifo_wr = sdr_rd_valid;
wire    rddatafifo_rd = wb_ack_o & !wb_we_i & (rddatafifo_empty == 0);
 
 
 
   // READ DATA FIFO depth is kept small, assuming that Sys-CLock > SDRAM Clock
// Read FIFO read generation, when ever ack is generated along with read
 
// request.
 
// Note: Ack generation is already accounted the write FIFO Not Empty
 
//       condition
 
wire    rddatafifo_rd = wb_ack_o & !wb_we_i;
 
 
 
//-------------------------------------------------------------------------
 
// Async Read FIFO
 
// This block handles the clock domain change over + Read data from SDRAM
 
// controller to Application layer.
 
//  Note: 
 
//    1. READ DATA FIFO depth is kept small, assuming that Sys-CLock > SDRAM Clock
   // READ DATA + EOP
   // READ DATA + EOP
 
//    2. EOP indicate, last transfer of Burst Read Access. use-full for future
 
//       Tag handling per burst
 
//
 
// ------------------------------------------------------------------------
    async_fifo #(.W(dw+1), .DP(4)) u_rddatafifo (
    async_fifo #(.W(dw+1), .DP(4)) u_rddatafifo (
       // Write Path , SDRAM clock domain
       // Write Path , SDRAM clock domain
          .wr_clk     (sdram_clk),
          .wr_clk             (sdram_clk          ),
          .wr_reset_n (sdram_resetn),
          .wr_reset_n         (sdram_resetn       ),
          .wr_en      (rddatafifo_wr),
          .wr_en              (rddatafifo_wr      ),
          .wr_data    ({sdr_last_rd,
          .wr_data            ({sdr_last_rd,
                        sdr_rd_data}),
                                sdr_rd_data}      ),
          .afull      (),
          .afull              (                   ),
          .full       (rddatafifo_full),
          .full               (rddatafifo_full    ),
 
 
 
 
       // Read Path , SYS clock domain
       // Read Path , SYS clock domain
          .rd_clk     (wb_clk_i),
          .rd_clk             (wb_clk_i           ),
          .rd_reset_n (!wb_rst_i),
          .rd_reset_n         (!wb_rst_i          ),
          .empty      (rddatafifo_empty),
          .empty              (rddatafifo_empty   ),
          .aempty     (),
          .aempty             (                   ),
          .rd_en      (rddatafifo_rd),
          .rd_en              (rddatafifo_rd      ),
          .rd_data    ({rd_eop,
          .rd_data            ({rd_eop,
                        wb_dat_o})
                                wb_dat_o}         )
     );
     );
 
 
// synopsys translate_off
// synopsys translate_off
always @(posedge sdram_clk) begin
always @(posedge sdram_clk) begin
  if (rddatafifo_full == 1'b1 && rddatafifo_wr == 1'b1)  begin
  if (rddatafifo_full == 1'b1 && rddatafifo_wr == 1'b1)  begin
     $display("ERROR:%m READ DATA FIFO WRITE OVERFLOW");
     $display("ERROR:%m READ DATA FIFO WRITE OVERFLOW");
  end
  end
end
end
 
 
always @(posedge wb_clk_i) begin
always @(posedge wb_clk_i) begin
   if (rddatafifo_empty == 1'b1 && rddatafifo_rd == 1'b1) begin
   if (rddatafifo_empty == 1'b1 && rddatafifo_rd == 1'b1) begin
      $display("ERROR:%m READ DATA FIFO READ OVERFLOW");
      $display("ERROR:%m READ DATA FIFO READ OVERFLOW");
   end
   end
end
end
// synopsys translate_on
// synopsys translate_on
 
 
 
 
endmodule
endmodule
 
 

powered by: WebSVN 2.1.0

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