Skip to content

Commit bfe60a0

Browse files
authored
Merge pull request #971 from kaisa847/fix/ps2ip-sys-now-wrap
ps2ip: fix sys_now() and WaitSemaTimeout() timer overflow
2 parents 631461f + a2b78da commit bfe60a0

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎ee/network/tcpip/src/sys_arch.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <string.h>
1414
#include <kernel.h>
1515
#include <kernel_util.h>
16+
#include <timer.h>
1617
#include <time.h>
1718
#include <limits.h>
1819

@@ -217,7 +218,7 @@ static int WaitSemaTimeout(int sema, unsigned int msec)
217218
timeoutPtr = NULL;
218219

219220
if (msec > 0 && msec != UINT32_MAX) {
220-
timeoutUsec = msec * 1000;
221+
timeoutUsec = (u64)msec * 1000;
221222
timeoutPtr = &timeoutUsec;
222223
}
223224

@@ -507,7 +508,9 @@ void sys_init(void)
507508

508509
u32_t sys_now(void)
509510
{
510-
return(clock()/1000);
511+
/* clock() is a 32-bit count of microseconds and wraps after ~71.6 minutes;
512+
lwIP expects sys_now() to wrap only after 2^32 ms. */
513+
return (u32_t)(GetTimerSystemTime() / (kBUSCLK / 1000));
511514
}
512515

513516
void *ps2ip_calloc64(size_t n, size_t size)

0 commit comments

Comments
 (0)