Skip to content

Incremental Improvements to the W5500 Access Code

December 5, 2014

My W5500 access code works but it’s mildly awful. This is not the fault of the W5500, it’s my clumsiness and peculiar style. One of the awfulnesses is the rigamarole around sending a command and checking for completion. Because my basic wizWrite() and wizRead routines expect the payload to be sent and received as unsigned char *, each time i use it to send a command i have to make up a dummy variable with the command character in it and then make a pointer to it; also, I have tortured wizRead to return the contents of the last character read as its value which offends me; also, with any wizRead or wizWrite, you can pass the wrong opcode and do a read when you meant to do a write.

So, a wrapper routine:

void wizCmd(unsigned char cmd){ //send a command to socket 0 and wait for completion
	wizWrite(SnCR,WIZNET_WRITE_S0R,&cmd,1); //send the command
	while(wizRead(SnCR,WIZNET_READ_S0R,&cmd,1),cmd); //wait til command completes

and now

instead of
    unsigned char crclose=CR_CLOSE, crreadback=0xff;
    wizWrite(SnCR,WIZNET_WRITE_S0R,&crclose,1);    // Send Close Command
    while(wizRead(SnCR,WIZNET_READ_S0R,&crreadback,1));		// Wait for close Process

we write

It’s not perfect because it’s likely to be slower but I can live with that for now. This takes dozens of lines of cruft out of W5500code.c and some out of W5500code.h. I do note that the while loop condition in wizCmd is a BIT tricky in that it uses the comma operator: it calls wizRead, then accesses the returned value from the passed command area rather than needing wizRead to return it.

I’ll do a couple more wrapper routines and see if any underlying theme occurs to me.


From → web server

One Comment
  1. Bongjun Hur permalink

    I felt your master spirit from your concern. I also expect good works.
    Good luck~ 😀

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: