In order to ease changing devices and to permit systems with multiple ports, version 3 and above of the Powernet TCP/IP stack use a generalised interface to the hardware, which is usually an Ethernet driver or a serial driver.
The interface consists of a vector (table) of XTs corresponding to the particular function required. The layout of the table is as follows:
create IPdevice
' MyInit , \ 0: initialisation
' MyTerm , \ 1: shutdown
' MyRx? , \ 2: receive test
' MyRx \ 3: receive packet
' MyTx? , \ 4: transmit test
' MyTx , \ 5: transmit packet
' MyGetAddr , \ 6: Get device addresses
' MySetAddr , \ 7: Set device addresses
' MySave , \ 8: Save IP device addresses and state
' MyDiscard , \ 9: Discard current receive packet
by default, the system code requires a default IP device called IPDevice. IPDevice will be used when PowerNet is started.
cell +User IPDVec \ -- addr
IPDVec is a USER variable which contains the address
of the current Internet Protocol Device (IPD) vector.
All tasks must initialise IPDVEC before using the
ETHERCOM interface.
IPDevice IPDVec !
: IPDinit \ --
Initialise (open) the current IP device.
: IPDterm \ --
Shutdown (close) the current IP device.
: IPDRx? \ -- flag ; check receive char
Return true if a packet is available at the current IP
device.
: IPDRx \ buff size -- len ; receive packet
Receive a packet into buff of size bytes, returning len the
number of bytes received. Use IPDRX? to check that a packet
is available.
; IPDTx? \ len -- flag ; check TX capability
Return true if the current IP device can send a packet
of size len bytes.
: IPDTx \ buff len -- ; send packet
Transmit the given packet.
: IPDGetAddr \ -- ipaddr netaddr flags
Returns: a pointer to the IP address used by this
device, or 0 if it has not been set yet: a pointer
to the network address of the device, e.g. the Ethernet
MAC address or 0 if not set or irrelevant: and a set of flags
which are currently 0 for IPv4 and Ethernet/SLIP/PPP devices.
: IPDSetAddr \ ipaddr netaddr flags --
Consumes: a pointer to the IP address used by this
device, or 0 for no change: a pointer
to the network address of the device, e.g. the Ethernet
MAC address or 0 for no change: and a set of flags
which are currently 0 for IPv4 and Ethernet/SLIP/PPP devices.
: IPDSave \ --
Save the device state to non-volatile storage so that
it can be reloaded at the next power up or IPDinit.
: IPDDiscard \ --
Discard the current receive packet, usually because
PowerNet has run out of buffer space. This is only
valid if IPDRX? has returned true to say that a packet
is available.