From ca5c829a84602ffdabd9fac210b75af6bcd94735 Mon Sep 17 00:00:00 2001 From: Morten Priess Date: Fri, 25 Oct 2019 13:30:17 +0200 Subject: [PATCH] bluetooth: controller: Move calculation of max_tx_octets to ULL Move calculation of max_tx_octets from Nordic lll_conn.c to ULL, to allow usage by other vendors and prevent duplicate code. Signed-off-by: Morten Priess --- subsys/bluetooth/controller/ll_sw/lll_conn.h | 1 + .../controller/ll_sw/nordic/lll/lll_conn.c | 64 +---------------- subsys/bluetooth/controller/ll_sw/ull_conn.c | 70 +++++++++++++++++++ 3 files changed, 72 insertions(+), 63 deletions(-) diff --git a/subsys/bluetooth/controller/ll_sw/lll_conn.h b/subsys/bluetooth/controller/ll_sw/lll_conn.h index 2f4ad06997f..df722af8eaf 100644 --- a/subsys/bluetooth/controller/ll_sw/lll_conn.h +++ b/subsys/bluetooth/controller/ll_sw/lll_conn.h @@ -163,3 +163,4 @@ void lll_conn_pdu_tx_prep(struct lll_conn *lll, struct pdu_data **pdu_data_tx); void lll_conn_flush(struct lll_conn *lll); extern void ull_conn_lll_ack_enqueue(u16_t handle, struct node_tx *tx); +extern u16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll); diff --git a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c index 37a5466e31b..f61b7b1cd86 100644 --- a/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c +++ b/subsys/bluetooth/controller/ll_sw/nordic/lll/lll_conn.c @@ -537,69 +537,7 @@ void lll_conn_pdu_tx_prep(struct lll_conn *lll, struct pdu_data **pdu_data_tx) p->len = lll->packet_tx_head_len - lll->packet_tx_head_offset; p->md = 0; -#if defined(CONFIG_BT_CTLR_DATA_LENGTH) -#if defined(CONFIG_BT_CTLR_PHY) - switch (lll->phy_tx_time) { - default: - case BIT(0): - /* 1M PHY, 1us = 1 bit, hence divide by 8. - * Deduct 10 bytes for preamble (1), access address (4), - * header (2), and CRC (3). - */ - max_tx_octets = (lll->max_tx_time >> 3) - 10; - break; - - case BIT(1): - /* 2M PHY, 1us = 2 bits, hence divide by 4. - * Deduct 11 bytes for preamble (2), access address (4), - * header (2), and CRC (3). - */ - max_tx_octets = (lll->max_tx_time >> 2) - 11; - break; - -#if defined(CONFIG_BT_CTLR_PHY_CODED) - case BIT(2): - if (lll->phy_flags & 0x01) { - /* S8 Coded PHY, 8us = 1 bit, hence divide by - * 64. - * Subtract time for preamble (80), AA (256), - * CI (16), TERM1 (24), CRC (192) and - * TERM2 (24), total 592 us. - * Subtract 2 bytes for header. - */ - max_tx_octets = ((lll->max_tx_time - 592) >> - 6) - 2; - } else { - /* S2 Coded PHY, 2us = 1 bit, hence divide by - * 16. - * Subtract time for preamble (80), AA (256), - * CI (16), TERM1 (24), CRC (48) and - * TERM2 (6), total 430 us. - * Subtract 2 bytes for header. - */ - max_tx_octets = ((lll->max_tx_time - 430) >> - 4) - 2; - } - break; -#endif /* CONFIG_BT_CTLR_PHY_CODED */ - } - -#if defined(CONFIG_BT_CTLR_LE_ENC) - if (lll->enc_tx) { - /* deduct the MIC */ - max_tx_octets -= 4U; - } -#endif /* CONFIG_BT_CTLR_LE_ENC */ - - if (max_tx_octets > lll->max_tx_octets) { - max_tx_octets = lll->max_tx_octets; - } -#else /* !CONFIG_BT_CTLR_PHY */ - max_tx_octets = lll->max_tx_octets; -#endif /* !CONFIG_BT_CTLR_PHY */ -#else /* !CONFIG_BT_CTLR_DATA_LENGTH */ - max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; -#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ + max_tx_octets = ull_conn_lll_max_tx_octets_get(lll); if (p->len > max_tx_octets) { p->len = max_tx_octets; diff --git a/subsys/bluetooth/controller/ll_sw/ull_conn.c b/subsys/bluetooth/controller/ll_sw/ull_conn.c index 2aaebe75025..1c1cd6fbc63 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_conn.c +++ b/subsys/bluetooth/controller/ll_sw/ull_conn.c @@ -1398,6 +1398,76 @@ u8_t ull_conn_llcp_req(void *conn) return 0; } +u16_t ull_conn_lll_max_tx_octets_get(struct lll_conn *lll) +{ + u16_t max_tx_octets; + +#if defined(CONFIG_BT_CTLR_DATA_LENGTH) +#if defined(CONFIG_BT_CTLR_PHY) + switch (lll->phy_tx_time) { + default: + case BIT(0): + /* 1M PHY, 1us = 1 bit, hence divide by 8. + * Deduct 10 bytes for preamble (1), access address (4), + * header (2), and CRC (3). + */ + max_tx_octets = (lll->max_tx_time >> 3) - 10; + break; + + case BIT(1): + /* 2M PHY, 1us = 2 bits, hence divide by 4. + * Deduct 11 bytes for preamble (2), access address (4), + * header (2), and CRC (3). + */ + max_tx_octets = (lll->max_tx_time >> 2) - 11; + break; + +#if defined(CONFIG_BT_CTLR_PHY_CODED) + case BIT(2): + if (lll->phy_flags & 0x01) { + /* S8 Coded PHY, 8us = 1 bit, hence divide by + * 64. + * Subtract time for preamble (80), AA (256), + * CI (16), TERM1 (24), CRC (192) and + * TERM2 (24), total 592 us. + * Subtract 2 bytes for header. + */ + max_tx_octets = ((lll->max_tx_time - 592) >> + 6) - 2; + } else { + /* S2 Coded PHY, 2us = 1 bit, hence divide by + * 16. + * Subtract time for preamble (80), AA (256), + * CI (16), TERM1 (24), CRC (48) and + * TERM2 (6), total 430 us. + * Subtract 2 bytes for header. + */ + max_tx_octets = ((lll->max_tx_time - 430) >> + 4) - 2; + } + break; +#endif /* CONFIG_BT_CTLR_PHY_CODED */ + } + +#if defined(CONFIG_BT_CTLR_LE_ENC) + if (lll->enc_tx) { + /* deduct the MIC */ + max_tx_octets -= 4U; + } +#endif /* CONFIG_BT_CTLR_LE_ENC */ + + if (max_tx_octets > lll->max_tx_octets) { + max_tx_octets = lll->max_tx_octets; + } +#else /* !CONFIG_BT_CTLR_PHY */ + max_tx_octets = lll->max_tx_octets; +#endif /* !CONFIG_BT_CTLR_PHY */ +#else /* !CONFIG_BT_CTLR_DATA_LENGTH */ + max_tx_octets = PDU_DC_PAYLOAD_SIZE_MIN; +#endif /* !CONFIG_BT_CTLR_DATA_LENGTH */ + return max_tx_octets; +} + static int init_reset(void) { /* Initialize conn pool. */