etherforth_logo

Node 115

This node reads data stream from 114, serializes them, calculates CRC16, and sends the bit stream to node 116.

Source code

usb node 114 node 116 node 115
115 serializer + crc
+crc 00 nb-n push dup 1 and push 2/
8000 or pop pop or if drop ;
then drop A001 or ;
crc 09 n a! 7 for a 1 and dup !b +crc a 2/ a! next ;
cmd 11 n dup 2* . if drop !b ; then drop drop r--- ;
clr 16 dup or
go 17 @b -if cmd go ; then crc go ;
crc! 1C n 15 for dup !b 2/ unext clr ; 20

init 1F5 r-l- b! clr ; 23

5 d 6 r 0 ether

Definitions

+crc
Start by pushing the bit and lsb of the growing CRC16 on return stack. Then shift CRC16 right and apply mask 8000, which is the same as inverting all incoming bits except first 16 bits. It is the oposite of what is normally done, i.e. invert first 16 bits of the bit stream. Then pull the two words from return stack and xor them. If the results is 1 leave +crc. If it is zero xor current CRC16 with polynom A001, which is reversed CRC-16-IBM polynom. Thus, xoring with polynom is done under exactly the oposite condition then in normal algorithm. The result is thus the same except for final inversion (see below).
crc
Read a byte, store it in A and serialize it, i.e. succesively mask all bits but T0, send this bit out and also to +crc for calculation, and shift the byte in A right.
cmd
Test for tokens. If 20000 then stop go and execute from RIGHT. Else (i.e. for all other words with T17 set) pass the token.
clr
Initialize CRC16 calculator to zero and fall throught to
go
Read bytes from LEFT and calculate CRC16. Pass tokens to RIGHT except for 20000 which ends CRC16 calculation. Now we can receive from RIGHT either a call to crc! which sends checksum upstream or execute clr which clears calculator and starts go again.
crc!
Shift 16 CRC16 bits out. No inversion of CRC16 at the end of calculation is needed as it is already inverted due to the algorithm itself.
init
Set B, and jump to clr

Description

This node serializes data bytes, i.e. low 8 bits of words read from node 114, into a stream of bits, and sends it to node 116. All data words have their msb zero.

Any word with msb set is a token, and is passed to node 116, except for token 20000, which forces node 115 to execute from RIGHT. This token gives node 114 opportunity to call any word in node 115 via RIGHT port execution.

RIGHT port execution is used when node 114 wants to reset CRC calculator and initiate new CRC calculation (clr), and to send current CRC as a stream of 16 bits (crc!). Sending CRC bits out clears the calculator and starts new CRC calculation automatically.