1

I've read several different documentation sources explaining how Apple's asynchronous ADB protocol works. Although quite convoluted, it makes some sense of several rereads. I am having difficulty wrapping my head around how ADB's collision resolution works. This protocol is ancient and no longer used, but perhaps someone with a fresh mind can parse the documentation better than me.

https://developer.apple.com/library/archive/technotes/hw/hw_01.html#Section2

First, during the device address resolution (device enumeration) the ADB Manager polls devices and the devices are responsible for detecting collisions. When a device responds, it is supposed to supply a "random" address to the ADB Manager. It's unclear how this random address factors into the address resolution. Specifically, here's what it says the ADB Manager does:

An ADB device's register 3 is 2 bytes long, and includes 4 bits in which the address is stored. When the device receives a listen register 3 command, it should take its address from this 4-bit field. When it receives a talk register 3 command, it would be redundant to put the device's address in that field: the device's address is already uniquely determined by the fact that the device is responding to the talk register 3 command, which was sent to a specific address. Instead, a random 4-bit value should be returned in this field; this makes it easier to detect collisions between two devices responding to a talk register 3.

It only says "it makes it easier to detect collisions." There's no further discussion about how it uses this address to determine a collision. Microchip's technote AN591, says the device is responsible, but it is still unclear:

When a device recognizes that the Host issued a “Talk Register 3” command, it responds by sending a random address. During the transfer of each Bit Cell of the random address the signal line is monitored for the expected signal level. If the signal is not what is expected there is an address conflict. If the address is sent successfully, the host will respond with a Listen Command to that device. The command will have a new Device Address to which that device will move. The device then only responds to commands at the new address. If there is a conflict, where two devices have the same default address, and respond at the same time, the device that finds the line low when it expects it to be high, immediately stops transmitting because it has determined that a collision has occurred.

Given this is an asynchronous operation, it's impossible to read the ADB signal while writing a signal.

Second, ADB is supposed to support up to 16 devices since the device address is 4 bits. During the device resolution, however, addresses $8-$F are used for address resolution. This means there can be a maximum of 8 devices of a specific device family, not 16? Am I correct here?

user148298
  • 2,215
  • 5
  • 36
  • 51
  • Assume there is a collision and two remote devices send an address back. If they used the address sent then they would be indistinguishable, if they send back a random address that is not the original probe, then you may be able to distinguish the collision (as long as they don't both send the same random address). – Jack Creasey Jun 29 '18 at 18:19
  • @JackCreasey. I updated my question with more details. The documentation is very confusing. How is it possible to read a signal and write a signal, especially when it's asynchronous. – user148298 Jun 29 '18 at 19:33
  • OF course you can read and write at the same time. They are checking bit times on the line. The target writes the value to the line bit by bit, and monitors that if it wanted to send a '1' a '1' arrives on the line. If it wanted to send a '1' bit, but detected a '0' or vice-versa than it know someone else is also writing to the line. Hence it know thare is a collision. – Jack Creasey Jun 29 '18 at 20:19
  • OK. I see now. So writing to a line is not momentary. It can be toggled. Thanks. One addendum. The documentation mentions open collector, but and Microchip mentions tristating the pins. Does this mean you can read a no value? – user148298 Jun 30 '18 at 01:09
  • Also, the random address isn't really an address, but just a random token which is used for bit testing. I must say the terminology used in the protocol takes some liberties in its definitions. Thanks for clearing it up for me. – user148298 Jun 30 '18 at 01:14
  • It does not matter if it's tri-state or wired 'or' on the line. If more than one sender pulls the line to a wrong state you can detect it for at least some bits. – Jack Creasey Jun 30 '18 at 02:27

1 Answers1

0

It's in the second paragraph.

Because the ADB bus is open collector, collisions can be detected when a device is attempting to drive the bus high and another device pulls it low. This means that whenever the device is driving the bus high, it should be watching to make sure the bus is actually high; if the bus goes low, some other device is sending at the same time. When a device detects a collision, it should immediately stop transmitting: this means that if two devices are colliding, one of them will detect the collision, while one will not. This occurs because a device can only detect the collision if it is driving the bus high and another device drives it low. The device driving it low has no way to tell that there was a collision, as the bus follows it. Since the detecting device immediately stops transmitting, the other device will not detect the collision. Thus, if there are a number of devices transmitting on the bus, only one of them will complete its transmission without detecting the collision, unless the unlikely occurrence of more than one device transmitting exactly the same data with the same timing occurs, and neither detects the collision.

Open collector means the device makes the bus voltage go low by actively conducting current to ground, but lets a resistor make it go high, thus when any device is not commanding the bus low, but letting it rest high it can monitor the bus to see if another device is using it.

Two devices who have taken the same address when commanded to return register 3 will by returning a random number instead of an address (which would match exactly) have a chance of disagreeing on the random number and thus one of them will detect the collision.

  • Thanks for your answer. I figured it out. What threw me for a loop was the "random address" term. It turns out the random address serves a couple of purposes other than what it is named. It is not an address that's used for identifying the device. – user148298 Aug 09 '18 at 14:48
  • It's actual purpose is to generate a random a stream of bit patterns. All the devices with the same default address send out a random bit and then check if the bus is in the same state. If not, it means another device is sending data, meaning there is an address collision. The documentation could have clarified this a lot better. Documentation should be written by throwing it over a wall just like reverse engineering patented algorithms. – user148298 Aug 09 '18 at 14:52