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

Josar notifications at github.com
Fri Apr 26 22:03:51 CEST 2019

Josar 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))));

I´m quite sure that `TOV2` will ever be 0. But i might be wrong.

Bit 0 – TOV: Timer/Counter2, Overflow Flag
The TOV bit is set (one) when an overflow occurs in Timer/Counter2. TOV is cleared by hardware when
executing the corresponding interrupt handling vector.
As the interrupt is enabled `TOV2` will be cleared. Polling it only is usefull when no `IRQ routine` is used, imho. 
Maybe handling like in xtimer would be an idea.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190426/f5611530/attachment-0001.html>

More information about the notifications mailing list