⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_new_pck_configuration.vhdl

📁 实现USB接口功能的VHDL和verilog完整源代码
💻 VHDL
📖 第 1 页 / 共 3 页
字号:

  function GetConfiguration(Config: S_ConfigArray)
              return S_ConfigurationRange;

  function AllowConnect(Config: S_ConfigArray)
              return boolean;

  function NoLazyClock(Config: S_ConfigArray)
              return boolean;

  function NumberOfDownstreamPorts(Config: S_ConfigArray)
              return integer;

  function ClockDiv(Config: S_ConfigArray)
              return integer;

  function GangModePower(Config: S_ConfigArray)
              return boolean;


subtype S_RAMSizeRange is integer range 0 to RAM_SIZE;

-- RAM address support
constant MAX_RAM_ADDRESS: integer := RAM_SIZE;
subtype S_RAMAddr_range is integer range 0 to MAX_RAM_ADDRESS-1;
constant RAMADDR_ADDRWIDTH: integer := log2 (MAX_RAM_ADDRESS);
subtype S_RAMAddr_bits is unsigned(RAMAddr_ADDRWIDTH - 1 downto 0);

-- types for Buffer Start property
type T_USBBufferStart_1d is array (0 to 15) of S_RamSizeRange;
type T_USBBufferStart_2d is array (0 to N_DEVICES-1) of T_USBBufferStart_1d;
type T_USBBufferStart is array (0 to N_CONFIGURATIONS-1) of T_USBBufferStart_2d;


-- Constants for determing default endpoints

type T_DEFAULT_EP_DEV is
     array(0 to 1 - 1) of integer;

type T_DEFAULT_EP is
     array(0 to 2 - 1) of T_DEFAULT_EP_DEV;

constant DEFAULT_OUT_EP: T_DEFAULT_EP:= (
                                         0 => (0 => 0),
                                         1 => (0 => 0)                                        );

constant DEFAULT_IN_EP:  T_DEFAULT_EP:= (
                                         0 => (0 => 1),
                                         1 => (0 => 1)                                        );

  
  -- Types for UC_HANDLER (ID = 0) --

  type T_UC_HANDLER_RAMType is record
         BufferSize:   S_BufferSizeRange;
         BufferStart:  S_RAMSizeRange;
  end record;

  type T_UC_HANDLER_Endpoint is record
         EndpointType: T_EndpointType_enum;
         USBDirection: T_Direction_enum;
         HasCorrespondingEP: boolean;
         CorrespondingEP: S_PhysEndpointRange;
         N_Buffers: integer;
  end record;

  type T_UC_HANDLER_Endpoint_Array is 
       array(0 to NUM_ENDPOINTS(0)-1) of T_UC_HANDLER_Endpoint; 

  type T_UC_HANDLER_info is 
       array(0 to N_CONFIGURATIONS-1) of T_UC_HANDLER_Endpoint_Array; 

  function UC_HANDLER_Info return T_UC_HANDLER_Info;
					       
  type T_UC_HANDLER_RAM_Array is 
       array(0 to NUM_ENDPOINTS(0)-1) of T_UC_HANDLER_RAMType; 

  type T_UC_HANDLER_RAMinfo is 
       array(0 to N_CONFIGURATIONS-1) of T_UC_HANDLER_RAM_Array; 

  -- function UC_HANDLER_RAMInfo return T_UC_HANDLER_RAMInfo; ** Murali **
					       


  -- Types for DEVICE_HANDLER (ID = 1) --


end PCK_CONFIGURATION;


package body PCK_CONFIGURATION is

  function Equal(ConfigArray: S_ConfigArray;
    	         PatternArray: T_PatternArray) return boolean is
    variable IsEqual: boolean;
  begin
    IsEqual := TRUE;
    for i in 0 to CONFIG_RANGE-1 loop
      if (PatternArray(i) /= X) then
        if (PatternArray(i) = T) and (not ConfigArray(i)) then
    	  IsEqual := FALSE;
	  exit;
        elsif (PatternArray(i) = F) and ConfigArray(i) then
	  IsEqual := FALSE;
	  exit;
        end if;
      end if;
    end loop;
    return IsEqual;
  end Equal;


  function GetUSBEndpointSetup return T_USBEndpointSetup is
    variable USBEndpointSetup: T_USBEndpointSetup;
  begin

    for i in 0 to N_CONFIGURATIONS-1 loop
      for j in 0 to N_DEVICES-1 loop
        for k in 0 to 15 loop
  	  USBEndpointSetup.OUTEP.EndpointType (i)(j)(k):= UNUSED;
	  USBEndpointSetup.OUTEP.PhysEndpoint (i)(j)(k):= 0;
	  USBEndpointSetup.OUTEP.BufferSize (i)(j)(k):= 0;
--	  USBEndpointSetup.OUTEP.BufferStart (i)(j)(k):= 0;
	  USBEndpointSetup.OUTEP.DoubleBuffer (i)(j)(k):= FALSE;
	  USBEndpointSetup.OUTEP.Handler (i)(j)(k):= 0;
	  USBEndpointSetup.INEP.EndpointType (i)(j)(k):= UNUSED;
	  USBEndpointSetup.INEP.PhysEndpoint (i)(j)(k):= 0;
	  USBEndpointSetup.INEP.BufferSize (i)(j)(k):= 0;
--	  USBEndpointSetup.INEP.BufferStart (i)(j)(k):= 0;
	  USBEndpointSetup.INEP.DoubleBuffer (i)(j)(k):= FALSE;
	  USBEndpointSetup.INEP.Handler (i)(j)(k):= 0;
        end loop;
      end loop;
    end loop;



 --===============================================
 --==              Configuration 0              ==
 --===============================================


   ----------------------------------------
   --              Device 0              --
   ----------------------------------------


  -- Endpoint 0, Out
  USBEndpointSetup.OUTEP.EndpointType (0)(0)(0):= CONTROL;
--  USBEndpointSetup.OUTEP.BufferSize (0)(0)(0):= 8;
  USBEndpointSetup.OUTEP.BufferSize (0)(0)(0):= 16; 
  USBEndpointSetup.OUTEP.PhysEndpoint (0)(0)(0):= 0;
  USBEndpointSetup.OUTEP.DoubleBuffer (0)(0)(0):= FALSE; 
  USBEndpointSetup.OUTEP.Handler (0)(0)(0):= 0;

  -- Endpoint 0, In
  USBEndpointSetup.INEP.EndpointType (0)(0)(0):= CONTROL;
--  USBEndpointSetup.INEP.BufferSize (0)(0)(0):= 8;
  USBEndpointSetup.INEP.BufferSize (0)(0)(0):= 16; 
  USBEndpointSetup.INEP.PhysEndpoint (0)(0)(0):= 1;
 USBEndpointSetup.INEP.DoubleBuffer (0)(0)(0):= FALSE; 
  USBEndpointSetup.INEP.Handler (0)(0)(0):= 0;

  -- Endpoint 1, Out
  USBEndpointSetup.OUTEP.EndpointType (0)(0)(1):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.OUTEP.BufferSize (0)(0)(1):= 16;
  USBEndpointSetup.OUTEP.BufferSize (0)(0)(1):= 4; 
  USBEndpointSetup.OUTEP.PhysEndpoint (0)(0)(1):= 2;
  USBEndpointSetup.OUTEP.DoubleBuffer (0)(0)(1):= FALSE; 
  USBEndpointSetup.OUTEP.Handler (0)(0)(1):= 0;

  -- Endpoint 1, In
  USBEndpointSetup.INEP.EndpointType (0)(0)(1):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.INEP.BufferSize (0)(0)(1):= 16;
  USBEndpointSetup.INEP.BufferSize (0)(0)(1):= 16; 
  USBEndpointSetup.INEP.PhysEndpoint (0)(0)(1):= 3;
  USBEndpointSetup.INEP.DoubleBuffer (0)(0)(1):= FALSE; 
  USBEndpointSetup.INEP.Handler (0)(0)(1):= 0;

  -- Endpoint 2, Out
  USBEndpointSetup.OUTEP.EndpointType (0)(0)(2):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.OUTEP.BufferSize (0)(0)(2):= 16;
  USBEndpointSetup.OUTEP.BufferSize (0)(0)(2):= 64; 
  USBEndpointSetup.OUTEP.PhysEndpoint (0)(0)(2):= 4;
  USBEndpointSetup.OUTEP.DoubleBuffer (0)(0)(2):= TRUE;  -- changed by fma 99/07/13: no double buffering for Endp2 
  USBEndpointSetup.OUTEP.Handler (0)(0)(2):= 0;

  -- Endpoint 2, In
  USBEndpointSetup.INEP.EndpointType (0)(0)(2):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.INEP.BufferSize (0)(0)(2):= 16;
  USBEndpointSetup.INEP.BufferSize (0)(0)(2):= 64; 
  USBEndpointSetup.INEP.PhysEndpoint (0)(0)(2):= 5;
  USBEndpointSetup.INEP.DoubleBuffer (0)(0)(2):= TRUE; -- changed by fma 99/07/13: no double buffering for Endp2 
  USBEndpointSetup.INEP.Handler (0)(0)(2):= 0;

  -- Endpoint 3, Out
  USBEndpointSetup.OUTEP.EndpointType (0)(0)(3):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.OUTEP.BufferSize (0)(0)(3):= 64;
  USBEndpointSetup.OUTEP.BufferSize (0)(0)(3):= 64; 
  USBEndpointSetup.OUTEP.PhysEndpoint (0)(0)(3):= 6;
  USBEndpointSetup.OUTEP.DoubleBuffer (0)(0)(3):= TRUE; 
  USBEndpointSetup.OUTEP.Handler (0)(0)(3):= 0;

  -- Endpoint 3, In
  USBEndpointSetup.INEP.EndpointType (0)(0)(3):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.INEP.BufferSize (0)(0)(3):= 64;
  USBEndpointSetup.INEP.BufferSize (0)(0)(3):= 64; 
  USBEndpointSetup.INEP.PhysEndpoint (0)(0)(3):= 7;
  USBEndpointSetup.INEP.DoubleBuffer (0)(0)(3):= TRUE; 
  USBEndpointSetup.INEP.Handler (0)(0)(3):= 0;

  -- Endpoint 4, Out
  USBEndpointSetup.OUTEP.EndpointType (0)(0)(4):= ISOCHRONOUS;
--  USBEndpointSetup.OUTEP.BufferSize (0)(0)(4):= 294;
  USBEndpointSetup.OUTEP.BufferSize (0)(0)(4):= 32; 
  USBEndpointSetup.OUTEP.PhysEndpoint (0)(0)(4):= 8;
  USBEndpointSetup.OUTEP.DoubleBuffer (0)(0)(4):= TRUE; 
  USBEndpointSetup.OUTEP.Handler (0)(0)(4):= 0;

  -- Endpoint 4, In
  USBEndpointSetup.INEP.EndpointType (0)(0)(4):= ISOCHRONOUS;
--  USBEndpointSetup.INEP.BufferSize (0)(0)(4):= 294;
  USBEndpointSetup.INEP.BufferSize (0)(0)(4):= 32; 
  USBEndpointSetup.INEP.PhysEndpoint (0)(0)(4):= 9;
  USBEndpointSetup.INEP.DoubleBuffer (0)(0)(4):= TRUE; 
  USBEndpointSetup.INEP.Handler (0)(0)(4):= 0;


 --===============================================
 --==              Configuration 1              ==
 --===============================================


   ----------------------------------------
   --              Device 0              --
   ----------------------------------------

-- changed by fma 99/07/13: only one configuration

  -- Endpoint 0, Out
--  USBEndpointSetup.OUTEP.EndpointType (1)(0)(0):= CONTROL;
--  USBEndpointSetup.OUTEP.BufferSize (1)(0)(0):= 8;
--  USBEndpointSetup.OUTEP.PhysEndpoint (1)(0)(0):= 0;
--  USBEndpointSetup.OUTEP.DoubleBuffer (1)(0)(0):= FALSE;
--  USBEndpointSetup.OUTEP.Handler (1)(0)(0):= 0;

  -- Endpoint 0, In
--  USBEndpointSetup.INEP.EndpointType (1)(0)(0):= CONTROL;
--  USBEndpointSetup.INEP.BufferSize (1)(0)(0):= 8;
--  USBEndpointSetup.INEP.PhysEndpoint (1)(0)(0):= 1;
--  USBEndpointSetup.INEP.DoubleBuffer (1)(0)(0):= FALSE;
--  USBEndpointSetup.INEP.Handler (1)(0)(0):= 0;

  -- Endpoint 1, Out
--  USBEndpointSetup.OUTEP.EndpointType (1)(0)(1):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.OUTEP.BufferSize (1)(0)(1):= 8;
--  USBEndpointSetup.OUTEP.PhysEndpoint (1)(0)(1):= 2;
--  USBEndpointSetup.OUTEP.DoubleBuffer (1)(0)(1):= FALSE;
--  USBEndpointSetup.OUTEP.Handler (1)(0)(1):= 0;

  -- Endpoint 1, In
--  USBEndpointSetup.INEP.EndpointType (1)(0)(1):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.INEP.BufferSize (1)(0)(1):= 8;
--  USBEndpointSetup.INEP.PhysEndpoint (1)(0)(1):= 3;
--  USBEndpointSetup.INEP.DoubleBuffer (1)(0)(1):= FALSE;
--  USBEndpointSetup.INEP.Handler (1)(0)(1):= 0;

  -- Endpoint 2, Out
--  USBEndpointSetup.OUTEP.EndpointType (1)(0)(2):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.OUTEP.BufferSize (1)(0)(2):= 8;
--  USBEndpointSetup.OUTEP.PhysEndpoint (1)(0)(2):= 4;
--  USBEndpointSetup.OUTEP.DoubleBuffer (1)(0)(2):= TRUE;
--  USBEndpointSetup.OUTEP.Handler (1)(0)(2):= 0;

  -- Endpoint 2, In
--  USBEndpointSetup.INEP.EndpointType (1)(0)(2):= BULK_OR_INTERRUPT;
--  USBEndpointSetup.INEP.BufferSize (1)(0)(2):= 8;
--  USBEndpointSetup.INEP.PhysEndpoint (1)(0)(2):= 5;
--  USBEndpointSetup.INEP.DoubleBuffer (1)(0)(2):= TRUE;
--  USBEndpointSetup.INEP.Handler (1)(0)(2):= 0;

  -- Endpoint 3, Out
--  USBEndpointSetup.OUTEP.EndpointType (1)(0)(3):= ISOCHRONOUS;
--  USBEndpointSetup.OUTEP.BufferSize (1)(0)(3):= 196;
--  USBEndpointSetup.OUTEP.PhysEndpoint (1)(0)(3):= 6;
--  USBEndpointSetup.OUTEP.DoubleBuffer (1)(0)(3):= TRUE;
--  USBEndpointSetup.OUTEP.Handler (1)(0)(3):= 0;

  -- Endpoint 3, In
--  USBEndpointSetup.INEP.EndpointType (1)(0)(3):= ISOCHRONOUS;
--  USBEndpointSetup.INEP.BufferSize (1)(0)(3):= 196;
-- USBEndpointSetup.INEP.PhysEndpoint (1)(0)(3):= 7;
--  USBEndpointSetup.INEP.DoubleBuffer (1)(0)(3):= TRUE;
--  USBEndpointSetup.INEP.Handler (1)(0)(3):= 0;
    return USBEndpointSetup;

  end GetUSBEndpointSetup; 



  -- Functions for UC_HANDLER (ID = 0) --

  function UC_HANDLER_info return T_UC_HANDLER_Info is
    variable Result: T_UC_HANDLER_Info;
  begin

  -- Configuration 0

  -- Endpoint 0
    Result(0)(0).EndpointType      := CONTROL;
    Result(0)(0).USBDirection      := DIR_OUT;
    Result(0)(0).HasCorrespondingEP:= TRUE;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -