Skip to content

Commit 3239868

Browse files
authored
Merge pull request ARMmbed#13880 from heuisam/master
S1SBP6A fix RTC range
2 parents 65097e1 + eb32b25 commit 3239868

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-1
lines changed

targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,35 @@ uint32_t bp6a_rtc_bin2bcd(uint8_t bin)
4040
return ((bin / 10u) << 4u) + (bin % 10);
4141
}
4242

43+
void bp6a_rtc_offset_write(uint32_t offset, uint32_t flag)
44+
{
45+
uint8_t i;
46+
47+
bp6a_rtc_unlock(true);
48+
for (i = 0; i < 4; i++)
49+
putreg32(0x40019000 + 0xB8 + i * 4, ((offset >> (i * 8)) & 0xFF));
50+
51+
putreg32(0x40019000 + 0x90, flag);
52+
bp6a_rtc_unlock(false);
53+
}
54+
55+
uint32_t bp6a_rtc_read_offset(uint32_t *flag)
56+
{
57+
uint8_t i;
58+
uint32_t offset = 0;
59+
60+
bp6a_rtc_unlock(true);
61+
62+
for (i = 0; i < 4; i++)
63+
offset |= getreg32(0x40019000 + 0xB8 + i * 4) << (i * 8);
64+
65+
*flag = getreg32(0x40019000 + 0x90);
66+
67+
bp6a_rtc_unlock(false);
68+
69+
return offset;
70+
}
71+
4372
void bp6a_rtc_getdatetime(struct rtc_bcd_s *rtc)
4473
{
4574
bp6a_rtc_unlock(true);

targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/device/s1sbp6a_rtc.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ void bp6a_rtc_getdatetime(struct rtc_bcd_s *rtc);
3636
void bp6a_rtc_setdatetime(struct rtc_bcd_s *rtc);
3737
void bp6a_rtc_init(void);
3838
void bp6a_set_rtc_delay(uint32_t delay);
39-
39+
uint32_t bp6a_rtc_read_offset(uint32_t *flag);
40+
void bp6a_rtc_offset_write(uint32_t offset, uint32_t flag);
4041
#endif /*__S1SBP6A_RTC_H */

targets/TARGET_Samsung/TARGET_SIDK_S1SBP6A/rtc_api.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
#include "mbed_debug.h"
3131

3232
#define BP6A_RTC_START_TIME 946684800
33+
#define BP6A_MAX_REG 0x0FFFFFFF
3334
static bool rtc_initialized = false;
3435
static bool g_before2000 = false;
36+
static time_t g_rtc_offset = 0;
3537

3638
void rtc_init(void)
3739
{
@@ -40,6 +42,7 @@ void rtc_init(void)
4042

4143
bp6a_set_rtc_delay((uint32_t)((float)sys_clk * 2 / 32789));
4244
bp6a_rtc_init();
45+
g_rtc_offset = bp6a_rtc_read_offset(&g_before2000);
4346
rtc_initialized = true;
4447
}
4548
}
@@ -73,6 +76,8 @@ time_t rtc_read(void)
7376
return 0;
7477
}
7578

79+
t += g_rtc_offset;
80+
7681
if (g_before2000) {
7782
t -= BP6A_RTC_START_TIME;
7883
}
@@ -84,6 +89,12 @@ void rtc_write(time_t t)
8489
struct rtc_bcd_s rtc_val;
8590
struct tm timeinfo;
8691

92+
if (t > BP6A_MAX_REG) {
93+
g_rtc_offset = t;
94+
t = 0;
95+
} else
96+
g_rtc_offset = 0;
97+
8798
/*BP6A : The implicit number of thousands place is 20.*/
8899
if (t < BP6A_RTC_START_TIME) {
89100
g_before2000 = true;
@@ -92,6 +103,7 @@ void rtc_write(time_t t)
92103
g_before2000 = false;
93104
}
94105

106+
bp6a_rtc_offset_write(g_rtc_offset, (uint32_t)g_before2000);
95107

96108
if (_rtc_localtime(t, &timeinfo, RTC_4_YEAR_LEAP_YEAR_SUPPORT) == false) {
97109
return;

0 commit comments

Comments
 (0)