diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c index bd0eebfc708..d30c0359ddf 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_adv.c @@ -83,9 +83,9 @@ static inline bool isr_rx_ci_adva_check(uint8_t tx_addr, uint8_t *addr, struct pdu_adv *ci); #if defined(CONFIG_BT_CTLR_ADV_EXT) -#define PAYLOAD_BASED_FRAG_COUNT ((CONFIG_BT_CTLR_ADV_DATA_LEN_MAX + \ - PDU_AC_PAYLOAD_SIZE_MAX - 1) / \ - PDU_AC_PAYLOAD_SIZE_MAX) +#define PAYLOAD_BASED_FRAG_COUNT \ + ceiling_fraction(CONFIG_BT_CTLR_ADV_DATA_LEN_MAX, \ + PDU_AC_PAYLOAD_SIZE_MAX) #define PAYLOAD_FRAG_COUNT MAX(PAYLOAD_BASED_FRAG_COUNT, BT_CTLR_DF_PER_ADV_CTE_NUM_MAX) #define BT_CTLR_ADV_AUX_SET CONFIG_BT_CTLR_ADV_AUX_SET #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_test.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_test.c index 314bb625417..6aea369bdb0 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_test.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_test.c @@ -106,8 +106,7 @@ static void isr_tx(void *param) /* LE Test Packet Interval */ l = radio_tmr_end_get() - radio_tmr_ready_get(); - i = ((l + 249 + (SCAN_INT_UNIT_US - 1)) / SCAN_INT_UNIT_US) * - SCAN_INT_UNIT_US; + i = ceiling_fraction((l + 249), SCAN_INT_UNIT_US) * SCAN_INT_UNIT_US; t = radio_tmr_end_get() - l + i; t -= radio_tx_ready_delay_get(test_phy, test_phy_flags); diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.c index 4a32ffe1f65..1c0663380da 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_adv.c @@ -79,9 +79,9 @@ static inline bool isr_rx_ci_adva_check(struct pdu_adv *adv, struct pdu_adv *ci); #if defined(CONFIG_BT_CTLR_ADV_EXT) -#define PAYLOAD_FRAG_COUNT ((CONFIG_BT_CTLR_ADV_DATA_LEN_MAX + \ - PDU_AC_PAYLOAD_SIZE_MAX - 1) / \ - PDU_AC_PAYLOAD_SIZE_MAX) +#define PAYLOAD_BASED_FRAG_COUNT \ + ceiling_fraction(CONFIG_BT_CTLR_ADV_DATA_LEN_MAX, \ + PDU_AC_PAYLOAD_SIZE_MAX) #define BT_CTLR_ADV_AUX_SET CONFIG_BT_CTLR_ADV_AUX_SET #if defined(CONFIG_BT_CTLR_ADV_PERIODIC) #define BT_CTLR_ADV_SYNC_SET CONFIG_BT_CTLR_ADV_SYNC_SET diff --git a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_test.c b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_test.c index 485b130e834..1e805a38f2f 100644 --- a/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_test.c +++ b/subsys/bluetooth/controller/ll_sw/openisa/lll/lll_test.c @@ -102,8 +102,7 @@ static void isr_tx(void *param) /* LE Test Packet Interval */ l = radio_tmr_end_get() - radio_tmr_ready_get(); - i = ((l + 249 + (SCAN_INT_UNIT_US - 1)) / SCAN_INT_UNIT_US) * - SCAN_INT_UNIT_US; + i = ceiling_fraction((l + 249), SCAN_INT_UNIT_US) * SCAN_INT_UNIT_US; t = radio_tmr_end_get() - l + i; t -= radio_tx_ready_delay_get(test_phy, test_phy_flags); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index 2b5abbb6209..1f35a38bb77 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -1221,9 +1221,8 @@ uint8_t ll_adv_enable(uint8_t enable) interval_min_us = time_us + (scan_delay + scan_window) * USEC_PER_MSEC; if ((interval * SCAN_INT_UNIT_US) < interval_min_us) { - interval = (interval_min_us + - (SCAN_INT_UNIT_US - 1)) / - SCAN_INT_UNIT_US; + interval = ceiling_fraction(interval_min_us, + SCAN_INT_UNIT_US); } /* passive scanning */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c index b7ef309dadd..71858b19922 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_iso.c @@ -183,11 +183,10 @@ uint8_t ll_big_create(uint8_t big_handle, uint8_t adv_handle, uint8_t num_bis, lll_adv_iso->num_bis = num_bis; /* BN (Burst Count), Mandatory BN = 1 */ - bn = (max_sdu + (lll_adv_iso->max_pdu - 1U)) / lll_adv_iso->max_pdu; + bn = ceiling_fraction(max_sdu, lll_adv_iso->max_pdu); if (bn > PDU_BIG_BN_MAX) { lll_adv_iso->bn = PDU_BIG_BN_MAX; - bn = ((bn + (PDU_BIG_BN_MAX - 1)) / PDU_BIG_BN_MAX) * - PDU_BIG_BN_MAX; + bn = ceiling_fraction(bn, PDU_BIG_BN_MAX) * PDU_BIG_BN_MAX; } else { lll_adv_iso->bn = bn; } diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 91cca1c3bb3..7ac8f075eaf 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -3126,9 +3126,9 @@ static inline int event_conn_upd_prep(struct ll_conn *conn, uint16_t lazy, instant_latency; lll->periph.window_widening_periodic_us = - (((lll_clock_ppm_local_get() + - lll_clock_ppm_get(conn->periph.sca)) * - conn_interval_us) + (1000000 - 1)) / 1000000U; + ceiling_fraction(((lll_clock_ppm_local_get() + + lll_clock_ppm_get(conn->periph.sca)) * + conn_interval_us), USEC_PER_SEC); lll->periph.window_widening_max_us = (conn_interval_us >> 1) - EVENT_IFS_US; lll->periph.window_size_prepare_us = diff --git a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c index 2af494d7e38..9c3e84a5be0 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_peripheral.c +++ b/subsys/bluetooth/controller/ll_sw/ull_peripheral.c @@ -190,9 +190,9 @@ void ull_periph_setup(struct node_rx_hdr *rx, struct node_rx_ftr *ftr, /* calculate the window widening */ conn->periph.sca = pdu_adv->connect_ind.sca; lll->periph.window_widening_periodic_us = - (((lll_clock_ppm_local_get() + - lll_clock_ppm_get(conn->periph.sca)) * - conn_interval_us) + (1000000 - 1)) / 1000000U; + ceiling_fraction(((lll_clock_ppm_local_get() + + lll_clock_ppm_get(conn->periph.sca)) * + conn_interval_us), USEC_PER_SEC); lll->periph.window_widening_max_us = (conn_interval_us >> 1) - EVENT_IFS_US; lll->periph.window_size_event_us = pdu_adv->connect_ind.win_size * diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync.c b/subsys/bluetooth/controller/ll_sw/ull_sync.c index 1cb1ee90aae..517329229db 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync.c @@ -579,8 +579,9 @@ void ull_sync_setup(struct ll_scan_set *scan, struct ll_scan_aux_set *aux, #endif /* CONFIG_BT_CTLR_SYNC_ISO */ lll->window_widening_periodic_us = - (((lll_clock_ppm_local_get() + lll_clock_ppm_get(sca)) * - interval_us) + (1000000 - 1)) / 1000000U; + ceiling_fraction(((lll_clock_ppm_local_get() + + lll_clock_ppm_get(sca)) * + interval_us), USEC_PER_SEC); lll->window_widening_max_us = (interval_us >> 1) - EVENT_IFS_US; if (si->offs_units) { lll->window_size_event_us = OFFS_UNIT_300_US; diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c index c1891f3209a..1959e286890 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_iso.c @@ -335,8 +335,9 @@ void ull_sync_iso_setup(struct ll_sync_iso_set *sync_iso, sca = sync_iso->sync->lll.sca; lll->window_widening_periodic_us = - (((lll_clock_ppm_local_get() + lll_clock_ppm_get(sca)) * - interval_us) + (1000000 - 1)) / 1000000U; + ceiling_fraction(((lll_clock_ppm_local_get() + + lll_clock_ppm_get(sca)) * + interval_us), USEC_PER_SEC); lll->window_widening_max_us = (interval_us >> 1) - EVENT_IFS_US; if (bi->offs_units) { lll->window_size_event_us = 300U;