etherforth_logo

Node 015

This part of the controller is responsible for reset and initializaton of keyboard in boot protocol.

Source code

usb node 014 node 016 node 015
015 controller
err 00 @p drop @p ; err! 01 !p ; 10 ,
err* 03 10 err! ;
x! 05 n @p !b !b ; @p !
err? 07 n-n dup 1 . + if drop err* ; then - err + if * err! ;
sof 0E 12002 sof x! @ 30001 or if ** drop ;
rqst 14 a begin sof dup x! @ err? D2 ack or ..
if drop swap end then ;
stat 1C 1200A in00 begin sof dup x! @ err? 4B data1 or ..
if drop swap end then @ @ @ 12008 ack x! ;
go 28 then ** @ then * err*
12004 rst x!
1200E setc rqst stat
12012 setp rqst stat
12016 seti rqst stat
1201A setr rqst 1201E led rqst stat
12024 keys !b r--- ; 3D

init left a! right b! go ; 41

6 d 6 r 0 ether

Definitions

err, err!
It is an error down counter. Preset to 10. If ten consecutive error tokens (3FFFF) received it results in RESET being invoked by err?.
err*
Reset err counter to 10.
x!
It is used to pass data to node 114 via port execution in node 14.
err?
Check T and if equal to 3FFFF (-1) decrement err. If result in err is zero jump to go skipping @ and immediatelly initiate reset of the device. If not tenth consecutive error then ignore it. Note that receiving correct token resets err counter to 10.
sof
Initiate sof in 216, and read result of attached/detached line test (30000, 30001). If attached then return, else jump to go waiting for a device to be attached again.
rqst
Expect address of transaction in T. Call sof, which tests for attached/detached line state. If attached then it's ok and return to rqst. Else jump directly to go. Then send address of transaction to 114 via port execution in 14 and wait for acknowledgement. We may receive an error flag (taken care of by err?) or acknowledge packet. If we receive NAK or STALL (not supported) retry the transaction. If ACK then return from rqst.
stat
Request status handshake, i.e. send IN ENDP 0 packet and expect DATA1 packet. Start by sending SOF and test attached/detached state of the line in the same way as in rqst. Then read a byte and test if it is DATA1. If not, retry this transaction. If so, read three words (two zero data bytes plus CRC16), and send ACK packet to acknowledge this transaction. We do not check CRC16 received.
go
Wait for attachment signal fetching from LEFT, then reset and configure the keyboard, switch CapsLock LED on and start keys in node 14. Then execute from RIGHT.
init
Set A and B, and jump to go.

Description

Upon booting this node starts executing word go. It fetches a word from RIGHT, which may only be a signal that a keyboard has been attached. Until then nothing happens. Following the keyboard attachment, we reset error counter err*, reset the keyboard, and start an initialization sequence, i.e. we request USB functions Set_configuration, Set_protocol, Set_idle, Set_report, and finally we turn the Caps Lock LED on.

Each USB function is requested with word rqst, and outcome is checked with word stat. If the status is OK, we continue the sequence, otherwise we decrement error counter err* and retry. When there are 10 consecutive errors, we abandon this initialization sequence, reset the keyboard, and start initialization all over again.

When the keyboard is successfully initialized into boot protocol, we call word keys in node 014, and jump to RIGHT, which means that from now on node 014 controlls execution in node 015.