📄 usb_new_device_handler_rtl.vhdl
字号:
----------------------------------------------------------------------------------------
---- File >>> usb_new_device_handler_rtl.vhdl
---- Iden >>> 980318-11:12:45
----
---- Project: USB Developement
---- Customer: Philips_ITCL
----
---- VHDL Design Unit: architecture RTL of DEVICE_HANDLER
---- Written by: Usb User
---- Easics nv
---- http://www.easics.com
---- mailto: vhdl@easics.be
----
---- Creation Date: Wed, 18 Mar 1998
----
---- Purpose:
----
---- Revision history:
----
----------------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
library work;
use work.PCK_GENERAL.all;
use work.PCK_COMMANDS.all;
use work.PCK_USB.all;
use work.PCK_CONFIGURATION.all;
use work.PCK_HANDLERS.all;
architecture RTL of DEVICE_HANDLER is
constant MAX_INDEX: integer := Maximum((N_INTR_BITS+7)/8,
Maximum((UCCONFIG_RANGE+7)/8,
Maximum((PINCONFIG_RANGE+7)/8,
Maximum((CHIPID_WIDTH+7)/8,2))));
subtype S_Index is integer range 0 to MAX_INDEX;
signal Selected: boolean;
signal DataToUC: T_Handlers_to_UC;
signal UCConfigArray: S_UCConfigArray;
signal DataToSIE: T_Handlers_to_SIE;
signal Connect: boolean;
signal VBusDebounced: boolean;
signal FrameNumber: eleven_bits;
signal DH_Interrupt: boolean;
constant INTERRUPT_PULSE_LENGTH: integer := 12; -- 1us
-- DOC_BEGIN: Device Status Bit Positions
constant CONNECT_BIT_POS: integer := 0;
constant CONNECT_CHANGE_BIT_POS: integer := 1;
constant SUSPEND_BIT_POS: integer := 2;
constant SUSPEND_CHANGE_BIT_POS: integer := 3;
constant RESET_BIT_POS: integer := 4;
constant REMOTEWAKEUP_BIT_POS: integer := 5;
-- DOC_END
signal ConfigArray_int: S_ConfigArray;
-- DOC_BEGIN: Function GetDeviceStatus
-- This function assembles the device status register
function GetDeviceStatus(Connect: boolean;
ChangeConnect: boolean;
Suspend: boolean;
SuspendChange: boolean;
BusReset: boolean;
RemoteWakeupEvent: boolean) return byte is
variable Result: byte;
begin
Result := (others => '0');
Result(CONNECT_BIT_POS) := conv_active_high(Connect);
Result(CONNECT_CHANGE_BIT_POS) := conv_active_high(ChangeConnect);
Result(SUSPEND_BIT_POS) := conv_active_high(Suspend);
Result(SUSPEND_CHANGE_BIT_POS) := conv_active_high(SuspendChange);
Result(RESET_BIT_POS) := conv_active_high(BusReset);
Result(REMOTEWAKEUP_BIT_POS) := conv_active_high(RemoteWakeupEvent);
return Result;
end;
-- DOC_END
type T_Command_enum is (GET_INTERRUPT,
GET_FRAMENUMBER,
GETSET_MODE,
GET_ERROR,
GET_CHIPID,
GETSET_DEVICE_STATUS,
INVALID
);
-- DOC_BEGIN: Functions GetByteSlice and SetByteSlice
-- GetByteSlice extracts a byte from a larger register. If
-- the requestes bits are outside the range of the register,
-- 0's are returned.
function GetByteSlice(Source: unsigned;
Index: S_Index) return byte is
variable ReturnValue: byte;
begin
ReturnValue := (others => '0');
for i in 0 to 7 loop
if 8*Index+i <= Source'high then
ReturnValue(i) := Source(8*Index+i);
end if;
end loop;
return ReturnValue;
end GetByteSlice;
-- SetByteSlice replaces a byte in a larger register.
-- Bits that fall outside the range of the register are
-- ignored.
function SetByteSlice(Destination: unsigned;
Source: byte;
Index: S_Index) return unsigned is
variable ReturnValue: unsigned(Destination'high downto 0);
begin
ReturnValue := Destination;
for i in 0 to 7 loop
if 8*Index+i <= Destination'high then
ReturnValue(8*Index+i) := Source(i);
end if;
end loop;
return ReturnValue;
end SetByteSlice;
-- DOC_END
-- DOC_BEGIN: Function EncodeError
-- This function converts the enumerated type containing the
-- error type into a 4 bit code. This code is returned to the
-- micro controler.
function EncodeError(ErrorCode: T_PACKET_ERROR_enum) return four_bits is
begin
case ErrorCode is
when ERROR_PID_ENCODING => return "0001";
when ERROR_PID_UNKNOWN => return "0010";
when ERROR_PACKET_UNEXPECTED => return "0011";
when ERROR_TOKEN_CRC => return "0100";
when ERROR_DATA_CRC => return "0101";
when ERROR_TIMEOUT => return "0110";
when ERROR_BABBLE => return "0111";
when ERROR_TR_EOP => return "1000";
when ERROR_SENT_RECEIVED_NAK => return "1001";
when ERROR_SENT_STALL => return "1010";
when ERROR_OVERRUN => return "1011";
when ERROR_SENT_EMPTYPACK => return "1100";
when ERROR_BITSTUFF_ERROR => return "1101";
when ERROR_SYNC_ERROR => return "1110";
when ERROR_DATA_IGNORED_WRONG_DATA01 => return "1111";
when others => return "0000";
end case;
end;
-- DOC_END
begin
-- Connection to micro-controller
UCConnector(DataToUC_Out, DataToUC_In,
DataToUC, Selected);
-- Connection to SIE for devices that don't support
-- endpoint data handling
DummySIEConnector(ID, DataFromHandlers_Out, DataFromHandlers_In, DataToSIE);
ConfigArray_int <= PINConfigArray & UCConfigArray;
ConfigArray <= ConfigArray_int;
FrameNumber <= DataToHandlers.FrameNumber when SUPPORT_C_GETFRAMENUMBER else
(others => '0');
MAIN: process(FsClk, PUReset_N)
variable ByteCounter: S_Index;
variable Command: T_Command_enum;
variable BusResetInterrupt: boolean;
variable SuspendChangeInterrupt: boolean;
variable TM_Suspend_Z: boolean;
variable ConnectChangeInterrupt: boolean;
variable AllowConnect: boolean;
subtype S_DebounceTimer is integer range 0 to VBUS_DEBOUNCE_TIME;
variable DebounceTimer: S_DebounceTimer;
variable InterruptLevel: boolean;
variable InterruptEdge: boolean;
variable Interrupt_Z: S_Interrupt_bool;
variable EdgeTimer: integer range 0 to INTERRUPT_PULSE_LENGTH -1;
variable RemoteWakeupEvent: boolean;
begin
if (PUReset_N = ACTIVE_LOW) then
Selected <= FALSE;
DataToUC <= HandlersToUCDefault;
DataToSIE.RemoteWakeup <= FALSE;
ByteCounter := 0;
Command := INVALID;
BusResetInterrupt := FALSE;
SuspendChangeInterrupt := FALSE;
TM_Suspend_Z := FALSE;
DH_Interrupt <= FALSE;
UCConfigArray <= CONFIG_RESET;
DebounceTimer := VBUS_DEBOUNCE_TIME;
Connect <= FALSE;
AllowConnect := FALSE;
DataToSIE.Interrupts(0) <= FALSE;
VbusDebounced <= FALSE;
ConnectChangeInterrupt := FALSE;
Interrupt_Z := (others => FALSE);
EdgeTimer := 0;
RemoteWakeupEvent := FALSE;
DH_Interrupt_Ep0 <= FALSE;
DH_Interrupt_Ep1 <= FALSE;
DH_Interrupt_Ep2 <= FALSE;
DH_Interrupt_Ep3 <= FALSE;
DH_Interrupt_Ep4 <= FALSE;
DH_Interrupt_Ep5 <= FALSE;
DH_Interrupt_Ep6 <= FALSE;
DH_Interrupt_Ep7 <= FALSE;
DH_Interrupt_Dev <= FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -