LWIP 1.4.1 bindings patch

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
TexZK
Posts: 57
Joined: Sat Sep 22, 2012 7:06 pm

LWIP 1.4.1 bindings patch

Post 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.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: LWIP 1.4.1 bindings patch

Post by Giovanni »

Thanks for the patch, I hope to integrate lwIP 1.4.1 soon.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: LWIP 1.4.1 bindings patch

Post by Giovanni »

Please continue this discussion here: viewtopic.php?f=3&t=849

Giovanni
Post Reply