lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] RAW TCP client gets terminated


From: Hugh Reynolds
Subject: Re: [lwip-users] RAW TCP client gets terminated
Date: Mon, 16 Mar 2020 17:38:40 -0000

Jonas, many thanks.

Regards


-----Original Message-----
From: lwip-users <lwip-users-bounces+hugh=address@hidden> On Behalf Of Jonas97
Sent: 16 March 2020 15:38
To: address@hidden
Subject: Re: [lwip-users] RAW TCP client gets terminated

Hi Hugh,

I did not find any specific documentation on the way sys_now() should be
implemented.
After debugging I noticed that sys_check_timeouts was using following macro:

/* Check if timer's expiry time is greater than time and care about u32_t
wraparounds */
#define TIME_LESS_THAN(t, compare_to) ( (((u32_t)((t)-(compare_to))) >
LWIP_MAX_TIMEOUT) ? 1 : 0 )

So I suspect that the timer should run all the way to the unsigned 32 bit
wraparound point. This is only hit after 49 days so I didn't dig deeper as
my application doesn't run that long.

The problem was that the ms function for my microcontroller was wrapping
around after 71583 so instead of hitting 71584 it would start at zero again.

Below is my quick and dirty fix for this which might contain future bugs, is
gcc specific and also specific to the 71583 wrap around point. Feedback
always appreciated.

u32_t sys_now( void )
{
    static uint32_t ms = 0;
    static uint32_t lastMs = 0;

    uint32_t newMs = cpu_cy_2_ms( Get_sys_count(), sysclk_get_cpu_hz() );
    uint32_t diffMs;

    if( newMs < lastMs )
    {
        diffMs = ( newMs + 4294895712 ) - ( lastMs + 4294895712 );
        diffMs -= 4294895712;
    }
    else
    {
        diffMs = newMs - lastMs;
    }

    lastMs = newMs;
    ms += diffMs;

    return ms;
}




--
Sent from: http://lwip.100.n7.nabble.com/lwip-users-f3.html

_______________________________________________
lwip-users mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/lwip-users


--
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]