Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Adjusted current time with elapsed ticks #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/bsp/platform/stm32fx/xi_bsp_time_stm32fx.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@
#endif
#include <xi_bsp_time_stm32fx_sntp.h>

static uint32_t ticks_at_start = 0;

void xi_bsp_time_init()
{
xi_bsp_time_sntp_init( NULL );
if (xi_bsp_time_sntp_getseconds_posix() != 0)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this condition necessary?
If the getseconds equals zero, then isn't it a failure? Failure during getting the time from SNTP server? Also means the HAL_GetTick() returns zero, right?

If time isn't received from SNTP service the connection to broker should fail anyway. So, I would stick to a simple:

ticks_at_start = HAL_GetTick(); without a condition.

ticks_at_start = HAL_GetTick();
}
}

xi_time_t xi_bsp_time_getcurrenttime_seconds()
{
return xi_bsp_time_sntp_getseconds_posix() + HAL_GetTick() / 1000;
return xi_bsp_time_sntp_getseconds_posix() + (HAL_GetTick()-ticks_at_start) / 1000;
}

xi_time_t xi_bsp_time_getcurrenttime_milliseconds()
{
return xi_bsp_time_sntp_getseconds_posix() + HAL_GetTick() / 1000;
return xi_bsp_time_sntp_getseconds_posix() + (HAL_GetTick()-ticks_at_start) / 1000;
}