Bluetooth: controller: Refactor to use max macro
Cleaned up the use of conditional statements to use the max macro. Fixes #6230. Signed-off-by: David Maitland <hello@davidmaitland.me> Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
This commit is contained in:
parent
3642a69a6b
commit
f77469a3bb
3 changed files with 50 additions and 98 deletions
|
@ -1132,11 +1132,8 @@ static inline u32_t isr_rx_adv(u8_t devmatch_ok, u8_t devmatch_id,
|
|||
HAL_TICKER_US_TO_TICKS(RADIO_TICKER_XTAL_OFFSET_US);
|
||||
conn->hdr.ticks_preempt_to_start =
|
||||
HAL_TICKER_US_TO_TICKS(RADIO_TICKER_PREEMPT_PART_MIN_US);
|
||||
ticks_slot_offset =
|
||||
(conn->hdr.ticks_active_to_start <
|
||||
conn->hdr.ticks_xtal_to_start) ?
|
||||
conn->hdr.ticks_xtal_to_start :
|
||||
conn->hdr.ticks_active_to_start;
|
||||
ticks_slot_offset = max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_xtal_to_start);
|
||||
conn_interval_us -=
|
||||
conn->slave.window_widening_periodic_us;
|
||||
|
||||
|
@ -1583,10 +1580,8 @@ static inline u32_t isr_rx_scan(u8_t devmatch_ok, u8_t devmatch_id,
|
|||
conn->hdr.ticks_preempt_to_start = HAL_TICKER_US_TO_TICKS(
|
||||
RADIO_TICKER_PREEMPT_PART_MIN_US);
|
||||
conn->hdr.ticks_slot = _radio.scanner.ticks_conn_slot;
|
||||
ticks_slot_offset = (conn->hdr.ticks_active_to_start <
|
||||
conn->hdr.ticks_xtal_to_start) ?
|
||||
conn->hdr.ticks_xtal_to_start :
|
||||
conn->hdr.ticks_active_to_start;
|
||||
ticks_slot_offset = max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_xtal_to_start);
|
||||
|
||||
/* Stop Scanner */
|
||||
ticker_status = ticker_stop(RADIO_TICKER_INSTANCE_ID_RADIO,
|
||||
|
@ -4707,9 +4702,8 @@ static void prepare_normal_set(struct shdr *hdr, u8_t ticker_user_id,
|
|||
if (hdr->ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticker_status;
|
||||
u32_t ticks_prepare_to_start =
|
||||
(hdr->ticks_active_to_start >
|
||||
hdr->ticks_preempt_to_start) ? hdr->
|
||||
ticks_active_to_start : hdr->ticks_preempt_to_start;
|
||||
max(hdr->ticks_active_to_start,
|
||||
hdr->ticks_preempt_to_start);
|
||||
u32_t ticks_drift_minus = (hdr->ticks_xtal_to_start &
|
||||
~XON_BITMASK) -
|
||||
ticks_prepare_to_start;
|
||||
|
@ -4827,15 +4821,11 @@ static void mayfly_xtal_stop_calc(void *params)
|
|||
|
||||
/* Compensate for current ticker in reduced prepare */
|
||||
if (hdr_curr->ticks_xtal_to_start & XON_BITMASK) {
|
||||
ticks_slot_abs = (hdr_curr->ticks_active_to_start >
|
||||
hdr_curr->ticks_preempt_to_start) ?
|
||||
hdr_curr->ticks_active_to_start :
|
||||
hdr_curr->ticks_preempt_to_start;
|
||||
ticks_slot_abs = max(hdr_curr->ticks_active_to_start,
|
||||
hdr_curr->ticks_preempt_to_start);
|
||||
} else {
|
||||
ticks_slot_abs = (hdr_curr->ticks_active_to_start >
|
||||
hdr_curr->ticks_xtal_to_start) ?
|
||||
hdr_curr->ticks_active_to_start :
|
||||
hdr_curr->ticks_xtal_to_start;
|
||||
ticks_slot_abs = max(hdr_curr->ticks_active_to_start,
|
||||
hdr_curr->ticks_xtal_to_start);
|
||||
}
|
||||
ticks_slot_abs += hdr_curr->ticks_slot;
|
||||
|
||||
|
@ -4843,10 +4833,9 @@ static void mayfly_xtal_stop_calc(void *params)
|
|||
hdr_next = hdr_conn_get(ticker_id_next, &conn_next);
|
||||
LL_ASSERT(hdr_next);
|
||||
|
||||
ticks_prepare_to_start_next = (hdr_next->ticks_active_to_start >
|
||||
hdr_next->ticks_preempt_to_start) ?
|
||||
hdr_next->ticks_active_to_start :
|
||||
hdr_next->ticks_preempt_to_start;
|
||||
ticks_prepare_to_start_next =
|
||||
max(hdr_next->ticks_active_to_start,
|
||||
hdr_next->ticks_preempt_to_start);
|
||||
|
||||
/* Compensate for next ticker in reduced prepare */
|
||||
if (hdr_next->ticks_xtal_to_start & XON_BITMASK) {
|
||||
|
@ -4993,10 +4982,8 @@ static void sched_after_mstr_free_slot_get(u8_t user_id,
|
|||
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
|
||||
if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_preempt_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_preempt_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_preempt_to_start);
|
||||
|
||||
ticks_slot_abs_curr =
|
||||
conn->hdr.ticks_xtal_to_start &
|
||||
|
@ -5008,10 +4995,8 @@ static void sched_after_mstr_free_slot_get(u8_t user_id,
|
|||
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
|
||||
{
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_xtal_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_xtal_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_xtal_to_start);
|
||||
|
||||
ticks_slot_abs_curr = ticks_prepare_to_start;
|
||||
}
|
||||
|
@ -5122,10 +5107,8 @@ static void sched_free_win_offset_calc(struct connection *conn_curr,
|
|||
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
|
||||
if (conn_curr->hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn_curr->hdr.ticks_active_to_start >
|
||||
conn_curr->hdr.ticks_preempt_to_start) ?
|
||||
conn_curr->hdr.ticks_active_to_start :
|
||||
conn_curr->hdr.ticks_preempt_to_start;
|
||||
max(conn_curr->hdr.ticks_active_to_start,
|
||||
conn_curr->hdr.ticks_preempt_to_start);
|
||||
|
||||
ticks_slot_abs = conn_curr->hdr.ticks_xtal_to_start &
|
||||
~XON_BITMASK;
|
||||
|
@ -5134,10 +5117,8 @@ static void sched_free_win_offset_calc(struct connection *conn_curr,
|
|||
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
|
||||
{
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn_curr->hdr.ticks_active_to_start >
|
||||
conn_curr->hdr.ticks_xtal_to_start) ?
|
||||
conn_curr->hdr.ticks_active_to_start :
|
||||
conn_curr->hdr.ticks_xtal_to_start;
|
||||
max(conn_curr->hdr.ticks_active_to_start,
|
||||
conn_curr->hdr.ticks_xtal_to_start);
|
||||
|
||||
ticks_slot_abs = ticks_prepare_to_start;
|
||||
}
|
||||
|
@ -5215,10 +5196,8 @@ static void sched_free_win_offset_calc(struct connection *conn_curr,
|
|||
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
|
||||
if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_preempt_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_preempt_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_preempt_to_start);
|
||||
|
||||
ticks_slot_abs_curr =
|
||||
conn->hdr.ticks_xtal_to_start &
|
||||
|
@ -5230,10 +5209,8 @@ static void sched_free_win_offset_calc(struct connection *conn_curr,
|
|||
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
|
||||
{
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_xtal_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_xtal_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_xtal_to_start);
|
||||
|
||||
ticks_slot_abs_curr = ticks_prepare_to_start;
|
||||
}
|
||||
|
@ -5487,10 +5464,8 @@ static void event_common_prepare(u32_t ticks_at_expire,
|
|||
* active to start duration.
|
||||
*/
|
||||
if (_ticks_xtal_to_start & XON_BITMASK) {
|
||||
_ticks_xtal_to_start =
|
||||
(_ticks_active_to_start > ticks_preempt_to_start) ?
|
||||
_ticks_active_to_start :
|
||||
ticks_preempt_to_start;
|
||||
_ticks_xtal_to_start = max(_ticks_active_to_start,
|
||||
ticks_preempt_to_start);
|
||||
}
|
||||
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
|
||||
|
||||
|
@ -5594,10 +5569,8 @@ static void event_common_prepare(u32_t ticks_at_expire,
|
|||
}
|
||||
#endif /* CONFIG_BT_CTLR_XTAL_ADVANCED */
|
||||
|
||||
ticks_to_start_new = (_radio.ticks_active_to_start <
|
||||
*ticks_xtal_to_start) ?
|
||||
*ticks_xtal_to_start :
|
||||
_radio.ticks_active_to_start;
|
||||
ticks_to_start_new = max(_radio.ticks_active_to_start,
|
||||
*ticks_xtal_to_start);
|
||||
|
||||
/* drift the primary as required due to active line change */
|
||||
ticker_status =
|
||||
|
@ -6350,10 +6323,8 @@ static void event_scan_prepare(u32_t ticks_at_expire, u32_t remainder,
|
|||
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
|
||||
if (_radio.scanner.hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(_radio.scanner.hdr.ticks_active_to_start >
|
||||
_radio.scanner.hdr.ticks_preempt_to_start) ?
|
||||
_radio.scanner.hdr.ticks_active_to_start :
|
||||
_radio.scanner.hdr.ticks_preempt_to_start;
|
||||
max(_radio.scanner.hdr.ticks_active_to_start,
|
||||
_radio.scanner.hdr.ticks_preempt_to_start);
|
||||
|
||||
ticks_at_expire_normal -=
|
||||
(_radio.scanner.hdr.ticks_xtal_to_start &
|
||||
|
@ -6541,10 +6512,8 @@ static inline void event_conn_upd_init(struct connection *conn,
|
|||
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
|
||||
if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_preempt_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_preempt_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_preempt_to_start);
|
||||
|
||||
conn->llcp.conn_upd.ticks_anchor -=
|
||||
(conn->hdr.ticks_xtal_to_start &
|
||||
|
@ -6705,10 +6674,8 @@ static inline u32_t event_conn_upd_prep(struct connection *conn,
|
|||
/* restore to normal prepare */
|
||||
if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_preempt_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_preempt_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_preempt_to_start);
|
||||
|
||||
conn->hdr.ticks_xtal_to_start &= ~XON_BITMASK;
|
||||
ticks_at_expire -= (conn->hdr.ticks_xtal_to_start -
|
||||
|
@ -6732,11 +6699,8 @@ static inline u32_t event_conn_upd_prep(struct connection *conn,
|
|||
conn->latency_prepare -= (instant_latency - latency);
|
||||
|
||||
/* calculate the offset, window widening and interval */
|
||||
ticks_slot_offset =
|
||||
(conn->hdr.ticks_active_to_start <
|
||||
conn->hdr.ticks_xtal_to_start) ?
|
||||
conn->hdr.ticks_xtal_to_start :
|
||||
conn->hdr.ticks_active_to_start;
|
||||
ticks_slot_offset = max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_xtal_to_start);
|
||||
conn_interval_us = conn->llcp.conn_upd.interval * 1250;
|
||||
periodic_us = conn_interval_us;
|
||||
if (conn->role) {
|
||||
|
@ -7249,10 +7213,8 @@ static inline void event_conn_param_req(struct connection *conn,
|
|||
#if defined(CONFIG_BT_CTLR_XTAL_ADVANCED)
|
||||
if (conn->hdr.ticks_xtal_to_start & XON_BITMASK) {
|
||||
u32_t ticks_prepare_to_start =
|
||||
(conn->hdr.ticks_active_to_start >
|
||||
conn->hdr.ticks_preempt_to_start) ?
|
||||
conn->hdr.ticks_active_to_start :
|
||||
conn->hdr.ticks_preempt_to_start;
|
||||
max(conn->hdr.ticks_active_to_start,
|
||||
conn->hdr.ticks_preempt_to_start);
|
||||
|
||||
conn->llcp_conn_param.ticks_ref -=
|
||||
(conn->hdr.ticks_xtal_to_start &
|
||||
|
@ -10146,10 +10108,8 @@ u32_t radio_adv_enable(u16_t interval, u8_t chan_map, u8_t filter_policy,
|
|||
_radio.advertiser.hdr.ticks_slot = HAL_TICKER_US_TO_TICKS(slot_us);
|
||||
|
||||
ticks_slot_offset =
|
||||
(_radio.advertiser.hdr.ticks_active_to_start <
|
||||
_radio.advertiser.hdr.ticks_xtal_to_start) ?
|
||||
_radio.advertiser.hdr.ticks_xtal_to_start :
|
||||
_radio.advertiser.hdr.ticks_active_to_start;
|
||||
max(_radio.advertiser.hdr.ticks_active_to_start,
|
||||
_radio.advertiser.hdr.ticks_xtal_to_start);
|
||||
|
||||
/* High Duty Cycle Directed Advertising if interval is 0. */
|
||||
_radio.advertiser.is_hdcd = !interval &&
|
||||
|
@ -10330,11 +10290,8 @@ u32_t radio_scan_enable(u8_t type, u8_t init_addr_type, u8_t *init_addr,
|
|||
HAL_TICKER_US_TO_TICKS(RADIO_TICKER_XTAL_OFFSET_US));
|
||||
}
|
||||
|
||||
ticks_slot_offset =
|
||||
(_radio.scanner.hdr.ticks_active_to_start <
|
||||
_radio.scanner.hdr.ticks_xtal_to_start) ?
|
||||
_radio.scanner.hdr.ticks_xtal_to_start :
|
||||
_radio.scanner.hdr.ticks_active_to_start;
|
||||
ticks_slot_offset = max(_radio.scanner.hdr.ticks_active_to_start,
|
||||
_radio.scanner.hdr.ticks_xtal_to_start);
|
||||
|
||||
ticks_anchor = ticker_ticks_now_get();
|
||||
|
||||
|
|
|
@ -327,16 +327,12 @@ struct pdu_data_q_tx {
|
|||
#define LL_MEM_TXQ (sizeof(struct pdu_data_q_tx) * \
|
||||
(RADIO_PACKET_COUNT_TX_MAX + 2))
|
||||
|
||||
#define LL_MEM_RX_POOL_SZ (MROUND(offsetof(struct radio_pdu_node_rx,\
|
||||
pdu_data) + ((\
|
||||
(PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA) < \
|
||||
(offsetof(struct pdu_data, lldata) + \
|
||||
RADIO_LL_LENGTH_OCTETS_RX_MAX)) ? \
|
||||
(offsetof(struct pdu_data, lldata) + \
|
||||
RADIO_LL_LENGTH_OCTETS_RX_MAX) \
|
||||
: \
|
||||
(PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA))) * \
|
||||
(RADIO_PACKET_COUNT_RX_MAX + 3))
|
||||
#define LL_MEM_RX_POOL_SZ (MROUND(offsetof(struct radio_pdu_node_rx, \
|
||||
pdu_data) + \
|
||||
max((PDU_AC_SIZE_MAX + PDU_AC_SIZE_EXTRA), \
|
||||
(offsetof(struct pdu_data, lldata) + \
|
||||
RADIO_LL_LENGTH_OCTETS_RX_MAX))) * \
|
||||
(RADIO_PACKET_COUNT_RX_MAX + 3))
|
||||
|
||||
#define LL_MEM_RX_LINK_POOL (sizeof(void *) * 2 * ((RADIO_PACKET_COUNT_RX_MAX +\
|
||||
4) + RADIO_CONNECTION_CONTEXT_MAX))
|
||||
|
|
|
@ -1033,8 +1033,7 @@ static inline void ticker_job_compare_update(struct ticker_instance *instance,
|
|||
cc = instance->ticks_current;
|
||||
ticks_elapsed = ticker_ticks_diff_get(ctr, cc) +
|
||||
COUNTER_CMP_OFFSET_MIN;
|
||||
cc += ((ticks_elapsed < ticks_to_expire) ?
|
||||
ticks_to_expire : ticks_elapsed);
|
||||
cc += max(ticks_elapsed, ticks_to_expire);
|
||||
cc &= 0x00FFFFFF;
|
||||
|
||||
instance->trigger_set_cb(cc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue