nRF Connect SDK API 3.3.99
Loading...
Searching...
No Matches
bt_le_audio_tx.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
15#ifndef _LE_AUDIO_TX_H_
16#define _LE_AUDIO_TX_H_
17
18#include <zephyr/net_buf.h>
19#include <zephyr/sys/atomic.h>
20#include <zephyr/bluetooth/audio/audio.h>
21#include <zephyr/bluetooth/audio/bap.h>
22#include <zephyr/bluetooth/audio/cap.h>
23
24#include "le_audio.h"
25
28 struct bt_cap_stream *cap_stream;
30};
31
33
34#define HCI_ISO_BUF_PER_CHAN 2
35
36#if defined(CONFIG_BT_ISO_MAX_CIG) && defined(CONFIG_BT_ISO_MAX_BIG)
37#define GROUP_MAX (CONFIG_BT_ISO_MAX_BIG + CONFIG_BT_ISO_MAX_CIG)
38#elif defined(CONFIG_BT_ISO_MAX_CIG)
39#define GROUP_MAX CONFIG_BT_ISO_MAX_CIG
40#elif defined(CONFIG_BT_ISO_MAX_BIG)
41#define GROUP_MAX CONFIG_BT_ISO_MAX_BIG
42#else
43#error Neither CIG nor BIG defined
44#endif
45
46#if (defined(CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT) && defined(CONFIG_BT_BAP_UNICAST))
47#define SUBGROUP_MAX (1 + CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT)
48#elif (defined(CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT) && !defined(CONFIG_BT_BAP_UNICAST))
49#define SUBGROUP_MAX CONFIG_BT_BAP_BROADCAST_SRC_SUBGROUP_COUNT
50#else
51#define SUBGROUP_MAX 1
52#endif
53
54#define TX_STREAMS_MAX CONFIG_BT_ISO_MAX_CHAN
55
56#define TX_BUF_NUM (GROUP_MAX * SUBGROUP_MAX * TX_STREAMS_MAX * HCI_ISO_BUF_PER_CHAN)
57
59 STATUS_NOT_SET = 0, /* Initial status */
60 STATUS_SENT_WITH_TS, /* Data sent with timestamp */
61 STATUS_SENT_WITHOUT_TS, /* Data sent without timestamp */
62 STATUS_OVERRUN_FLUSHED, /* Data overrun, flushed */
63 STATUS_UNDERRUN_EMPTY_SDU_ON_AIR, /* Data underrun, empty SDU on air */
64};
65
66struct tx_inf {
68 struct bt_iso_tx_info iso_tx;
69 struct bt_iso_tx_info iso_tx_readback;
72};
73
75 struct net_buf_pool *iso_tx_pool;
77 /* Estimated timestamp from the controller and validity */
80 /* Real timestamp from the controller */
82 /* Timestamp - when the last correction was applied */
84 /* Counter to track subsequent rapid corrections. Indicates an error state */
86 /* Correction between estimated and real timestamps */
87 int64_t corr_diff_us;
88 /* The previous "now" timestamp and validity */
89 uint32_t ts_last_us;
91 /* This device is Bluetooth clock master (central/unicast client or broadcast source) */
93 /* Status of the last submitted data */
95};
96
97#define BT_LE_AUDIO_TX_DEFINE(name) \
98 NET_BUF_POOL_FIXED_DEFINE(name##_cfg_buf, TX_BUF_NUM, \
99 BT_ISO_SDU_BUF_SIZE(CONFIG_BT_ISO_TX_MTU), \
100 CONFIG_BT_CONN_TX_USER_DATA_SIZE, NULL); \
101 static struct bt_le_audio_tx_ctx name##_ctx = { \
102 .iso_tx_pool = &name##_cfg_buf, \
103 }; \
104 static struct bt_le_audio_tx_ctx *name = &name##_ctx
105
126int bt_le_audio_tx_send(struct bt_le_audio_tx_ctx *ctx, struct net_buf const *const audio_frame,
127 struct le_audio_tx_info *tx, uint8_t num_tx);
128
140
152
164int bt_le_audio_tx_init(struct bt_le_audio_tx_ctx *ctx, bool is_clock_master);
165
172#endif /* _LE_AUDIO_TX_H_ */
int bt_le_audio_tx_stream_started(struct bt_le_audio_tx_ctx *ctx, struct stream_index stream_idx)
Initializes a stream. Must be called when a TX stream is started.
int bt_le_audio_tx_send(struct bt_le_audio_tx_ctx *ctx, struct net_buf const *const audio_frame, struct le_audio_tx_info *tx, uint8_t num_tx)
Allocates buffers and sends data to the controller.
int bt_le_audio_tx_stream_sent(struct bt_le_audio_tx_ctx *ctx, struct stream_index stream_idx)
Frees a TX buffer. Must be called when a TX stream has been sent.
int bt_le_audio_tx_init(struct bt_le_audio_tx_ctx *ctx, bool is_clock_master)
Initializes the TX path for ISO transmission.
bt_le_audio_tx_last_data_status
Definition bt_le_audio_tx.h:58
@ STATUS_SENT_WITH_TS
Definition bt_le_audio_tx.h:60
@ STATUS_UNDERRUN_EMPTY_SDU_ON_AIR
Definition bt_le_audio_tx.h:63
@ STATUS_SENT_WITHOUT_TS
Definition bt_le_audio_tx.h:61
@ STATUS_OVERRUN_FLUSHED
Definition bt_le_audio_tx.h:62
@ STATUS_NOT_SET
Definition bt_le_audio_tx.h:59
#define SUBGROUP_MAX
Definition bt_le_audio_tx.h:51
#define TX_STREAMS_MAX
Definition bt_le_audio_tx.h:54
bool is_ble_clock_master
Definition bt_le_audio_tx.h:92
struct net_buf_pool * iso_tx_pool
Definition bt_le_audio_tx.h:75
bool ts_ctlr_esti_us_valid
Definition bt_le_audio_tx.h:79
bool ts_last_us_valid
Definition bt_le_audio_tx.h:90
uint32_t ts_ctlr_real_us_last
Definition bt_le_audio_tx.h:81
uint32_t ts_last_us
Definition bt_le_audio_tx.h:89
uint32_t subsequent_rapid_corrections
Definition bt_le_audio_tx.h:85
uint32_t ts_ctlr_esti_us
Definition bt_le_audio_tx.h:78
int64_t corr_diff_us
Definition bt_le_audio_tx.h:87
enum bt_le_audio_tx_last_data_status last_data_status
Definition bt_le_audio_tx.h:94
uint32_t ts_last_correction
Definition bt_le_audio_tx.h:83
struct tx_inf tx_info_arr[GROUP_MAX][1][CONFIG_BT_ISO_MAX_CHAN]
Definition bt_le_audio_tx.h:76
Definition bt_le_audio_tx.h:74
struct bt_cap_stream * cap_stream
Definition bt_le_audio_tx.h:28
struct stream_index idx
Definition bt_le_audio_tx.h:27
uint8_t audio_location
Definition bt_le_audio_tx.h:29
Definition bt_le_audio_tx.h:26
Stream index structure for identifying audio streams.
Definition le_audio.h:75
struct bt_iso_tx_info iso_tx
Definition bt_le_audio_tx.h:68
bool hci_wrn_printed
Definition bt_le_audio_tx.h:71
atomic_t iso_tx_pool_alloc
Definition bt_le_audio_tx.h:70
struct bt_iso_tx_info iso_tx_readback
Definition bt_le_audio_tx.h:69
uint16_t iso_conn_handle
Definition bt_le_audio_tx.h:67
Definition bt_le_audio_tx.h:66