You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2019/12/11 21:54:20 UTC

[GitHub] [mynewt-core] kasjer commented on a change in pull request #2126: hw/mcu/nordic: Fix hal_timer firing too early

kasjer commented on a change in pull request #2126: hw/mcu/nordic: Fix hal_timer firing too early
URL: https://github.com/apache/mynewt-core/pull/2126#discussion_r356849942
 
 

 ##########
 File path: hw/mcu/nordic/nrf52xxx/src/hal_timer.c
 ##########
 @@ -165,14 +165,34 @@ nrf_timer_set_ocmp(struct nrf52_hal_timer *bsptimer, uint32_t expiry)
         delta_t = (int32_t)(expiry - temp);
 
         /*
-         * The nrf documentation states that you must set the output
-         * compare to 2 greater than the counter to guarantee an interrupt.
-         * Since the counter can tick once while we check, we make sure
-         * it is greater than 2.
+         * The nRF52xxx documentation states that COMPARE event is guaranteed
+         * only if value written to CC register is at least 2 greater than the
+         * current counter value. To guarantee that interrupt happens at the
+         * proper tick, we need to do some extra magic if expiry value delta is
+         * less than 3 (we include also +2 since counter can tick once while we
+         * check).
          */
-        if (delta_t < 3) {
+        if (delta_t < 1) {
+            /* We are past or exactly at expiry value, trigger interrupt now */
+            rtctimer->INTENCLR = RTC_INTENCLR_TICK_Msk;
             NVIC_SetPendingIRQ(bsptimer->tmr_irq_num);
-        } else  {
+        } else if (delta_t == 1) {
 
 Review comment:
   what about this:
   ```
           if (delta_t < 3) {
               rtctimer->INTENSET = RTC_INTENSET_TICK_Msk;
               /* Check if timer advanced, if so force interrupt in case line above was too late to enable tick */
               if (rtctimer->COUNTER != (temp & 0x00ffffff)) {
                   NVIC_SetPendingIRQ(bsptimer->tmr_irq_num);
               }
   ```
   Then in hal_timer_chk_queue() new logic with expired variable would not be needed I guess

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services