Skip to content

Commit 4bf5718

Browse files
committed
bluetooth: host: Change uses of interval to interval_us
Since Shorter Connection Intervals changes the unit that connection intervals can be represented in. It is necessary to change how they are stored and represented. This commit deprecates interval in favour of interval_us. Remove use of interval in internal bt_conn struct since it is no longer needed. Signed-off-by: Timothy Keys <timothy.keys@nordicsemi.no> (cherry picked from commit c14dcaf)
1 parent bd8dad0 commit 4bf5718

File tree

15 files changed

+56
-38
lines changed

15 files changed

+56
-38
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,9 +1056,19 @@ struct bt_conn_le_info {
10561056
/** Connection interval in microseconds */
10571057
uint32_t interval_us;
10581058
#if !defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS) || defined(__DOXYGEN__)
1059-
/** Connection interval in units of 1.25 ms */
1060-
uint16_t interval;
1059+
union {
1060+
/** @brief Connection interval in units of 1.25 ms
1061+
*
1062+
* @deprecated Use @ref bt_conn_le_info.interval_us instead
1063+
*/
1064+
__deprecated uint16_t interval;
1065+
/** @cond INTERNAL_HIDDEN */
1066+
/** Workaround for setting deprecated @ref bt_conn_le_info.interval */
1067+
uint16_t _interval;
1068+
/** @endcond */
1069+
};
10611070
#endif /* !CONFIG_BT_SHORTER_CONNECTION_INTERVALS */
1071+
10621072
uint16_t latency; /**< Connection peripheral latency */
10631073
uint16_t timeout; /**< Connection supervision timeout */
10641074

@@ -1096,7 +1106,7 @@ struct bt_conn_le_info {
10961106
*
10971107
* Multiply by 125 to get microseconds.
10981108
*/
1099-
#define BT_CONN_SCI_INTERVAL_TO_US(interval) ((interval) * BT_HCI_LE_SCI_INTERVAL_UNIT_US)
1109+
#define BT_CONN_SCI_INTERVAL_TO_US(_interval) ((_interval) * BT_HCI_LE_SCI_INTERVAL_UNIT_US)
11001110

11011111
/** BR/EDR Connection Info Structure */
11021112
struct bt_conn_br_info {

include/zephyr/bluetooth/hci_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3289,6 +3289,8 @@ struct bt_hci_evt_le_advertising_report {
32893289
#define BT_HCI_LE_SUPERVISON_TIMEOUT_MIN 0x000a
32903290
#define BT_HCI_LE_SUPERVISON_TIMEOUT_MAX 0x0c80
32913291

3292+
#define BT_HCI_LE_INTERVAL_UNIT_US (1250U)
3293+
32923294
#define BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE 0x03
32933295
struct bt_hci_evt_le_conn_update_complete {
32943296
uint8_t status;

subsys/bluetooth/audio/ascs.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -525,22 +525,22 @@ static void state_transition_work_handler(struct k_work *work)
525525
err = ase_state_notify(ase);
526526
if (err == -ENOMEM) {
527527
struct bt_conn_info info;
528-
uint32_t retry_delay_ms;
528+
uint32_t retry_delay_us;
529529

530530
/* Revert back to old state */
531531
ase->ep.state = old_state;
532532

533533
err = bt_conn_get_info(ase->conn, &info);
534534
__ASSERT_NO_MSG(err == 0);
535535

536-
retry_delay_ms = BT_CONN_INTERVAL_TO_MS(info.le.interval);
536+
retry_delay_us = info.le.interval_us;
537537

538538
/* Reschedule the state transition */
539-
err = k_work_reschedule(d_work, K_MSEC(retry_delay_ms));
539+
err = k_work_reschedule(d_work, K_USEC(retry_delay_us));
540540
if (err >= 0) {
541541
LOG_DBG("Out of buffers for ase state notification. "
542-
"Will retry in %dms",
543-
retry_delay_ms);
542+
"Will retry in %dus",
543+
retry_delay_us);
544544
return;
545545
}
546546
}

subsys/bluetooth/audio/bap_broadcast_assistant.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,12 @@ static void long_bap_read(struct bt_conn *conn, uint16_t handle)
453453
if (err != 0) {
454454
LOG_DBG("Failed to get conn info, use default interval");
455455

456-
conn_info.le.interval = BT_GAP_INIT_CONN_INT_MIN;
456+
conn_info.le.interval_us = BT_CONN_INTERVAL_TO_US(BT_GAP_INIT_CONN_INT_MIN);
457457
}
458458

459459
/* Wait a connection interval to retry */
460460
err = k_work_reschedule(&inst->bap_read_work,
461-
K_USEC(BT_CONN_INTERVAL_TO_US(conn_info.le.interval)));
461+
K_USEC(conn_info.le.interval_us));
462462
if (err < 0) {
463463
LOG_DBG("Failed to reschedule read work: %d", err);
464464
bap_long_read_reset(inst);

subsys/bluetooth/audio/bap_scan_delegator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static void receive_state_notify_cb(struct bt_conn *conn, void *data)
240240

241241
LOG_DBG("Could not notify receive state: %d", err);
242242
err = k_work_reschedule(&internal_state->notify_work,
243-
K_USEC(BT_CONN_INTERVAL_TO_US(conn_info.le.interval)));
243+
K_USEC(conn_info.le.interval_us));
244244
__ASSERT(err >= 0, "Failed to reschedule work: %d", err);
245245
}
246246
}

subsys/bluetooth/audio/bap_unicast_client.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,12 +1767,12 @@ static void long_ase_read(struct bt_bap_unicast_client_ep *client_ep)
17671767
if (err != 0) {
17681768
LOG_DBG("Failed to get conn info, use default interval");
17691769

1770-
conn_info.le.interval = BT_GAP_INIT_CONN_INT_MIN;
1770+
conn_info.le.interval_us = BT_CONN_INTERVAL_TO_US(BT_GAP_INIT_CONN_INT_MIN);
17711771
}
17721772

17731773
/* Wait a connection interval to retry */
17741774
err = k_work_reschedule(&client_ep->ase_read_work,
1775-
K_USEC(BT_CONN_INTERVAL_TO_US(conn_info.le.interval)));
1775+
K_USEC(conn_info.le.interval_us));
17761776
if (err < 0) {
17771777
LOG_DBG("Failed to reschedule ASE long read work: %d", err);
17781778
}

subsys/bluetooth/audio/tbs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ static void notify_handler_cb(struct bt_conn *conn, void *data)
10051005
LOG_DBG("Notify failed (%d), retrying next connection interval", err);
10061006
reschedule:
10071007
err = k_work_reschedule(&inst->notify_work,
1008-
K_USEC(BT_CONN_INTERVAL_TO_US(info.le.interval)));
1008+
K_USEC(info.le.interval_us));
10091009
__ASSERT(err >= 0, "Failed to reschedule work: %d", err);
10101010
}
10111011

subsys/bluetooth/host/att.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3538,7 +3538,7 @@ static k_timeout_t credit_based_connection_delay(struct bt_conn *conn)
35383538
* result in an overflow
35393539
*/
35403540
const uint32_t calculated_delay_us =
3541-
2 * (conn->le.latency + 1) * BT_CONN_INTERVAL_TO_US(conn->le.interval);
3541+
2 * (conn->le.latency + 1) * conn->le.interval_us;
35423542
const uint32_t calculated_delay_ms = calculated_delay_us / USEC_PER_MSEC;
35433543

35443544
return K_MSEC(MAX(100, calculated_delay_ms + rand_delay));

subsys/bluetooth/host/conn.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,30 +1960,30 @@ void bt_conn_notify_remote_info(struct bt_conn *conn)
19601960

19611961
void bt_conn_notify_le_param_updated(struct bt_conn *conn)
19621962
{
1963+
uint16_t interval_1250us = conn->le.interval_us / BT_HCI_LE_INTERVAL_UNIT_US;
1964+
19631965
/* If new connection parameters meet requirement of pending
19641966
* parameters don't send peripheral conn param request anymore on timeout
19651967
*/
19661968
if (atomic_test_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET) &&
1967-
conn->le.interval >= conn->le.interval_min &&
1968-
conn->le.interval <= conn->le.interval_max &&
1969+
interval_1250us >= conn->le.interval_min &&
1970+
interval_1250us <= conn->le.interval_max &&
19691971
conn->le.latency == conn->le.pending_latency &&
19701972
conn->le.timeout == conn->le.pending_timeout) {
19711973
atomic_clear_bit(conn->flags, BT_CONN_PERIPHERAL_PARAM_SET);
19721974
}
19731975

1974-
19751976
BT_CONN_CB_DYNAMIC_FOREACH(callback) {
19761977
if (callback->le_param_updated) {
1977-
callback->le_param_updated(conn, conn->le.interval,
1978+
callback->le_param_updated(conn, interval_1250us,
19781979
conn->le.latency, conn->le.timeout);
19791980
}
19801981
}
19811982

19821983
STRUCT_SECTION_FOREACH(bt_conn_cb, cb) {
19831984
if (cb->le_param_updated) {
1984-
cb->le_param_updated(conn, conn->le.interval,
1985-
conn->le.latency,
1986-
conn->le.timeout);
1985+
cb->le_param_updated(conn, interval_1250us,
1986+
conn->le.latency, conn->le.timeout);
19871987
}
19881988
}
19891989
}
@@ -2866,7 +2866,7 @@ int bt_conn_get_info(const struct bt_conn *conn, struct bt_conn_info *info)
28662866
}
28672867
info->le.interval_us = conn->le.interval_us;
28682868
#if !defined(CONFIG_BT_SHORTER_CONNECTION_INTERVALS)
2869-
info->le.interval = conn->le.interval_us / BT_HCI_LE_INTERVAL_UNIT_US;
2869+
info->le._interval = conn->le.interval_us / BT_HCI_LE_INTERVAL_UNIT_US;
28702870
#endif
28712871
info->le.latency = conn->le.latency;
28722872
info->le.timeout = conn->le.timeout;

subsys/bluetooth/host/conn_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ struct bt_conn_le {
107107
bt_addr_le_t init_addr;
108108
bt_addr_le_t resp_addr;
109109

110-
uint16_t interval;
110+
uint32_t interval_us;
111111
uint16_t interval_min;
112112
uint16_t interval_max;
113113

0 commit comments

Comments
 (0)