You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2017/03/20 16:38:55 UTC

incubator-mynewt-core git commit: Un-tested but I think the changes are complete.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/nrf_cputime 6db66772c -> 82f7fb15d


Un-tested but I think the changes are complete.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/82f7fb15
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/82f7fb15
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/82f7fb15

Branch: refs/heads/nrf_cputime
Commit: 82f7fb15d004676dedb2ce9ab9aba49259bc9f5f
Parents: 6db6677
Author: William San Filippo <wi...@runtime.io>
Authored: Mon Mar 20 09:38:23 2017 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Mon Mar 20 09:38:23 2017 -0700

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll.h      |   5 -
 .../controller/include/controller/ble_ll_xcvr.h |   2 +-
 net/nimble/controller/src/ble_ll_scan.c         |   4 +-
 net/nimble/controller/src/ble_ll_sched.c        |  30 +++---
 net/nimble/controller/src/ble_ll_xcvr.c         | 108 +++++++------------
 5 files changed, 57 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82f7fb15/net/nimble/controller/include/controller/ble_ll.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll.h b/net/nimble/controller/include/controller/ble_ll.h
index cdb170f..9319c55 100644
--- a/net/nimble/controller/include/controller/ble_ll.h
+++ b/net/nimble/controller/include/controller/ble_ll.h
@@ -395,11 +395,6 @@ int ble_ll_rand_data_get(uint8_t *buf, uint8_t len);
 void ble_ll_rand_prand_get(uint8_t *prand);
 int ble_ll_rand_start(void);
 
-/* Clock management */
-#ifdef BLE_XCVR_RFCLK
-void ble_ll_rfclk_start(uint32_t cputime);
-#endif
-
 /*
  * XXX: temporary LL debug log. Will get removed once we transition to real
  * log

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82f7fb15/net/nimble/controller/include/controller/ble_ll_xcvr.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_xcvr.h b/net/nimble/controller/include/controller/ble_ll_xcvr.h
index 0ede701..c59b009 100644
--- a/net/nimble/controller/include/controller/ble_ll_xcvr.h
+++ b/net/nimble/controller/include/controller/ble_ll_xcvr.h
@@ -32,13 +32,13 @@ extern "C" {
 #define BLE_RFCLK_STATE_SETTLED (2)
 
 int ble_ll_xcvr_rfclk_state(void);
-void ble_ll_xcvr_rfclk_start(uint32_t cputime);
 void ble_ll_xcvr_rfclk_start_now(uint32_t now);
 void ble_ll_xcvr_rfclk_stop(void);
 void ble_ll_xcvr_rfclk_enable(void);
 void ble_ll_xcvr_rfclk_disable(void);
 uint32_t ble_ll_xcvr_rfclk_time_till_settled(void);
 void ble_ll_xcvr_rfclk_timer_exp(void *arg);
+void ble_ll_xcvr_rfclk_timer_start(uint32_t cputime);
 #endif
 
 #ifdef __cplusplus

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82f7fb15/net/nimble/controller/src/ble_ll_scan.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_scan.c b/net/nimble/controller/src/ble_ll_scan.c
index 5b81219..f5eca7f 100644
--- a/net/nimble/controller/src/ble_ll_scan.c
+++ b/net/nimble/controller/src/ble_ll_scan.c
@@ -930,14 +930,12 @@ ble_ll_scan_event_proc(struct os_event *ev)
                 }
             }
 
-            /* WWW: This should just be an enable. No need to start
-               cputimer here! */
             /*
              * If clock off, start clock. Set next event time to now plus
              * the clock setting time.
              */
             if (rxstate == BLE_RFCLK_STATE_OFF) {
-                ble_ll_xcvr_rfclk_start(now);
+                ble_ll_xcvr_rfclk_start_now(now);
             }
             next_event_time = now + xtal_ticks;
             goto rfclk_not_settled;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82f7fb15/net/nimble/controller/src/ble_ll_sched.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_sched.c b/net/nimble/controller/src/ble_ll_sched.c
index b5109dd..ffe8ef3 100644
--- a/net/nimble/controller/src/ble_ll_sched.c
+++ b/net/nimble/controller/src/ble_ll_sched.c
@@ -262,7 +262,7 @@ ble_ll_sched_conn_reschedule(struct ble_ll_conn_sm *connsm)
 #ifdef BLE_XCVR_RFCLK
     entry = TAILQ_FIRST(&g_ble_ll_sched_q);
     if (entry == sch) {
-        ble_ll_rfclk_start(sch->start_time);
+        ble_ll_xcvr_rfclk_timer_start(sch->start_time);
     } else {
         sch = entry;
     }
@@ -572,7 +572,7 @@ ble_ll_sched_slave_new(struct ble_ll_conn_sm *connsm)
 
 #ifdef BLE_XCVR_RFCLK
     if (first) {
-        ble_ll_rfclk_start(sch->start_time);
+        ble_ll_xcvr_rfclk_timer_start(sch->start_time);
     }
 #endif
 
@@ -639,7 +639,7 @@ ble_ll_sched_adv_new(struct ble_ll_sched_item *sch)
 
 #ifdef BLE_XCVR_RFCLK
     if (orig == sch) {
-        ble_ll_rfclk_start(sch->start_time);
+        ble_ll_xcvr_rfclk_timer_start(sch->start_time);
     }
 #endif
 
@@ -764,7 +764,7 @@ ble_ll_sched_adv_reschedule(struct ble_ll_sched_item *sch, uint32_t *start,
 
 #ifdef BLE_XCVR_RFCLK
         if (sch == TAILQ_FIRST(&g_ble_ll_sched_q)) {
-            ble_ll_rfclk_start(sch->start_time);
+            ble_ll_xcvr_rfclk_timer_start(sch->start_time);
         }
 #endif
     }
@@ -959,6 +959,15 @@ ble_ll_sched_next_time(uint32_t *next_event_time)
 }
 
 #ifdef BLE_XCVR_RFCLK
+/**
+ * Checks to see if we need to restart the cputime timer which starts the
+ * rf clock settling.
+ *
+ * NOTE: Should only be called from the Link Layer task!
+ *
+ * Context: Link-Layer task.
+ *
+ */
 void
 ble_ll_sched_rfclk_chk_restart(void)
 {
@@ -974,26 +983,19 @@ ble_ll_sched_rfclk_chk_restart(void)
     if (ble_ll_sched_next_time(&next_time)) {
         /*
          * If the time until the next event is too close, no need to start
-         * the timer and leave the clock on
+         * the timer. Leave clock on.
          */
         time_till_next = (int32_t)(next_time - os_cputime_get32());
         if (time_till_next > g_ble_ll_data.ll_xtal_ticks) {
             /* Stop the clock */
             stop = 1;
-
-            /*
-             * Restart the timer as long as not advertising or in connection
-             * event
-             */
-            if (!((ll_state == BLE_LL_STATE_ADV) ||
-                  (ll_state == BLE_LL_STATE_CONNECTION))) {
-                ble_ll_xcvr_rfclk_start(next_time - g_ble_ll_data.ll_xtal_ticks);
-            }
+            ble_ll_xcvr_rfclk_timer_start(next_time);
         }
     } else {
         stop = 1;
     }
 
+    /* Only disable the rfclk if doing nothing */
     if (stop && (ll_state == BLE_LL_STATE_STANDBY)) {
         ble_ll_log(BLE_LL_LOG_ID_RFCLK_SCHED_DIS, g_ble_ll_data.ll_rfclk_state,
                    0, 0);

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/82f7fb15/net/nimble/controller/src/ble_ll_xcvr.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_xcvr.c b/net/nimble/controller/src/ble_ll_xcvr.c
index 43a2e49..50ab32e 100644
--- a/net/nimble/controller/src/ble_ll_xcvr.c
+++ b/net/nimble/controller/src/ble_ll_xcvr.c
@@ -25,26 +25,6 @@
 #include "controller/ble_ll.h"
 #include "controller/ble_ll_xcvr.h"
 
-#if 0
-#include <string.h>
-#include "sysinit/sysinit.h"
-#include "os/os.h"
-#include "stats/stats.h"
-#include "bsp/bsp.h"
-#include "nimble/ble.h"
-#include "nimble/nimble_opt.h"
-#include "nimble/hci_common.h"
-#include "nimble/ble_hci_trans.h"
-#include "controller/ble_hw.h"
-#include "controller/ble_ll_adv.h"
-#include "controller/ble_ll_sched.h"
-#include "controller/ble_ll_scan.h"
-#include "controller/ble_ll_hci.h"
-#include "controller/ble_ll_whitelist.h"
-#include "controller/ble_ll_resolv.h"
-#include "ble_ll_conn_priv.h"
-#endif
-
 #ifdef BLE_XCVR_RFCLK
 int
 ble_ll_xcvr_rfclk_state(void)
@@ -61,39 +41,6 @@ ble_ll_xcvr_rfclk_state(void)
     return g_ble_ll_data.ll_rfclk_state;
 }
 
-/**
- * Start the rf clock timer running at the specified cputime. The cputime
- * is when the clock should start; it will be settled after xtal ticks have
- * expired.
- *
- * If the clock is ON or SETTLED there is no need to start the timer. If the
- * clock is OFF the timer might be set for some time in the future. If it is,
- * we will reset the time if 'cputime' is earlier than the expiry time.
- *
- * @param cputime
- */
-void
-ble_ll_xcvr_rfclk_start(uint32_t cputime)
-{
-    if (g_ble_ll_data.ll_rfclk_state == BLE_RFCLK_STATE_OFF) {
-
-        /*
-         * If the timer is on the list, we need to see if its expiry is before
-         * 'cputime'. If the expiry is before, no need to do anything. If it
-         * is after, we need to stop the timer and start at new time.
-         */
-        if (g_ble_ll_data.ll_rfclk_timer.link.tqe_prev != NULL) {
-            if ((int32_t)(cputime - g_ble_ll_data.ll_rfclk_timer.expiry) >= 0) {
-                return;
-            }
-            os_cputime_timer_stop(&g_ble_ll_data.ll_rfclk_timer);
-        }
-        os_cputime_timer_start(&g_ble_ll_data.ll_rfclk_timer, cputime);
-        ble_ll_log(BLE_LL_LOG_ID_RFCLK_START, g_ble_ll_data.ll_rfclk_state, 0,
-                   g_ble_ll_data.ll_rfclk_timer.expiry);
-    }
-}
-
 void
 ble_ll_xcvr_rfclk_enable(void)
 {
@@ -135,7 +82,9 @@ ble_ll_xcvr_rfclk_time_till_settled(void)
 }
 
 /**
- * Called when the timer to turn on the RF CLOCK expires
+ * Called when the timer to turn on the RF CLOCK expires. This function checks
+ * the state of the clock. If the clock is off, the clock is turned on.
+ * Otherwise, we just exit.
  *
  * Context: Interrupt
  *
@@ -145,16 +94,15 @@ void
 ble_ll_xcvr_rfclk_timer_exp(void *arg)
 {
     if (g_ble_ll_data.ll_rfclk_state == BLE_RFCLK_STATE_OFF) {
-        ble_ll_xcvr_rfclk_enable();
-        g_ble_ll_data.ll_rfclk_start_time = g_ble_ll_data.ll_rfclk_timer.expiry;
-        ble_ll_log(BLE_LL_LOG_ID_RFCLK_ENABLE, g_ble_ll_data.ll_rfclk_state, 0,
-                   g_ble_ll_data.ll_rfclk_start_time);
+        ble_ll_xcvr_rfclk_start_now(os_cputime_get32());
     }
 }
 
 /**
- * This API is used to turn on the rfclock without setting the cputimer timer
- * to start the clock at some later point.
+ * This API is used to turn on the rfclock without setting the cputime timer to
+ * start the clock at some later point.
+ *
+ * NOTE: presumes that the state of the rf clock was checked prior to calling.
  *
  * @param now
  */
@@ -163,21 +111,43 @@ ble_ll_xcvr_rfclk_start_now(uint32_t now)
 {
     ble_ll_xcvr_rfclk_enable();
     g_ble_ll_data.ll_rfclk_start_time = now;
-    ble_ll_log(BLE_LL_LOG_ID_RFCLK_ENABLE, g_ble_ll_data.ll_rfclk_state, 0,
-               g_ble_ll_data.ll_rfclk_start_time);
+    ble_ll_log(BLE_LL_LOG_ID_RFCLK_ENABLE, 0, 0, now);
 }
 
-/* WWW: This is really confusing. This is called when we add something
- * to schedule at the start. We want to stop the current cputime timer
- * for the clock and restart it at the new time.
+/**
+ * Starts the timer that will turn the rf clock on. The 'cputime' is
+ * the time at which the clock needs to be settled.
  *
+ * @param cputime   Time at which rfclock should be on and settled.
  */
 void
-ble_ll_rfclk_start(uint32_t cputime)
+ble_ll_xcvr_rfclk_timer_start(uint32_t cputime)
 {
-    /* If we are currently doing something, no need to start the clock */
-    if (g_ble_ll_data.ll_state == BLE_LL_STATE_STANDBY) {
-        ble_ll_xcvr_rfclk_start(cputime - g_ble_ll_data.ll_xtal_ticks);
+    /*
+     * If we are currently in an advertising event or a connection event,
+     * no need to start the cputime timer
+     */
+    if ((g_ble_ll_data.ll_state == BLE_LL_STATE_ADV) ||
+        (g_ble_ll_data.ll_state == BLE_LL_STATE_CONNECTION)) {
+        return;
+    }
+
+    /* Account for the settling time */
+    cputime -= g_ble_ll_data.ll_xtal_ticks;
+
+    /*
+     * If the timer is on the list, we need to see if its expiry is before
+     * 'cputime'. If the expiry is before, no need to do anything. If it
+     * is after, we need to stop the timer and start at new time.
+     */
+    if (g_ble_ll_data.ll_rfclk_timer.link.tqe_prev != NULL) {
+        if ((int32_t)(cputime - g_ble_ll_data.ll_rfclk_timer.expiry) >= 0) {
+            return;
+        }
+        os_cputime_timer_stop(&g_ble_ll_data.ll_rfclk_timer);
     }
+    os_cputime_timer_start(&g_ble_ll_data.ll_rfclk_timer, cputime);
+    ble_ll_log(BLE_LL_LOG_ID_RFCLK_START, g_ble_ll_data.ll_rfclk_state, 0,
+               g_ble_ll_data.ll_rfclk_timer.expiry);
 }
 #endif