1 /*
2  * Copyright (c) 2020-2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /* Calculate ISO PDU buffers required considering SDU fragmentation */
8 #if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO)
9 /* Internal ISO Tx SDU maximum length.
10  * A length that is minimum of the resultant combination of the HCI ISO data fragments provided and
11  * the user configured maximum transmit SDU length (CONFIG_BT_CTLR_ISO_TX_SDU_LEN_MAX).
12  */
13 #define BT_CTLR_ISO_TX_SDU_LEN_MAX MIN(((CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE * \
14 					 CONFIG_BT_CTLR_ISO_TX_BUFFERS) - \
15 					BT_HCI_ISO_SDU_HDR_SIZE), \
16 				       CONFIG_BT_CTLR_ISO_TX_SDU_LEN_MAX)
17 
18 BUILD_ASSERT(BT_CTLR_ISO_TX_SDU_LEN_MAX == CONFIG_BT_CTLR_ISO_TX_SDU_LEN_MAX,
19 	     "Insufficient ISO Buffer Size and Count for the required ISO SDU Length");
20 
21 /* Internal ISO Tx buffers to be allocated.
22  * Based on the internal ISO Tx SDU maximum length, calculate the required ISO Tx buffers (PDUs)
23  * required to fragment the SDU into PDU sizes scheduled for transmission.
24  */
25 /* Defines the minimum required PDU length to help calculate the number of PDU buffers required
26  * At least one of CONFIG_BT_CTLR_ADV_ISO or CONFIG_BT_CTLR_CONN_ISO will always be enabled,
27  * so if either of them is not defined, it can default to the other
28  */
29 #define BT_CTLR_ISO_TX_MIN_PDU_LEN \
30 	MIN(COND_CODE_1(IS_ENABLED(CONFIG_BT_CTLR_ADV_ISO), \
31 			(CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX), \
32 			(CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX)), \
33 	    COND_CODE_1(IS_ENABLED(CONFIG_BT_CTLR_CONN_ISO), \
34 			(CONFIG_BT_CTLR_CONN_ISO_PDU_LEN_MAX), \
35 			(CONFIG_BT_CTLR_ADV_ISO_PDU_LEN_MAX)))
36 #define BT_CTLR_ISO_TX_PDU_BUFFERS \
37 	(DIV_ROUND_UP(BT_CTLR_ISO_TX_SDU_LEN_MAX, \
38 		      MIN((CONFIG_BT_CTLR_ISO_TX_BUFFER_SIZE - BT_HCI_ISO_SDU_TS_HDR_SIZE), \
39 			  BT_CTLR_ISO_TX_MIN_PDU_LEN)) * \
40 	 CONFIG_BT_CTLR_ISO_TX_BUFFERS)
41 #else /* !CONFIG_BT_CTLR_ADV_ISO && !CONFIG_BT_CTLR_CONN_ISO */
42 #define BT_CTLR_ISO_TX_PDU_BUFFERS 0
43 #endif /* !CONFIG_BT_CTLR_ADV_ISO && !CONFIG_BT_CTLR_CONN_ISO */
44 
45 int ull_iso_init(void);
46 int ull_iso_reset(void);
47 struct ll_iso_datapath *ull_iso_datapath_alloc(void);
48 void ull_iso_datapath_release(struct ll_iso_datapath *dp);
49 void ll_iso_rx_put(memq_link_t *link, void *rx);
50 void *ll_iso_rx_get(void);
51 void ll_iso_rx_dequeue(void);
52 void ll_iso_transmit_test_send_sdu(uint16_t handle, uint32_t ticks_at_expire);
53 uint32_t ull_iso_big_sync_delay(uint8_t num_bis, uint32_t bis_spacing, uint8_t nse,
54 				uint32_t sub_interval, uint8_t phy, uint8_t max_pdu, bool enc);
55 
56 /* Must be implemented by vendor if vendor-specific data path is supported */
57 bool ll_data_path_configured(uint8_t data_path_dir, uint8_t data_path_id);
58 /* Must be implemented by vendor if vendor-specific data path is supported */
59 bool ll_data_path_sink_create(uint16_t handle,
60 			      struct ll_iso_datapath *datapath,
61 			      isoal_sink_sdu_alloc_cb *sdu_alloc,
62 			      isoal_sink_sdu_emit_cb *sdu_emit,
63 			      isoal_sink_sdu_write_cb *sdu_write);
64 /* Must be implemented by vendor if vendor-specific data path is supported */
65 bool ll_data_path_source_create(uint16_t handle,
66 				struct ll_iso_datapath *datapath,
67 				isoal_source_pdu_alloc_cb *pdu_alloc,
68 				isoal_source_pdu_write_cb *pdu_write,
69 				isoal_source_pdu_emit_cb *pdu_emit,
70 				isoal_source_pdu_release_cb *pdu_release);
71 
72 /* Must be implemented by vendor if vendor-specific data path is supported */
73 void ll_data_path_tx_pdu_release(uint16_t handle, struct node_tx_iso *node_tx);
74 
75 void ull_iso_resume_ticker_start(struct lll_event *resume_event,
76 				 uint16_t group_handle,
77 				 uint16_t stream_handle,
78 				 uint8_t  role,
79 				 uint32_t ticks_anchor,
80 				 uint32_t resume_timeout);
81