From 4a184d980e8d670adadd2ae4801f2f8a34988002 Mon Sep 17 00:00:00 2001 From: Sissors Date: Sat, 28 Feb 2015 12:21:55 +0100 Subject: [PATCH] Made attach_rtc with disabled irqs --- libraries/mbed/api/rtc_time.h | 2 ++ libraries/mbed/common/rtc_time.c | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/mbed/api/rtc_time.h b/libraries/mbed/api/rtc_time.h index f82f4977df..565897366e 100644 --- a/libraries/mbed/api/rtc_time.h +++ b/libraries/mbed/api/rtc_time.h @@ -70,6 +70,8 @@ extern "C" { void set_time(time_t t); /** Attach an external RTC to be used for the C time functions + * + * Do not call this function from an interrupt while an RTC read/write operation may be occurring * * @param read_rtc pointer to function which returns current UNIX timestamp * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL diff --git a/libraries/mbed/common/rtc_time.c b/libraries/mbed/common/rtc_time.c index d6754c5d80..9822797469 100644 --- a/libraries/mbed/common/rtc_time.c +++ b/libraries/mbed/common/rtc_time.c @@ -47,11 +47,9 @@ time_t time(time_t *timer) } } - time_t t; + time_t t = 0; if (_rtc_read != NULL) { t = _rtc_read(); - } else { - t = 0; } if (timer != NULL) { @@ -76,10 +74,12 @@ clock_t clock() { } void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) { + __disable_irq(); _rtc_read = read_rtc; _rtc_write = write_rtc; _rtc_init = init_rtc; _rtc_isenabled = isenabled_rtc; + __enable_irq(); }