Perhaps it might be wise to move lwip_chksum into sys_arch.c?
If that were done, then the chksum could be implemented in a manner
appropriate to the CPU and compiler in question. Since the algorithm
operates on all the data in all tcp and udp packets, speed is a pretty
important consideration.
Chris WIlliams wrote:
We all have our own way of coding. This is my routine at the moment.
I can't tell if this is faster of slower than John Taylors. If people
find this of use, could it be included properly?
Good luck.
static u16_t
lwip_chksum(void *dataptr, int len)
{
u32_t acc = 0;
unsigned char *dp = (unsigned char *)dataptr;
int half_len;
for(half_len = len / 2;half_len;half_len--){
acc += ((u16_t)*dp++) << 8;
acc += *dp++;
}
if(len & 1){
acc += ((u16_t)*dp++) << 8;
}
acc = (acc >> 16) + (acc & 0xffffUL);
if ((acc & 0xffff0000L) != 0) {
acc = (acc >> 16) + (acc & 0xffffUL);
}
return (u16_t)acc;
}
--
E-mail signature
Jim Gibbons
|
address@hidden
|
Gibbons and Associates, Inc.
|
TEL: (408) 984-1441
|
900 Lafayette, Suite 704, Santa Clara, CA
|
FAX: (408) 247-6395
|
|