[riot-notifications] [RIOT-OS/RIOT] cpu/atmega_common: RTT and RTC support (#8842)

ZetaR60 notifications at github.com
Wed May 1 18:31:13 CEST 2019


ZetaR60 commented on this pull request.



> +/* This safely reads time_cnt and TCNT2, since an atomic read cannot be provided.
+ * Note: still requires prior synch using _asynch_wait() */
+static inline time_t _safe_time_get(void)
+{
+    time_t time_tmp;
+    uint8_t irq_flag, cnt_tmp;
+
+    do {
+        /* Operations must occur in this order: */
+        irq_flag = TIFR2 & (1 << TOV2);
+        time_tmp = time_cnt;
+        cnt_tmp = TCNT2;
+
+    /* Detect rollover after time_tmp read. If condition is met, then rollover
+     * just occured, and it is safe to read again now. */
+    } while ((time_tmp != time_cnt) || (irq_flag != (TIFR2 & (1 << TOV2))));

`TOV2` is checked in case interrupts are disabled. These two checks are not really polls, because the condition is only expected to occur zero or one times. It is just more space efficient than using `if`, since the compiler is not allowed to optimize this due to volatile.

-- 
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/8842#discussion_r280128174
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190501/8de32451/attachment.html>


More information about the notifications mailing list