Download introduction

Transcript
300
USING MULTICORE FOR NETWORKING APPLICATIONS
Functionally, all the mode method does is set the pins that map to the W5100
mode pins to output and set them according to the opmode input parameter. To
make the W5100 100 Mbps and full duplex, call the mode method with opmode
equal to 0.
The only other two methods that don’t use the read and write
methods are the start and stop methods. You should recognize these, as they are used
in practically all drivers for the HYDRA.
We’ll discuss the stop method first, as it is the most simple. It simply stops the SPI
layer and frees the cog it runs on. There, done!
The start method starts the SPI layer (written in assembly), which handles the
actual bit-banging of the SPI data to the W5100 in a new cog and returns the new cog
number that the SPI layer lives in. If you choose to call the mode method, it should be
called before the start method. All other Spin method calls (including read and write)
should be called after the start method has been called.
The code for start and stop is shown here:
Start and Stop
PUB start : okay
" This is the public start method. It starts
" a new cog at the assembly entry point
'Start the SPI code in a new COG
stop
okay := cogon := (cog := cognew(@entry, @SPIRW)) > 0
PUB stop
" Stops driverfrees a cog
if cogon~
cogstop(cog)
The init method should be called right after the start method. It initializes the
W5100 by telling it what our gateway, subnet, IP address, and MAC address are. The
init method is shown here:
Init
PUB init (gway, subnet, ip, mac)
'Init the registers
'Gateway
write($00,$01,byte[gway])
write($00,$02,byte[gway+1])
write($00,$03,byte[gway+2])
write($00,$04,byte[gway+3])