ASH1: I/O Operations
Hi again. It’s been a long time since my last blog. So, let’s catch up with ASH1 updates,
The plan now is to take into consideration USB operation first with the intention to include all other I/O operations afterwards (especially MAC Ethernet)..
In order to get familiar with USB operations (Rev1.1), I had to go through several references, among them are:
In general, USB Operations can be summarized as the following:
- Tiered (level) Star Topology.
- Master/Slave Architecture.
- Two Speeds: Full Speed (12Mbps), Low Speed (1.5Mbps).
- The Protocol is a host-centric protocol, i.e. the host handles most of the protocol complexity while the peripheral design is simple. (Protocol layers to be discussed later).
- No interrupts or asynchronous messages from the peripheral.
- USB Protocol Architecture:
- Concerned with transmission of unstructured bit stream over the physical medium
- Data Link
- Concerned with providing the reliable transfer of information across the physical link, it provides the necessary synchronization, error and flow control
- User (upper layers)
- User (application) can access the USB devices through device drivers which handle the communication with them in terms of detecting the states of status signals, toggling control signals and sending over data and address information for the communication to take place.
It can be subdivided into the following layers
- Bus State
The USB transfers signals and power over a four-wire cable. The signaling occurs over a differential pair of signals (D+ and D-) to reduce the noise level. The noise is reduced as when the two lines are subtracted, the noise will be removed and the correct data will be preserved.
The Bus state (for both full speed and low speed) can be one of four:
- Differential 1: D+ is logic high, D- is logic low.
- Differential 0: D+ is logic low, D- is logic high.
- Single-Ended Zero (SE0): Both Ds are logic low
- Single-Ended One (SE1): Both Ds are logic high (invalid)
Differential 1 and 0 states can be defined (according to the bus speed) as Data J and K states alternatively.
Bus State Low Speed Full Speed Differential 1 J K Differential 0 K J
A combination of the first three states with different durations, specific events are encoded. They are:
IDLE: Data J state. RESUME: Data K state (20 ms) followed by a low-speed EOP. SOP: Data K state after IDLE (same as SYNC field). EOP: SE0 for two bit time followed by a Data J for one bit time. CONNECT: IDLE for at least 2.5 µseconds. DISCONNECT: SE0 at least 2.5 µseconds. RESET: SE0 at least 2.5 µseconds (10 milliseconds).
- Bit Stuffing
- Bit stuffing along with NRZI (discussed below) ensure the receiver remains synchronized with the transmitter without the overhead of sending a separate clock signal or start and stop bits for each byte. Bit stuffing adds a 0 after six consecutive 1s (Bit stuffing applies to all packet bits starting with the last bit from SYNC field till the last bit of CRC field)
- Data on the bus is encoded with NRZI, an encoding format that. In NRZI encoding, a 0 causes a change and a 1 causes no change.
Data Link Layer
Its functions can be categorized as the following:
- Error Control
- USB provides a reliable end-to-end communication. This includes (among others) the following important functions:
- Packet Error
- Bus Turn-around Timing (Time-Out): timer starts counting on the SE0-to-J of the EOP and stops counting when the Idle-to-K SOP transition is detected. The host time-out is 18 bit times. If the host wishes to indicate an error condition via a timeout, it must wait at least 18 bit times before issuing the next token to ensure that all downstream devices have timed out. The device uses its bus turn-around timer between token and data or data and handshake phases. The host uses its timer between data and handshake or token and data phases. If the host receives a corrupted data packet, it must wait before sending out the next token. This wait interval guarantees that the host does not attempt to issue a token immediately after a false EOP
- Synchronization Control
- To synchronize the receivers, Bit stuffing and NRZI encoding is not enough. The receiver needs to know the start of packet which can be achieved through the SYNC field which generates (KJKJKJKK) seven transitions.
To provide an additional timing reference, the host sends a Start-of-Frame (SOF) packet every 1 millisecond at full speed. For low-speed devices, the host sends a keep-alive signal which is a simpler End-of-Packet (EOP) signal that sent once per frame (1milliseconds)
- Flow Control
- As it was mentioned earlier, USB is a host-centric bus. The host is responsible for initiating all data exchange. Data exchange or communications are of two types:
- Configuration Communication (Enumeration): In which the host will get to know the attached device and configure it accordingly.
- Application Communication: occurs when the host exchanges data for use with applications.
These two types of communication take place in form of transfers, which made up of transactions. Each transaction is made up of packets. The first packet is called a token packet (generated by host); it provides the necessary details about the following packet. The next packet is generally a data packet carrying the payload followed by a handshaking packet. Each packet consists of fields that are: SYNC, PID, ADDR, ENDP, CRC, EOP. Each packet has its purpose
Upper layers (user)
Under an operating system, any communication with a USB peripheral must pass through a device driver that knows how to communicate both with the system’s USB drivers and with the applications that access the device. When a device is attached, the device manager handles enumeration automatically. This is done through several layers (not of our concern)
- The user plugs a device into a USB port.
- The host detects the device.
- The host learns about the new device.
- The host detects whether the device is low or full speed.
- The host resets the device.
- The host establishes a path with the device.
- The host sends a GET_DESCRIPTOR request to learn the maximum packet size
- The host assigns the device with an address.
- The host learns about the device abilities further.
- A device driver is assigned.
- The device driver selects a configuration
- The device is now ready to use.