Zephyr Project API
3.4.0
A Scalable Open Source RTOS
buf.h
Go to the documentation of this file.
1
5
/*
6
* Copyright (c) 2016 Intel Corporation
7
*
8
* SPDX-License-Identifier: Apache-2.0
9
*/
10
11
#ifndef ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
12
#define ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_
13
21
#include <
stdint.h
>
22
23
#include <
zephyr/net/buf.h
>
24
#include <
zephyr/bluetooth/hci.h
>
25
#include <
zephyr/sys/util.h
>
26
27
#ifdef __cplusplus
28
extern
"C"
{
29
#endif
30
32
enum
bt_buf_type
{
34
BT_BUF_CMD
,
36
BT_BUF_EVT
,
38
BT_BUF_ACL_OUT
,
40
BT_BUF_ACL_IN
,
42
BT_BUF_ISO_OUT
,
44
BT_BUF_ISO_IN
,
46
BT_BUF_H4
,
47
};
48
50
struct
bt_buf_data
{
51
uint8_t
type
;
52
};
53
54
#if defined(CONFIG_BT_HCI_RAW)
55
#define BT_BUF_RESERVE MAX(CONFIG_BT_HCI_RESERVE, CONFIG_BT_HCI_RAW_RESERVE)
56
#else
57
#define BT_BUF_RESERVE CONFIG_BT_HCI_RESERVE
58
#endif
59
61
#define BT_BUF_SIZE(size) (BT_BUF_RESERVE + (size))
62
64
#define BT_BUF_ACL_SIZE(size) BT_BUF_SIZE(BT_HCI_ACL_HDR_SIZE + (size))
65
67
#define BT_BUF_EVT_SIZE(size) BT_BUF_SIZE(BT_HCI_EVT_HDR_SIZE + (size))
68
70
#define BT_BUF_CMD_SIZE(size) BT_BUF_SIZE(BT_HCI_CMD_HDR_SIZE + (size))
71
73
#define BT_BUF_ISO_SIZE(size) BT_BUF_SIZE(BT_HCI_ISO_HDR_SIZE + \
74
BT_HCI_ISO_TS_DATA_HDR_SIZE + \
75
(size))
76
78
#define BT_BUF_ACL_RX_SIZE BT_BUF_ACL_SIZE(CONFIG_BT_BUF_ACL_RX_SIZE)
79
81
#define BT_BUF_EVT_RX_SIZE BT_BUF_EVT_SIZE(CONFIG_BT_BUF_EVT_RX_SIZE)
82
83
#if defined(CONFIG_BT_ISO)
84
#define BT_BUF_ISO_RX_SIZE BT_BUF_ISO_SIZE(CONFIG_BT_ISO_RX_MTU)
85
#define BT_BUF_ISO_RX_COUNT CONFIG_BT_ISO_RX_BUF_COUNT
86
#else
87
#define BT_BUF_ISO_RX_SIZE 0
88
#define BT_BUF_ISO_RX_COUNT 0
89
#endif
/* CONFIG_BT_ISO */
90
92
#define BT_BUF_RX_SIZE (MAX(MAX(BT_BUF_ACL_RX_SIZE, BT_BUF_EVT_RX_SIZE), \
93
BT_BUF_ISO_RX_SIZE))
94
96
#define BT_BUF_RX_COUNT (MAX(MAX(CONFIG_BT_BUF_EVT_RX_COUNT, \
97
CONFIG_BT_BUF_ACL_RX_COUNT), \
98
BT_BUF_ISO_RX_COUNT))
99
101
#define BT_BUF_CMD_TX_SIZE BT_BUF_CMD_SIZE(CONFIG_BT_BUF_CMD_TX_SIZE)
102
114
struct
net_buf
*
bt_buf_get_rx
(
enum
bt_buf_type
type,
k_timeout_t
timeout
);
115
129
struct
net_buf
*
bt_buf_get_tx
(
enum
bt_buf_type
type,
k_timeout_t
timeout
,
130
const
void
*
data
,
size_t
size
);
131
141
struct
net_buf
*
bt_buf_get_cmd_complete
(
k_timeout_t
timeout
);
142
154
struct
net_buf
*
bt_buf_get_evt
(
uint8_t
evt,
bool
discardable,
k_timeout_t
timeout
);
155
161
static
inline
void
bt_buf_set_type
(
struct
net_buf
*buf,
enum
bt_buf_type
type)
162
{
163
((
struct
bt_buf_data
*)
net_buf_user_data
(buf))->
type
=
type
;
164
}
165
172
static
inline
enum
bt_buf_type
bt_buf_get_type
(
struct
net_buf
*buf)
173
{
174
return
(
enum
bt_buf_type
)((
struct
bt_buf_data
*)
net_buf_user_data
(buf))
175
->
type
;
176
}
177
182
#ifdef __cplusplus
183
}
184
#endif
185
186
#endif
/* ZEPHYR_INCLUDE_BLUETOOTH_BUF_H_ */
timeout
ZTEST_BMEM int timeout
Definition:
main.c:31
bt_buf_get_type
static enum bt_buf_type bt_buf_get_type(struct net_buf *buf)
Definition:
buf.h:172
bt_buf_get_rx
struct net_buf * bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)
bt_buf_get_tx
struct net_buf * bt_buf_get_tx(enum bt_buf_type type, k_timeout_t timeout, const void *data, size_t size)
bt_buf_get_evt
struct net_buf * bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeout)
bt_buf_get_cmd_complete
struct net_buf * bt_buf_get_cmd_complete(k_timeout_t timeout)
bt_buf_set_type
static void bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
Definition:
buf.h:161
bt_buf_type
bt_buf_type
Definition:
buf.h:32
BT_BUF_EVT
@ BT_BUF_EVT
Definition:
buf.h:36
BT_BUF_ISO_OUT
@ BT_BUF_ISO_OUT
Definition:
buf.h:42
BT_BUF_ACL_OUT
@ BT_BUF_ACL_OUT
Definition:
buf.h:38
BT_BUF_ISO_IN
@ BT_BUF_ISO_IN
Definition:
buf.h:44
BT_BUF_CMD
@ BT_BUF_CMD
Definition:
buf.h:34
BT_BUF_H4
@ BT_BUF_H4
Definition:
buf.h:46
BT_BUF_ACL_IN
@ BT_BUF_ACL_IN
Definition:
buf.h:40
net_buf_user_data
static void * net_buf_user_data(const struct net_buf *buf)
Get a pointer to the user data of a buffer.
Definition:
buf.h:1464
hci.h
buf.h
Buffer management.
stdint.h
uint8_t
__UINT8_TYPE__ uint8_t
Definition:
stdint.h:88
bt_buf_data
This is a base type for bt_buf user data.
Definition:
buf.h:50
bt_buf_data::type
uint8_t type
Definition:
buf.h:51
k_timeout_t
Kernel timeout type.
Definition:
sys_clock.h:65
net_buf
Network buffer representation.
Definition:
buf.h:906
net_buf::size
uint16_t size
Definition:
buf.h:938
data
static fdata_t data[2]
Definition:
test_fifo_contexts.c:15
util.h
Misc utilities.
include
zephyr
bluetooth
buf.h
Generated on Sat Jun 17 2023 07:48:26 for Zephyr Project API by
1.9.2