Merge pull request #6852 from mprse/issue_5308_fix

Fix for issue #5308 - RTC set/get time issue on NCS36510
pull/6887/head
Cruz Monrreal 2018-05-10 23:26:06 -05:00 committed by GitHub
commit 30e39eeb10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View File

@ -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
@ -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
@ -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.

View File

@ -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)
@ -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 */

View File

@ -3753,7 +3753,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": {