Hi,

I had similar problems, although not in the same piece of code. It had more to do with misaligned access than with endianess. IIRC, on the LPC213x (and maybe all ARM's, not sure), misaligned accesses to 16-bit values (ie. most IP addresses in uIP) can cause a read from the 32-bit aligned address followed by a bit rotate to get the correct bytes. Also, if you are attempting to typecast a misaligned buffer to a structure make sure the structure is defined as "packed".

One fix that I had to use was to define the Link Layer Header length to a multiple of 4 to ensure that the uIP buffer was properly aligned and thus the IP headers were properly aligned as well.

One other thing I noticed when sifting through the assembler output was that the GCC optimizer took two adjacent 16-bit compares such as:

  u16_t x[2], y[2]
    /* ... */
  if ((x[0] == y[0]) && (x[1] == y[1]))
  {
    /* Do something interesting */
  }

and optimized into something like this:

  u32_t X, Y
    /* ... */
  if (X == Y)
  {
    /* Do something interesting */
  }

The above is only correct if both x[] and y[] are aligned on a 32-bit boundary which may not be the case if they are part of a packed or misaligned structure.

Please note: The above example is for illustration only. It is what I remember of a simple hand "decompilation" of some generated assembler code from several months ago. I noticed this behaviour on structures that were not defined with a specific alignment or packed attribute, so it is quite possible that those attributes might prevent such optimization.

Hope this helps.
Patrick


Daniel Rost wrote:
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Willi Schulte
Sent: den 5 mars 2007 15:30
To: uip-users@sics.se
Subject: [uip-users] Byte ordering problem with ARM7

Hi all,

I try to port uIP 1.0 to the LC2132. First of all I had trouble
with the uIP Log Message "ip: Invalid version or header length".

Obviously there is a problem with the linker. Mr. McKenney had the
same problems and could give me some hints to fix it
(struct ... __attribute__((packed));)

Now I had the next problem: ARP does not work. With debug-prints
I found out that there is an endian problem.
The quick fix in main() was:
---------------------------------------------------------------------
// uip_ipaddr(ipaddr, 192,168,1,160); // looks good but does not work
   uip_ipaddr(ipaddr, 168,192,160,1); // looks crazy but ARP works
   uip_sethostaddr(ipaddr);
// ... the same change for the netmask and ARP and PING works!
---------------------------------------------------------------------
I can't believe that this is the "solution". Something else must be wrong here. Has anyone an idea what had happened?

I am using GNU-C with KEIL-IDE and the LPC2132 in "little edian" mode, also in "uipopt.h".

Thanks a lot in advance,
Willi

Reply via email to