Skip to content

Add low power timer fallback for platforms without RTC #6878

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2018
Merged
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
41 changes: 39 additions & 2 deletions platform/mbed_rtc_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,53 @@
static SingletonPtr<PlatformMutex> _mutex;

#if DEVICE_RTC

static void (*_rtc_init)(void) = rtc_init;
static int (*_rtc_isenabled)(void) = rtc_isenabled;
static time_t (*_rtc_read)(void) = rtc_read;
static void (*_rtc_write)(time_t t) = rtc_write;
#else

#elif DEVICE_LOWPOWERTIMER

#include "drivers/LowPowerTimer.h"

static SingletonPtr<mbed::LowPowerTimer> _rtc_lp_timer;
static uint64_t _rtc_lp_base;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that _rtc_lp_base is getting written in the write function below, how is it used?

Copy link
Member Author

Choose a reason for hiding this comment

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

_rtc_lp_base is used as a start time and then we add the actual timer value to it as timer starts from 0.

static bool _rtc_enabled;

static void _rtc_lpticker_init(void)
{
_rtc_lp_timer->start();
_rtc_enabled = true;
}

static int _rtc_lpticker_isenabled(void)
{
return (_rtc_enabled == true);
}

static time_t _rtc_lpticker_read(void)
{
return (uint64_t)_rtc_lp_timer->read() + _rtc_lp_base;
}

static void _rtc_lpticker_write(time_t t)
{
_rtc_lp_base = t;
}

static void (*_rtc_init)(void) = _rtc_lpticker_init;
static int (*_rtc_isenabled)(void) = _rtc_lpticker_isenabled;
static time_t (*_rtc_read)(void) = _rtc_lpticker_read;
static void (*_rtc_write)(time_t t) = _rtc_lpticker_write;

#else /* DEVICE_LOWPOWERTIMER */

static void (*_rtc_init)(void) = NULL;
static int (*_rtc_isenabled)(void) = NULL;
static time_t (*_rtc_read)(void) = NULL;
static void (*_rtc_write)(time_t t) = NULL;
#endif
#endif /* DEVICE_LOWPOWERTIMER */

#ifdef __cplusplus
extern "C" {
Expand Down