zaro

What is USB Interrupt?

Published in USB Communication 3 mins read

A USB interrupt refers to a specific type of data transfer mechanism used in the Universal Serial Bus (USB) protocol, primarily designed for transferring small amounts of data at regular intervals between a USB host and a device.

Understanding USB Interrupt Endpoints

USB devices can be designed with support for special communication channels called interrupt endpoints. These endpoints are distinct from other types like Bulk, Isochronous, or Control endpoints. Their purpose is to enable timely data exchange, particularly for devices that need to report status changes or user input promptly.

How USB Interrupt Transfers Work

Unlike traditional hardware interrupts where a device signals the CPU asynchronously whenever it needs attention, the USB interrupt transfer operates differently. It is entirely controlled by the USB host.

Based on the USB specification and the provided reference:

  • Regular Polling: To facilitate interrupt transfers, the host actively polls the device at specific, pre-defined intervals. These intervals are negotiated during device configuration.
  • Data Transmission: Data is transmitted each time the host polls the device. The device prepares the data (if any) it needs to send, and this data is sent back to the host during the polling cycle.
  • Mechanism, not Signal: This means the "interrupt" in "USB interrupt" doesn't signify the device interrupting the host's CPU like a hardware interrupt. Instead, it describes a scheduled polling mechanism initiated by the host to check for data from the device at regular times.

Here's a simple view of the host-controlled flow:

  • Host schedules polling for the interrupt endpoint at regular intervals (e.g., every 1ms, 10ms).
  • At the scheduled time, the host sends a special "IN" token (or "OUT" for host-to-device interrupt data, though less common for this transfer type) to the device's interrupt endpoint.
  • If the device has data ready for that endpoint, it sends the data back to the host.
  • If the device has no data ready, it responds with a NAK (Negative Acknowledge), indicating it's not ready to transfer, and the host will try again at the next scheduled interval.

Primary Use Cases

Interrupt transfers are commonly used for devices where low latency for small data packets is crucial, but the data rate is not very high. According to the reference, interrupt transfers are mostly used for getting interrupt data from the device.

Examples include:

  • Human Interface Devices (HIDs): Keyboards reporting key presses, mice reporting movement and clicks, game controllers reporting button states.
  • Status Reporting: Devices reporting their current state or error conditions.
  • Serial Port Emulation: Some devices might use interrupt transfers to emulate serial communication for short messages or control signals.

This method ensures that the host regularly checks for critical, time-sensitive input from the device without the device needing to initiate a complex transfer process asynchronously.

Summary of USB Interrupt Transfer

Here is a brief overview:

Feature Description
Mechanism Host-driven polling at regular intervals.
Data Flow Typically device-to-host (getting data from the device).
Purpose Transfer small data packets at regular, predictable intervals.
Endpoint Type Requires dedicated interrupt endpoints on the device.
"Interrupt" Meaning Refers to scheduled polling for timely data, not a traditional hardware interrupt signal.

In essence, the USB interrupt transfer type provides a reliable and timely way for devices to deliver small, important data packets to the host on a scheduled basis managed by the host's polling mechanism.