|
21 | 21 | #include "util/mayfly.h" |
22 | 22 | #include "util/dbuf.h" |
23 | 23 |
|
| 24 | +#include "ticker/ticker.h" |
| 25 | + |
24 | 26 | #include "pdu_df.h" |
25 | 27 | #include "lll/pdu_vendor.h" |
26 | 28 | #include "pdu.h" |
|
36 | 38 | #include "lll_conn.h" |
37 | 39 | #include "lll_conn_iso.h" |
38 | 40 | #include "lll_iso_tx.h" |
| 41 | +#include "lll/lll_vendor.h" |
39 | 42 |
|
40 | 43 | #include "ll_sw/ull_tx_queue.h" |
41 | 44 |
|
@@ -107,6 +110,11 @@ static struct ll_iso_datapath datapath_pool[BT_CTLR_ISO_STREAMS]; |
107 | 110 | static void *datapath_free; |
108 | 111 |
|
109 | 112 | #if defined(CONFIG_BT_CTLR_SYNC_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO) |
| 113 | +static void ticker_resume_op_cb(uint32_t status, void *param); |
| 114 | +static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, |
| 115 | + uint32_t remainder, uint16_t lazy, uint8_t force, |
| 116 | + void *param); |
| 117 | + |
110 | 118 | #define NODE_RX_HEADER_SIZE (offsetof(struct node_rx_pdu, pdu)) |
111 | 119 | /* ISO LL conformance tests require a PDU size of maximum 251 bytes + header */ |
112 | 120 | #define ISO_RX_BUFFER_SIZE (2 + 251) |
@@ -1973,3 +1981,128 @@ static int init_reset(void) |
1973 | 1981 |
|
1974 | 1982 | return 0; |
1975 | 1983 | } |
| 1984 | + |
| 1985 | +#if defined(CONFIG_BT_CTLR_CONN_ISO) || defined(CONFIG_BT_CTLR_SYNC_ISO) |
| 1986 | +void ull_iso_resume_ticker_start(struct lll_event *resume_event, |
| 1987 | + uint16_t group_handle, |
| 1988 | + uint16_t stream_handle, |
| 1989 | + uint8_t role, |
| 1990 | + uint32_t ticks_anchor, |
| 1991 | + uint32_t resume_timeout) |
| 1992 | +{ |
| 1993 | + uint32_t resume_delay_us; |
| 1994 | + int32_t resume_offset_us; |
| 1995 | + uint8_t ticker_id = 0; |
| 1996 | + uint32_t ret; |
| 1997 | + |
| 1998 | + resume_delay_us = EVENT_OVERHEAD_START_US; |
| 1999 | + resume_delay_us += EVENT_TICKER_RES_MARGIN_US; |
| 2000 | + |
| 2001 | + if (0) { |
| 2002 | +#if defined(CONFIG_BT_CTLR_CONN_ISO) |
| 2003 | + } else if (IS_CIS_HANDLE(stream_handle)) { |
| 2004 | + ticker_id = TICKER_ID_CONN_ISO_RESUME_BASE + group_handle; |
| 2005 | +#endif /* CONFIG_BT_CTLR_CONN_ISO */ |
| 2006 | +#if defined(CONFIG_BT_CTLR_SYNC_ISO) |
| 2007 | + } else if (IS_SYNC_ISO_HANDLE(stream_handle)) { |
| 2008 | + ticker_id = TICKER_ID_SCAN_SYNC_ISO_RESUME_BASE + group_handle; |
| 2009 | +#endif /* CONFIG_BT_CTLR_SYNC_ISO */ |
| 2010 | + } else { |
| 2011 | + LL_ASSERT(0); |
| 2012 | + } |
| 2013 | + |
| 2014 | + if (role == BT_HCI_ROLE_PERIPHERAL) { |
| 2015 | + /* Add peripheral specific delay */ |
| 2016 | + resume_delay_us += EVENT_JITTER_US; |
| 2017 | + if (0) { |
| 2018 | +#if defined(CONFIG_BT_CTLR_PHY) |
| 2019 | + } else { |
| 2020 | + uint8_t phy = 0; |
| 2021 | + |
| 2022 | + if (0) { |
| 2023 | +#if defined(CONFIG_BT_CTLR_CONN_ISO) |
| 2024 | + } else if (IS_CIS_HANDLE(stream_handle)) { |
| 2025 | + struct ll_conn_iso_stream *cis; |
| 2026 | + struct ll_conn *conn; |
| 2027 | + |
| 2028 | + cis = ll_conn_iso_stream_get(stream_handle); |
| 2029 | + conn = ll_conn_get(cis->lll.acl_handle); |
| 2030 | + phy = conn->lll.phy_rx; |
| 2031 | +#endif /* CONFIG_BT_CTLR_CONN_ISO */ |
| 2032 | +#if defined(CONFIG_BT_CTLR_SYNC_ISO) |
| 2033 | + } else if (IS_SYNC_ISO_HANDLE(stream_handle)) { |
| 2034 | + struct ll_sync_iso_set *sync_iso; |
| 2035 | + uint16_t stream_idx; |
| 2036 | + |
| 2037 | + stream_idx = LL_BIS_SYNC_IDX_FROM_HANDLE(stream_handle); |
| 2038 | + sync_iso = ull_sync_iso_by_stream_get(stream_idx); |
| 2039 | + phy = sync_iso->lll.phy; |
| 2040 | +#endif /* CONFIG_BT_CTLR_SYNC_ISO */ |
| 2041 | + } else { |
| 2042 | + LL_ASSERT(0); |
| 2043 | + } |
| 2044 | + |
| 2045 | + resume_delay_us += |
| 2046 | + lll_radio_rx_ready_delay_get(phy, PHY_FLAGS_S8); |
| 2047 | +#else |
| 2048 | + } else { |
| 2049 | + resume_delay_us += lll_radio_rx_ready_delay_get(0, 0); |
| 2050 | +#endif /* CONFIG_BT_CTLR_PHY */ |
| 2051 | + } |
| 2052 | + } |
| 2053 | + |
| 2054 | + resume_offset_us = (int32_t)(resume_timeout - resume_delay_us); |
| 2055 | + LL_ASSERT(resume_offset_us >= 0); |
| 2056 | + |
| 2057 | + /* Setup resume timeout as single-shot */ |
| 2058 | + ret = ticker_start(TICKER_INSTANCE_ID_CTLR, |
| 2059 | + TICKER_USER_ID_LLL, |
| 2060 | + ticker_id, |
| 2061 | + ticks_anchor, |
| 2062 | + HAL_TICKER_US_TO_TICKS(resume_offset_us), |
| 2063 | + TICKER_NULL_PERIOD, |
| 2064 | + TICKER_NULL_REMAINDER, |
| 2065 | + TICKER_NULL_LAZY, |
| 2066 | + TICKER_NULL_SLOT, |
| 2067 | + ticker_resume_cb, resume_event, |
| 2068 | + ticker_resume_op_cb, NULL); |
| 2069 | + |
| 2070 | + LL_ASSERT((ret == TICKER_STATUS_SUCCESS) || |
| 2071 | + (ret == TICKER_STATUS_BUSY)); |
| 2072 | +} |
| 2073 | + |
| 2074 | +static void ticker_resume_op_cb(uint32_t status, void *param) |
| 2075 | +{ |
| 2076 | + ARG_UNUSED(param); |
| 2077 | + |
| 2078 | + LL_ASSERT(status == TICKER_STATUS_SUCCESS); |
| 2079 | +} |
| 2080 | + |
| 2081 | +static void ticker_resume_cb(uint32_t ticks_at_expire, uint32_t ticks_drift, |
| 2082 | + uint32_t remainder, uint16_t lazy, uint8_t force, |
| 2083 | + void *param) |
| 2084 | +{ |
| 2085 | + static memq_link_t link; |
| 2086 | + static struct mayfly mfy = {0, 0, &link, NULL, lll_resume}; |
| 2087 | + struct lll_event *resume_event; |
| 2088 | + uint32_t ret; |
| 2089 | + |
| 2090 | + ARG_UNUSED(ticks_drift); |
| 2091 | + LL_ASSERT(lazy == 0); |
| 2092 | + |
| 2093 | + resume_event = param; |
| 2094 | + |
| 2095 | + /* Append timing parameters */ |
| 2096 | + resume_event->prepare_param.ticks_at_expire = ticks_at_expire; |
| 2097 | + resume_event->prepare_param.remainder = remainder; |
| 2098 | + resume_event->prepare_param.lazy = 0; |
| 2099 | + resume_event->prepare_param.force = force; |
| 2100 | + mfy.param = resume_event; |
| 2101 | + |
| 2102 | + /* Kick LLL resume */ |
| 2103 | + ret = mayfly_enqueue(TICKER_USER_ID_ULL_HIGH, TICKER_USER_ID_LLL, |
| 2104 | + 0, &mfy); |
| 2105 | + |
| 2106 | + LL_ASSERT(!ret); |
| 2107 | +} |
| 2108 | +#endif /* CONFIG_BT_CTLR_CONN_ISO || CONFIG_BT_CTLR_SYNC_ISO */ |
0 commit comments