|
| #define | ZB_RESERVED_BUF_TO_ALIGN_HDR_SIZE 1u |
| |
| #define | ZB_BUF_INVALID 0U |
| |
| #define | ZB_UNDEFINED_BUFFER 0U |
| |
| #define | TRACE_PROTO_VOID void |
| |
| #define | TRACE_PROTO |
| |
| #define | TRACE_CALL_VOID |
| |
| #define | TRACE_CALL |
| |
| #define | ZB_TRACE_BUFS_USAGE() |
| |
| #define | zb_buf_get(is_in, max_size) zb_buf_get_func(TRACE_CALL (is_in), (max_size)) |
| |
| #define | zb_buf_get_out() zb_buf_get_out_func(TRACE_CALL_VOID) |
| |
| #define | zb_buf_get_any() zb_buf_get_any_func(TRACE_CALL_VOID) |
| |
| #define | zb_buf_get_hipri(a) zb_buf_get_hipri_func(TRACE_CALL (a)) |
| |
| #define | zb_buf_get_max_size(a) zb_buf_get_max_size_func(TRACE_CALL (a)) |
| |
| #define | zb_buf_get_out_delayed(callback) zb_buf_get_out_delayed_func(TRACE_CALL (callback)) |
| | Allocate OUT buffer, call a callback when the buffer is available. More...
|
| |
| #define | zb_buf_get_in_delayed(callback) zb_buf_get_in_delayed_func(TRACE_CALL (callback)) |
| | Allocate IN buffer, call a callback when the buffer is available. More...
|
| |
| #define | zb_buf_get_out_delayed_ext(callback, arg, max_size) zb_buf_get_out_delayed_ext_func(TRACE_CALL (callback),(arg),(max_size)) |
| | Allocate OUT buffer, call a callback when the buffer is available. More...
|
| |
| #define | zb_buf_get_in_delayed_ext(callback, arg, max_size) zb_buf_get_in_delayed_ext_func(TRACE_CALL (callback),(arg),(max_size)) |
| | Allocate IN buffer, call a callback when the buffer is available. More...
|
| |
| #define | zb_buf_free(buf) zb_buf_free_func(TRACE_CALL (buf)) |
| | Free packet buffer and put it into free list. More...
|
| |
| #define | zb_buf_begin(buf) zb_buf_begin_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_end(buf) zb_buf_end_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_len(buf) zb_buf_len_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_copy(dst_buf, src_buf) zb_buf_copy_func(TRACE_CALL (dst_buf),(src_buf)) |
| |
| #define | zb_buf_initial_alloc(buf, size) zb_buf_initial_alloc_func(TRACE_CALL (buf),(size)) |
| | Initial data space allocation in buffer. More...
|
| |
| #define | zb_buf_reuse(buf) zb_buf_reuse_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_alloc_tail(buf, size) zb_buf_alloc_tail_func(TRACE_CALL (buf),(size)) |
| |
| #define | zb_buf_get_tail(buf, size) zb_buf_get_tail_func(TRACE_CALL (buf),(size)) |
| |
| #define | ZB_BUF_GET_PARAM(buf, type) ((type *)zb_buf_get_tail_func(TRACE_CALL (buf), sizeof(type))) |
| |
| #define | zb_buf_cut_right(buf, size) zb_buf_cut_right_func(TRACE_CALL (buf),(size)) |
| |
| #define | zb_buf_cut_left(buf, size) zb_buf_cut_left_func(TRACE_CALL (buf),(size)) |
| |
| #define | zb_buf_alloc_right(buf, size) zb_buf_alloc_right_func(TRACE_CALL (buf),(size)) |
| |
| #define | zb_buf_alloc_left(buf, size) zb_buf_alloc_left_func(TRACE_CALL (buf),(size)) |
| |
| #define | zb_buf_flags_or(buf, val) zb_buf_flags_or_func(TRACE_CALL (buf),(val)) |
| |
| #define | zb_buf_flags_clr(buf, mask) zb_buf_flags_clr_func(TRACE_CALL (buf),(mask)) |
| |
| #define | zb_buf_flags_clr_encr(buf) zb_buf_flags_clr_encr_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_flags_get(buf) zb_buf_flags_get_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_get_status(buf) zb_buf_get_status_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_set_status(buf, status) zb_buf_set_status_func(TRACE_CALL (buf), (zb_ret_t)(status)) |
| |
| #define | zb_buf_get_handle(buf) zb_buf_get_handle_func(TRACE_CALL (buf)) |
| |
| #define | zb_buf_set_handle(buf, handle) zb_buf_set_handle_func(TRACE_CALL (buf),(handle)) |
| |
| #define | ZB_BUF_COPY_FLAG_APS_PAYLOAD(dst, src) |
| |
- Packet buffers
The main idea is to be simple, CPU effective and eliminate data copy when possible (again, to decrease CPU load).
One of the main data structure of the ZBOSS stack is memory buffer, which is used for storing Zigbee packet. Zigbee packets has limited size (127 bytes). Zigbee packets are usually not fragmented, excluding fragmentation of big packets at APS layer. Extended buffers are used to store big packets.
To use extended buffers in application use zb_buf_get_out_delayed_ext() and zb_buf_get_in_delayed_ext() functions.
So, the same memory buffer can be used for a single packet going down-up or up-down between the user application and ZBOSS layers. Each layer or the application can modify the memory buffer: remove data partly or fully or add more data if there is free memory space in the buffer.
ZBOSS uses pre-defined pool of the fixed size memory buffers. The size of buffer pool can be changed, see more information about it in Memory configuration feature. A memory buffer consists of a header and a data buffer of 148 bytes. An application or the stack functions can get a single memory buffer from the pool (allocate the memory buffer) when it is necessary or put the buffer back when it is not needed anymore (release the memory buffer).
Every buffer has a header with these header fields:
- current layer data pointer
- current layer length
- 'status' for 'confirm' interface
- 'handle' for data and confirm interfaces
- flags
To avoid data copying, the following technique is used: when a Zigbee packet moves up between the Zigbee layers, the data related to the lower layers is removed by modifying the data pointer and data length in the buffer header. When a Zigbee packet is passing down between the Zigbee layers, the initial data is stored not from the beginning of the data buffer, but in the middle, so some space is reserved before and after the data. Therefore, if a lower Zigbee layer puts some data to a header or to a tail, data copying is generally not required. However, if there is not enough space for a header or a tail, the existing data may be moved to the right or to the left.
Logically, the memory buffers are divided into 2 types: for in and out packets. Thus, the buffer pool allocates both 'in' and 'out' types of buffers. This approach helps prevent allocating of all the memory buffers for incoming or outgoing packets, only those that may block ZBOSS from sending or receiving respectively any data. Obviously, such blocking may cause a scenario where it is impossible to send an acknowledgement for the received packet and the packet will be retransmitted by a remote due to the lack of the acknowledgement.
Memory buffers are commonly used for passing parameters to ZBOSS API functions. The following technique is used: data space needed for storing the parameters is allocated in the memory buffer at the end of its data buffer. The limitation is that both a caller and called functions must be aware of the parameter sizes, so it makes it impossible to pass parameters with a variable length. Special helpers are provided for storing and getting parameters form the memory buffer: ZB_BUF_GET_PARAM().
§ TRACE_CALL
§ TRACE_CALL_VOID
§ TRACE_PROTO
§ TRACE_PROTO_VOID
| #define TRACE_PROTO_VOID void |
§ zb_buf_alloc_left
| #define zb_buf_alloc_left |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_alloc_left_func(TRACE_CALL (buf),(size)) |
§ zb_buf_alloc_right
| #define zb_buf_alloc_right |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_alloc_right_func(TRACE_CALL (buf),(size)) |
§ zb_buf_alloc_tail
| #define zb_buf_alloc_tail |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_alloc_tail_func(TRACE_CALL (buf),(size)) |
§ zb_buf_begin
| #define zb_buf_begin |
( |
|
buf | ) |
zb_buf_begin_func(TRACE_CALL (buf)) |
§ zb_buf_copy
| #define zb_buf_copy |
( |
|
dst_buf, |
|
|
|
src_buf |
|
) |
| zb_buf_copy_func(TRACE_CALL (dst_buf),(src_buf)) |
§ ZB_BUF_COPY_FLAG_APS_PAYLOAD
| #define ZB_BUF_COPY_FLAG_APS_PAYLOAD |
( |
|
dst, |
|
|
|
src |
|
) |
| |
§ zb_buf_cut_left
| #define zb_buf_cut_left |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_cut_left_func(TRACE_CALL (buf),(size)) |
§ zb_buf_cut_right
| #define zb_buf_cut_right |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_cut_right_func(TRACE_CALL (buf),(size)) |
§ zb_buf_end
| #define zb_buf_end |
( |
|
buf | ) |
zb_buf_end_func(TRACE_CALL (buf)) |
§ zb_buf_flags_clr
| #define zb_buf_flags_clr |
( |
|
buf, |
|
|
|
mask |
|
) |
| zb_buf_flags_clr_func(TRACE_CALL (buf),(mask)) |
§ zb_buf_flags_clr_encr
| #define zb_buf_flags_clr_encr |
( |
|
buf | ) |
zb_buf_flags_clr_encr_func(TRACE_CALL (buf)) |
§ zb_buf_flags_get
| #define zb_buf_flags_get |
( |
|
buf | ) |
zb_buf_flags_get_func(TRACE_CALL (buf)) |
§ zb_buf_flags_or
| #define zb_buf_flags_or |
( |
|
buf, |
|
|
|
val |
|
) |
| zb_buf_flags_or_func(TRACE_CALL (buf),(val)) |
§ zb_buf_free
| #define zb_buf_free |
( |
|
buf | ) |
zb_buf_free_func(TRACE_CALL (buf)) |
§ zb_buf_get
| #define zb_buf_get |
( |
|
is_in, |
|
|
|
max_size |
|
) |
| zb_buf_get_func(TRACE_CALL (is_in), (max_size)) |
#include </conan-data/ti_zigbee/9.14.00.04/library-lprf/ga/build/f6d18801b7b469a709ae7e8290b03ecdc7a7ad4c/zboss_r23/include/zboss_api_buf.h>
Synchronous buffer allocation. If no buffers available, does not block. Note: this is low-level API. Usually user calls blocked alloc API.
- Parameters
-
| is_in | if ZB_TRUE, allocate IN buffer, else allocate OUT buffer |
| max_size | required maximum buffer payload size (in bytes). It can be bigger or smaller than the default buffer size. Depending on the specific value, the buffer pool may decide to use a fraction of buffer or long buffers. Special value 0 means "single default buffer". |
- Returns
- buffer ID or ZB_BUF_INVALID if no buffers available
§ zb_buf_get_any
§ zb_buf_get_handle
| #define zb_buf_get_handle |
( |
|
buf | ) |
zb_buf_get_handle_func(TRACE_CALL (buf)) |
§ zb_buf_get_hipri
| #define zb_buf_get_hipri |
( |
|
a | ) |
zb_buf_get_hipri_func(TRACE_CALL (a)) |
§ zb_buf_get_in_delayed
| #define zb_buf_get_in_delayed |
( |
|
callback | ) |
zb_buf_get_in_delayed_func(TRACE_CALL (callback)) |
§ zb_buf_get_in_delayed_ext
| #define zb_buf_get_in_delayed_ext |
( |
|
callback, |
|
|
|
arg, |
|
|
|
max_size |
|
) |
| zb_buf_get_in_delayed_ext_func(TRACE_CALL (callback),(arg),(max_size)) |
#include </conan-data/ti_zigbee/9.14.00.04/library-lprf/ga/build/f6d18801b7b469a709ae7e8290b03ecdc7a7ad4c/zboss_r23/include/zboss_api_buf.h>
Allocate IN buffer, call a callback when the buffer is available.
If buffer is available, schedules callback for execution immediately. If no buffers are available now, schedule callback later, when buffer will be available.
- Parameters
-
| callback | - callback to call. |
| arg | - second argument for a callback |
| max_size | required maximum buffer payload size (in bytes). The buffer payload size is the sum of both data and parameters, so the max_size parameter should reflect this. It can be bigger or smaller than the default buffer size. Depending on the specific value, the buffer pool may decide to use a fraction of buffer or long buffers. If the value is set to 0, the payload size will be equal to the size of a single default buffer. |
- Returns
- RET_OK if allocation has successfully scheduled. RET_ERROR if there is no room to schedule buffer allocation. RET_OUT_OF_RANGE if buffer with such payload size can't be allocated.
§ zb_buf_get_max_size
| #define zb_buf_get_max_size |
( |
|
a | ) |
zb_buf_get_max_size_func(TRACE_CALL (a)) |
§ zb_buf_get_out
§ zb_buf_get_out_delayed
| #define zb_buf_get_out_delayed |
( |
|
callback | ) |
zb_buf_get_out_delayed_func(TRACE_CALL (callback)) |
§ zb_buf_get_out_delayed_ext
| #define zb_buf_get_out_delayed_ext |
( |
|
callback, |
|
|
|
arg, |
|
|
|
max_size |
|
) |
| zb_buf_get_out_delayed_ext_func(TRACE_CALL (callback),(arg),(max_size)) |
#include </conan-data/ti_zigbee/9.14.00.04/library-lprf/ga/build/f6d18801b7b469a709ae7e8290b03ecdc7a7ad4c/zboss_r23/include/zboss_api_buf.h>
Allocate OUT buffer, call a callback when the buffer is available.
If buffer is available, schedules callback for execution immediately. If no buffers are available now, schedule callback later, when buffer will be available.
- Parameters
-
| callback | - callback to call. |
| arg | - second argument for a callback |
| max_size | - required maximum buffer payload size (in bytes). The buffer payload size is the sum of both data and parameters, so the max_size parameter should reflect this. It can be bigger or smaller than the default buffer size. Depending on the specific value, the buffer pool may decide to use a fraction of buffer or long buffers. If the value is set to 0, the payload size will be equal to the size of a single default buffer. |
- Returns
- RET_OK if allocation has successfully scheduled. RET_ERROR if there is no room to schedule buffer allocation. RET_OUT_OF_RANGE if buffer with such payload size can't be allocated.
§ ZB_BUF_GET_PARAM
| #define ZB_BUF_GET_PARAM |
( |
|
buf, |
|
|
|
type |
|
) |
| ((type *)zb_buf_get_tail_func(TRACE_CALL (buf), sizeof(type))) |
§ zb_buf_get_status
| #define zb_buf_get_status |
( |
|
buf | ) |
zb_buf_get_status_func(TRACE_CALL (buf)) |
§ zb_buf_get_tail
| #define zb_buf_get_tail |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_get_tail_func(TRACE_CALL (buf),(size)) |
§ ZB_BUF_HAS_APS_PAYLOAD
| #define ZB_BUF_HAS_APS_PAYLOAD (1U << 6) |
§ ZB_BUF_HAS_APS_USER_PAYLOAD
| #define ZB_BUF_HAS_APS_USER_PAYLOAD (1U << 7) |
§ zb_buf_initial_alloc
| #define zb_buf_initial_alloc |
( |
|
buf, |
|
|
|
size |
|
) |
| zb_buf_initial_alloc_func(TRACE_CALL (buf),(size)) |
§ ZB_BUF_INVALID
| #define ZB_BUF_INVALID 0U |
§ ZB_BUF_IS_IN
| #define ZB_BUF_IS_IN (1U << 0) |
§ zb_buf_len
| #define zb_buf_len |
( |
|
buf | ) |
zb_buf_len_func(TRACE_CALL (buf)) |
§ zb_buf_reuse
| #define zb_buf_reuse |
( |
|
buf | ) |
zb_buf_reuse_func(TRACE_CALL (buf)) |
§ ZB_BUF_SECUR_ALL_ENCR
§ ZB_BUF_SECUR_APS_ENCR
| #define ZB_BUF_SECUR_APS_ENCR (1U << 2) |
§ ZB_BUF_SECUR_MAC_ENCR
| #define ZB_BUF_SECUR_MAC_ENCR (1U << 3) |
§ ZB_BUF_SECUR_NO_ENCR
| #define ZB_BUF_SECUR_NO_ENCR 0U |
§ ZB_BUF_SECUR_NWK_ENCR
| #define ZB_BUF_SECUR_NWK_ENCR (1U << 1) |
§ zb_buf_set_handle
| #define zb_buf_set_handle |
( |
|
buf, |
|
|
|
handle |
|
) |
| zb_buf_set_handle_func(TRACE_CALL (buf),(handle)) |
§ zb_buf_set_status
| #define zb_buf_set_status |
( |
|
buf, |
|
|
|
status |
|
) |
| zb_buf_set_status_func(TRACE_CALL (buf), (zb_ret_t)(status)) |
§ ZB_BUF_USE_SAME_KEY
| #define ZB_BUF_USE_SAME_KEY (1U << 4) |
§ ZB_BUF_ZDO_CMD_NO_RESP
| #define ZB_BUF_ZDO_CMD_NO_RESP (1U << 5) |
§ ZB_IN_BUFFER
§ ZB_OUT_BUFFER
§ ZB_RESERVED_BUF_TO_ALIGN_HDR_SIZE
| #define ZB_RESERVED_BUF_TO_ALIGN_HDR_SIZE 1u |
§ ZB_TRACE_BUFS_USAGE
| #define ZB_TRACE_BUFS_USAGE |
( |
| ) |
|
§ ZB_UNDEFINED_BUFFER
| #define ZB_UNDEFINED_BUFFER 0U |
§ zb_buf_ent_t
§ zb_buf_flags_bm_t
§ zb_buf_hdr_t
§ zb_buffer_types_t
§ zb_bufid_t
§ zb_leg_buf_t
§ zb_mult_buf_t
§ zb_buf_get_mac_rx_need()
§ zb_buf_have_rx_bufs()
§ zb_buf_is_oom_state()
§ zb_buf_memory_low()
§ zb_buf_oom_trace()
| void zb_buf_oom_trace |
( |
void |
| ) |
|
§ zb_buf_set_mac_rx_need()
| void zb_buf_set_mac_rx_need |
( |
zb_bool_t |
needs | ) |
|