[riot-notifications] [RIOT-OS/RIOT] cpu: RTC implementation for STM32F1 (#11258)

Marian Buschsieweke notifications at github.com
Tue Apr 9 10:55:07 CEST 2019


maribu commented on this pull request.



> +    if (is_rtc_enable) {
+        cur_time = _rtc_get_time();
+    }
+
+    /* config RTC */
+    _rtc_config();
+
+    /* restore current time after config */
+    if (is_rtc_enable) {
+        _rtc_set_time(cur_time);
+    }
+}
+
+int rtc_set_time(struct tm *time)
+{
+    time_t timestamp = mktime(time);

`mktime()` returns `(time_t) -1` on error. In that case `rtc_set_time()` should return `-1` according to the API doc.

> +}
+
+int rtc_set_alarm(struct tm *time, rtc_alarm_cb_t cb, void *arg)
+{
+    /* enable global RTC interrupt */
+    if (cb && !NVIC_GetEnableIRQ(RTC_IRQn)) {
+        NVIC_EnableIRQ(RTC_IRQn);
+        DEBUG("%s enable RTC IRQ\n", __func__);
+    }
+
+    /* save callback and argument */
+    isr_ctx.cb = cb;
+    isr_ctx.arg = arg;
+
+    /* set wakeup time */
+    time_t timestamp = mktime(time);

`mktime()` returns `(time_t) -1` on error. In that case `rtc_set_alarm()` should return `-2` according to the API doc.

Btw: I'm personally would favor to always check the arguments for being plausible (e.g. `time` and `cb` should not be `NULL`, `time` should be in the future).

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11258#pullrequestreview-224266575
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190409/4f1e722d/attachment.html>


More information about the notifications mailing list