Skip to content

Commit 4a184d9

Browse files
committed
Made attach_rtc with disabled irqs
1 parent f0d04f5 commit 4a184d9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

libraries/mbed/api/rtc_time.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ extern "C" {
7070
void set_time(time_t t);
7171

7272
/** Attach an external RTC to be used for the C time functions
73+
*
74+
* Do not call this function from an interrupt while an RTC read/write operation may be occurring
7375
*
7476
* @param read_rtc pointer to function which returns current UNIX timestamp
7577
* @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL

libraries/mbed/common/rtc_time.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ time_t time(time_t *timer)
4747
}
4848
}
4949

50-
time_t t;
50+
time_t t = 0;
5151
if (_rtc_read != NULL) {
5252
t = _rtc_read();
53-
} else {
54-
t = 0;
5553
}
5654

5755
if (timer != NULL) {
@@ -76,10 +74,12 @@ clock_t clock() {
7674
}
7775

7876
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
77+
__disable_irq();
7978
_rtc_read = read_rtc;
8079
_rtc_write = write_rtc;
8180
_rtc_init = init_rtc;
8281
_rtc_isenabled = isenabled_rtc;
82+
__enable_irq();
8383
}
8484

8585

0 commit comments

Comments
 (0)