Re: [lwip-users] Little endian

2014-06-27 Thread Fabian Cenedese
At 18:09 26.06.2014, you wrote:
Hi Fabian,
for clarity's sake:

lwIP uses internally its own representation, and there are macros to
convert from network format to host format. I guess all systems are more
or less like that.

You are supposed to have a fast macro, preferably with machine code
instructions, because it is going to be used a lot. That should be a
part of your arch port.
Have a look at (or just use) my ARM Cortex-M generic (CMSIS) port:
http://scaprile.ldir.com.ar/cms/category/os/lwip-port
and also have a look at my ethernet code to see how it uses that macro:
http://scaprile.ldir.com.ar/cms/el-ingeniero/open-source-projects-im-working-on/

I got it working now. We already have implementations for faster
swappings, I just need to use them. But thanks for the links
anyway, I did take a look.

bye  Fabi


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Little endian

2014-06-27 Thread Adriano Pallavicino
Hi Fabi, have you followed this guide
http://lwip.wikia.com/wiki/Porting_for_an_OS ? In particular:
Packet headers data is stored in network byte order
http://en.wikipedia.org/wiki/Endianness#Endianness_in_networking which is
the the big-endian mode http://en.wikipedia.org/wiki/Endianness#Big-endian.
If your processor architure is little-endian
http://en.wikipedia.org/wiki/Endianness#Little-endian, then we need to
convert data using htons()/htonl()/ntohs()/ntohl()
http://www.opengroup.org/onlinepubs/007908799/xns/htonl.html functions.

Here an example (the following code use CMSIS, so you must be sure to have
it enabled)


---
u16_t
lwip_le_htons(u16_t n)
{
return ((n  0xff)  8) | ((n  0xff00)  8);
}

/**
 * Convert an u16_t from network- to host byte order.
 *
 * @param n u16_t in network byte order
 * @return n in host byte order
 */
u16_t
lwip_le_ntohs(u16_t n)
{
return ((n  0xff)  8) | ((n  0xff00)  8);
}

/**
 * Convert an u32_t from host- to network byte order.
 *
 * @param n u32_t in host byte order
 * @return n in network byte order
 */
u32_t
lwip_le_htonl(u32_t n)
{
return __REV(n);
}

/**
 * Convert an u32_t from network- to host byte order.
 *
 * @param n u32_t in network byte order
 * @return n in host byte order
 */
u32_t
lwip_le_ntohl(u32_t n)
{
return __REV(n);
}
---

you must insert these functions in /core/def.c and check the #define chain

Bye Adriano


2014-06-26 11:14 GMT+02:00 Fabian Cenedese cened...@indel.ch:

 Hi

 I'm using lwip 1.4.1 on big endian targets and it works. Now I
 want to use the same software on little endian targets (ARM)
 and have problems. Should that work from the lwip part? The
 Ethernet frame of course is always big endian why it works
 without problems on big endian targets. However I'm not sure
 that all places do the correct conversion between host and
 network order.

 E.g. the IP address for the interface:

 IP4_ADDR(ipaddr, 192, 168, 1, 197)
 netif_add(m_Netif, ipaddr...

 gives a debug trace

 ... set to 197.1.168.192

 Is the trace wrong or did I give a wrong address?


 Sending (e.g. ARP reply):
 ip_output_if_opt

 The ip address is copied directly into the frame:
 ip_addr_copy(iphdr-src, *src);

 Shouldn't that be
 ip_addr_set_hton(iphdr-src, src);

 if the runnig hardware is little endian?

 And yes, I do have
 #define BYTE_ORDER LITTLE_ENDIAN

 Thanks

 bye  Fabi


 ___
 lwip-users mailing list
 lwip-users@nongnu.org
 https://lists.nongnu.org/mailman/listinfo/lwip-users




-- 
Adriano Pallavicino
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] Little endian

2014-06-26 Thread Fabian Cenedese
At 11:14 26.06.2014, you wrote:
Is the trace wrong or did I give a wrong address?

I got this sorted out, I was using a different variable for the netif_add.

Shouldn't that be
ip_addr_set_hton(iphdr-src, src);

And I read in the documentation that ipaddr is always network order
so copying directly is ok.

Sorry for the noise.

bye  Fabi


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] Little endian

2014-06-26 Thread Sergio R. Caprile
Hi Fabian,
for clarity's sake:

lwIP uses internally its own representation, and there are macros to
convert from network format to host format. I guess all systems are more
or less like that.

You are supposed to have a fast macro, preferably with machine code
instructions, because it is going to be used a lot. That should be a
part of your arch port.
Have a look at (or just use) my ARM Cortex-M generic (CMSIS) port:
http://scaprile.ldir.com.ar/cms/category/os/lwip-port
and also have a look at my ethernet code to see how it uses that macro:
http://scaprile.ldir.com.ar/cms/el-ingeniero/open-source-projects-im-working-on/

Regards

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users