7#ifndef ZEPHYR_INCLUDE_IPC_PBUF_H_
8#define ZEPHYR_INCLUDE_IPC_PBUF_H_
25#define PBUF_PACKET_LEN_SZ sizeof(uint32_t)
28#define _PBUF_IDX_SIZE sizeof(uint32_t)
36#define _PBUF_MIN_DATA_LEN ROUND_UP(PBUF_PACKET_LEN_SZ + 1 + _PBUF_IDX_SIZE, _PBUF_IDX_SIZE)
38#if defined(CONFIG_ARCH_POSIX)
40#define PBUF_MAYBE_CONST
42#define PBUF_MAYBE_CONST const
115#define PBUF_CFG_INIT(mem_addr, size, dcache_align) \
117 .rd_idx_loc = (uint32_t *)(mem_addr), \
118 .wr_idx_loc = (uint32_t *)((uint8_t *)(mem_addr) + \
119 MAX(dcache_align, _PBUF_IDX_SIZE)), \
120 .data_loc = (uint8_t *)((uint8_t *)(mem_addr) + \
121 MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE), \
122 .len = (uint32_t)((uint32_t)(size) - MAX(dcache_align, _PBUF_IDX_SIZE) - \
124 .dcache_alignment = (dcache_align), \
134#define PBUF_HEADER_OVERHEAD(dcache_align) \
135 (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE)
145#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \
146 BUILD_ASSERT(dcache_align >= 0, \
147 "Cache line size must be non negative."); \
148 BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \
149 "Incorrect size."); \
150 BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \
151 "Misaligned memory."); \
152 BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \
153 _PBUF_MIN_DATA_LEN), "Insufficient size."); \
154 static PBUF_MAYBE_CONST struct pbuf_cfg cfg_##name = \
155 PBUF_CFG_INIT(mem_addr, size, dcache_align); \
156 static struct pbuf name = { \
157 .cfg = &cfg_##name, \
int pbuf_tx_init(struct pbuf *pb)
Initialize the Tx packet buffer.
int pbuf_read(struct pbuf *pb, char *buf, uint16_t len)
Read specified amount of data from the packet buffer.
int pbuf_rx_init(struct pbuf *pb)
Initialize the Rx packet buffer.
int pbuf_write(struct pbuf *pb, const char *buf, uint16_t len)
Write specified amount of data to the packet buffer.
#define PBUF_MAYBE_CONST
Definition pbuf.h:42
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Control block of packet buffer.
Definition pbuf.h:49
uint8_t * data_loc
Definition pbuf.h:63
uint32_t dcache_alignment
Definition pbuf.h:58
uint32_t len
Definition pbuf.h:62
volatile uint32_t * rd_idx_loc
Definition pbuf.h:50
volatile uint32_t * wr_idx_loc
Definition pbuf.h:54
Data block of the packed buffer.
Definition pbuf.h:72
volatile uint32_t wr_idx
Definition pbuf.h:73
volatile uint32_t rd_idx
Definition pbuf.h:77
Scure packed buffer.
Definition pbuf.h:96
const struct pbuf_cfg *const cfg
Definition pbuf.h:97
struct pbuf_data data
Definition pbuf.h:100