|
55 | 55 | #include "hal/debug.h" |
56 | 56 |
|
57 | 57 | static void ticker_op_stop_scan_cb(uint32_t status, void *param); |
| 58 | +#if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_CTLR_PHY_CODED) |
| 59 | +static void ticker_op_stop_scan_other_cb(uint32_t status, void *param); |
| 60 | +#endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_CTLR_PHY_CODED */ |
58 | 61 | static void ticker_op_cb(uint32_t status, void *param); |
59 | 62 | static inline void conn_release(struct ll_scan_set *scan); |
60 | 63 |
|
@@ -669,28 +672,28 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx, |
669 | 672 | uint8_t ticker_id_scan, ticker_id_conn; |
670 | 673 | uint8_t peer_addr[BDADDR_SIZE]; |
671 | 674 | uint32_t ticks_slot_overhead; |
672 | | - struct ll_scan_set *scan; |
673 | 675 | uint32_t ticks_slot_offset; |
| 676 | + struct ll_scan_set *scan; |
674 | 677 | struct pdu_adv *pdu_tx; |
675 | | - struct node_rx_cc *cc; |
676 | | - struct ll_conn *conn; |
677 | 678 | uint8_t peer_addr_type; |
678 | 679 | uint32_t ticker_status; |
| 680 | + struct node_rx_cc *cc; |
| 681 | + struct ll_conn *conn; |
679 | 682 | uint8_t chan_sel; |
680 | 683 |
|
681 | | - ((struct lll_scan *)ftr->param)->conn = NULL; |
682 | | - |
683 | | - scan = ((struct lll_scan *)ftr->param)->hdr.parent; |
684 | | - conn = lll->hdr.parent; |
685 | | - |
| 684 | + /* Get reference to Tx-ed CONNECT_IND PDU */ |
686 | 685 | pdu_tx = (void *)((struct node_rx_pdu *)rx)->pdu; |
687 | 686 |
|
| 687 | + /* Backup peer addr and type, as we reuse the Tx-ed PDU to generate |
| 688 | + * event towards LL |
| 689 | + */ |
688 | 690 | peer_addr_type = pdu_tx->rx_addr; |
689 | 691 | memcpy(peer_addr, &pdu_tx->connect_ind.adv_addr[0], BDADDR_SIZE); |
690 | 692 |
|
691 | 693 | /* This is the chan sel bit from the received adv pdu */ |
692 | 694 | chan_sel = pdu_tx->chan_sel; |
693 | 695 |
|
| 696 | + /* Populate the fields required for connection complete event */ |
694 | 697 | cc = (void *)pdu_tx; |
695 | 698 | cc->status = 0U; |
696 | 699 | cc->role = 0U; |
@@ -723,11 +726,14 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx, |
723 | 726 | memcpy(cc->peer_addr, &peer_addr[0], BDADDR_SIZE); |
724 | 727 | } |
725 | 728 |
|
| 729 | + scan = HDR_LLL2ULL(ftr->param); |
| 730 | + |
726 | 731 | cc->interval = lll->interval; |
727 | 732 | cc->latency = lll->latency; |
728 | 733 | cc->timeout = scan->lll.conn_timeout; |
729 | 734 | cc->sca = lll_clock_sca_local_get(); |
730 | 735 |
|
| 736 | + conn = lll->hdr.parent; |
731 | 737 | lll->handle = ll_conn_handle_get(conn); |
732 | 738 | rx->handle = lll->handle; |
733 | 739 |
|
@@ -804,8 +810,34 @@ void ull_master_setup(memq_link_t *link, struct node_rx_hdr *rx, |
804 | 810 | ticker_status = ticker_stop(TICKER_INSTANCE_ID_CTLR, |
805 | 811 | TICKER_USER_ID_ULL_HIGH, |
806 | 812 | ticker_id_scan, ticker_op_stop_scan_cb, |
807 | | - (void *)(uint32_t)ticker_id_scan); |
808 | | - ticker_op_stop_scan_cb(ticker_status, (void *)(uint32_t)ticker_id_scan); |
| 813 | + scan); |
| 814 | + LL_ASSERT((ticker_status == TICKER_STATUS_SUCCESS) || |
| 815 | + (ticker_status == TICKER_STATUS_BUSY)); |
| 816 | + |
| 817 | +#if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_CTLR_PHY_CODED) |
| 818 | + /* Determine if coded PHY was also enabled, if so, reset the assigned |
| 819 | + * connection context. |
| 820 | + */ |
| 821 | + struct ll_scan_set *scan_other = |
| 822 | + ull_scan_is_enabled_get(SCAN_HANDLE_PHY_CODED); |
| 823 | + if (scan_other) { |
| 824 | + if (scan_other == scan) { |
| 825 | + scan_other = ull_scan_is_enabled_get(SCAN_HANDLE_1M); |
| 826 | + } |
| 827 | + |
| 828 | + if (scan_other) { |
| 829 | + ticker_id_scan = TICKER_ID_SCAN_BASE + |
| 830 | + ull_scan_handle_get(scan_other); |
| 831 | + ticker_status = ticker_stop(TICKER_INSTANCE_ID_CTLR, |
| 832 | + TICKER_USER_ID_ULL_HIGH, |
| 833 | + ticker_id_scan, |
| 834 | + ticker_op_stop_scan_other_cb, |
| 835 | + scan_other); |
| 836 | + LL_ASSERT((ticker_status == TICKER_STATUS_SUCCESS) || |
| 837 | + (ticker_status == TICKER_STATUS_BUSY)); |
| 838 | + } |
| 839 | + } |
| 840 | +#endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_CTLR_PHY_CODED */ |
809 | 841 |
|
810 | 842 | /* Scanner stop can expire while here in this ISR. |
811 | 843 | * Deferred attempt to stop can fail as it would have |
@@ -912,9 +944,45 @@ void ull_master_ticker_cb(uint32_t ticks_at_expire, uint32_t remainder, uint16_t |
912 | 944 |
|
913 | 945 | static void ticker_op_stop_scan_cb(uint32_t status, void *param) |
914 | 946 | { |
915 | | - /* TODO: */ |
| 947 | + /* NOTE: Nothing to do here, present here to add debug code if required |
| 948 | + */ |
916 | 949 | } |
917 | 950 |
|
| 951 | +#if defined(CONFIG_BT_CTLR_ADV_EXT) && defined(CONFIG_BT_CTLR_PHY_CODED) |
| 952 | +static void ticker_op_stop_scan_other_cb(uint32_t status, void *param) |
| 953 | +{ |
| 954 | + static memq_link_t link; |
| 955 | + static struct mayfly mfy = {0, 0, &link, NULL, NULL}; |
| 956 | + struct ll_scan_set *scan; |
| 957 | + struct ull_hdr *hdr; |
| 958 | + |
| 959 | + /* Ignore if race between thread and ULL */ |
| 960 | + if (status != TICKER_STATUS_SUCCESS) { |
| 961 | + /* TODO: detect race */ |
| 962 | + |
| 963 | + return; |
| 964 | + } |
| 965 | + |
| 966 | + /* NOTE: We are in ULL_LOW which can be pre-empted by ULL_HIGH. |
| 967 | + * As we are in the callback after successful stop of the |
| 968 | + * ticker, the ULL reference count will not be modified |
| 969 | + * further hence it is safe to check and act on either the need |
| 970 | + * to call lll_disable or not. |
| 971 | + */ |
| 972 | + scan = param; |
| 973 | + hdr = &scan->ull; |
| 974 | + mfy.param = &scan->lll; |
| 975 | + if (ull_ref_get(hdr)) { |
| 976 | + uint32_t ret; |
| 977 | + |
| 978 | + mfy.fp = lll_disable; |
| 979 | + ret = mayfly_enqueue(TICKER_USER_ID_ULL_LOW, |
| 980 | + TICKER_USER_ID_LLL, 0, &mfy); |
| 981 | + LL_ASSERT(!ret); |
| 982 | + } |
| 983 | +} |
| 984 | +#endif /* CONFIG_BT_CTLR_ADV_EXT && CONFIG_BT_CTLR_PHY_CODED */ |
| 985 | + |
918 | 986 | static void ticker_op_cb(uint32_t status, void *param) |
919 | 987 | { |
920 | 988 | ARG_UNUSED(param); |
|
0 commit comments