Software APIs
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes
USBDevice Class Reference

Public Types

enum  USBDevState {
  StateStreaming ,
  StateSuspending ,
  StateSuspended ,
  StateResuming
}
 
enum  usbdev_suspend_phase_t {
  kSuspendPhaseSuspend = 0u ,
  kSuspendPhaseSleepResume ,
  kSuspendPhaseSleepReset ,
  kSuspendPhaseSleepDisconnect ,
  kSuspendPhaseDeepResume ,
  kSuspendPhaseDeepReset ,
  kSuspendPhaseDeepDisconnect ,
  kSuspendPhaseShutdown
}
 Test phases; named according to the event that we are expecting to occur. More...
 
enum  usb_testutils_test_number {
  kUsbTestNumberSmoke = 0 ,
  kUsbTestNumberStreams ,
  kUsbTestNumberIso ,
  kUsbTestNumberMixed ,
  kUsbTestNumberSuspend ,
  kUsbTestNumberExc
}
 
enum  usbdev_stream_flags_t {
  kUsbdevStreamFlagID = 0x0FU ,
  kUsbdevStreamFlagRetrieve = 0x10U ,
  kUsbdevStreamFlagCheck = 0x20U ,
  kUsbdevStreamFlagRetry = 0x40U ,
  kUsbdevStreamFlagSend = 0x80U ,
  kUsbdevStreamFlagsDefault
}
 
typedef enum USBDevice::usb_testutils_test_number usb_testutils_test_number_t
 

Public Member Functions

 USBDevice (bool verbose=false, bool manual=false)
 
bool Init (uint16_t productID, uint16_t vendorID, uint8_t devAddress=0u, uint8_t busNumber=0u)
 Initialize USB device before test; called once at startup. More...
 
bool Fin ()
 Finalize USB device before completing test. More...
 
bool Open ()
 (Re)open the device. More...
 
bool Close ()
 Close the device, if open. More...
 
bool Service ()
 Service the device; keep libusb transfers being processed. More...
 
bool ManualControl () const
 Is test progress being directed/controlled manually?
 
usbdev_suspend_phase_t TestPhase () const
 Returns the current phase of the test.
 
bool Delay (uint32_t time_us, bool with_traffic=true)
 Delay for at least the requested number of microseconds (wall time); this is important in ensuring the appropriate time intervals (eg. More...
 
bool ReadTestDesc ()
 Read Test Descriptor from the DUT using a Vendor-Specific command. More...
 
uint8_t TestNumber () const
 Return the test number from the test descriptor. More...
 
uint8_t TestArg (unsigned arg) const
 Return the specified test argument from the test descriptor. More...
 
bool Reset ()
 Reset and Reconfigure the DUT. More...
 
bool Suspend ()
 Suspend device. More...
 
bool Resume ()
 Resume operation of suspended device.
 
bool Connect ()
 Connect device to the USB. More...
 
bool Disconnect ()
 Disconnect device from the USB. More...
 
USBDevState CurrentState () const
 Returns the current state of the device. More...
 
void SetState (USBDevState state)
 Sets the current state of the device in the Suspend/Resume signaling. More...
 

Static Public Member Functions

static uint32_t TimeFrames (unsigned frames)
 Returns microseconds corresponding to the given number of bus frame delays.
 
static const char * PhaseName (usbdev_suspend_phase_t phase)
 Return the textual name of the specified test phase. More...
 

Static Public Attributes

static constexpr uint8_t kVendorGetData = 0x7du
 
static constexpr uint8_t kVendorPutData = 0x7fu
 
static constexpr unsigned kDevDataMaxPacketSize = 0x40U
 
static constexpr unsigned kDevIsoMaxPacketSize = 0x40U
 

Detailed Description

Definition at line 15 of file usb_device.h.

Member Enumeration Documentation

◆ usbdev_stream_flags_t

Enumerator
kUsbdevStreamFlagID 

Mask for extracting the stream ID number.

kUsbdevStreamFlagRetrieve 

Host shall retrieve IN data from the device for this stream.

kUsbdevStreamFlagCheck 

Host shall check that IN data matches as expected.

kUsbdevStreamFlagRetry 

DPI model (or Host) shall retry IN data fetches, where possible.

kUsbdevStreamFlagSend 

Host shall send OUT data to the device for this stream.

kUsbdevStreamFlagsDefault 

Default stream flags; for non-libusb builds.

Definition at line 95 of file usb_device.h.

◆ usbdev_suspend_phase_t

Test phases; named according to the event that we are expecting to occur.

Enumerator
kSuspendPhaseSuspend 

First test phase just tests regular Suspend/Resume signaling; after we've resumed, we expect a Bus Reset from the DPI/Host.

kSuspendPhaseSleepResume 

This test phase instructs the DPI model to put the DUT into Suspend long enough that this software will attempt to put the device into its Normal Sleep state and exercise the AON/Wakeup module, stopping the clocks but not powering down.

kSuspendPhaseSleepDisconnect 

As above, but this time we're expecting a VBUS/SENSE loss.

kSuspendPhaseDeepResume 

Mirrors Resume detection for normal sleep, but this time we enter Deep Sleep and the power is removed too.

kSuspendPhaseDeepReset 

Mirrors Bus Reset detection for normal sleep, but this time we enter Deep Sleep and the power is removed too.

kSuspendPhaseDeepDisconnect 

As above, but this time we're expecting a VBUS/SENSE loss.

kSuspendPhaseShutdown 

Final phase; shut down.

Definition at line 43 of file usb_device.h.

Member Function Documentation

◆ Close()

bool USBDevice::Close ( )

Close the device, if open.

If the device is already closed, this function just returns immediately.

Returns
true iff closing was successful, or the device was already closed.

Definition at line 218 of file usb_device.cc.

◆ Connect()

bool USBDevice::Connect ( )

Connect device to the USB.

Parameters
trueiff the operation was succesful.

Definition at line 522 of file usb_device.cc.

◆ CurrentState()

USBDevState USBDevice::CurrentState ( ) const
inline

Returns the current state of the device.

Returns
current state.

Definition at line 383 of file usb_device.h.

◆ Delay()

bool USBDevice::Delay ( uint32_t  time_us,
bool  with_traffic = true 
)

Delay for at least the requested number of microseconds (wall time); this is important in ensuring the appropriate time intervals (eg.

Resume Signaling) are met.

For verbose reporting, the also indicates whether traffic is expected, and may be visually paired up with any device-side logging or logic analyzer traces.

Parameters
time_usMinimum time delay, in microseconds.
with_trafficIndicates whether USB traffic is expected during this time.
Returns
true iff delayed without error

Definition at line 339 of file usb_device.cc.

◆ Disconnect()

bool USBDevice::Disconnect ( )

Disconnect device from the USB.

Parameters
trueiff the operation was succesful.

Definition at line 553 of file usb_device.cc.

◆ Fin()

bool USBDevice::Fin ( )

Finalize USB device before completing test.

Returns
true iff finalization was successful.

Definition at line 43 of file usb_device.cc.

◆ Init()

bool USBDevice::Init ( uint16_t  productID,
uint16_t  vendorID,
uint8_t  devAddress = 0u,
uint8_t  busNumber = 0u 
)

Initialize USB device before test; called once at startup.

Parameters
vendorIDVendor ID code of the USB device.
productIDProduct ID code of the USB device.
devAddressDevice address (0 for first accessible device).
busNumberBus number (if devAddress non-zero).
Returns
true iff initialization was successful.

Definition at line 21 of file usb_device.cc.

◆ Open()

bool USBDevice::Open ( )

(Re)open the device.

If the device is already open, this function just returns immediately.

Returns
true iff opening was successful, or the device was already open.

Definition at line 56 of file usb_device.cc.

◆ PhaseName()

const char * USBDevice::PhaseName ( usbdev_suspend_phase_t  phase)
static

Return the textual name of the specified test phase.

Parameters
phaseTest phase.
Returns
Textual name.

Definition at line 242 of file usb_device.cc.

◆ ReadTestDesc()

bool USBDevice::ReadTestDesc ( )

Read Test Descriptor from the DUT using a Vendor-Specific command.

Returns
true iff the operation was successful.

Definition at line 265 of file usb_device.cc.

◆ Reset()

bool USBDevice::Reset ( )

Reset and Reconfigure the DUT.

Returns
true iff the operation was successful.

Definition at line 357 of file usb_device.cc.

◆ Service()

bool USBDevice::Service ( )

Service the device; keep libusb transfers being processed.

Returns
true iff the device is still operational.

Definition at line 230 of file usb_device.cc.

◆ SetState()

void USBDevice::SetState ( USBDevState  state)
inline

Sets the current state of the device in the Suspend/Resume signaling.

Parameters
stateThe current state of the device.

Definition at line 389 of file usb_device.h.

◆ Suspend()

bool USBDevice::Suspend ( )

Suspend device.

Returns
true iff the operation was successful.

Definition at line 397 of file usb_device.cc.

◆ TestArg()

uint8_t USBDevice::TestArg ( unsigned  arg) const
inline

Return the specified test argument from the test descriptor.

Parameters
argArgument number.
Returns
test argument

Definition at line 339 of file usb_device.h.

◆ TestNumber()

uint8_t USBDevice::TestNumber ( ) const
inline

Return the test number from the test descriptor.

Returns
test number

Definition at line 332 of file usb_device.h.