Extension to lwip sntp to provide a weak callback notifying us the time has been set by sntp

This commit is contained in:
Mark Webb-Johnson 2018-03-01 08:48:06 +08:00
parent 6acb38af4c
commit 4df0599374
1 changed files with 15 additions and 2 deletions

View File

@ -198,6 +198,19 @@ static ip_addr_t sntp_last_server_address;
static u32_t sntp_last_timestamp_sent[2];
#endif /* SNTP_CHECK_RESPONSE >= 2 */
/**
* Weak callbacks to implement setting system time
*/
extern void __attribute__((weak)) sntp_setsystemtime_us(u32_t t, u32_t us)
{
SNTP_SET_SYSTEM_TIME_US(t, us);
}
extern void __attribute__((weak)) sntp_setsystemtime(u32_t t)
{
SNTP_SET_SYSTEM_TIME(t);
}
/**
* SNTP processing of received timestamp
*/
@ -214,14 +227,14 @@ sntp_process(u32_t *receive_timestamp)
#if SNTP_CALC_TIME_US
u32_t us = ntohl(receive_timestamp[1]) / 4295;
SNTP_SET_SYSTEM_TIME_US(t, us);
sntp_setsystemtime_us(t, us);
/* display local time from GMT time */
LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s, %"U32_F" us", ctime(&tim), us));
#else /* SNTP_CALC_TIME_US */
/* change system time and/or the update the RTC clock */
SNTP_SET_SYSTEM_TIME(t);
sntp_setsystemtime(t);
/* display local time from GMT time */
LWIP_DEBUGF(SNTP_DEBUG_TRACE, ("sntp_process: %s", ctime(&tim)));