etherforth_logo

Node 216

This node receives a bit stream (already including stuffing bits) from LEFT and encodes them into J and K states of D+ and D- lines. It also receives and executes tokens (see below), and keep alive signal from node 316 each ms. It controls node 217 by executing words in its RIGHT.

Source code

usb node 316 node 217 node 116 node 216
216 encoder
bit 00 @p drop @p ; bit! 01 !p ; 0 ,
eop 03 @p ! @p . 1200F se0 , 1200F se0 ,
! @p ! @p 12003 j , 12012 idle , ! dup or bit! ;
enc 0B b bit over - or 1 and if @p ! . . 12009 k ,
else @p ! . . 12003 j , then bit! ;
alive 15 @ eop ;
tmit 16 @b -if push ex tmit ; then enc tmit ;
sof 1B @ eop @p ! @p 12034 rest , 1201D atch? , ! ;
rst 20 1000 for @ unext .. @p ! . . 1200F se0 ,
25 for @ unext 25 for alive next ;
rsm 2D @p ! 12009 k , 20 for @ unext alive ;
rx 33 @p ! ; 12023 ear ,
go 35 @p ! ; 12038 go , 37

init 195 rd-- a! up b! tmit ; 3B

4 d 7 r 0 u ether

Definitions

bit, bit!
Keep value of the last bit encoded.
eop
Send end-of-packet signal. It consists of two bits of SE0, one bit of J state, and then setting transmitter to idle state. It also clears bit.
enc
Take a bit from T (0 or 1) and compare it with value stored in bit. If the same then K state is set, else J state. The current bit thus encoded is stored with bit!.
alive
Send a keep alive signal when timer in 316 indicates one millisecond interval is over.
tmit
Read next word from the stream provided by node 116. If it is a token (T17 set) it is pushed to return stack and ex calls it (notice that bits T17 - T10 are disregarded in the address). Else it's a bit and it is encoded. Then return back and wait for next word in the stream.
sof
First send EOP, then call rest and atch? in 217 to check if the device is still attached. Then return to tmit. Note that atch? is the word in 217 that sends a signal to controller as of attached/detached state of the line.
rst
Reset token. Based on Win7 USB trafic recorcded first wait 350 ms, then sends SE0 for 25.7 ms, then sends 25 EOP signals.
rsm
Resume token. NOT TESTED!
rx
Switch node 217 to receive mode by calling ear.
go
Call go in 217.
init
Set registers A and B, and jump to tmit.

Description

Upon initialization this node jumps to word tmit, and waits for data written to its UP port. Data are either bits, which are encoded into J and K states with word enc, which calls words j and k in node 217, or tokens, which are actually addresses of words defined in this node. They are executed with push ex instructions.

Some tokens are defined as a sequence of states (eop), and some are more complex, calling other words in node 217 (sof, rx, go) or using 1 ms clock signal provided by node 316 for timing purposes (alive, sof, rst).