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)
108#define PBUF_CFG_INIT(mem_addr, size, dcache_align) \
110 .rd_idx_loc = (uint32_t *)(mem_addr), \
111 .wr_idx_loc = (uint32_t *)((uint8_t *)(mem_addr) + \
112 MAX(dcache_align, _PBUF_IDX_SIZE)), \
113 .data_loc = (uint8_t *)((uint8_t *)(mem_addr) + \
114 MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE), \
115 .len = (uint32_t)((uint32_t)(size) - MAX(dcache_align, _PBUF_IDX_SIZE) - \
117 .dcache_alignment = (dcache_align), \
127#define PBUF_HEADER_OVERHEAD(dcache_align) \
128 (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE)
138#define PBUF_DEFINE(name, mem_addr, size, dcache_align) \
139 BUILD_ASSERT(dcache_align >= 0, \
140 "Cache line size must be non negative."); \
141 BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \
142 "Incorrect size."); \
143 BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \
144 "Misaligned memory."); \
145 BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \
146 _PBUF_MIN_DATA_LEN), "Insufficient size."); \
148 static const struct pbuf_cfg cfg_##name = \
149 PBUF_CFG_INIT(mem_addr, size, dcache_align); \
150 static struct pbuf name = { \
151 .cfg = &cfg_##name, \
int pbuf_read(struct pbuf *pb, char *buf, uint16_t len)
Read specified amount of data from the packet buffer.
int pbuf_init(struct pbuf *pb)
Initialize the packet buffer.
int pbuf_write(struct pbuf *pb, const char *buf, uint16_t len)
Write specified amount of data to the packet buffer.
__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:42
uint8_t * data_loc
Definition pbuf.h:56
uint32_t dcache_alignment
Definition pbuf.h:51
uint32_t len
Definition pbuf.h:55
volatile uint32_t * rd_idx_loc
Definition pbuf.h:43
volatile uint32_t * wr_idx_loc
Definition pbuf.h:47
Data block of the packed buffer.
Definition pbuf.h:65
volatile uint32_t wr_idx
Definition pbuf.h:66
volatile uint32_t rd_idx
Definition pbuf.h:70
Scure packed buffer.
Definition pbuf.h:89
const struct pbuf_cfg *const cfg
Definition pbuf.h:90
struct pbuf_data data
Definition pbuf.h:93