Page 1 of 1

LWIP 1.4.1 bindings patch

Posted: Wed Dec 19, 2012 8:53 pm
by TexZK
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:
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.

Re: LWIP 1.4.1 bindings patch

Posted: Wed Dec 19, 2012 9:29 pm
by Giovanni
Thanks for the patch, I hope to integrate lwIP 1.4.1 soon.

Giovanni

Re: LWIP 1.4.1 bindings patch

Posted: Sat Dec 22, 2012 11:17 am
by Giovanni
Please continue this discussion here: viewtopic.php?f=3&t=849

Giovanni