这个页面的 最新开发版本 可能比这个发布的 2.3-beta.1 版本新。

数据缓冲区

API 参考

group bt_buf

Data buffers.

Defines

BT_BUF_RESERVE
BT_BUF_SIZE(size)

Helper to include reserved HCI data in buffer calculations

BT_BUF_ACL_SIZE(size)

Helper to calculate needed buffer size for HCI ACL packets

BT_BUF_EVT_SIZE(size)

Helper to calculate needed buffer size for HCI Event packets.

BT_BUF_CMD_SIZE(size)

Helper to calculate needed buffer size for HCI Command packets.

BT_BUF_ISO_SIZE(size)

Helper to calculate needed buffer size for HCI ISO packets.

BT_BUF_ACL_RX_SIZE

Data size needed for HCI ACL RX buffers

BT_BUF_EVT_RX_SIZE

Data size needed for HCI Event RX buffers

BT_BUF_ISO_RX_SIZE
BT_BUF_ISO_RX_COUNT
BT_BUF_RX_SIZE

Data size needed for HCI ACL, HCI ISO or Event RX buffers

BT_BUF_RX_COUNT

Buffer count needed for HCI ACL, HCI ISO or Event RX buffers

BT_BUF_CMD_TX_SIZE

Data size needed for HCI Command buffers.

Enums

enum bt_buf_type

Possible types of buffers passed around the Bluetooth stack

Values:

enumerator BT_BUF_CMD

HCI command

enumerator BT_BUF_EVT

HCI event

enumerator BT_BUF_ACL_OUT

Outgoing ACL data

enumerator BT_BUF_ACL_IN

Incoming ACL data

enumerator BT_BUF_ISO_OUT

Outgoing ISO data

enumerator BT_BUF_ISO_IN

Incoming ISO data

enumerator BT_BUF_H4

H:4 data

Functions

struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)

Allocate a buffer for incoming data

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_recv_prio().

参数:
  • type – Type of buffer. Only BT_BUF_EVT, BT_BUF_ACL_IN and BT_BUF_ISO_IN are allowed.

  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

返回:

A new buffer.

struct net_buf *bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, const void *data, size_t size)

Allocate a buffer for outgoing data

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_send().

参数:
  • type – Type of buffer. Only BT_BUF_CMD, BT_BUF_ACL_OUT or BT_BUF_H4, when operating on H:4 mode, are allowed.

  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

  • data – Initial data to append to buffer.

  • size – Initial data size.

返回:

A new buffer.

struct net_buf *bt_buf_get_cmd_complete(k_timeout_t timeout)

Allocate a buffer for an HCI Command Complete/Status Event

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_recv_prio().

参数:

timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

返回:

A new buffer.

struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout)

Allocate a buffer for an HCI Event

This will set the buffer type so bt_buf_set_type() does not need to be explicitly called before bt_recv_prio() or bt_recv().

参数:
  • evt – HCI event code

  • discardable – Whether the driver considers the event discardable.

  • timeout – Non-negative waiting period to obtain a buffer or one of the special values K_NO_WAIT and K_FOREVER.

返回:

A new buffer.

static inline void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)

Set the buffer type

参数:
  • buf – Bluetooth buffer

  • type – The BT_* type to set the buffer to

static inline enum bt_buf_type bt_buf_get_type(struct net_buf *buf)

Get the buffer type

参数:

buf – Bluetooth buffer

返回:

The BT_* type to of the buffer

void bt_buf_init(void)

Init bt buffer lifo queue.

void bt_buf_deinit(void)

DeInit bt buffer lifo queue.

struct bt_buf_data

This is a base type for bt_buf user data.