USB Host

The following shows how to control USB HostSlave IP Core with simple software driver.

USB Host Core Initial Configuration

Connecting the game pad and turning the USB bus in Bus Reset mode, USB slave device (game pad) goes in Default State. Then USB HostSlave IP Core connection event is sent to the CPU as an interrupt signal (CONNECTION_EVENT) . The USB slave device in this state accepts transactions for default address(0).

usb_pic4

Process to Default State

Data Transfer between USB Host and Slave

USB Host Core and USB slave device communicate with IN, OUT, SETUP transaction.
OUT Transaction
OUT Transaction is used to send data from USB Host to USB Slave. The transaction starts in the following steps.

  1. Setting HOST_TX_TRANS_REG register’s TRANSACTION_TYPE field as OUTDATA0_TRANS or OUTDATA1_TRANS
  2. Setting send data to USB_TX_FIFO_DATA
  3. Setting HOST_TX_CONTROL_REG register’s TRANS_REQ_BIT field as 1
usb_pic5

OUT Transaction Flow

IN Transaction
In Transaction is used to receive data from USB Slave Device to USB Host. The transaction starts in the following steps.

  1. Setting HOST_TX_TRANS_REG register’s TRANSACTION_TYPE as IN_TRANS
  2. Setting HOST_TX_CONTROL_REG register’s TRANS_REQ_BIT field as 1
  3. Waiting USB_INTERRUPT_STATUS_REG register’s TRANS_DONE_BIT field turns to 1
  4. Reading USB_RX_FIFO_DATA_COUNT_LSB to know the number of received bytes
  5. Reading USB_RX_FIFO_DATA register same count as SB_RX_FIFO_DATA_COUNT_LSB
usb_pic6

IN Transaction Flow

SETUP Transaction
Setup transaction is used in Control Transfer. SETUP transaction transmits information to the USB device. The transaction starts in the following steps.

  1. Setting HOST_TX_TRANS_REG register’s TRANSACTION_TYPE as SETUP_TRANS
  2. Setting device request data to USB_TX_FIFO_DATA register
  3. Setting HOST_TX_CONTROL_REG register’s TRANS_REQ_BIT field as 1
usb_pic7

SETUP Transaction Flow

Getting Descriptors

The standard USB descriptors contain information about what kind of device is connected to the connector.

  • Device Descriptor
  • Configuration Descriptor
  • Interface Descriptor
  • HID Descriptor
  • Endpoint Descriptor

These descriptors are provided by the device in response to control transfer. HID(Human Interface Device) descriptor is a class specific descriptor and only available in HID class device.
Detailed descriptions of each descriptor…
From the descriptors, it appears that the game pad has in the following features.

  • The number of configurations is 1
  • The number of interfaces is 1
  • The number of endpoints is 1(except endpoint0)
  • Interface class is 33(HID)
  • Endpoint address is 1
  • The type of endpoint 1 is Interrupt IN transfer
  • Maximum packet size of endpoint 1 is 4

Interrupt Transfer
The descriptors of the game pad specify that the data is transferred by Interrupt transfer to endpoint 1. Interrupt transfer starts at regular intervals which is generated by timer functionality of the CPU. the game pad returns pad information at that time in response to the interrupt transfer.

usb_pic10

Interrupt Transfer Flow

Getting Game Pad Data

The pad information(which button is pushed, which button is released) is stored in the returned data of interrupt transfer. The game pad in this case returned pad status as 4 bytes data. The bit position of each button is obtained by HID class REPORT descriptor.

Byte Field Description
0 x Arrow Key Left: 0 Center:0x7f, Right: 0xff
1 y Arrow Key Up: 0 Center:0x7f, Down: 0xff
3 Button Group0 8 buttons status are assigned to each bit of 8bits OFF:0, ON:1
4 Button Group1 2 buttons status are assinged to bit0 and bit1 of 8bits OFF:0, ON:1

Test Program

This is a simple program for testing the implementation.

  • USB device address is 5
  • Interrupt transfer is issued every 1 second by CPU timer interrupt
  • USB Host Core FIFO is read at IRQ1 from FPGA, then the data is stored in game pad data struct

Program (excerpt)

Main

Timer configuration

Interrupt handler(Timer interrupt)

Interrupt handler (FPGA IRQ1interrupt)

Game pad data struct


スポンサーリンク
広告大
広告大
  • このエントリーをはてなブックマークに追加
スポンサーリンク
広告大