From eb32b25c8abb37f0aab505451074448e7e420517 Mon Sep 17 00:00:00 2001 From: Heuisam Kwag Date: Mon, 9 Nov 2020 20:04:33 +0900 Subject: [PATCH] SIDK_S1SBP6A: fix to support rtc range from 0 to 0xEFFFFFFF BP6A do not support from 0 to 0xEFFFFFFF in SOC. This patch fixes it in s/w manner. Signed-off-by: Heuisam Kwag --- .../TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.c | 29 +++++++++++++++++++ .../TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.h | 3 +- .../TARGET_SIDK_S1SBP6A/rtc_api.c | 12 ++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.c b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.c index e986e32f87..1739138803 100644 --- a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.c +++ b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.c @@ -40,6 +40,35 @@ uint32_t bp6a_rtc_bin2bcd(uint8_t bin) return ((bin / 10u) << 4u) + (bin % 10); } +void bp6a_rtc_offset_write(uint32_t offset, uint32_t flag) +{ + uint8_t i; + + bp6a_rtc_unlock(true); + for (i = 0; i < 4; i++) + putreg32(0x40019000 + 0xB8 + i * 4, ((offset >> (i * 8)) & 0xFF)); + + putreg32(0x40019000 + 0x90, flag); + bp6a_rtc_unlock(false); +} + +uint32_t bp6a_rtc_read_offset(uint32_t *flag) +{ + uint8_t i; + uint32_t offset = 0; + + bp6a_rtc_unlock(true); + + for (i = 0; i < 4; i++) + offset |= getreg32(0x40019000 + 0xB8 + i * 4) << (i * 8); + + *flag = getreg32(0x40019000 + 0x90); + + bp6a_rtc_unlock(false); + + return offset; +} + void bp6a_rtc_getdatetime(struct rtc_bcd_s *rtc) { bp6a_rtc_unlock(true); diff --git a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.h b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.h index fcaed2db17..0a323af697 100644 --- a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.h +++ b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.h @@ -36,5 +36,6 @@ void bp6a_rtc_getdatetime(struct rtc_bcd_s *rtc); void bp6a_rtc_setdatetime(struct rtc_bcd_s *rtc); void bp6a_rtc_init(void); void bp6a_set_rtc_delay(uint32_t delay); - +uint32_t bp6a_rtc_read_offset(uint32_t *flag); +void bp6a_rtc_offset_write(uint32_t offset, uint32_t flag); #endif /*__S1SBP6A_RTC_H */ diff --git a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/rtc_api.c b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/rtc_api.c index 00f9beb629..823a52f3f9 100644 --- a/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/rtc_api.c +++ b/targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/rtc_api.c @@ -30,8 +30,10 @@ #include "mbed_debug.h" #define BP6A_RTC_START_TIME 946684800 +#define BP6A_MAX_REG 0x0FFFFFFF static bool rtc_initialized = false; static bool g_before2000 = false; +static time_t g_rtc_offset = 0; void rtc_init(void) { @@ -40,6 +42,7 @@ void rtc_init(void) bp6a_set_rtc_delay((uint32_t)((float)sys_clk * 2 / 32789)); bp6a_rtc_init(); + g_rtc_offset = bp6a_rtc_read_offset(&g_before2000); rtc_initialized = true; } } @@ -73,6 +76,8 @@ time_t rtc_read(void) return 0; } + t += g_rtc_offset; + if (g_before2000) { t -= BP6A_RTC_START_TIME; } @@ -84,6 +89,12 @@ void rtc_write(time_t t) struct rtc_bcd_s rtc_val; struct tm timeinfo; + if (t > BP6A_MAX_REG) { + g_rtc_offset = t; + t = 0; + } else + g_rtc_offset = 0; + /*BP6A : The implicit number of thousands place is 20.*/ if (t < BP6A_RTC_START_TIME) { g_before2000 = true; @@ -92,6 +103,7 @@ void rtc_write(time_t t) g_before2000 = false; } + bp6a_rtc_offset_write(g_rtc_offset, (uint32_t)g_before2000); if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) { return;