Thursday, September 5, 2019

Two Bit Swap Protocol

Two Bit Swap Protocol

Describing the protocol

Brief decription of the protocol: Two lines are used. Both are open collector pulled up. There is a sender and a receiver. The distinction is not a concern of the protocol as long as the upper level executive knows when it's supposed to send or receive.

At the most basic level, the two wires are used to send individual bits. Both D0 and D1 are normally idle at "1". To send a "0" the sender pulls D0 low. Or to send a "1" the sender pulls D1 low. In either case, the receiver sees one of those lines go low and then uses the opposite line as an ack. So if the receiver sees D0 go low, it pulls D1 low to ack the "0". When the sender sees D1 go low, it knows the receiver has the bit and lets D0 go back high. The receiver sees D0 is idle again, so it lets D1 go high as well. Now both D0 and D1 are in the idle state and the next bit can be sent.

But we would like to sync the bytes. This is done as follows:

Nine bits are sent for every byte. The most significant bit -- the one sent first -- is the sync bit. This bit is always "1" for a normal byte. So every byte is sent as a "1" followed by the serialization of the byte's bits, MSB to LSB. Alternatively, a context frame starts with the sync bit of "0" along with 8 more "0"s. This means that in a normal bit stream there will never be a series of 9 "0" bits.

So to specify a context for the data, send 9 "0"s followed by the context byte, which is the first normal byte after the context switch.

Using this context switch it's possible for the upper level executive to manage an api to toggle between sender and receiver. The low-level protocol itself doesn't care how that is handled.

The animation below demonstrates this protocol. (The Javascript doesn't actually implement it.) To see how bytes and contexts are sent, hit STOP. You can enter a comma separated list of bytes. These bytes will be displayed as "sent" either once or repeating. To send a context switch, specify "c" instead of a number.

Example: c,0x10,0x02,3

This will set the context to 0x10 because 0x10 is the first byte following the context switch. Then it will send 2 and 3. The bytes can be specified in hex or decimal.

Code will be included soon.

Enter Data:
Sending Data: 0xF0
repeat
slow