📄 usb_new_pck_usb.vhdl
字号:
-----------------------------------------------------------------------------------
---- File >>> usb_new_pck_usb.vhdl
---- Iden >>> 950804-09:06:18
----
---- Project: USB Development
---- Customer: Philips_ITCL
----
---- Module: package for USB
---- Written by: Jan Zegers (e-mail: janz@easics.be)
---- Easics nv
---- Kapeldreef 60
---- B-3001 Leuven
---- Belgium
---- Tel +32-16-270.400
---- Fax +32-16-270.319
---- e-mail: vhdl@easics.be
----
---- Creation Date: Fri, 04 Aug 1995
----
---- Purpose:
----
---- Revision history:
----
-----------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
library work;
use work.PCK_GENERAL.all;
package PCK_USB is
----------------------------------------------------------------
-- Hub Port Status and port Status Change
----------------------------------------------------------------
type T_HubPortStatus is record
Connect: boolean;
Enable: boolean;
Suspend: boolean;
OverCurrent: boolean;
Reset: boolean;
Power: boolean;
LowSpeed: boolean;
end record;
type T_HubPortStatusChange is record
Connect: boolean;
Enable: boolean;
Suspend: boolean;
OverCurrent: boolean;
Reset: boolean;
end record;
type T_EmbPortStatus is record
Connect: boolean;
Enable: boolean;
Suspend: boolean;
Reset: boolean;
Power: boolean;
end record;
type T_EmbPortStatusChange is record
Connect: boolean;
Enable: boolean;
Suspend: boolean;
Reset: boolean;
end record;
type T_HubPortStatus_array is array(integer range <>) of T_HubPortStatus;
type T_HubPortStatusChange_array is array(integer range <>) of T_HubPortStatusChange;
type T_EmbPortStatus_array is array(integer range <>) of T_EmbPortStatus;
type T_EmbPortStatusChange_array is array(integer range <>) of T_EmbPortStatusChange;
----------------------------------------------------------------
-- Packet size
----------------------------------------------------------------
-- Maximum data packet size is specified as 1024 bytes in length
-- This is only the data size, not including SYNC etc.
constant MAX_PACKET_LENGTH: integer := 1024;
subtype S_PACKET_LENGTH_range is
integer range 0 to MAX_PACKET_LENGTH - 1;
-----------------------------------------------------------------
-- Device addresses
-- addresses on USB range from 0 to 127
-- address 0 is reserved
-----------------------------------------------------------------
constant MAX_DEVICE_ADDRESS: integer := 128;
subtype S_DevAddr_range is integer range 0 to MAX_DEVICE_ADDRESS - 1;
--
--constant DevAddr_ADDRWIDTH: integer := 7;
constant DevAddr_ADDRWIDTH: integer := Log2(MAX_DEVICE_ADDRESS);
subtype S_DevAddr_bits is
unsigned(DevAddr_ADDRWIDTH - 1 downto 0);
constant DEFAULT_DEVICE_ADDRESS: S_DevAddr_range := 0;
-----------------------------------------------------------------
-- End points
-- Full speed devices may have any of the 16 possible endpoints
-- Low speed devices are limited one additional endpoint address
-- Control endpoint 0 is reserved in all cases
-----------------------------------------------------------------
constant MAX_ENDPOINT_ADDRESS: integer := 16;
subtype S_EndpAddr_range is integer range 0 to MAX_ENDPOINT_ADDRESS - 1;
subtype S_EndpAddr_booleans is
booleans(MAX_ENDPOINT_ADDRESS - 1 downto 0);
--constant EndpAddr_ADDRWIDTH: integer := 4;
constant EndpAddr_ADDRWIDTH: integer := Log2(MAX_ENDPOINT_ADDRESS);
subtype S_EndpAddr_bits is
unsigned(EndpAddr_ADDRWIDTH - 1 downto 0);
constant DEFAULT_ENDPOINT_ADDRESS: S_EndpAddr_range := 0;
----------------------------------------------------------------
-- Check if device/endpoint combination is addressed
----------------------------------------------------------------
-- If a device is not configured, it should respond to the
-- DEFAULT_DEVICE_ADDRESS and ignore whatever endpoint is specified
-- If a device is configured, it should respond to its own
-- configured DevAddr and to the active endpoints indicated
-- in ActiveEndps. If we put the DEFAULT_ENDPOINT_ADDRESS to TRUE in
-- this boolean array, the device will always respond to
-- the default pipe.
function IsDevAddr (DevAddr: S_DevAddr_range;
EndpAddr: S_EndpAddr_range;
ThisDevAddr: S_DevAddr_range;
ActiveEndps: S_EndpAddr_booleans;
DevConf: boolean)
return boolean;
----------------------------------------------------------------
-- Speeds of the USB devices and bus
-- Full speed is 12 MHz => Tfs = 83.33 ns
-- Low speed is 12 MHz / 8 = 1.5 MHz => Tls = 666.66 ns
----------------------------------------------------------------
type T_UsbSpeed_enum is (USB_FULL_SPEED,
USB_LOW_SPEED
);
function DecodeUsbSpeed (SpeedType: one_bit)
return T_UsbSpeed_enum;
function EncodeUsbSpeed (SpeedType: T_UsbSpeed_enum)
return one_bit;
----------------------------------------------------------------
-- Frame length and EOF points
----------------------------------------------------------------
constant FLTyp: integer := 11999;
constant FLMIN: integer := 11955;
constant FLMAX: integer := 12045;
constant EOF1_POINT: integer := 32;
constant EOF2_POINT: integer := 10;
constant FRAMELENGTH_FS: integer := 12000;
constant FRAMELENGTH_LS: integer := 1500;
function GetFrameLength(Speed: T_UsbSpeed_enum)
return integer;
----------------------------------------------------------------
-- Frame timing (SOF)
----------------------------------------------------------------
constant FRAME_TIME: integer := FLMax;
subtype S_FRAME_TIME_range is integer range 0 to FRAME_TIME - 1;
--constant FRAME_TIME_WIDTH: integer := 11;
constant FRAME_TIME_WIDTH: integer := Log2(FRAME_TIME);
subtype S_FRAME_TIME_WIDTH_bits is
unsigned(FRAME_TIME_WIDTH - 1 downto 0);
function ConvertAddrToTime (DevAddr: S_DevAddr_range;
EndpAddr: S_EndpAddr_range)
return S_FRAME_TIME_range;
----------------------------------------------------------------
-- Definitions for the USB bus convertions
----------------------------------------------------------------
-- Enumerated type representing the logical values of the bus
-- for both the Rx and Tx direction
-- In Rx direction the values are single-ended zero, J, K and
-- single-ended one
-- In Tx direction the values are single-ended zero, J, K and
-- tristate or Z
type T_UsbLog_enum is (USB_LOG_SE0,
USB_LOG_J,
USB_LOG_K,
USB_LOG_SE1_OR_Z);
function UsbBus2Log (DifInput: one_bit;
LineInput: two_bits;
SpeedType: T_UsbSpeed_enum)
return T_UsbLog_enum;
function UsbDif2Log (DifInput: two_bits;
SpeedType: T_UsbSpeed_enum)
return T_UsbLog_enum;
function UsbLog2Dif (LogInput: T_UsbLog_enum;
SpeedType: T_UsbSpeed_enum)
return two_bits;
----------------------------------------------------------------
-- Start Of Packet (SOP)
----------------------------------------------------------------
-- Detects a J->K transition
function StartOfPacket (PrevLogVal: T_UsbLog_enum;
CurrLogVal: T_UsbLog_enum)
return boolean;
----------------------------------------------------------------
-- End Of Packet (EOP)
----------------------------------------------------------------
constant EOP_MAX_SE0: integer := 2;
subtype S_EOP_MAX_SE0_range is integer range 0 to EOP_MAX_SE0;
-- This function only detects the SE0 in a packet
-- transmission. It returns TRUE if the CurrLogVal = SE0
function EndOfPacket (CurrLogVal: T_UsbLog_enum)
return boolean;
----------------------------------------------------------------
-- NRZI decoding function
----------------------------------------------------------------
-- Function DecodeNRZI returns the data bit by comparing the
-- previous value on the bus with the current value. If the
-- previous value is different we have a LOW otherwise we
-- have a HIGH data bit.
function DecodeNRZI (PrevLogVal: T_UsbLog_enum;
CurrLogVal: T_UsbLog_enum)
return one_bit;
function EncodeNRZI (PrevLogVal: T_UsbLog_enum;
CurrDataVal: one_bit)
return T_UsbLog_enum;
----------------------------------------------------------------
-- Bit-stuffing
-- The BITSTUFF_LENGTH gives the number of BITSTUFF_VALUE bits
-- that have to be detected before inserting the inverse bit.
-- It is an Error not to have a transition when
-- the BITSTUFF_LENGTH count is reached
-- In USB, six consecutive HIGH should be interrupted with LOW
----------------------------------------------------------------
constant BITSTUFF_LENGTH: integer := 6;
subtype S_BitStuff_range is integer range 0 to BITSTUFF_LENGTH;
constant BITSTUFF_VALUE: one_bit := HIGH;
function IncStuffedBitCnt (BitValue: one_bit)
return boolean;
function IsStuffedBit (BitValue: one_bit;
BitStuffCnt: S_BitStuff_range)
return boolean;
function IsBitStuffError (BitValue: one_bit;
BitStuffCnt: S_BitStuff_range)
return boolean;
-- Procedure DeStuff will determine based on the current BitValue
-- and the current number of bits with BITSTUFF_VALUE whether:
-- a bitstuff error has occurred
-- whether this bit is a stuffed bit
-- and a new BitStuffCnt value
procedure DeStuff (BitValue: in one_bit;
BitStuffCnt: in S_BitStuff_range;
BitStuffError: out boolean;
StuffedBit: out boolean;
NewBitStuffCnt: out S_BitStuff_range);
-- Procedure Stuff will determine based on the current BitValue
-- and the current number of bits with BITSTUFF_VALUE whether:
-- a bitstuff error has to be forced
-- whether this bit position should be stuffed
-- and a new BitStuffCnt value
procedure Stuff (BitValue: in one_bit;
BitStuffCnt: in S_BitStuff_range;
BitStuffError: in boolean;
StuffedBit: out boolean;
NewBitStuffCnt: out S_BitStuff_range);
----------------------------------------------------------------
-- Sync pattern is sent at the beginning of any packet on the
-- USB bus. The bits are sent LSB first.
-- This will result in J-K-J-K-J-K-J-K-K
----------------------------------------------------------------
constant SYNC_PATTERN: byte := "10000000";
----------------------------------------------------------------
-- All connect/disconnect/reset/timeout constants are specified
-- in clock cycles of the full speed (12 MHz) clock
----------------------------------------------------------------
-- If a device is connected or disconnected to/from host or hub,
-- this is detected after 56 Full Speed bit times.
constant LS_HUB_CONNECT: integer := 56;
constant LS_HUB_DISCONNECT: integer := 56;
constant FS_HUB_CONNECT: integer := 56;
constant FS_HUB_DISCONNECT: integer := 56;
constant RESET_PERIOD: integer := 56;
constant HOST_TIMEOUT: integer := 24;
constant DEVICE_TIMEOUT: integer := 16;
subtype S_LS_HUB_CONNECT_range is
integer range 0 to LS_HUB_CONNECT - 1;
subtype S_LS_HUB_DISCONNECT_range is
integer range 0 to LS_HUB_DISCONNECT - 1;
subtype S_FS_HUB_CONNECT_range is
integer range 0 to FS_HUB_CONNECT - 1;
subtype S_FS_HUB_DISCONNECT_range is
integer range 0 to FS_HUB_DISCONNECT - 1;
subtype S_RESET_PERIOD_range is integer range 0 to RESET_PERIOD - 1;
subtype S_HOST_TIMEOUT_range is integer range 0 to HOST_TIMEOUT - 1;
subtype S_DEVICE_TIMEOUT_range is integer range 0 to DEVICE_TIMEOUT - 1;
----------------------------------------------------------------
-- Data transferred between the Transceiver and PrtMgr
----------------------------------------------------------------
subtype S_RxData_bits is byte;
subtype S_TxData_bits is byte;
constant RXDATA_WIDTH: integer := S_RxData_bits'length;
constant TXDATA_WIDTH: integer := S_TxData_bits'length;
subtype S_RXDATA_WIDTH_range is integer range 0 to RXDATA_WIDTH - 1;
subtype S_TXDATA_WIDTH_range is integer range 0 to TXDATA_WIDTH - 1;
subtype S_UsbWord_bits is byte;
constant USBWORD_WIDTH: integer := S_UsbWord_bits'length;
subtype S_UsbWord_range is integer range 0 to ((2**USBWORD_WIDTH) - 1);
subtype S_USBWORD_WIDTH_range is integer range 0 to USBWORD_WIDTH - 1;
type T_PACKET_ERROR_enum is (ERROR_NO_ERROR,
ERROR_PID_ENCODING,
ERROR_PID_UNKNOWN,
ERROR_PACKET_UNEXPECTED,
ERROR_TOKEN_CRC,
ERROR_DATA_CRC,
ERROR_TIMEOUT,
ERROR_BABBLE,
ERROR_TR_EOP,
ERROR_SENT_RECEIVED_NAK,
ERROR_SENT_STALL,
ERROR_OVERRUN,
ERROR_SENT_EMPTYPACK,
ERROR_BITSTUFF_ERROR,
ERROR_SYNC_ERROR,
ERROR_DATA_IGNORED_WRONG_DATA01
);
type T_Pid_enum is (
PID_INVALID, -- 16#0#, unused, invalid pid
PID_OUT, -- 16#1#, Host -> device
PID_ACK, -- 16#2#, Rx accepts error-free packet
PID_DATA0, -- 16#3#, Even data packet
PID_RESERVED_1, -- 16#4#, unused
PID_SOF, -- 16#5#, Start of Frame, Frame nr
PID_ERR, -- 16#6#, Rx CRC or bitstuff error
PID_RESERVED_2, -- 16#7#, unused
PID_RESERVED_3, -- 16#8#, unused
PID_IN, -- 16#9#, Device -> host
PID_NAK, -- 16#A#, Rx can't accept, Tx no data
PID_DATA1, -- 16#B#, Even data packet
PID_PRE, -- 16#C#, preamble LS->FS
PID_SETUP, -- 16#D#, Setup for ctrl transaction
PID_STALL, -- 16#E#, Endpoint is stalled
PID_RESERVED_4 -- 16#F#, unused
);
-- File>>> Pid.def.vhd
--
-- Generated by: AccessVHDL
----
---- Copyright(c) 1995 by Easics NV. All rights reserved.
----
---- This source file is proprietary and confidential information
---- of Easics NV and may be used and disclosed only as authorized
---- in a consulting and/or subcontracting agreement where the
---- source code is part of the statement of work specified in
---- the agreement, or if Easics NV has given it's written consent
---- to such use or disclosure.
---- This source file remains the sole property of
---- Easics NV, Kapeldreef 60, B-3001 Leuven, Belgium.
----
-- Current user: Jan Zegers 08/95 tijdel. NO ITCL
-- Current date: Tue Aug 22 16:44:25 1995
--
--
-- Definitions for Pid RAM
-- Words x Bits = 0 x 8
-- Field InvVal of 4 bits at offset 4.
-- Field Val of 4 bits at offset 0.
-- Layout of data fields:
--
-- +----------+----------+
-- +InvVal |Val |
-- +7 downto 4|3 downto 0|
-- +----------+----------+
--
--
constant Pid_DATAWIDTH: integer := 8;
subtype S_Pid_DATAWIDTH_bits is
unsigned (Pid_DATAWIDTH - 1 downto 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -