Michael Williamson escreveu:
Actually, I happen to be a developer that uses a compiler that doesn't
even have structure packing (TI's Code Composer Studio for their DSP
products),
that is an important platform... :(
It would be really handy, if, somehow, there could be a sys_arch style
hook or macro for protocol fragment encoding/decoding that would default
to structure overlaying, but let you override it with byte-by-byte
copying to a compiler friendly data structure if you need to.
I have seen a comm packet long time ago that used macros with pointers,
and I used that for some small things. It is 100% portable and
performance would be hw dependent. Probably in chips like ARM7/9 it
would be bad, but on PCs and Cortex that have byte access it would be
better, no idea about 16 bits DSP. Also remember that 99% of protocol
header variables are contained in 32 bit words so it will not be too bad.
the example would be:
struct dns_answer {
/* DNS answer record starts with either a domain name or a pointer
to a name already present somewhere in the packet. */
u16_t type;
u16_t class;
u32_t ttl;
u16_t len;
} PACK_STRUCT_STRUCT;
char dns_answer[10];
#define dns_answer_type (*((u16_t*)dns_answer))
#define dns_answer_class (*((u16_t*)&dns_answer[2]))
#define dns_answer_ttl (*((u32_t*)&dns_answer[4]))
#define dns_answer_len (*((u16_t*)&dns_answer[8]))
or with pointers:
#define dns_answer_type(p) (*((u16_t*)p))
#define dns_answer_class(p) (*((u16_t*)(p+2)))
or some variations... (or fixes, I may have it wrong)
This could be a
Alain
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users