Zephyr Project API 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Packed Buffer API

Packed buffer API. More...

Data Structures

struct  pbuf_cfg
 Control block of packet buffer. More...
 
struct  pbuf_data
 Data block of the packed buffer. More...
 
struct  pbuf
 Scure packed buffer. More...
 

Macros

#define PBUF_PACKET_LEN_SZ   sizeof(uint32_t)
 Size of packet length field.
 
#define PBUF_MAYBE_CONST   const
 
#define PBUF_CFG_INIT(mem_addr, size, dcache_align)
 Macro for configuration initialization.
 
#define PBUF_HEADER_OVERHEAD(dcache_align)    (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE)
 Macro calculates memory overhead taken by the header in shared memory.
 
#define PBUF_DEFINE(name, mem_addr, size, dcache_align)
 Statically define and initialize pbuf.
 

Functions

int pbuf_tx_init (struct pbuf *pb)
 Initialize the Tx 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.
 
int pbuf_read (struct pbuf *pb, char *buf, uint16_t len)
 Read specified amount of data from the packet buffer.
 

Detailed Description

Packed buffer API.

Macro Definition Documentation

◆ PBUF_CFG_INIT

#define PBUF_CFG_INIT (   mem_addr,
  size,
  dcache_align 
)

#include <include/zephyr/ipc/pbuf.h>

Value:
{ \
.rd_idx_loc = (uint32_t *)(mem_addr), \
.wr_idx_loc = (uint32_t *)((uint8_t *)(mem_addr) + \
MAX(dcache_align, _PBUF_IDX_SIZE)), \
.data_loc = (uint8_t *)((uint8_t *)(mem_addr) + \
MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE), \
.len = (uint32_t)((uint32_t)(size) - MAX(dcache_align, _PBUF_IDX_SIZE) - \
_PBUF_IDX_SIZE), \
.dcache_alignment = (dcache_align), \
}
#define MAX(a, b)
Obtain the maximum of two values.
Definition util.h:385
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88

Macro for configuration initialization.

It is recommended to use this macro to initialize packed buffer configuration.

Parameters
mem_addrMemory address for pbuf.
sizeSize of the memory.
dcache_alignData cache alignment.

◆ PBUF_DEFINE

#define PBUF_DEFINE (   name,
  mem_addr,
  size,
  dcache_align 
)

#include <include/zephyr/ipc/pbuf.h>

Value:
BUILD_ASSERT(dcache_align >= 0, \
"Cache line size must be non negative."); \
BUILD_ASSERT((size) > 0 && IS_PTR_ALIGNED_BYTES(size, _PBUF_IDX_SIZE), \
"Incorrect size."); \
BUILD_ASSERT(IS_PTR_ALIGNED_BYTES(mem_addr, MAX(dcache_align, _PBUF_IDX_SIZE)), \
"Misaligned memory."); \
BUILD_ASSERT(size >= (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE + \
_PBUF_MIN_DATA_LEN), "Insufficient size."); \
static PBUF_MAYBE_CONST struct pbuf_cfg cfg_##name = \
PBUF_CFG_INIT(mem_addr, size, dcache_align); \
static struct pbuf name = { \
.cfg = &cfg_##name, \
}
#define PBUF_MAYBE_CONST
Definition pbuf.h:42
#define IS_PTR_ALIGNED_BYTES(ptr, bytes)
Definition common.h:198
Control block of packet buffer.
Definition pbuf.h:49
Scure packed buffer.
Definition pbuf.h:96

Statically define and initialize pbuf.

Parameters
nameName of the pbuf.
mem_addrMemory address for pbuf.
sizeSize of the memory.
dcache_alignData cache line size.

◆ PBUF_HEADER_OVERHEAD

#define PBUF_HEADER_OVERHEAD (   dcache_align)     (MAX(dcache_align, _PBUF_IDX_SIZE) + _PBUF_IDX_SIZE)

#include <include/zephyr/ipc/pbuf.h>

Macro calculates memory overhead taken by the header in shared memory.

It contains the read index, write index and padding.

Parameters
dcache_alignData cache alignment.

◆ PBUF_MAYBE_CONST

#define PBUF_MAYBE_CONST   const

◆ PBUF_PACKET_LEN_SZ

#define PBUF_PACKET_LEN_SZ   sizeof(uint32_t)

#include <include/zephyr/ipc/pbuf.h>

Size of packet length field.

Function Documentation

◆ pbuf_read()

int pbuf_read ( struct pbuf pb,
char *  buf,
uint16_t  len 
)

#include <include/zephyr/ipc/pbuf.h>

Read specified amount of data from the packet buffer.

Single read allows to read the message send by the single write. The provided p buf must be big enough to store the whole message.

Parameters
pbA buffer from which data will be read.
bufData pointer to which read data will be written. If NULL, len of stored message is returned.
lenNumber of bytes to be read from the buffer.
Return values
intBytes read, negative error code on fail. Bytes to be read, if buf == NULL. -EINVAL, if any of input parameter is incorrect. -ENOMEM, if message can not fit in provided buf. -EAGAIN, if not whole message is ready yet.

◆ pbuf_rx_init()

int pbuf_rx_init ( struct pbuf pb)

#include <include/zephyr/ipc/pbuf.h>

Initialize the Rx packet buffer.

This function initializes the Rx packet buffer. If the configuration is incorrect, the function will return error.

It is recommended to use PBUF_DEFINE macro for build time initialization.

Parameters
pbPointer to the packed buffer containing configuration and data. Configuration has to be fixed before the initialization.
Return values
0on success.
-EINVALwhen the input parameter is incorrect.

◆ pbuf_tx_init()

int pbuf_tx_init ( struct pbuf pb)

#include <include/zephyr/ipc/pbuf.h>

Initialize the Tx packet buffer.

This function initializes the Tx packet buffer based on provided configuration. If the configuration is incorrect, the function will return error.

It is recommended to use PBUF_DEFINE macro for build time initialization.

Parameters
pbPointer to the packed buffer containing configuration and data. Configuration has to be fixed before the initialization.
Return values
0on success.
-EINVALwhen the input parameter is incorrect.

◆ pbuf_write()

int pbuf_write ( struct pbuf pb,
const char *  buf,
uint16_t  len 
)

#include <include/zephyr/ipc/pbuf.h>

Write specified amount of data to the packet buffer.

This function call writes specified amount of data to the packet buffer if the buffer will fit the data.

Parameters
pbA buffer to which to write.
bufPointer to the data to be written to the buffer.
lenNumber of bytes to be written to the buffer. Must be positive.
Return values
intNumber of bytes written, negative error code on fail. -EINVAL, if any of input parameter is incorrect. -ENOMEM, if len is bigger than the buffer can fit.