On Saturday 19 May 2007 6:01 pm, Simon fgc wrote:
> Hello,
>
> I am using Mips 32 target and i use below structure
>
> typedef struct packet_t {
>     unsigned int length;
>     unsigned short int value;
>     unsigned id;
>     union {
>             struct {
>                 unsigned int p1;
>                 unsigned int p2;
>             } patterns;
>     unsigned char data[3]


Firstly I strongly suggest you use size-specifc integer types for
portability, as assuming unsigned int is 32 bits on all platforms is not
portable. Try using uint32 instead (of course this will mean modifying
your data array size too).

For endianness conversion, you need some sort of macro, such as

#define USB_ENDIAN_32(X) \
      | ((((uint32)(X) & 0xff000000) >> 24) \
      | (((uint32)(X) & 0x00ff0000) >> 8) \
      | (((uint32)(X) & 0x0000ff00) << 8) \
      | (((uint32)(X) & 0x000000ff) << 24))

#define HOST_ENDIAN_32 USB_ENDIAN_32

(note that I haven't test this but it should work)

Again, for portability of your code I suggest you check for BIG_ENDIAN
and LITTLE_ENDIAN and define these macros as null if LITTLE_ENDIAN is
defined (such as on x86 cpus).


-Taj.


_______________________________________________
ilugd mailinglist -- ilugd@lists.linux-delhi.org
http://frodo.hserus.net/mailman/listinfo/ilugd
Archives at: http://news.gmane.org/gmane.user-groups.linux.delhi 
http://www.mail-archive.com/ilugd@lists.linux-delhi.org/

Reply via email to