Endianess problem

Oct 08, 2007 4 Replies

Hi,



I am writing a driver for a ethernet controller. The controller i connected to the io memory and expects data to be in the Little endia format (will call it LE now and BE for big endian). The main cpu whic runs the driver code is a BE machine. During the startup I write th descriptors into the io memory in the LE format. In the send and receiv routine which is called by the IP stack I have pointers that access th descriptors. The pointers are actually pointing to data which is in L format, so if I want to access a bit(a part of the desc bit field) lik ptr->own_bit it will refer to the wrong bit. How can I come over thi problem.



wr, Sid


You have identified the problem. To overcome it, fix the code.

I thought the comm data was in Big-Endian order. Are you talking about control and status registers' content?

----------------------------------------------------------------------- "Big-Endian byte order is known as 'normal', 'intuitive', or 'obvious'. Little-Endian is sometimes called 'perverse', 'annoying', 'dysfunctional', or 'stupid'. These designations do not, of course, imply any bias or preference."

Christopher R. Hertel, "Implementing CIFS" 2004

There is also the possibility that the two machines/compilers will allocate bit fields in a different order. Fortunately for me, the Keil 8051 and MSVC86 compilers both allocate bit fields from LS bit up. This only matters if you are hoping to share structure definitions between machines.

In the past I have written alternate forms of struct definitions, with the bitfields appropriately adjusted to align. One machine uses one definition and the other processor uses the other. An #ifdef selected the proper form based on the target.

Thad

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required