[riot-notifications] [RIOT-OS/RIOT] drivers/ds3231: add alarm support (#16180)

benpicco notifications at github.com
Tue Apr 6 13:38:28 CEST 2021


@benpicco commented on this pull request.



> @@ -236,6 +257,158 @@ int ds3231_set_time(const ds3231_t *dev, const struct tm *time)
     return 0;
 }
 
+#if IS_USED(MODULE_DS3231_INT)
+int ds3231_await_alarm(ds3231_t *dev)
+{
+    mutex_t mutex = MUTEX_INIT_LOCKED;
+
+    assert(dev != NULL);
+    assert(gpio_is_valid(dev->int_pin));
+
+    if (gpio_init_int(dev->int_pin, GPIO_IN, GPIO_FALLING, _unlock, &mutex) < 0) {
+            return -EIO;
+    }
+
+    /* wait for alarm */
+    mutex_lock(&mutex);
+

You should also cal `gpio_irq_disable` here, otherwise if the interrupt happens a second time (when outside this function) `&mutex` will point to random stack memory. 

-- 
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/16180#pullrequestreview-628867923
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20210406/c113fb7e/attachment.htm>


More information about the notifications mailing list