Skip to content

Fix for issue #5308 - RTC set/get time issue on NCS36510 #6852

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 3 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions TESTS/mbed_drivers/rtc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void test_attach_RTC_stub_funtions()
TEST_ASSERT_EQUAL(false, rtc_init_called);

/* Check if time has been successfully set and retrieved. */
TEST_ASSERT_EQUAL(CUSTOM_TIME_1, seconds);
TEST_ASSERT_UINT32_WITHIN(RTC_DELTA, CUSTOM_TIME_1, seconds);
}

/* This test verifies if attach_rtc provides availability to
Expand Down Expand Up @@ -183,7 +183,7 @@ void test_attach_RTC_org_funtions()
TEST_ASSERT_EQUAL(false, rtc_init_called);

/* Check if time has been successfully set and retrieved. */
TEST_ASSERT_EQUAL(CUSTOM_TIME_1, seconds);
TEST_ASSERT_UINT32_WITHIN(RTC_DELTA, CUSTOM_TIME_1, seconds);
}

/* This test verifies if time() function returns
Expand Down Expand Up @@ -430,7 +430,7 @@ void test_functional_set()
set_time(timeValue);

/* Get current time and verify that new value has been set. */
TEST_ASSERT_EQUAL(timeValue, time(NULL));
TEST_ASSERT_UINT32_WITHIN(1, timeValue, time(NULL));
}

/* This test verifies if RTC counts seconds.
Expand Down
20 changes: 18 additions & 2 deletions targets/TARGET_ONSEMI/TARGET_NCS36510/rtc_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
#include "rtc.h"
#include "cmsis_nvic.h"

#define US_PER_SEC 1000000

static time_t m_time_base;

static uint32_t rtc_seconds_get()
{
return (uint32_t)((fRtcRead() / US_PER_SEC) & 0xFFFFFFFF);
}

/* See rtc_apc.h for description */

void rtc_init(void)
Expand All @@ -61,13 +70,20 @@ int rtc_isenabled(void)
/* See rtc_apc.h for description */
time_t rtc_read(void)
{
return (uint32_t)(fRtcRead() & 0xFFFFFFFF); /* TODO Truncating 64 bit value to 32 bit */
return m_time_base + rtc_seconds_get();
}

/* See rtc_apc.h for description */
void rtc_write(time_t t)
{
fRtcWrite(t);
uint32_t seconds;
do {
seconds = rtc_seconds_get();
m_time_base = t - seconds;
/* If the number of seconds indicated by the counter changed during the
update of the time base, just repeat the update, now using the new
number of seconds. */
} while (seconds != rtc_seconds_get());
}

#endif /* DEVICE_RTC */
2 changes: 1 addition & 1 deletion targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -3736,7 +3736,7 @@
"post_binary_hook": {"function": "NCS36510TargetCode.ncs36510_addfib"},
"macros": ["CM3", "CPU_NCS36510", "TARGET_NCS36510", "LOAD_ADDRESS=0x3000"],
"supported_toolchains": ["GCC_ARM", "ARM", "IAR"],
"device_has": ["ANALOGIN", "SERIAL", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "LOWPOWERTIMER", "TRNG", "SPISLAVE"],
"device_has": ["ANALOGIN", "SERIAL", "I2C", "INTERRUPTIN", "PORTIN", "PORTINOUT", "PORTOUT", "PWMOUT", "SERIAL", "SERIAL_FC", "SLEEP", "SPI", "LOWPOWERTIMER", "TRNG", "SPISLAVE", "RTC"],
"release_versions": ["2", "5"]
},
"NUMAKER_PFM_M453": {
Expand Down