Usb Implementation Using Utmi Macrocell
Usb Implementation Using Utmi Macrocell
0 SPECIFICATIONS
1. INTRODUCTION
and clock recovery and synchronization. The primary focus of this block is
to shift the clock domain of the data from the USB 2.0 rate to one that is
compatible with the general logic in the ASIC.
The UTMI is designed to support HS/FS, FS Only and LS Only UTM
implementations. The three options allow a single SIE implementation to be
used with any speed USB transceiver. A vendor can choose the transceiver
performance that best meets their needs.
A HS/FS implementation of the transceiver can operate at either a 480
Mb/s or a 12 Mb/s rate. Two modes of operation are required to properly
emulate High-speed device connection and suspend/resume features of USB
2.0, as well as Full-speed connections if implementing a Dual-Mode device.
FS Only and LS Only UTM implementations do not require the speed
selection signals since there is no alternate speed to switch to.
Serial Interface Engine
This block can be further sub-divided into 2 types of sub-blocks; the
SIE Control Logic and the Endpoint logic. The SIE Control Logic contains
the USB PID and address recognition logic, and other sequencing and state
machine logic to handle USB packets and transactions. The Endpoint Logic
contains the endpoint specific logic: endpoint number recognition, FIFOs
and FIFO control, etc. Generally the SIE Control Logic is required for any
USB implementation while the number and types of endpoints will vary as
function of application and performance requirements.
SIE logic module can be developed by peripheral vendors or
purchased from IP vendors. The standardization of the UTMI allows
compatible SIE VHDL to drop into an ASIC that provides the macro cell.
Device Specific Logic:
This is the glue that ties the USB interface to the specific application of the
device.
boundary can be stretched to 45 CLK cycles, and two stuffed bits would
result in a 50 CLK delay between bytes.
Figure 2.2 shows the relationship between CLK and the receive data
transfer signals in FS mode. RXActive "frames" a packet, transitioning only
at the beginning and end of a packet, however transitions of RXValid may
take place any time 8 bits of data are available. Figure 2.2 also shows how
RXValid is only asserted for one CLK cycle per byte time even though the
data may be presented for the full byte time. The Macro cell is required to
present valid data for only for one clock cycle (while RXValid is asserted),
although it may be presented until new data is received.
NRZI Encoder
This is a standard USB 1.X compliant serial NRZI encoder module,
which can operate at full-speed or high-speed USB data rates. Whenever a
bit ‘1’ is encountered in the data stream, it is negated. A bit ‘0’ is transmitted
as it is depend on the Operational Mode.
Bitstuff Logic
In order to ensure adequate signal transitions, bit stuffing is employed
when sending data on USB. A zero is inserted after every six consecutive
ones in the data stream before the data is NRZI encoded, to enforce a
transition in the NRZI data stream. Bit stuffing is enabled beginning with the
SYNC Pattern and through the entire transmission. The data "one" that ends
the SYNC Pattern is counted as the first one in a sequence. In FS mode bit
stuffing by the transmitter is always enforced, without exception. If required
by the bit stuffing rules, a zero bit is inserted even after the last bit before the
TXValid signal is negated.
After 8 bits are stuffed into the USB data stream TXReady is negated
for one byte time to hold up the data stream on the DataIn bus. Figure 2.5
show the timing relationship between TXReady and DataIn.
The Byte CLK in Figure 2.5 is identical to the CLK signal in HS mode and
CLK/40 in FS mode.
Rx Shift/Hold Registers
Figure 2.6 shows the receive shift and hold register. This module is
responsible for converting serial data received from the USB to parallel data.
This module consists of an 8-bit primary RX Shift Register for serial to
parallel conversion and an 8-bit RX Hold Register used to buffer received
data bytes and present them to the Data Out bus.
The bit rate on USB is constant, however the bit rate as presented by
the UTMI to the SIE is slightly reduced due to the extraction of inserted 1
bits. Normally a byte of data is presented on the DataOut bus for every 8 bits
received, however after eight stuffed bits are eliminated from the data stream
a byte time is skipped in the DataOut stream. Figure 2.7 shows how
RXValid is used to skip bytes in the DataOut byte stream.
Figure 2.7: Receive Timing for Data with after Unstuffing Bits
CLK
Conceptually, there is a "CLKUsable" signal, internal to the UTM,
which blocks any transitions of CLK until it is "usable". This "CLKUsable"
signal is also used to switch the Line State output between CLK
synchronized and combinatorial signaling.
Options
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 14
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
is required to drive and listen to the bus with the HS transceiver. In all other
cases the state of the XcvrSelect and TermSelect signals are identical.
FS Only and LS Only UTM implementations do not require the
XcvrSelect and TermSelect speed selection signals since there is no alternate
speed to switch to.
Line State
The Line State signals are used by the SIE for detecting reset, speed
signaling, packet timing, and to transition from one behavior to another.
While data packets are being transmitted or received on the USB the Line
State signals may toggle randomly between the 'J' and 'K' states in FS, and
remain in the ‘J’ state in HS. The SIE should ignore these transitions.
Synchronization
To minimize unwanted transitions to the SIE during normal operation,
the Line State is internally synchronized with CLK. When synchronized, the
setup and hold timing of Line State is identical to Data Out. The exception to
this is when CLK is not "usable". If CLK is not "usable" then the Line State
signals are not synchronized, but driven with combinatorial logic directly
from the DP and DM signal lines. The UTM must multiplex between
combinatorial and synchronous Line State output depending on whether
CLK is "usable.
Bus Packet Timing
Line State must be used by the SIE for the precise timing of packet
data on the DP/DM signal lines. The SIE uses Line State transitions to
identify the beginning and end of receive or transmit packets on the bus.
Line State represents bus activity within 2 or 3 CLK times of the actual
events on the bus.
HS Mode
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 16
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
The table 2.3 gives the summary of data interface signals those are
referred by the SIE and the UTMI while data is being transmitted. Each of
the signals given in the table 2.3 is clearly described below.
Receive Active
RX Active is used by the SIE to time inter-packet gaps. It is important
that RX Active accurately reflects the state of the USB. For instance, HS
If TX Valid is asserted (1) then the signals Data0-7 accepts transmit data
from the SIE. If TX Valid is negated (0) then the signals Data0-7 present
received data to the SIE.
long as the transmit state machine can empty the TX Holding Register
before the next rising edge of CLK.
When TXValid is negated the transmit state machine enters the Send EOP
state where it sends the EOP. While the EOP is being transmitted TXReady
is negated and the state machine will remain in the Send EOP state. After the
EOP is transmitted the Transmit State Machine returns to the TX Wait state.
The summary of the above description is given below.
• After the SIE asserts TXValid it can assume that the transmission has
started when it detects TXReady asserted.
• The SIE assumes that the UTMI has consumed a data byte if
TXReady and TXValid are asserted.
• TXValid and TXReady are sampled on the rising edge of CLK.
• The SIE must use LineState to verify a bus Idle condition before
asserting TXValid in the TX Wait state.
Figure 3.2 shows the timing relationship between TXValid, DataIn,
TXReady and the transmitted data (DP/DM).
3.1.1 FS Operations
The CLK signal is marked "not to scale" because cycles are dropped
in Figure 3.3 to show how CLK edges align with the byte boundaries of the
FS data transmission.
3.1.1.2 FS End Of Packet
In FS mode, a single ended zero (SE0) state is used to indicate EOP
and a 'J' state indicates Idle. The SE0 state is asserted for 2 bit times then a 'J'
state is asserted for 1 bit time which is shown in figure 3.4.
Negating the TXValid signal initiates the FS EOP process; bit stuffing
will cease, the bit stuff state machine will be reset, and the FS EOP (two bit
times of SE0 followed by a single 'J' bit) will be asserted on the bus.
TXReady is negated after TXValid is detected false and cannot be
reasserted (dashed line) until after the EOP pattern and 'J' state bit are
transmitted. The delay between the assertion of TXValid and the first
assertion of TXReady is UTM implementation dependent.
3.1.2 HS Operation
The following sections provide examples of HS SYNC and EOP
generation by the Transmit State Machine.
3.1.2.1 HS Start of Packet
The assertion of TXValid will initiate the generation of the HS SYNC
pattern on the USB by the Transmit State Machine. A SYNC pattern is the
32-bit binary string "KJKJK…JKJKJKK", in its NRZI encoding. To
generate this pattern four bytes of SYNC data pattern (0x00, 0x00, 0x00,
0x80) are forced into the Transmit Shift Register by the Transmit State
Machine. As long as TXValid is asserted the Transmit State Machine will
assume that valid packet data is available on the DataIn bus to be loaded into
the Transmit Holding Register.
Figure 3.5 demonstrates how the detection of a zero to one transition
of TXValid forces the transmit state machine of the transceiver to send a 32-
bit Sync pattern then begin transmission with bit stuffing enabled.
TXReady is negated to indicate to the SIE that the data on the DataIn
bus has not been loaded into the Transmit Data Holding Register.
When the EOP is detected the state machine will enter the Strip EOP
state and negate RXActive and RXValid. After the EOP has been stripped
the Receive State Machine will reenter the RX Wait state and begin looking
for the next packet.
If a Receive Error is detected, the Error State is entered and RXError
is asserted. Then either the Abort 1 State is entered where RXActive,
RXValid, and RXError are negated, or the Abort 2 State is entered where
only RXValid, and RXError are negated. The Abort 1 State proceeds directly
to the RX Wait State, while Abort 2 State proceeds to the Terminate State
after an Idle bus state is detected on DP and DM. The Terminate State
proceeds directly to the RX Wait State.
When the last data byte is clocked off the DataOut bus the SIE must
also capture the state of the RXError signal. The description of the receiver
given above is summarized below.
will enter into RX error state where RX error signal is asserted. At the next
rising edge of the clock, the receive state machine will enter into the abort1
state where RX active, RX valid and RX error signals are negated.
3.4.4 Receive Shift and Hold Register
The serial data received from the bit Unstuffer is shifted into the
receive shift register. After the shift Register is full, it is held there for one
clock duration and then the data is placed on to the data out bus. This 8-bit
data is sampled by the SIE at the next rising edge of the clock during
shifting, the receive state machine is in RX data wait state. During holding,
the receive state machine is in RX data state where it asserts RX valid
signal.
3.4.5 EOP Detector
A state machine is developed for EOP detection, which is invoked at
every rising edge of the clock. When two single ended zeroes fallowed by a
‘J’ state is detected, it asserts a signal called eop_detect which is checked by
the Receive state machine at every rising edge of the clock. When this signal
is high, the receive state machine will enter in to Strip eop state where the
EOP pattern is stripped off and RX active, RX valid signals are negated. At
the next rising edge of the clock. The Receive state machine will enter into
the RX wait state.
4. SIMULATION RESULTS
The Transmitter module and the Receiver modules of the UTMI are
designed with VHDL and they are simulated in the Model Sim 6.0 simulator.
The fallowing sections give the source code, test bench and simulation
results for each module.
The UTMI is designed by combining these two modules and it is
simulated in the Model Sim 6.0. The source code, test bench and simulation
results are given in the fallowing sections.
4.1 Source Code for Transmitter Module
library Ieee;
use Ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity tx_sm is
port( reset,txvalid:in std_logic;
clk : in std_logic;
txready,txdp,txdm: out std_logic;
dataln : in std_logic_vector(7 downto 0));
end tx_sm;
architecture tx_sm_arch of tx_sm is
signal eop_done,sync_enable,load_data,load_eop: std_logic;
signal txhldreg:std_logic_vector(7 downto 0);
signal
bitstuff_enable,serial_out,serial_bs,serial_nrzi,shift_done:std_logic;
signal count : std_logic_vector(2 downto 0);
signal eop_cnt:std_logic_vector(1 downto 0);
signal eop_start:std_logic;
type st is (idle,txwait,send_sync,data_load,data_wait,send_eop);
signal state : st ;
begin
process( clk)
begin
load_eop<='0';
state<=idle;
end if;
when others => state<=idle;
end case;
else
state<=idle;
txready<='0';
load_eop<='0';
eop_done<='0';
end if;
end if;
end process;
--process for loading & shifting
process(clk)
begin
if clk='1' and clk'event then
if(reset='0')then
if(load_data='1') then
txhldreg<=dataln;
else if(load_data='0' )then
serial_out<=txhldreg(7);
txhldreg<= txhldreg(6 downto 0) & '0';
end if;
else
txhldreg<="01111110";
end if;
end if;
end process;
--process for count
process(clk)
begin
if clk='1' and clk'event then
if(reset='0')then
if(sync_enable='1' or load_data='0')then
count<= count + "001";
if(count="111" )then
shift_done<='1';
else shift_done<='0';
end if;
end if;
else
count<="000";
shift_done<='0';
end if;
end if;
end process;
-- process for bit stuffing
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 41
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
process(clk)
begin
if clk='1' and clk'event then
if(reset='0')then
if (bitstuff_enable='1') then
serial_bs<='0';
else serial_bs<= serial_out;
end if;
else serial_bs<='0';
end if;
end if;
end process;
--process for to detect data to be bit stuffed
process(clk)
type seq_state is (s0,s1,s2,s3,s4,s5);
variable st : seq_state;
begin
if clk='1' and clk'event then
if(reset='0')then
if(state=data_wait) then
case st is
when s0 => bitstuff_enable<='0';
if (serial_out ='1') then st:= s1;
else st:=s0;
end if;
when s1 => bitstuff_enable<='0';
if (serial_out ='1') then
st:= s2;
else st:=s0;
end if;
when s2 => bitstuff_enable<='0';
if (serial_out ='1') then
st:= s3;
else st:=s0;
end if;
when s3 => bitstuff_enable<='0';
if (serial_out ='1') then
st:= s4;
else st:=s0;
end if;
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 42
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
end if;
end if;
else if(serial_bs='1') then
serial_nrzi<=not serial_nrzi;
else
serial_nrzi<= serial_nrzi;
end if;
end if;
else
eop_cnt <="00";
serial_nrzi<='0';
eop_done<='0';
eop_start<='0';
end if;
end if;
end process;
--process for data out
process(clk)
begin
if clk='1' and clk'event then
if(reset='0')then
if(load_eop='0')then
txdp<=serial_nrzi;
txdm<= not serial_nrzi;
else if(eop_start='1')
txdp<=serial_nrzi;
txdm<=serial_nrzi;
else
txdp<=serial_nrzi;
txdm<= not serial_nrzi;
end if;
end if;
end if;
end if;
end process;
end tx_sm_arch;
4.2 Test Bench for Transmitter Module
library Ieee;
use Ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 44
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
use ieee.std_logic_unsigned.all;
entity tx_sm_tb is
end tx_sm_tb;
txready=>txready_i,
dataln=> dataln_i,
txdp =>txdp_i,
txdm =>txdm_i);
clk_i<= not clk_i after 50 ns;
reset_i<= '0' after 200 ns;
txvalid_i<='1' after 300 ns,'0'after 8 us;
process(clk_i)
begin
if clk_i='1' and clk_i'event then
if(reset_i='0')then
if(count<="0111")then
count<=count+"0001";
else
dataln_i<=dataln_i+"00000001";
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 45
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
count<="0000";
end if;
else
count<="0000";
dataln_i<="00000000";
end if;
end if;
end process;
end tx_sm_arch_tb;
The figure 4.10 shows when reset_i is low and txvalid_i signal is
asserted by the SIE, Encoded sync pattern 01010100 is sent on to the
txdp_i line. The opmode 00 shows that the transmitter is in normal mode and
the data 10110100 is NRZI encoded and sent on to the txdp_i line after sync
has been transmitted after txreday_i goes high. The txready_i signal goes
low immediately after the SIE data loaded into TXhold register. When
reset_i is high the transmitter is in reset state.
The figure 4.13 shows that when reset_i is low and txvalid_i is de
asserted by SIE, the EOP pattern (two SE0s and one J state) is transmitted on
to txdp_i, txdm_i lines after the
EOP pattern is transmitted, the transmitter enters into TX wait state
where it is waiting for the SYNC pattern.
4.4 Source Code for Receiver Module
library Ieee;
use Ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity rx_sm is
port( reset,rxdp,rxdm:in std_logic;
rxvalid,rxactive,rxerror_o:out std_logic;
clk : in std_logic;
data_out: out std_logic_vector(7 downto 0));
end rx_sm;
architecture rx_sm_arch of rx_sm is
signal eop_detect,sync_detect,rxerror_bs:std_logic;
signal sync_error,j,k,se0:std_logic;
signal rxhldreg:std_logic_vector(7 downto 0);
signal unstuff_enable,shift_done,serial_in:std_logic;
signal count : std_logic_vector(3 downto 0);
signal rxerror:std_logic;
signal temp: std_logic;
type st is
(rx_wait,strip_sync,rx_data,rxdata_wait,strip_eop,rx_
error_st, abort);
signal state_m : st;
begin
j<= rxdp and not(rxdm);
k<= not(rxdp) and rxdm;
se0<= not(rxdp) and not(rxdm);
rxerror_o <= rxerror;
--process for RECEIVE STATE MACHINE
process( clk,reset)
begin
if clk='1' and clk'event then
if reset ='0' then
case state_m is
when rx_wait => if (sync_detect ='1')then
state_m<=strip_sync;
else state_m<=rx_wait;
end if;
when strip_sync => rxactive<='1';
state_m<=rx_data;
when rx_data =>if(rxerror_bs='0')then
if(eop_detect='0')then
rxvalid<='1';
state_m<=rxdata_wait;
else
state_m<=strip_eop;
end if;
else state_m<=rx_error_st;
end if;
when rxdata_wait => rxvalid<='0';
if(rxerror_bs='0')then
if(eop_detect='0')then
if(shift_done='1')then
state_m<=rx_data; else
state_m<=rxdata_wait;
end if;
else
state_m<=strip_eop;
end if;
else
state_m<=rx_error_st;
end if;
when strip_eop => rxactive <='0';
rxvalid<='0';
state_m<=rx_wait;
when rx_error_st=> rxerror<='1';
state_m<=abort;
state_m<=rx_wait;
sync_error<='1';
sync_detect<='0';
end if;
when s1 => if(j='1')then
st:=s2;
else st:=s0;
sync_error<='1';
sync_detect<='0';
end if;
when s2 => if(k='1')then
st:=s3;
else st:=s0;
sync_error<='1';
sync_detect<='0';
end if;
when s3 => if(j='1')then
st:=s4;
else st:=s0;
sync_error<='1';
sync_detect<='0';
end if;
when s4 => if(k='1')then
st:=s5;
else st:=s0;
sync_error<='1';
sync_detect<='0';
end if;
when s5 => if(j='1')then
st:=s6;
else st:=s0;
sync_error<='1';
sync_detect<='0
end if;
when s6 => if(k='1')then
st:=s7;
else st:=s0;
sync_error<='1';
sync_detect<='0';
end if;
when s7 => if(k='1')then
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 51
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
st:=s0;
sync_detect<='1';
sync_error<='0';
else st:=s0;
sync_error<='1';
sync_detect<='0';
end if;
when others=> st:=s0;
sync_detect<='0';
end case;
end if;
else
st:=s0;
sync_detect<='0';
sync_error<='0';
end if;
end if;
end process;
--process for eop detection //2 seo's - 1j
process(clk)
type state is(s0,s1,s2);
variable st: state;
begin
if clk='1' and clk'event then
if(reset='0')then
if(state_m=rxdata_wait or state_m=rx_data)then
case st is
when s0 => if se0='1' then
st:=s1;
else
st:=s0;
eop_detect<='0';
end if;
when s1 => if se0='1' then
st:=s2;
else
st:=s0;
eop_detect<='0';
end if;
when s2 => if j ='1' then
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 52
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
st:=s0;
eop_detect<='1';
else
st:=s0;
eop_detect<='0';
end if;
when others=> st:=s0;
eop_detect<='0';
end case;
else
eop_detect<='0';
end if;
else
st:=s0;
eop_detect<='0';
end if;
end if;
end process;
--process for NRZI DECODING
process(clk,rxdp)
begin
if clk='1' and clk'event then
if (reset='0')then
if(state_m=rxdata_wait)then
if( rxdp='1'and temp ='1')then
serial_in<='0';
temp<=rxdp;
else if(rxdp='0'and temp='1')then
serial_in<='1';
temp<=rxdp;
else if(rxdp='1'and
temp ='0')then
serial_in<='1';
temp<=rxdp;
else if(rxdp='0'and temp
='0')then
serial_in<='0';
temp<=rxdp;
end if;
end if;
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 53
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
end if;
end if;
end if;
else
serial_in<='0';
temp<='0';
end if;
end if;
end process;
--process for bit RX ERROR REPORT
Process (clk)
type state is(s0,s1,s2,s3,s4,s5,s6);
variable st:state;
begin
if clk='1' and clk'event then
if (reset='0') then
if(state_m=rxdata_wait or state_m=rx_data)then case st is
when s0 => rxerror_bs<='0';
unstuff_enable<='0';
if (serial_in ='1')then
st:=s1;
else
st:=s0;
end if;
when s1 => rxerror_bs<='0';
unstuff_enable<='0';
if (serial_in ='1')then
st:=s2;
else
st:=s0;
end if;
when s2 => rxerror_bs<='0';
unstuff_enable<='0';
if (serial_in ='1')then
st:=s3;
else
st:=s0;
end if;
when s3 => rxerror_bs<='0';
unstuff_enable<='0';
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 54
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
if (serial_in ='1')then
st:=s4;
else
st:=s0;
end if;
when s4 => rxerror_bs<='0';
unstuff_enable<='0';
if (serial_in ='1')then
st:=s5;
else
st:=s0;
end if;
when s5 => rxerror_bs<='0';
unstuff_enable<='0';
if (serial_in ='1')then
st:=s5;
else
st:=s0;
end if;
when s6 => if (serial_in ='0')then
unstuff_enable<='1';
rxerror_bs<='0';
st:=s0;
else
rxerror_bs<='1';
unstuff_enable<='0';
st:=s0;
end if;
when others=> st:=s0;
end case;
else
rxerror_bs<='0';
end if;
else
st:=s0;
rxerror_bs<='0';
unstuff_enable<='0';
end if;
end if;--process
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 55
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
end process;
--process for RX REGISTER loading
process(clk)
begin
if clk='1' and clk'event then
if(reset='0') then
if(state_m=rxdata_wait ) then
if(unstuff_enable='0')then
rxhldreg(7 downto 0)<= rxhldreg(6 downto 0) &
serial_in;
else
rxhldreg(7 downto 0)<= rxhldreg(7 downto
0);
end if;
end if;
if(shift_done='1')then
data_out<= rxhldreg;
end if;
else
rxhldreg(7 downto 0)<= "00000000";
end if;
end if;
end process;
--process for COUNT
process(clk)
begin
if clk='1' and clk'event then
if(reset='0') then
if(state_m=rxdata_wait)then
end if;
else
shift_done<='0';
count<="0000";
end if;
end if;
end process;
end rx_sm_arch;
library Ieee;
use Ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity rx_sm_tb is
end rx_sm_tb;
architecture rx_sm_arch_tb of rx_sm_tb is
signal rxdp_i,rxdm_i,rxd_i: std_logic;
signal reset_i:std_logic:='1';
signal rxvalid_o,rxactive_o,rxerror_o:
std_logic;
signal clk_i : std_logic:='0';
signal data_out:std_logic_vector(7 downto 0);
signal cnt:std_logic_vector(7 downto 0);
signal count:std_logic_vector(3 downto 0);
signal data_count:std_logic_vector(3 downto 0);
signal eop_count:std_logic_vector(1 downto 0);
signal data_in:std_logic_vector(7 downto 0);
signal eop_start:std_logic;
component rx_sm
port( reset,rxdp,rxdm:in std_logic;
rxvalid,rxactive,rxerror_o:out std_logic;
clk : in std_logic;
data_out : out std_logic_vector(7 downto 0));
end component;
begin
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 57
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
instance: rx_sm
port map( reset=>reset_i,
rxdp=>rxdp_i,
rxdm=>rxdm_i,
rxvalid=>rxvalid_o,
rxactive=>rxactive_o,
rxerror_o=>rxerror_o,
clk=>clk_i,
data_out=>data_out);
clk_i<= not clk_i after 50 ns;
reset_i<= '0' after 200 ns;
rxdp_i<=rxdp_i;
rxdm_i<=not(rxdp_i) when data_count <=”1010”
and eop_start=’0’ else
rxdp_i;
process(clk_i)
begin
if clk_i='1' and clk_i'event then
if(reset_i='1')then
eop_start<=’0’;
cnt<="01010100";
count<="0000" ;
data_in<="10110101";
data_count<="0000";
eop_count<="00";
else if(count<="0111")then
rxd_i<=cnt(7);
cnt<= cnt(6 downto 0)&'0';
count<= count+"0001";
else if(data_count<="1001")then
count<="0000";
data_in<= data_in+"00000001";
cnt<=data_in;
data_count<=data_count+"0001";
else if(eop_count<="01")then
eop_start<=’1’;
rxdp_i<='0';
eop_count<=eop_count+"01";
data_count=”1011";
else
SAI SPURTHI INSTITUE OF TECHNOLOGY Page 58
FPGA IMPLEMENTATION OF UTMI WITH USB 2.0 SPECIFICATIONS
rxdp_i<='1';
eop_start<=’0’;
data_count=”0000";
end if;
end if;
end if;
end if;
end if;
end process;
end rx_sm_arch_tb ;
The figure 4.14 shows that when reset_i is low and the SYNC pattern
“01010100” is detected on the serial bus, rxactive_i is asserted and the data
“00101100” received on rxdp_i is decoded because the receiver is in
normal mode (i.e., opmode is “00”). The data is sent on to the data_out bus
and the receiver asserts rxvalid_o signal.
The figure 4.15 shows that when reset_i is low and rxactive_i is high
and opmode is “10”, NRZI decoding is disabled and the data received on the
bus is sent on to the data_out bus as it is. The receiver asserts the rxvalid_o
signal.
The figure 4.16 shows that when reset _i is low and rxactive_i is
high, EOP pattern (two SEOs and one J state ) is detected on the serial bus.
Whenever the EOP pattern is detected on the bus, the receiver enters into
Strip EOP State where rxactive_o and rxvalid_i signals are de asserted. At
the raising edge of the next clock the receiver enters into RX wait state
where it is waiting for next SYNC pattern on the serial bus.
The figure 4.17 shows that when reset_i is low and rxactive_i is high
and if a zero is not detected after six consecutive one’s are detected on the
serial bus, the receiver asserts the rxerror_o signal. Consequently rxerror_o
goes low and rxvalid_o is also low. The receiver enters into RX wait state.
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity utmi_top is
port(txvalid,xcvr,suspendM,term_select,reset : in std_logic;
rxvalid,rxactive,rxerror : out std_logic;
linestate : out std_logic_vector(0 to 1);
clk,dp,dm : inout std_logic;
data_bustx,data_busrx : inout std_logic_vector(0 to 7));
end utmi_top;
architecture utmi_top_arch of utmi_top is
component tx_sm
port( reset,txvalid:in std_logic;
clk : in std_logic;
txready,txdp,txdm: out std_logic;
dataln: in std_logic_vector(7 downto 0));
end component;
component rx_sm
port(reset,rxdp,rxdm:in std_logic;
rxvalid,rxactive,rxerror_o:out std_logic;
clk : in std_logic;
data_out: out std_logic_vector(7 downto 0));
end component;
signal fs_clk,hs_clk:std_logic;
begin
instance1:tx_sm port map(reset=>reset,
txvalid=>txvalid,
txdp=>dp,
txdm=>dm,
clk=>clk,
dataln=>data_bustx);
instance2:rx_sm port map(reset=>reset,
rxvalid=>rxvalid,
rxactive=>rxactive,
rxerror_o=>rxerror,
clk=>clk,
rxdp=>dp,
rxdm=>dm,
data_out=>data_busrx);
clk<= fs_clk when xcvr='1'else
hs_clk;
process(clk)
begin
if clk='1' and clk'event then
if reset='0' then
if suspendM='1' then
linestate(1)<= dp;
linestate(0)<= dm;
end if;
end if;
end if;
end process;
end utmi_top_arch;
end if;
end process;
end utmi_arch_tb;
The figure 4.18 shows that when reset is low and xcvr signal is
high(i.e, full speed operation) the clock duration is 84 ns i.e., the fs_clk
signal is assigned to the clk signal. When txvalid is asserted by the SIE,
encoded SYNC pattern “01010100” is transmitted on to the serial bus (i.e,
DP, DM lines) when the receiver detects the SYNC pattern, it asserts RX
active signal. After SYNC has been transmitted, the data “00000000” is
transmitted on to the bus after NRZI encoding. After the data “00000000”
has been transmitted, the transmitter asserts TX ready signal. When the
encoded data is received on the serial bus, the receiver decodes the data
asserts rxvalid signal and the data on the data_bustx is sent onto the
data_busrx. The receiver is in normal mode (i.e, the opmode signalis “00”).
The figure 4.19 shows that when reset is low and suspend M goes low, TX
valid signal is de asserts SIE. The EOP pattern is transmitted on to the serial
bus, whenever receiver receives EOP pattern rxactive signal goes low and
ravalid goes low whatever the data present on the data_busrx is remained as
it is until next SYNC pattern is detected.
The figure 4.20 shows that when reset is low and xcvr signal goes low
(i.e, high speed operation) the clock duration is 2ns i.e, the hs_clk signal is
assigned to the clk signal and the data on the data_bustx is sent on the
data_busrx through DP, DM lines. All the operations are same as full speed
operation but these operations on done according to the high speed clock.
It can also be designed to generate CRCs for control and data packets.
If an SIE and Device specific logic are designed, the combination of
UTMI, SIE and Device specific logic can be used as controller of a USB
device.
6.APPLICATIONS:
The UTMI has been developed into a common code (Generalized USB
Transceiver) which can be used for developing the complete USB device
stack.
Some of the Low speed and High speed USB devices, which are presently in
the market, are:
1. Optical Mouse
2. Key Board
3. Printer
4. Scanner
5. Joy Stick
6. Memory Stick
7. Flash Memory
8. Mobiles
9. Video cameras.
REFERENCE
Reference books:
Reference websites:
www.usb.org
www.opencore.org
www.digitalcoredesign.org
www.deeps.org