etherforth_logo

Node 016

This node reads bit stream from 017, deserializes the stream, calculates CRC16, and performs error check.

Source code

usb node 015 node 017 node 016
016 deserializer + crc
byte 00 @p drop @p ; byte! 01 !p ; 0 ,
+crc 03 nb-n push dup 1 and push 2/
8000 or pop pop or if drop ;
then drop A001 or ;
bytes 0C mn 7 for @ -if or 4FFE or !b pop ;
then byte 2/ over or byte!
2/ 2/ 2/ 2/ 2/ 2/ 2/ +crc next byte !b bytes ;
pid 1B -n dup or 7 for 2/ @ or unext ;
go 20 @ -if !b go ; then begin @ until
pid dup 43 or 77 and if drop !b @ go ; this @ eats eop 20000
then over !b bytes go ; 2D

init right a! left b! go ; 31

6 d 7 r 0 ether

Definitions

byte, byte!
A variable used for construction of a byte from bits received. One bit is received as 80 because bits are coming LSB first and constructed are with 2/ of byte content.
+crc
Start with the current remainder in S and bit (either zero or 80) in T. Calculate next CRC16 bit.
bytes
Start with current remainder (or zero if the first byte is being constructed) in T. Read 8 bits, constructs a byte, and calculate CRC16. Byte is then sent downstream. If instead of a bit a token is received (supposedly 20000 signalizing end of bit stream) it is xored with CRC16 remainder and sent downstream. If CRC16 ok, then it is zero and 20000 goes downstream. Else it signalizes an error.
pid
Read in 8 bits and constructs a byte. Used when we know this byte must be a PID. It does not use variable byte for this purpose.
go
Start by reading the first word from upstream and if token then send it downstream. Else it must be a sync pattern. Hence wait until one bit arrives (thus all zero bits are eliminated regardless how many are receive; due to errors or late synchronization not all seven zero bits may be received). Then get PID and test whether it is a DATAx PID. If not send this PID downstream and consume (@) 20000 token signalizing end of packet. Else send the PID downstream and call bytes. We get back from bytes when receiving end-of-packet 20000 token.
init
Set A and B, and jump to go.

Description

This node reads data stream from node 017. Any word with msb set is a token, and is passed to node 015. If not a token, it is a data packet. This node identifies the packet according to its PID. If DATAx packet, it deserializes data bits, calculates CRC16, and sends stream of bytes including CRC16 with msb set, which functions as a token indicating end-of-packet.