Node 117
This node performs three functions. First, it is used as a proxy by node 217 to change direction of the voltage level shifter. Second function is to inform host controller (nodes 014 and 015) upon request that a device has been/is still attached or detached. The last function implemented in this node is to control line receivers (nodes 217 and 317) during reception of data from a device (keyboard), and pass data bits downstream.
Source code
d- 00 @p drop @p ; d-! 01 !p ; 0 ,
in 03 155 !b ;
out 05 AA !b ;
atch 07 a down a! 30000 ! a! ;
dtch 0B in a down a! 30001 ! a! ;
tx 10 io b! @p . 12034 rest , ! @p ! . 101D5 r--- , ---u ;
bit 16 sf-sb drop d- over or . -if dup or ; then drop 80 ;
rcv 1C begin @ @ over or -if bit !b d-! @p ! . . 12028 nxt ,
swap end ; then 20000 !b tx ;
rx 27 down b! 20000 d-! @p ! @ . 1202A inp , if rcv ;
then - !b io b! ---u ; 33
init up a! io b! ---u ; 38
5 d 8 r 0 ether
Definitions
- d-, d-!
- It is a variable that keeps the last state of D- line.
- in, out
- Change direction of 4LVC2T45DC voltage level shifter (low and high on DIR pin, respectively).
- atch
- Send 30000 signal to controller about device having been attached.
- dtch
- Send 30001 signal to controller when device has been detached. Also switch direcion to input.
- tx
- Turn node 217 into transmitter. First let lines settle down by calling rest in 217, and then instruct node 217 to execute from RITHG and jump to UP.
- bit
- Discard flag from rcv and test for change of state in line D-; if changed return zero, else 80. The reason is that USB sends data LSB first. However, bytes are deserialized with 2/, so that bit 1 set is sent as shifted left by 7 bits.
- rcv
- Read two words from node 217; first comes state of D- line, then D+ line. Then test whether SE0 has been received (positive number in T) while D- line state is kept in S. If not, calling bit converts state to bit, which is sent downstream, and the last state of D- line is stored with d-!. Then next pair of lines states is requested from 217 with call to nxt. If end-of-packet received (SE0 state) send downstream a flag 20000, and switch node 217 to transmit mode, which makes 117 execute from UP again.
- rx
- Set d- to 20000 (formally the initial high state of D- line before the first bit of sync pattern is received). Then call inp in 217 and wait for reply. If non-zero, then a signal on data lines has been detected, thus jump to rcv. Else send -1 downstream as error flag and jump to UP.
- init
- Set A and B, and jump to UP.
Comments
This node starts execution from UP port. When the module is transmitting, node 217 calls out to set correct voltage level shifter direction. When entering idle state, it calls in.
Node 217 also calls atch and dtch when it needs to inform controller that a keyboard has been attached or detached, respectively.
Signals sent to the controller:
- 3FFFF
- Reciever error. likely timeout of a device.
- 20000
- End of packet.
- 30000
- Device attached.
- 30001
- Device detached.