LWIP 1.4.1 bindings patch
Posted: Wed Dec 19, 2012 8:53 pm
Hello! While porting an application to LWIP 1.4.1, I found that they require a new binding, as reported in doc/sys_arch.txt:
Currently, it is implemented this way in my source code (lwip_bindings/arch/sys_arch.c):
This is the only change in the bindings, as far as I can see.
For those using "strange" CH_FREQUENCY, there are some ways to avoid casting to 64 bits.
For some configurations, you also need:
- u32_t sys_now(void)
This optional function returns the current time in milliseconds (don't care
for wraparound, this is only used for time diffs).
Not implementing this function means you cannot use some modules (e.g. TCP
timestamps, internal timeouts for NO_SYS==1).
Currently, it is implemented this way in my source code (lwip_bindings/arch/sys_arch.c):
Code: Select all
u32_t sys_now(void) {
#if CH_FREQUENCY == 1000
return (u32_t)chTimeNow();
#elif (CH_FREQUENCY / 1000) >= 1 && (CH_FREQUENCY % 1000) == 0
return ((u32_t)chTimeNow() - 1) / (CH_FREQUENCY / 1000) + 1;
#elif (1000 / CH_FREQUENCY) >= 1 && (1000 % CH_FREQUENCY) == 0
return ((u32_t)chTimeNow() - 1) * (1000 / CH_FREQUENCY) + 1;
#else
return (u32_t)(((u64_t)(chTimeNow() - 1) * 1000) / CH_FREQUENCY) + 1;
#endif
}
This is the only change in the bindings, as far as I can see.
For those using "strange" CH_FREQUENCY, there are some ways to avoid casting to 64 bits.