📄 usb_new_pck_apb.vhdl
字号:
--------------------------------------------------------------------------------
--
-- P H I L I P S C O M P A N Y R E S T R I C T E D
--
-- Copyright (c) 1998.
--
-- Philips Electronics N.V.
--
-- Philips Semiconductors
-- Interconnectivity and Processor Peripheral group
-- Bangalore, India
-- All rights reserved. Reproduction in whole or in part is prohibited
-- without the written permission of the copyright owner.
--
--------------------------------------------------------------------------------
--
-- File : usb_new_pck_apb.vhdl
--
-- Module : PCK_APB
--
-- Project : VPB bus interface to USB 1.1 device (USBFS22)
--
-- Author :
--
-- Description : This includes all packages definitions, type declarations,
-- subtype declarations and constant declarations.
--
-- Contact address : sanjeev@blr.sc.philips.com
--
--------------------------------------------------------------------------------
LIBRARY ieee;
USE IEEE.std_logic_1164.all;
USE IEEE.numeric_std.all;
LIBRARY work;
USE work.PCK_GENERAL.all;
USE work.PCK_HANDLERS.all;
package pck_apb is
-- Parametes for configuring the interface
-- Number of IN end points
constant N_InEndpoints: integer := 5;
-- Number of OUT end points
constant N_OutEndpoints: integer := 5;
-- Total no of logical endpoints.
constant No_Phy_Endpoints: integer := N_InEndpoints + N_OutEndpoints;
-- Total no of logical endpoints.
constant No_Log_Endpoints: integer := 5;
-- Depth of the Receive RAM
constant RxRamDepth: natural := 93;
-- Address bus width of the receive RAM.
constant RxRAMAddr_Width: integer := 7;
-- Depth of the Transmit Ram
constant TxRamDepth: natural := 96;
-- Address bus width of the receive Ram.
constant TxRAMAddr_Width: integer := 7;
-- USB slave address related
constant WRONG_ADDRESS_ID : unsigned := "11011110101011011010101110111010";
constant USB_BASE_ADDRESS : unsigned := "100011110000000000000000";
constant USB_MAX_ADDRESS : unsigned := "00101100";
-- Parameters which will remain fixed
-- Addresses of the Registers
constant Addr_IntrStatusReg: byte := "00000000"; -- 0x00 Interrupt Status register
constant Addr_IntrEnableReg: byte := "00000100"; -- 0x04 Interrupt Enable Register
constant Addr_IntrClearReg: byte := "00001000"; -- 0x08 Interrupt Clear Register
constant Addr_IntrSetReg: byte := "00001100"; -- 0x0C Interrupt Set Register
constant Addr_CmdcodeReg: byte := "00010000"; -- 0x10 Command Code Register
constant Addr_CmddataReg: byte := "00010100"; -- 0x14 Command Data Register
constant Addr_RcvDataReg: byte := "00011000"; -- 0x18 Processor reads data from this register
constant Addr_TrnsmtDataReg: byte := "00011100"; -- 0x1C Processor writes data to this register
constant Addr_RxPacketLengthReg: byte := "00100000"; -- 0x20 Packet length of OUT endpoint
constant Addr_TxPacketLengthReg: byte := "00100100"; -- 0x24 Packet length of IN endpoint
constant Addr_UsbControlReg: byte := "00101000"; -- 0x28 Usb Control register
constant Addr_FiqSelReg: byte := "00101100"; -- 0x2C FIQ Sel register
constant MaxCountData: natural := 66;
-- Interrupt positions in Interrupt Status Register
constant IntrNo_Frame: natural := 0;
constant IntrNo_USB_Ep0: natural := 1;
constant IntrNo_USB_Ep1: natural := 2;
constant IntrNo_USB_Ep2: natural := 3;
constant IntrNo_USB_Ep3: natural := 4;
constant IntrNo_USB_Ep4: natural := 5;
constant IntrNo_USB_Ep5: natural := 6;
constant IntrNo_USB_Ep6: natural := 7;
constant IntrNo_USB_Ep7: natural := 8;
constant IntrNo_USB_Dev: natural := 9;
constant IntrNo_CmdCodeReg_Empty: natural := 10;
constant IntrNo_CmdDataReg_Full: natural := 11;
constant IntrNo_OUT_EndOfPacket: natural := 12;
constant IntrNo_IN_EndOfPacket: natural := 13;
-- EP status positions in Interrupt Status Register
constant Ep1_NAK: natural := 16;
constant Ep3_NAK: natural := 17;
constant Ep5_NAK: natural := 18;
constant Ep7_NAK: natural := 19;
type T_MipsWord is array (0 to 3) of byte;
subtype RxRAMAddr_bits is unsigned(RxRAMAddr_WIDTH - 1 downto 0);
subtype TxRAMAddr_bits is unsigned(TxRAMAddr_WIDTH - 1 downto 0);
subtype Int_RxAddrTableType is integer range 0 to 7;
subtype Int_TxAddrTableType is integer range 0 to 7;
subtype Int_OneBit is integer range 0 to 1;
subtype Int_TwoBits is integer range 0 to 3;
subtype Int_ThreeBits is integer range 0 to 7;
subtype Int_FourBits is integer range 0 to 15;
subtype Int_FiveBits is integer range 0 to 31;
subtype Int_CountDatatype is integer range 0 to MaxCountData - 1;
subtype Int_EndPointType is integer range 0 to No_Phy_Endpoints - 1;
subtype logical_ep_type is integer range 0 to No_Log_Endpoints - 1;
subtype Int_RxRamType is integer range 0 to RxRamDepth - 1;
subtype Int_TxRamType is integer range 0 to TxRamDepth - 1;
TYPE T_UC_to_pi_handler IS RECORD
rx_data : byte;
endpoint : Int_EndPointType;
setuppacket : boolean;
end_of_transfer : boolean;
END RECORD;
TYPE T_pi_to_uc_handler IS RECORD
rx_data : byte;
endpoint : Int_EndPointType;
data_ready : boolean;
END RECORD;
function logical_to_physical(endp: integer; special_data: one_bit) return Int_EndPointType;
function get_rx_buffer_address(index: natural) return integer;
function get_tx_buffer_address(index: natural) return integer;
function physical_to_logical (Endpoint: Natural) return logical_ep_type;
function dma_endp_iso(index: Int_EndPointType) return boolean;
end pck_apb;
package body pck_apb is
-- This function converts logical endpoint number into physical endpoint number
function logical_to_physical(endp: integer; special_data: one_bit) return Int_EndPointType is
variable endpoint : Int_EndPointType;
begin
if(special_data = '0') then
case endp is
when 0 => endpoint := 0;
when 1 => endpoint := 2;
when 2 => endpoint := 4;
when 3 => endpoint := 6;
when 4 => endpoint := 8;
when others =>
end case;
else
case endp is
when 0 => endpoint := 1;
when 1 => endpoint := 3;
when 2 => endpoint := 5;
when 3 => endpoint := 7;
when 4 => endpoint := 9;
when others =>
end case;
end if;
return endpoint;
end;
-- This function converts physical endpoint number into logical endpoint number
function physical_to_logical (Endpoint: Natural) return logical_ep_type is
variable destination_tag : logical_ep_type;
begin
case Endpoint is
when 0 => destination_tag := 0;
when 1 => destination_tag := 0;
when 2 => destination_tag := 1;
when 3 => destination_tag := 1;
when 4 => destination_tag := 2;
when 5 => destination_tag := 2;
when 6 => destination_tag := 3;
when 7 => destination_tag := 3;
when 8 => destination_tag := 4;
when 9 => destination_tag := 4;
when others =>
end case;
return destination_tag;
end;
-- This function returns the start address of a RX RAM buffer
function get_rx_buffer_address(index: natural) return integer is
variable address: integer;
begin
case index is
when 0 => address := 0;
when 1 => address := 5;
when 2 => address := 7;
when 3 => address := 24;
when 4 => address := 41;
when 5 => address := 58;
when 6 => address := 75;
when 7 => address := 84;
when others =>
end case;
return address;
end;
-- This function returns the start address of a TX RAM buffer
function get_tx_buffer_address(index: natural) return integer is
variable address: integer;
begin
case index is
when 0 => address := 0;
when 1 => address := 5;
when 2 => address := 10;
when 3 => address := 27;
when 4 => address := 44;
when 5 => address := 61;
when 6 => address := 78;
when 7 => address := 87;
when others =>
end case;
return address;
end;
-- This function determines whether an endpoint is ISO or not
function dma_endp_iso(index: Int_EndPointType) return boolean is
variable dma_iso : boolean;
begin
if(index = 8 or index = 9) then
dma_iso := true;
else
dma_iso := false;
end if;
return dma_iso;
end;
end pck_apb;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -