vi_dma.v 4.17 KB
 /************************************************************************\
 *                                                                        *
 *               Copyright (C) 1994, Silicon Graphics, Inc.               *
 *                                                                        *
 *  These coded instructions, statements, and computer programs  contain  *
 *  unpublished  proprietary  information of Silicon Graphics, Inc., and  *
 *  are protected by Federal copyright  law.  They  may not be disclosed  *
 *  to  third  parties  or copied or duplicated in any form, in whole or  *
 *  in part, without the prior written consent of Silicon Graphics, Inc.  *
 *                                                                        *
 \************************************************************************/

// $Id: vi_dma.v,v 1.7 2003/01/24 23:07:37 berndt Exp $

module vi_dma(clk, reset_l,
   cbus_read_enable, cbus_write_enable, cbus_select, cbus_command,
   read_grant, dma_address, dma_length, reg_read_data,
   read_request, reg_write_data, reg_address, reg_write_enable,
   cbus_din, cbus_dout);

`include "vi.vh"

parameter READ_DELAY = -8'd3;		     // 5 clock advance

input clk;                                   // system clock
input reset_l;                               // system reset_l

input cbus_read_enable;                      // enable cbus read mux
input cbus_write_enable;                     // enable cbus tristate drivers
input [1:0] cbus_select;    // cbus data select
input [2:0] cbus_command;  // cbus data type
input read_grant;                            // read response request granted
input [DRAM_ADDRESS_SIZE-1:0] dma_address;   // DMA slave address
input [DMA_LENGTH_SIZE-1:0] dma_length;      // DMA length in words
input [31:0] reg_read_data;    // register read data to cbus

output read_request;                         // request a read response cycle
output [31:0] reg_write_data;	// register write data from cbus
output [VI_REG_ADDRESS_SIZE-1:0] reg_address;	// register read/write address
output reg_write_enable;                     // register write enable

input [31:0] cbus_din;        // IO bus
output [31:0] cbus_dout;        // IO bus


// input/output registers
reg read_request;
reg reg_write_enable;
reg [VI_REG_ADDRESS_SIZE-1:0] reg_address;
reg [2:0] cbus_command_reg;
reg [31:0] cbus_data_reg;

// cbus tristate drivers
wire [31:0] cbus_dout = cbus_write_enable ? cbus_data_reg : 32'b0;

//cbus_driver cbus_driver_0(cbus_data_reg, cbus_write_enable, cbus_data);

assign reg_write_data = cbus_data_reg;


always @(posedge clk) begin : cbus_block
   reg [31:0] cbus_data_out;

   case (cbus_select)
      `CBUS_SEL_ADDR :
        cbus_data_out = dma_address;
      `CBUS_SEL_LEN :
        cbus_data_out = {`CBUS_DEV_VI, READ_DELAY, HIGH, dma_length};
      `CBUS_SEL_DATA :
        cbus_data_out = reg_read_data;
      default :
        cbus_data_out = 'bx;
      endcase

   cbus_command_reg <= cbus_command;
   cbus_data_reg <= cbus_read_enable ? cbus_din : cbus_data_out;
   end


always @(posedge clk) begin
   if (reset_l == 1'b0) begin
      // resetable registers
      read_request <= LOW;
      reg_write_enable <= LOW;
      end
   else begin : main_block
      reg next_read_request;
      reg next_reg_write_enable;
      reg [BUS_ID_SIZE-1:0] next_id;
      reg next_select;
      reg next_write_command;
      reg next_read_command;

      next_read_request = read_request;
      next_reg_write_enable = LOW;

      next_id = cbus_data_reg >> BUS_ID_OFFSET;
      next_select = next_id == `CBUS_VI;
      next_write_command = cbus_command_reg == `CBUS_CMD_WRITE;
      next_read_command = cbus_command_reg == `CBUS_CMD_READ;

      if (next_select) begin
         if (next_write_command) begin
            next_reg_write_enable = HIGH;
            reg_address <= cbus_data_reg >> 2;
            end
         else if (next_read_command) begin
            next_read_request = HIGH;
            reg_address <= cbus_data_reg >> 2;
            end
         end

      if (read_request && read_grant) begin
         next_read_request = LOW;
         end

      read_request <= next_read_request;
      reg_write_enable <= next_reg_write_enable;
      end
   end
endmodule