Last active
February 11, 2016 22:50
-
-
Save adzenith/f829e943e0193381ef93 to your computer and use it in GitHub Desktop.
Patch for app_timer.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git i/nordic_sdk/libraries/timer/app_timer.c w/nordic_sdk/libraries/timer/app_timer.c | |
index 9dfcd284..e641c779 100755 | |
--- i/nordic_sdk/libraries/timer/app_timer.c | |
+++ w/nordic_sdk/libraries/timer/app_timer.c | |
@@ -368,6 +368,7 @@ static void timer_timeouts_check(void) | |
{ | |
timer_node_t * p_timer; | |
timer_node_t * p_previous_timer; | |
+ uint32_t total_ticks_elapsed; | |
uint32_t ticks_elapsed; | |
uint32_t ticks_expired; | |
@@ -375,7 +376,8 @@ static void timer_timeouts_check(void) | |
ticks_expired = 0; | |
// ticks_elapsed is collected here, job will use it. | |
- ticks_elapsed = ticks_diff_get(rtc1_counter_get(), m_ticks_latest); | |
+ total_ticks_elapsed = ticks_diff_get(rtc1_counter_get(), m_ticks_latest); | |
+ ticks_elapsed = total_ticks_elapsed; | |
// Auto variable containing the head of timers expiring. | |
p_timer = mp_timer_id_head; | |
@@ -422,7 +424,7 @@ static void timer_timeouts_check(void) | |
} | |
// Queue the ticks expired. | |
- m_ticks_elapsed[m_ticks_elapsed_q_write_ind] = ticks_expired; | |
+ m_ticks_elapsed[m_ticks_elapsed_q_write_ind] = total_ticks_elapsed; | |
timer_list_handler_sched(); | |
} | |
@@ -432,10 +434,8 @@ static void timer_timeouts_check(void) | |
/**@brief Function for acquiring the number of ticks elapsed. | |
* | |
* @param[out] p_ticks_elapsed Number of ticks elapsed. | |
- * | |
- * @return TRUE if elapsed ticks was read from queue, FALSE otherwise. | |
*/ | |
-static bool elapsed_ticks_acquire(uint32_t * p_ticks_elapsed) | |
+static void elapsed_ticks_acquire(uint32_t * p_ticks_elapsed) | |
{ | |
// Pick the elapsed value from queue. | |
if (m_ticks_elapsed_q_read_ind != m_ticks_elapsed_q_write_ind) | |
@@ -448,18 +448,17 @@ static bool elapsed_ticks_acquire(uint32_t * p_ticks_elapsed) | |
} | |
*p_ticks_elapsed = m_ticks_elapsed[m_ticks_elapsed_q_read_ind]; | |
- | |
- m_ticks_latest += *p_ticks_elapsed; | |
- m_ticks_latest &= MAX_RTC_COUNTER_VAL; | |
- | |
- return true; | |
+ m_ticks_elapsed[m_ticks_elapsed_q_read_ind] = 0; | |
} | |
else | |
{ | |
- // No elapsed value in queue. | |
- *p_ticks_elapsed = 0; | |
- return false; | |
+ // No elapsed value in queue. Make sure that the elapsed count is up to date even if nothing | |
+ // has expired in a while. | |
+ *p_ticks_elapsed = ticks_diff_get(rtc1_counter_get(), m_ticks_latest); | |
} | |
+ | |
+ m_ticks_latest += *p_ticks_elapsed; | |
+ m_ticks_latest &= MAX_RTC_COUNTER_VAL; | |
} | |
@@ -527,13 +526,19 @@ static bool list_deletions_handler(void) | |
* @param[in] ticks_elapsed Number of elapsed ticks. | |
* @param[in] ticks_previous Previous known value of the RTC counter. | |
* @param[out] p_restart_list_head List of repeating timers to be restarted. | |
+ * | |
+ * @return TRUE if Capture Compare register must be updated, FALSE otherwise. | |
*/ | |
-static void expired_timers_handler(uint32_t ticks_elapsed, | |
+static bool expired_timers_handler(uint32_t ticks_elapsed, | |
uint32_t ticks_previous, | |
timer_node_t ** p_restart_list_head) | |
{ | |
+ timer_node_t * p_timer_id_old_head; | |
uint32_t ticks_expired = 0; | |
+ // Remember the old head, so as to decide if new compare needs to be set. | |
+ p_timer_id_old_head = mp_timer_id_head; | |
+ | |
while (mp_timer_id_head != NULL) | |
{ | |
timer_node_t * p_timer; | |
@@ -569,6 +574,8 @@ static void expired_timers_handler(uint32_t ticks_elapsed, | |
*p_restart_list_head = p_timer_expired; | |
} | |
} | |
+ | |
+ return (mp_timer_id_head != p_timer_id_old_head); | |
} | |
@@ -725,7 +732,6 @@ static void timer_list_handler(void) | |
uint32_t ticks_elapsed; | |
uint32_t ticks_previous; | |
- bool ticks_have_elapsed; | |
bool compare_update; | |
timer_node_t * p_timer_id_head_old; | |
@@ -734,15 +740,14 @@ static void timer_list_handler(void) | |
p_timer_id_head_old = mp_timer_id_head; | |
// Get number of elapsed ticks | |
- ticks_have_elapsed = elapsed_ticks_acquire(&ticks_elapsed); | |
+ elapsed_ticks_acquire(&ticks_elapsed); | |
// Handle list deletions | |
compare_update = list_deletions_handler(); | |
// Handle expired timers | |
- if (ticks_have_elapsed) | |
+ if (expired_timers_handler(ticks_elapsed, ticks_previous, &p_restart_list_head)) | |
{ | |
- expired_timers_handler(ticks_elapsed, ticks_previous, &p_restart_list_head); | |
compare_update = true; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment