33#ifndef MM_FAST_ROUND_UP
34#define MM_FAST_ROUND_UP(x, m) ((((x)-1) | ((m)-1)) + 1)
37#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
39#define MMPKT_DEBUG_MAGIC_OPENED (0x08254759)
41#define MMPKT_DEBUG_MAGIC_CLOSED (0xdeaddead)
43#define MMPKT_DEBUG_MAGIC_RELEASED (0x0bad0bad)
46struct mmdrv_cmd_metadata;
47struct mmdrv_tx_metadata;
48struct mmdrv_rx_metadata;
61 struct mmdrv_tx_metadata *
tx;
63 struct mmdrv_rx_metadata *
rx;
65 struct mmdrv_cmd_metadata *
cmd;
103#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
104 uint32_t debug_magic;
138 uint32_t data_start_offset,
const struct mmpkt_ops *ops)
145#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
146 mmpkt->debug_magic = MMPKT_DEBUG_MAGIC_CLOSED;
168 uint32_t space_at_start, uint32_t space_at_end,
178 if (space_at_end != UINT32_MAX)
190 if ((int32_t)
data_len < (int32_t)space_at_start)
201 data_start = ((uint8_t *)
mmpkt) + header_size;
205 if (metadata_size != 0)
228 uint32_t metadata_size);
253#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
255 mmpkt->debug_magic = MMPKT_DEBUG_MAGIC_OPENED;
257 return (
struct mmpktview *)
mmpkt;
269#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
274 mmpkt->debug_magic = MMPKT_DEBUG_MAGIC_CLOSED;
289 return (
struct mmpkt *)view;
302#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
318#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
348#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
364#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
380#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
402#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
425 memcpy(dest, data, len);
441static inline uint8_t *
mmpkt_append(
struct mmpktview *view, uint32_t len)
444#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
465 memcpy(dest, data, len);
506#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
535#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
605#if defined(MMPKT_DEBUG) && MMPKT_DEBUG
608 return ((
const uint8_t *)ptr >= &
mmpkt->
buf[0]
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
struct mmpkt * mmpkt_alloc_on_heap(uint32_t space_at_start, uint32_t space_at_end, uint32_t metadata_size)
Allocate a new mmpkt on the heap (using mmosal_malloc()).
static void mmpkt_append_data(struct mmpktview *view, const uint8_t *data, uint32_t len)
Appends the given data to the data already in the mmpkt.
static struct mmpkt * mmpkt_init_buf(uint8_t *buf, uint32_t buf_len, uint32_t space_at_start, uint32_t space_at_end, uint32_t metadata_size, const struct mmpkt_ops *ops)
Initialize an mmpkt in a single buffer using the given values.
static struct mmpkt * mmpkt_from_view(struct mmpktview *view)
Get the underlying mmpkt from an opened view.
static void mmpkt_close(struct mmpktview **view)
Close the given view.
void mmpkt_release(struct mmpkt *mmpkt)
Release a reference to the given mmpkt.
static void mmpkt_init(struct mmpkt *mmpkt, uint8_t *buf, uint32_t buf_len, uint32_t data_start_offset, const struct mmpkt_ops *ops)
Initialize an mmpkt header with the given values.
static union mmpkt_metadata_ptr mmpkt_get_metadata(struct mmpkt *mmpkt)
Retrieve a reference to the metadata associated with the given mmpkt.
static struct mmpkt * mmpkt_get_next(struct mmpkt *mmpkt)
Get the next pointer embedded in the mmpkt.
static void mmpkt_adjust_start_offset(struct mmpkt *mmpkt, int32_t delta)
Adjust the start offset of an mmpkt.
static uint32_t mmpkt_available_space_at_start(struct mmpktview *view)
Returns the amount of space available for prepending to the data in the buffer.
static uint32_t mmpkt_peek_data_length(const struct mmpkt *mmpkt)
Peek the length of the data currently from an unopened mmpkt.
#define MM_FAST_ROUND_UP(x, m)
Round x up to the next multiple of m (where m is a power of 2).
static uint8_t * mmpkt_get_data_end(struct mmpktview *view)
Gets a pointer to the end of the data in the mmpkt.
static uint8_t * mmpkt_prepend(struct mmpktview *view, uint32_t len)
Reserves space immediately before the data currently in the given mmpkt and returns a pointer to this...
static void mmpkt_truncate(struct mmpkt *mmpkt, uint32_t len)
Truncate the mmpkt data to the given length.
static uint32_t mmpkt_get_data_length(struct mmpktview *view)
Gets the length of the data currently in the mmpkt.
static uint32_t mmpkt_available_space_at_end(struct mmpktview *view)
Returns the amount of space available for appending to the data in the buffer.
static void mmpkt_prepend_data(struct mmpktview *view, const uint8_t *data, uint32_t len)
Prepends the given data to the data already in the mmpkt.
static uint8_t * mmpkt_remove_from_end(struct mmpktview *view, uint32_t len)
Remove data from the end of the mmpkt.
static struct mmpktview * mmpkt_open(struct mmpkt *mmpkt)
Open a view of the given mmpkt.
static uint8_t * mmpkt_append(struct mmpktview *view, uint32_t len)
Reserves space immediately after the data currently in the given mmpkt and returns a pointer to this ...
static uint8_t * mmpkt_get_data_start(struct mmpktview *view)
Gets a pointer to the start of the data in the mmpkt.
static bool mmpkt_contains_ptr(struct mmpktview *view, const void *ptr)
Check whether the given pointer is pointing inside the mmpkt's buffer.
static uint8_t * mmpkt_remove_from_start(struct mmpktview *view, uint32_t len)
Remove data from the start of the mmpkt.
static void mmpkt_set_next(struct mmpkt *mmpkt, struct mmpkt *next)
Set the next pointer embedded in the mmpkt.
static unsigned char buf[1024]
Statically allocated buffer for MQTT.
Operations data structure for mmpkt.
void(* free_mmpkt)(void *mmpkt)
Free the given mmpkt.
Core mmpkt data structure.
uint32_t buf_len
Length of the buffer.
uint32_t data_len
Length of actual data in the buffer.
uint32_t start_offset
Offset where actual data starts in the buffer.
const struct mmpkt_ops * ops
Reference to operations data structure for this mmpkt.
uint8_t * buf
The buffer where data is stored.
union mmpkt_metadata_ptr metadata
Packet metadata used by driver (context dependent).
struct mmpkt *volatile next
Pointer that can be used to construct linked lists.