mbed library sources

Dependents:   STM32F103C8T6-RangoTec STM32-103C8_Plantilla_USB

Revision:
441:8a0b45cd594f
Parent:
304:89b9c3a9a045
--- a/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/app_common/app_timer.c	Mon Dec 15 09:30:07 2014 +0000
+++ b/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/app_common/app_timer.c	Tue Dec 16 08:15:08 2014 +0000
@@ -135,6 +135,7 @@
 static uint8_t                       m_ticks_elapsed_q_write_ind;               /**< Timer internal elapsed ticks queue write index. */
 static app_timer_evt_schedule_func_t m_evt_schedule_func;                       /**< Pointer to function for propagating timeout events to the scheduler. */
 static bool                          m_rtc1_running;                            /**< Boolean indicating if RTC1 is running. */
+static bool                          m_rtc1_reset;                              /**< Boolean indicating if RTC1 counter has been reset due to last timer removed from timer list during the timer list handling. */
 static volatile uint64_t             overflowBits;                              /**< The upper 40 bits of the 64-bit value returned by cnt_get() */
 
 
@@ -311,10 +312,12 @@
     {
         m_timer_id_head = mp_nodes[m_timer_id_head].next;
 
-        // No more timers in the list. Disable RTC1.
+        // No more timers in the list. Reset RTC1 in case Start timer operations are present in the queue.
         if (m_timer_id_head == TIMER_NULL)
         {
-            rtc1_stop();
+            NRF_RTC1->TASKS_CLEAR = 1;
+            m_ticks_latest        = 0;
+            m_rtc1_reset          = true;
         }
     }
 
@@ -640,9 +643,14 @@
                 p_timer->ticks_first_interval    = p_user_op->params.start.ticks_first_interval;
                 p_timer->ticks_periodic_interval = p_user_op->params.start.ticks_periodic_interval;
                 p_timer->p_context               = p_user_op->params.start.p_context;
+
+                if (m_rtc1_reset)
+                {
+                    p_timer->ticks_at_start = 0;
+                }
             }
 
-            // Prepare the node to be inserted
+            // Prepare the node to be inserted.
             if (
                  ((p_timer->ticks_at_start - m_ticks_latest) & MAX_RTC_COUNTER_VAL)
                  <
@@ -763,6 +771,7 @@
     {
         compare_reg_update(timer_id_head_old);
     }
+    m_rtc1_reset = false;
 }