You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/04/26 08:37:25 UTC

[GitHub] andrzej-kaczmarek closed pull request #61: nimble/host: Change timeouts defs to ms instead of ticks

andrzej-kaczmarek closed pull request #61: nimble/host: Change timeouts defs to ms instead of ticks
URL: https://github.com/apache/mynewt-nimble/pull/61
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/mesh/src/adv.c b/nimble/host/mesh/src/adv.c
index f75dcb49..0b84bae1 100644
--- a/nimble/host/mesh/src/adv.c
+++ b/nimble/host/mesh/src/adv.c
@@ -159,7 +159,7 @@ adv_thread(void *args)
 
 			// FIXME: should we redefine K_SECONDS macro instead in glue?
 			if (timeout != K_FOREVER) {
-				timeout = OS_TICKS_PER_SEC * timeout / 1000;
+				timeout = os_time_ms_to_ticks32(timeout);
 			}
 
 			ev = os_eventq_poll(&eventq_pool, 1, timeout);
diff --git a/nimble/host/mesh/src/glue.c b/nimble/host/mesh/src/glue.c
index 15d8d9b2..9b0f0fc9 100644
--- a/nimble/host/mesh/src/glue.c
+++ b/nimble/host/mesh/src/glue.c
@@ -376,8 +376,7 @@ k_delayed_work_remaining_get (struct k_delayed_work *w)
 
     OS_EXIT_CRITICAL(sr);
 
-    /* We should return ms */
-    return t / OS_TICKS_PER_SEC * 1000;
+    return os_time_ticks_to_ms32(t);
 }
 
 int64_t k_uptime_get(void)
@@ -393,7 +392,11 @@ u32_t k_uptime_get_32(void)
 
 void k_sleep(int32_t duration)
 {
-    os_time_delay(OS_TICKS_PER_SEC * duration / 1000);
+    uint32_t ticks;
+
+    ticks = os_time_ms_to_ticks32(duration);
+
+    os_time_delay(ticks);
 }
 
 static uint8_t pub[64];
diff --git a/nimble/host/src/ble_gap.c b/nimble/host/src/ble_gap.c
index cbc7fb81..8f834b70 100644
--- a/nimble/host/src/ble_gap.c
+++ b/nimble/host/src/ble_gap.c
@@ -79,9 +79,9 @@
  * If an attempt to cancel an active procedure fails, the attempt is retried
  * at this rate (ms).
  */
-#define BLE_GAP_CANCEL_RETRY_RATE               100 /* ms */
+#define BLE_GAP_CANCEL_RETRY_TIMEOUT_MS         100 /* ms */
 
-#define BLE_GAP_UPDATE_TIMEOUT                  (30 * OS_TICKS_PER_SEC)
+#define BLE_GAP_UPDATE_TIMEOUT_MS               30000 /* ms */
 
 #define BLE_GAP_MAX_UPDATE_ENTRIES      1
 
@@ -1525,7 +1525,7 @@ ble_gap_master_timer(void)
         rc = ble_gap_conn_cancel_tx();
         if (rc != 0) {
             /* Failed to stop connecting; try again in 100 ms. */
-            return BLE_GAP_CANCEL_RETRY_RATE;
+            return os_time_ms_to_ticks32(BLE_GAP_CANCEL_RETRY_TIMEOUT_MS);
         } else {
             /* Stop the timer now that the cancel command has been acked. */
             ble_gap_master.exp_set = 0;
@@ -1545,7 +1545,7 @@ ble_gap_master_timer(void)
         rc = ble_gap_disc_enable_tx(0, 0);
         if (rc != 0) {
             /* Failed to stop discovery; try again in 100 ms. */
-            return BLE_GAP_CANCEL_RETRY_RATE;
+            return os_time_ms_to_ticks32(BLE_GAP_CANCEL_RETRY_TIMEOUT_MS);
         }
 
         ble_gap_disc_complete();
@@ -4406,7 +4406,9 @@ ble_gap_update_params(uint16_t conn_handle,
 
     entry->conn_handle = conn_handle;
     entry->params = *params;
-    entry->exp_os_ticks = os_time_get() + BLE_GAP_UPDATE_TIMEOUT;
+
+    entry->exp_os_ticks = os_time_get() +
+                          os_time_ms_to_ticks32(BLE_GAP_UPDATE_TIMEOUT_MS);
 
     BLE_HS_LOG(INFO, "GAP procedure initiated: ");
     ble_gap_log_update(conn_handle, params);
diff --git a/nimble/host/src/ble_gatt_priv.h b/nimble/host/src/ble_gatt_priv.h
index b36fdd23..f7641e69 100644
--- a/nimble/host/src/ble_gatt_priv.h
+++ b/nimble/host/src/ble_gatt_priv.h
@@ -100,10 +100,6 @@ struct ble_gatts_conn {
 
 /*** @client. */
 
-/** Convert the resume rate from milliseconds to OS ticks. */
-#define BLE_GATT_RESUME_RATE_TICKS                \
-    (MYNEWT_VAL(BLE_GATT_RESUME_RATE) * OS_TICKS_PER_SEC / 1000)
-
 int ble_gattc_locked_by_cur_task(void);
 void ble_gatts_indicate_fail_notconn(uint16_t conn_handle);
 
diff --git a/nimble/host/src/ble_gattc.c b/nimble/host/src/ble_gattc.c
index 56275814..4c764e3f 100644
--- a/nimble/host/src/ble_gattc.c
+++ b/nimble/host/src/ble_gattc.c
@@ -68,7 +68,7 @@
  * The maximum time to wait for a single ATT response.  The spec defines this
  * as the ATT transaction time (Vol. 3, Part F, 3.3.3)
  */
-#define BLE_GATTC_UNRESPONSIVE_TIMEOUT          (30 * OS_TICKS_PER_SEC)
+#define BLE_GATTC_UNRESPONSIVE_TIMEOUT_MS       30000 /* ms */
 
 #define BLE_GATT_OP_NONE                        UINT8_MAX
 #define BLE_GATT_OP_MTU                         0
@@ -731,7 +731,8 @@ ble_gattc_proc_insert(struct ble_gattc_proc *proc)
 static void
 ble_gattc_proc_set_exp_timer(struct ble_gattc_proc *proc)
 {
-    proc->exp_os_ticks = os_time_get() + BLE_GATTC_UNRESPONSIVE_TIMEOUT;
+    proc->exp_os_ticks = os_time_get() +
+                         os_time_ms_to_ticks32(BLE_GATTC_UNRESPONSIVE_TIMEOUT_MS);
 }
 
 static void
@@ -743,7 +744,8 @@ ble_gattc_proc_set_resume_timer(struct ble_gattc_proc *proc)
      * instead.
      */
     if (ble_gattc_resume_at == 0) {
-        ble_gattc_resume_at = os_time_get() + BLE_GATT_RESUME_RATE_TICKS;
+        ble_gattc_resume_at = os_time_get() +
+                              os_time_ms_to_ticks32(MYNEWT_VAL(BLE_GATT_RESUME_RATE));
 
         /* A value of 0 indicates the timer is unset.  Disambiguate this. */
         if (ble_gattc_resume_at == 0) {
diff --git a/nimble/host/src/ble_hs.c b/nimble/host/src/ble_hs.c
index 306a7be8..b0d624f3 100644
--- a/nimble/host/src/ble_hs.c
+++ b/nimble/host/src/ble_hs.c
@@ -61,7 +61,7 @@ static struct os_event ble_hs_ev_start = {
 uint8_t ble_hs_sync_state;
 static int ble_hs_reset_reason;
 
-#define BLE_HS_SYNC_RETRY_RATE          (OS_TICKS_PER_SEC / 10)
+#define BLE_HS_SYNC_RETRY_TIMEOUT_MS    100 /* ms */
 
 static struct os_task *ble_hs_parent_task;
 
@@ -327,6 +327,7 @@ ble_hs_synced(void)
 static int
 ble_hs_sync(void)
 {
+    uint32_t retry_tmo_ticks;
     int rc;
 
     /* Set the sync state to "bringup."  This allows the parent task to send
@@ -342,7 +343,8 @@ ble_hs_sync(void)
         ble_hs_sync_state = BLE_HS_SYNC_STATE_BAD;
     }
 
-    ble_hs_timer_sched(BLE_HS_SYNC_RETRY_RATE);
+    retry_tmo_ticks = os_time_ms_to_ticks32(BLE_HS_SYNC_RETRY_TIMEOUT_MS);
+    ble_hs_timer_sched(retry_tmo_ticks);
 
     if (rc == 0) {
         rc = ble_hs_misc_restore_irks();
diff --git a/nimble/host/src/ble_hs_hci.c b/nimble/host/src/ble_hs_hci.c
index ec88462b..bbd6c797 100644
--- a/nimble/host/src/ble_hs_hci.c
+++ b/nimble/host/src/ble_hs_hci.c
@@ -28,7 +28,7 @@
 #include "ble_hs_dbg_priv.h"
 #include "ble_monitor_priv.h"
 
-#define BLE_HCI_CMD_TIMEOUT     ((OS_TICKS_PER_SEC) * 2)
+#define BLE_HCI_CMD_TIMEOUT_MS  2000
 
 static struct os_mutex ble_hs_hci_mutex;
 static struct os_sem ble_hs_hci_sem;
@@ -243,6 +243,7 @@ ble_hs_hci_process_ack(uint16_t expected_opcode,
 static int
 ble_hs_hci_wait_for_ack(void)
 {
+    uint32_t cmd_tmo;
     int rc;
 
 #if MYNEWT_VAL(BLE_HS_PHONY_HCI_ACKS)
@@ -255,7 +256,8 @@ ble_hs_hci_wait_for_ack(void)
         rc = ble_hs_hci_phony_ack_cb(ble_hs_hci_ack, 260);
     }
 #else
-    rc = os_sem_pend(&ble_hs_hci_sem, BLE_HCI_CMD_TIMEOUT);
+    cmd_tmo = os_time_ms_to_ticks32(BLE_HCI_CMD_TIMEOUT_MS);
+    rc = os_sem_pend(&ble_hs_hci_sem, cmd_tmo);
     switch (rc) {
     case 0:
         BLE_HS_DBG_ASSERT(ble_hs_hci_ack != NULL);
diff --git a/nimble/host/src/ble_sm.c b/nimble/host/src/ble_sm.c
index e53b4ff1..513918ec 100644
--- a/nimble/host/src/ble_sm.c
+++ b/nimble/host/src/ble_sm.c
@@ -52,7 +52,7 @@
 #if NIMBLE_BLE_SM
 
 /** Procedure timeout; 30 seconds. */
-#define BLE_SM_TIMEOUT_OS_TICKS             (30 * OS_TICKS_PER_SEC)
+#define BLE_SM_TIMEOUT_MS             (30000)
 
 STAILQ_HEAD(ble_sm_proc_list, ble_sm_proc);
 
@@ -353,8 +353,8 @@ ble_sm_gen_csrk(struct ble_sm_proc *proc, uint8_t *csrk)
 static void
 ble_sm_proc_set_timer(struct ble_sm_proc *proc)
 {
-    /* Set a timeout of 30 seconds. */
-    proc->exp_os_ticks = os_time_get() + BLE_SM_TIMEOUT_OS_TICKS;
+    proc->exp_os_ticks = os_time_get() +
+                         os_time_ms_to_ticks32(BLE_SM_TIMEOUT_MS);
     ble_hs_timer_resched();
 }
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services