mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject [2/2] incubator-mynewt-larva git commit: Fix issues with starting a timer that has already been set. Assert if that happens
Date Thu, 03 Dec 2015 23:36:03 GMT
Fix issues with starting a timer that has already been set. Assert if that happens


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/165affba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/165affba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/165affba

Branch: refs/heads/master
Commit: 165affbad1018bd553372d31d69d5cbb9a2ae54a
Parents: bf65252
Author: wes3 <will@micosa.io>
Authored: Thu Dec 3 15:19:13 2015 -0800
Committer: wes3 <will@micosa.io>
Committed: Thu Dec 3 15:35:50 2015 -0800

----------------------------------------------------------------------
 hw/mcu/nordic/nrf52xxx/src/hal_cputime.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/165affba/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
----------------------------------------------------------------------
diff --git a/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c b/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
index fa56939..6f43740 100644
--- a/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
+++ b/hw/mcu/nordic/nrf52xxx/src/hal_cputime.c
@@ -110,6 +110,7 @@ cputime_chk_expiration(void)
     while ((timer = TAILQ_FIRST(&g_cputimer_q)) != NULL) {
         if ((int32_t)(cputime_get32() - timer->cputime) >= 0) {
             TAILQ_REMOVE(&g_cputimer_q, timer, link);
+            timer->link.tqe_prev = NULL;
             timer->cb(timer->arg);
         } else {
             break;
@@ -474,6 +475,7 @@ cputime_timer_init(struct cpu_timer *timer, cputimer_func fp, void *arg)
  *  
  * Start a cputimer that will expire at 'cputime'. If cputime has already 
  * passed, the timer callback will still be called (at interrupt context). 
+ * Cannot be called when the timer has already started. 
  * 
  * @param timer     Pointer to timer to start. Cannot be NULL.
  * @param cputime   The cputime at which the timer should expire.
@@ -485,6 +487,7 @@ cputime_timer_start(struct cpu_timer *timer, uint32_t cputime)
     uint32_t ctx;
 
     assert(timer != NULL);
+    assert(timer->link.tqe_prev == NULL);
 
     /* XXX: should this use a mutex? not sure... */
     __HAL_DISABLE_INTERRUPTS(ctx);
@@ -537,7 +540,7 @@ cputime_timer_relative(struct cpu_timer *timer, uint32_t usecs)
  *  
  * Stops a cputimer from running. The timer is removed from the timer queue 
  * and interrupts are disabled if no timers are left on the queue. Can be 
- * called even if timer is running. 
+ * called even if timer is not running. 
  * 
  * @param timer Pointer to cputimer to stop. Cannot be NULL.
  */
@@ -552,14 +555,15 @@ cputime_timer_stop(struct cpu_timer *timer)
 
     __HAL_DISABLE_INTERRUPTS(ctx);
 
-    /* If first on queue, we will need to reset OCMP */
     if (timer->link.tqe_prev != NULL) {
         reset_ocmp = 0;
         if (timer == TAILQ_FIRST(&g_cputimer_q)) {
+            /* If first on queue, we will need to reset OCMP */
             entry = TAILQ_NEXT(timer, link);
             reset_ocmp = 1;
         }
         TAILQ_REMOVE(&g_cputimer_q, timer, link);
+        timer->link.tqe_prev = NULL;
         if (reset_ocmp) {
             if (entry) {
                 cputime_set_ocmp(entry);


Mime
View raw message