You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/06/18 20:14:01 UTC

[1/2] incubator-mynewt-core git commit: libs/os - add os_time_ms_to_ticks() function.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop b7fa20bbd -> 2f57efe25


libs/os - add os_time_ms_to_ticks() function.

/**
 * Converts milliseconds to OS ticks.
 *
 * @param ms                    The milliseconds input.
 * @param out_ticks             The OS ticks output.
 *
 * @return                      0 on success; OS_EINVAL if the result is too
 *                                  large to fit in a uint32_t.
 */


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/a5681c18
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/a5681c18
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/a5681c18

Branch: refs/heads/develop
Commit: a5681c18911515dc0f17f247786c2878095824cb
Parents: b7fa20b
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Jun 18 12:55:52 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Jun 18 12:59:33 2016 -0700

----------------------------------------------------------------------
 libs/os/include/os/os_time.h |  1 +
 libs/os/src/os_time.c        | 31 +++++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a5681c18/libs/os/include/os/os_time.h
----------------------------------------------------------------------
diff --git a/libs/os/include/os/os_time.h b/libs/os/include/os/os_time.h
index 215d74c..7e577eb 100644
--- a/libs/os/include/os/os_time.h
+++ b/libs/os/include/os/os_time.h
@@ -105,5 +105,6 @@ struct os_timezone {
 int os_settimeofday(struct os_timeval *utctime, struct os_timezone *tz);
 int os_gettimeofday(struct os_timeval *utctime, struct os_timezone *tz);
 int64_t os_get_uptime_usec(void);
+int os_time_ms_to_ticks(uint32_t ms, uint32_t *out_ticks);
 
 #endif /* _OS_TIME_H */

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/a5681c18/libs/os/src/os_time.c
----------------------------------------------------------------------
diff --git a/libs/os/src/os_time.c b/libs/os/src/os_time.c
index e401ff4..2ce379e 100644
--- a/libs/os/src/os_time.c
+++ b/libs/os/src/os_time.c
@@ -211,3 +211,34 @@ os_get_uptime_usec(void)
 
   return(tv.tv_sec * 1000000 + tv.tv_usec);
 }
+
+/**
+ * Converts milliseconds to OS ticks.
+ *
+ * @param ms                    The milliseconds input.
+ * @param out_ticks             The OS ticks output.
+ *
+ * @return                      0 on success; OS_EINVAL if the result is too
+ *                                  large to fit in a uint32_t.
+ */
+int
+os_time_ms_to_ticks(uint32_t ms, uint32_t *out_ticks)
+{
+    uint64_t ticks;
+
+#if OS_TICKS_PER_SEC == 1000
+    *out_ticks = ms;
+    return 0;
+#endif
+
+    _Static_assert(OS_TICKS_PER_SEC <= UINT32_MAX,
+                   "OS_TICKS_PER_SEC must be <= UINT32_MAX");
+
+    ticks = (uint64_t)ms * OS_TICKS_PER_SEC / 1000;
+    if (ticks > UINT32_MAX) {
+        return OS_EINVAL;
+    }
+
+    *out_ticks = ticks;
+    return 0;
+}


[2/2] incubator-mynewt-core git commit: BLE Host - Handle overflow in large scan duration.

Posted by cc...@apache.org.
BLE Host - Handle overflow in large scan duration.

Use the os_time_ms_to_ticks() function to convert the scan duration from
milliseconds to OS ticks.  This function uses a uint64_t for its
intermediate value, preventing overflow.  This fixes the bug where a
large scan duration resulted in a short scan operation.


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/2f57efe2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/2f57efe2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/2f57efe2

Branch: refs/heads/develop
Commit: 2f57efe25b20c7dc693e305d771dfce1c925c288
Parents: a5681c1
Author: Christopher Collins <cc...@apache.org>
Authored: Sat Jun 18 13:09:27 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Sat Jun 18 13:10:07 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_gap.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/2f57efe2/net/nimble/host/src/ble_gap.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gap.c b/net/nimble/host/src/ble_gap.c
index b83cc7e..ee924b0 100644
--- a/net/nimble/host/src/ble_gap.c
+++ b/net/nimble/host/src/ble_gap.c
@@ -102,7 +102,7 @@ static bssnz_t struct {
     uint8_t op;
 
     unsigned exp_set:1;
-    uint32_t exp_os_ticks;
+    os_time_t exp_os_ticks;
 
     union {
         struct {
@@ -531,10 +531,9 @@ ble_gap_update_notify(uint16_t conn_handle, int status)
 }
 
 static void
-ble_gap_master_set_timer(uint32_t ms_from_now)
+ble_gap_master_set_timer(uint32_t ticks_from_now)
 {
-    ble_gap_master.exp_os_ticks =
-        os_time_get() + ms_from_now * OS_TICKS_PER_SEC / 1000;
+    ble_gap_master.exp_os_ticks = os_time_get() + ticks_from_now;
     ble_gap_master.exp_set = 1;
 }
 
@@ -1662,6 +1661,7 @@ ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
     return BLE_HS_ENOTSUP;
 #endif
 
+    uint32_t duration_ticks;
     int rc;
 
     ble_hs_lock();
@@ -1704,6 +1704,13 @@ ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
         duration_ms = BLE_GAP_GEN_DISC_SCAN_MIN;
     }
 
+    rc = os_time_ms_to_ticks(duration_ms, &duration_ticks);
+    if (rc != 0) {
+        /* Duration too great. */
+        rc = BLE_HS_EINVAL;
+        goto done;
+    }
+
     ble_gap_master.disc.disc_mode = discovery_mode;
     ble_gap_master.disc.cb = cb;
     ble_gap_master.disc.cb_arg = cb_arg;
@@ -1726,7 +1733,7 @@ ble_gap_disc(uint32_t duration_ms, uint8_t discovery_mode,
         goto done;
     }
 
-    ble_gap_master_set_timer(duration_ms);
+    ble_gap_master_set_timer(duration_ticks);
     ble_gap_master.op = BLE_GAP_OP_M_DISC;
 
     rc = 0;