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

Subversion Repositories turbo8051

[/] [turbo8051/] [trunk/] [rtl/] [lib/] [wb_rd_mem2mem.v] - Diff between revs 24 and 50

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 24 Rev 50
Line 41... Line 41...
////                                                              ////
////                                                              ////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
 
 
/**********************************************
/**********************************************
      Web-bone , Read from Wishbone Memory and Write to internal Memory
      Web-bone , Read from Wishbone Memory and Write to internal Memory
 
 
 
   This block handles following task
 
   1. Check the Descriptor Q for not empty
 
   2. If the Descriptor Q is not empty, the read the 32 bit descriptor
 
   3. The 32 bit descriptor holds following information
 
       [11:0]  - Packet Length
 
       [25:12] - MSB [15:2] of Packet Start Location
 
       [31:26] - Packet Status
 
   4. Based on the Packet Length, Read the data from external Data memory
 
      and write it to Internal Memory
 
 
**********************************************/
**********************************************/
 
 
module wb_rd_mem2mem (
module wb_rd_mem2mem (
 
 
              rst_n               ,
              rst_n               ,
              clk                 ,
              clk                 ,
 
 
 
    // descriptor handshake
 
              cfg_desc_baddr      ,
 
              desc_q_empty        ,
 
 
    // Master Interface Signal
    // Master Interface Signal
              mem_req             ,
 
              mem_txfr            ,
 
              mem_ack             ,
 
              mem_taddr           ,
              mem_taddr           ,
              mem_addr            ,
 
              mem_full            ,
              mem_full            ,
              mem_afull           ,
              mem_afull           ,
              mem_wr              ,
              mem_wr              ,
              mem_din             ,
              mem_din             ,
 
 
Line 84... Line 94...
//---------------------
//---------------------
// State Machine Parameter
// State Machine Parameter
//--------------------
//--------------------
 
 
parameter IDLE = 0;
parameter IDLE = 0;
parameter TXFR = 1;
parameter DESC_RD   = 1;
 
parameter DATA_WAIT = 2;
 
parameter TXFR      = 3;
 
 
 
 
//-------------------------------------------
//-------------------------------------------
// Input Declaration
// Input Declaration
//------------------------------------------
//------------------------------------------
Line 101... Line 113...
                                    // rising edge of [CLK_I]. 
                                    // rising edge of [CLK_I]. 
input               rst_n       ;  // RST_I The reset input [RST_I] forces the WISHBONE interface 
input               rst_n       ;  // RST_I The reset input [RST_I] forces the WISHBONE interface 
                                   // to restart. Furthermore, all internal self-starting state 
                                   // to restart. Furthermore, all internal self-starting state 
                                   // machines will be forced into an initial state. 
                                   // machines will be forced into an initial state. 
 
 
 
//---------------------------------
 
// Descriptor Interface
 
//---------------------------------
 
input [15:6]   cfg_desc_baddr    ;  // descriptor Base Address
 
input          desc_q_empty      ;
 
 
//------------------------------------------
//------------------------------------------
// Stanard Memory Interface
// Stanard Memory Interface
//------------------------------------------
//------------------------------------------
input               mem_req     ;
 
input [15:0]        mem_txfr    ;
 
output              mem_ack     ;
 
 
 
input [TAR_WD-1:0]  mem_taddr   ; // target address 
input [TAR_WD-1:0]  mem_taddr   ; // target address 
input [15:0]        mem_addr    ; // memory address 
 
input               mem_full    ; // memory full
input               mem_full    ; // memory full
input               mem_afull   ; // memory afull 
input               mem_afull   ; // memory afull 
output              mem_wr      ; // memory read
output              mem_wr      ; // memory Write
output  [7:0]       mem_din     ; // memory read data
output  [8:0]       mem_din     ; // memory read data
 
 
//------------------------------------------
//------------------------------------------
// External Memory WB Interface
// External Memory WB Interface
//------------------------------------------
//------------------------------------------
output              wbo_stb  ; // STB_O The strobe output [STB_O] indicates a valid data 
output              wbo_stb  ; // STB_O The strobe output [STB_O] indicates a valid data 
Line 183... Line 197...
 
 
//----------------------------------------
//----------------------------------------
// Register Declration
// Register Declration
//----------------------------------------
//----------------------------------------
 
 
reg                 state       ;
reg  [1:0]          state       ;
reg  [15:0]         cnt         ;
reg  [15:0]         cnt         ;
reg  [TAR_WD-1:0]   wbo_taddr   ;
reg  [TAR_WD-1:0]   wbo_taddr   ;
reg  [ADR_WD-1:0]   wbo_addr    ;
reg  [ADR_WD-1:0]   wbo_addr    ;
reg                 wbo_stb     ;
reg                 wbo_stb     ;
reg                 wbo_we      ;
reg                 wbo_we      ;
reg  [BE_WD-1:0]    wbo_be      ;
reg  [BE_WD-1:0]    wbo_be      ;
reg                 wbo_cyc     ;
reg                 wbo_cyc     ;
reg                 mem_ack     ;
reg [15:0]          mem_addr    ;
 
 
 
wire           mem_wr       = (state == TXFR) ? wbo_ack: 1'b0 ;
 
 
wire           mem_wr       = wbo_ack;
 
// Generate Next Address, to fix the read to address inc issue
// Generate Next Address, to fix the read to address inc issue
wire [15:0]    taddr   = mem_addr+1;
wire [15:0]    taddr   = mem_addr+1;
 
 
wire [7:0]          mem_din  = (mem_addr[1:0] == 2'b00) ? wbo_dout[7:0] :
assign mem_din[7:0]  = (mem_addr[1:0] == 2'b00) ? wbo_dout[7:0] :
                               (mem_addr[1:0] == 2'b01) ? wbo_dout[15:8] :
                               (mem_addr[1:0] == 2'b01) ? wbo_dout[15:8] :
                               (mem_addr[1:0] == 2'b10) ? wbo_dout[23:16] : wbo_dout[31:24]  ;
                               (mem_addr[1:0] == 2'b10) ? wbo_dout[23:16] : wbo_dout[31:24]  ;
 
 
 
assign mem_din[8]    = (cnt == 1) ? 1'b1 : 1'b0; // EOP generation at last transfer
 
 
 
reg [3:0]   desc_ptr;
 
 
always @(negedge rst_n or posedge clk) begin
always @(negedge rst_n or posedge clk) begin
   if(rst_n == 0) begin
   if(rst_n == 0) begin
      state       <= IDLE;
      state       <= IDLE;
      wbo_taddr   <= 0;
      wbo_taddr   <= 0;
      wbo_addr    <= 0;
      wbo_addr    <= 0;
      wbo_stb     <= 0;
      wbo_stb     <= 0;
      wbo_we      <= 0;
      wbo_we      <= 0;
      wbo_be      <= 0;
      wbo_be      <= 0;
      wbo_cyc     <= 0;
      wbo_cyc     <= 0;
      mem_ack     <= 0;
      desc_ptr    <= 0;
 
      mem_addr    <= 0;
   end
   end
   else begin
   else begin
      case(state)
      case(state)
         IDLE: begin
         IDLE: begin
            if(mem_req && !mem_full) begin
            // Check for Descriptor Q not empty
                cnt       <= mem_txfr;
            if(!desc_q_empty) begin
 
               wbo_taddr   <= mem_taddr;
 
               wbo_addr  <= {cfg_desc_baddr[15:6],desc_ptr[3:0]};
 
               wbo_be    <= 4'hF;
 
               wbo_we    <= 1'b0;
 
               wbo_stb   <= 1'b1;
 
               wbo_cyc   <= 1;
 
               state     <= DESC_RD;
 
               desc_ptr  <= desc_ptr+1;
 
            end
 
        end
 
       DESC_RD: begin
 
          // wait for web-bone ack
 
          if(wbo_ack) begin
 
              wbo_cyc   <= 1'b0;
 
              wbo_stb   <= 1'b0;
 
              state     <= IDLE;
 
              cnt       <= wbo_dout[11:0];
 
              mem_addr  <= {wbo_dout[27:12],2'b0};
 
              state     <= DATA_WAIT;
 
          end
 
       end
 
 
 
         DATA_WAIT: begin
 
            // check for internal memory not full and initiate
 
            // the transfer
 
            if(!mem_full) begin
                wbo_taddr <= mem_taddr;
                wbo_taddr <= mem_taddr;
                wbo_addr  <= mem_addr[14:2];
                wbo_addr  <= mem_addr[14:2];
                wbo_stb   <= 1'b1;
                wbo_stb   <= 1'b1;
                wbo_we    <= 1'b0;
                wbo_we    <= 1'b0;
                wbo_be    <= 1 << mem_addr[1:0];
                wbo_be      <= 4'hF;
                wbo_cyc   <= 1'b1;
                wbo_cyc   <= 1'b1;
                mem_ack   <= 1;
 
                state     <= TXFR;
                state     <= TXFR;
            end
            end
         end
         end
         TXFR: begin
         TXFR: begin
            mem_ack     <= 0;
 
            if(wbo_ack) begin
            if(wbo_ack) begin
 
               mem_addr     <= mem_addr+1;
               cnt      <= cnt-1;
               cnt      <= cnt-1;
               wbo_addr  <= taddr[14:2];
               wbo_addr  <= taddr[14:2];
               wbo_be    <= 1 << taddr[1:0];
               wbo_be       <= 4'hF;
               if(cnt == 1) begin
               if(cnt == 1) begin
                  wbo_stb   <= 1'b0;
                  wbo_stb   <= 1'b0;
                  wbo_cyc   <= 1'b0;
                  wbo_cyc   <= 1'b0;
                  state     <= IDLE;
                  state     <= IDLE;
               end
               end
               else if(mem_afull) begin
               else if(mem_afull) begin // to handle the interburst fifo  full case
 
                  wbo_cyc   <= 1'b0;
                  wbo_stb   <= 1'b0;
                  wbo_stb   <= 1'b0;
               end
               end
            end else if(!mem_full) begin
            end else if(!mem_full) begin // to handle interbust fifo full cases
 
                wbo_cyc     <= 1'b1;
                wbo_stb   <= 1'b1;
                wbo_stb   <= 1'b1;
            end
            end
         end
         end
      endcase
      endcase
   end
   end

powered by: WebSVN 2.1.0

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