home .. forth .. colorforth mail list archive ..

[colorforth] rtl8139b driver


Please take a look a the following code which comes from the colorForth rtl8139b network driver:

: tx ( -b ) [ $2000 block 4 * ] ;
: rx ( -b ) [ tx 1536 + ] ; variable ds 1 variable fr 42
: n ( -a ) [ ds ] @ [ $10 r ] + ;
: send ( an ) [ fr ] @ [ tx ] + swap dup [ fr ] +! move ;
: first ( an ) n @ $2000 and drop if [ ds ] dup @ 1 + 3 and swap ! 0 [ fr ] ! send ; then first ;
: last ( an ) send tx [ ds ] @ [ $20 r ] + ! [ fr ] @ 60 max n ! ;

If you are not familer with this code, the word 'r' returns the address of a register on the rtl8139b given a register offset. The word 'n' returns the address of one of four "transmit status register"s. Please see the rtl documentation for more information on these registers[1].

'first' checks whether the DMA operation on the previous packet is completed with the sequence "n @ 2000 and drop". If this true the transmit buffer is free for assembling the next packet, otherwise 'first' is repeated.

It seems the way this driver is programmed, all four "transmit status register"s are not needed and actually one would suffice. I believe this is true because the next packet must wait for the previous packet to be transfered by the rtl8139b, therefore the previous "transmit status register" can be reused for the next packet.

From my reading of the rtl8139b documentation the following code would be equivalent:

: tx ( -b ) [ $2000 block 4 * ] ;
: rx ( -b ) [ tx 1536 + ] ; variable fr 42
: n ( -a ) [ $10 r ] ;
: send ( an ) [ fr ] @ [ tx ] + swap dup [ fr ] +! move ;
: first ( an ) n @ $2000 and drop if 0 [ fr ] ! send ; then first ;
: last ( an ) send tx [ $20 r ] ! [ fr ] @ 60 max n ! ;

The difference is in the elimination of the 'ds' variable and related code. I don't have an rtl8139b, so I would be interested if anyone using this code could test my modifcation. Part of my interest in this code is documenting the existing colorForth networking and extending its capability.

Mark

[1] http://personalwebs.oakland.edu/~maslicke/colorforth/networking/rt8139b.pdf

---------------------------------------------------------------------
To unsubscribe, e-mail: colorforth-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: colorforth-help@xxxxxxxxxxxxxxxxxx
Main web page - http://www.colorforth.com