SMSC LAN91C111 32/16/8-Bit Three-In-One Fast Ethernet Controller
Revision 1.0 (08-14-08) 40 SMSC AN 9.6
APPLICATION NOTE
As with any software problem, there are many ways to accomplish this task. One method would be to
have a routine that swaps the bytes around prior to outputting them to the LAN91C111. Another
method might be too use a simple #define statement for each byte within a header file with the
understanding of how they are configured and how the output needs to be accomplished. There also
may be provisions for accomplishing this already available with the language, compiler, and processor
you are using. Please refer to your documentation for more details regarding any of these options.
Byte swapping is like parity. An even number of byte swaps produces the original ordering.
6.6 Source Code Example
As an example of some of the things that can be done in source code, please review the following
examples.
Here's a simple runtime check for endianness of your machine.
Here's the source to a generic endian swapper.
Another example of source code to do byte swapping was obtained from the following website:
http://www.phish.net/ftpspace/GSW/Sounds/Software/mozilla/lxr/1998-03-31/ns/dbm/include/mcom_db.h
is_little_endian()
{
int i=0;
((char *)(&i))[0] = 1;
return i == 1;
}
#define ENDIAN_SWAP(a) endian_swap(&(a), sizeof(a))
void
endian_swap(void *v, int size)
{
int i;
unsigned char *p = (unsigned char *) v, q;
for(i=0; i<size/2; i++) {
q = p[i];
p[i] = p[(size-1)-i];
p[(size-1)-i] = q;
}
}