Skip to content

Commit e635613

Browse files
author
Cruz Monrreal
authored
Merge pull request #7849 from TacoGrandeTX/fix_rtc_settime
Low power timer needs to be reset when setting time
2 parents 3046e31 + 0de5ab2 commit e635613

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

TESTS/mbed_hal/rtc_time/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,41 @@ void test_local_time_invalid_param()
169169
TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT));
170170
}
171171

172+
/* Test set_time() function called a few seconds apart.
173+
*
174+
* Given is set_time() function.
175+
* When set_time() is used to set the system time two times.
176+
* Then if the value returned from time() is always correct return true, otherwise return false.
177+
*/
178+
#define NEW_TIME 15
179+
void test_set_time_twice()
180+
{
181+
time_t current_time;
182+
183+
/* Set the time to NEW_TIME and check it */
184+
set_time(NEW_TIME);
185+
current_time = time(NULL);
186+
TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME));
187+
188+
/* Wait 2 seconds */
189+
wait_ms(2000);
190+
191+
/* set the time to NEW_TIME again and check it */
192+
set_time(NEW_TIME);
193+
current_time = time(NULL);
194+
TEST_ASSERT_EQUAL (true, (current_time == NEW_TIME));
195+
}
196+
172197
Case cases[] = {
173198
Case("test is leap year - RTC leap years full support", test_is_leap_year<RTC_FULL_LEAP_YEAR_SUPPORT>),
174199
Case("test is leap year - RTC leap years partial support", test_is_leap_year<RTC_4_YEAR_LEAP_YEAR_SUPPORT>),
175200
Case("test make time boundary values - RTC leap years full support", test_mk_time_boundary<RTC_FULL_LEAP_YEAR_SUPPORT>),
176201
Case("test make time boundary values - RTC leap years partial support", test_mk_time_boundary<RTC_4_YEAR_LEAP_YEAR_SUPPORT>),
177202
Case("test make time - invalid param", test_mk_time_invalid_param),
178203
Case("test local time - invalid param", test_local_time_invalid_param),
204+
#if DEVICE_RTC || DEVICE_LPTICKER
205+
Case("test set_time twice", test_set_time_twice),
206+
#endif
179207
};
180208

181209
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

platform/mbed_rtc_time.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ static time_t _rtc_lpticker_read(void)
5757

5858
static void _rtc_lpticker_write(time_t t)
5959
{
60+
_rtc_lp_timer->reset();
6061
_rtc_lp_base = t;
6162
}
6263

0 commit comments

Comments
 (0)