![]() |
Morse Micro IoT SDK
2.9.7
|
This API provides support for buffers tailored towards packet-like data that has headers and trailers that are applied at subsequent layers.
It is designed to support various backends for memory allocation. The default is allocation on the heap, but other methods could be used due to the flexible API.
Data Structures | |
| struct | mmbuf |
| Core mmbuf data structure. More... | |
| struct | mmbuf_ops |
| Operations data structure for mmbuf. More... | |
| struct | mmbuf_list |
| Structure that can be used as the head of a linked list of mmbufs that counts its length. More... | |
Macros | |
| #define | MMBUF_LIST_INIT { NULL, NULL, 0 } |
| Static initializer for mmbuf_list. More... | |
Functions | |
| static void | mmbuf_init (struct mmbuf *mmbuf, uint8_t *buf, uint32_t buf_len, uint32_t data_start_offset, const struct mmbuf_ops *ops) |
| Initialize an mmbuf header with the given values. More... | |
| struct mmbuf * | mmbuf_alloc_on_heap (uint32_t space_at_start, uint32_t space_at_end) |
| Allocate a new mmbuf on the heap (using mmosal_malloc()). More... | |
| struct mmbuf * | mmbuf_make_copy_on_heap (struct mmbuf *original) |
| Make a copy of the given mmbuf. More... | |
| void | mmbuf_release (struct mmbuf *mmbuf) |
| Release a reference to the given mmbuf. More... | |
| static uint8_t * | mmbuf_get_data_start (struct mmbuf *mmbuf) |
| Gets a pointer to the start of the data in the mmbuf. More... | |
| static uint8_t * | mmbuf_get_data_end (struct mmbuf *mmbuf) |
| Gets a pointer to the end of the data in the mmbuf. More... | |
| static uint32_t | mmbuf_get_data_length (struct mmbuf *mmbuf) |
| Gets the length of the data currently in the mmbuf. More... | |
| static uint32_t | mmbuf_available_space_at_start (struct mmbuf *mmbuf) |
| Returns the amount of space available for prepending to the data in the buffer. More... | |
| static uint32_t | mmbuf_available_space_at_end (struct mmbuf *mmbuf) |
| Returns the amount of space available for appending to the data in the buffer. More... | |
| static uint8_t * | mmbuf_prepend (struct mmbuf *mmbuf, uint32_t len) |
| Reserves space immediately before the data currently in the given mmbuf and returns a pointer to this space. More... | |
| static void | mmbuf_prepend_data (struct mmbuf *mmbuf, const uint8_t *data, uint32_t len) |
| Prepends the given data to the data already in the mmbuf. More... | |
| static uint8_t * | mmbuf_append (struct mmbuf *mmbuf, uint32_t len) |
| Reserves space immediately after the data currently in the given mmbuf and returns a pointer to this space. More... | |
| static void | mmbuf_append_data (struct mmbuf *mmbuf, const uint8_t *data, uint32_t len) |
| Appends the given data to the data already in the mmbuf. More... | |
| static uint8_t * | mmbuf_remove_from_start (struct mmbuf *mmbuf, uint32_t len) |
| Remove data from the start of the mmbuf. More... | |
| static uint8_t * | mmbuf_remove_from_end (struct mmbuf *mmbuf, uint32_t len) |
| Remove data from the end of the mmbuf. More... | |
| static void | mmbuf_truncate (struct mmbuf *mmbuf, uint32_t len) |
| Truncate the mmbuf data to the given length. More... | |
| static void | mmbuf_list_init (struct mmbuf_list *list) |
Initialization function for mmbuf_list, for cases where MMBUF_LIST_INIT cannot be used. More... | |
| void | mmbuf_list_prepend (struct mmbuf_list *list, struct mmbuf *mmbuf) |
| Add an mmbuf to the start of an mmbuf list. More... | |
| void | mmbuf_list_append (struct mmbuf_list *list, struct mmbuf *mmbuf) |
| Add an mmbuf to the end of an mmbuf list. More... | |
| bool | mmbuf_list_remove (struct mmbuf_list *list, struct mmbuf *mmbuf) |
| Remove an mmbuf from an mmbuf list. More... | |
| struct mmbuf * | mmbuf_list_dequeue (struct mmbuf_list *list) |
| Remove the mmbuf at the head of the list and return it. More... | |
| struct mmbuf * | mmbuf_list_dequeue_tail (struct mmbuf_list *list) |
| Remove the mmbuf at the tail of the list and return it. More... | |
| static struct mmbuf * | mmbuf_list_dequeue_all (struct mmbuf_list *list) |
| Remove all mmbufs from the list and return as a linked list. More... | |
| static bool | mmbuf_list_is_empty (struct mmbuf_list *list) |
| Checks whether the given mmbuf list is empty. More... | |
| static struct mmbuf * | mmbuf_list_peek (struct mmbuf_list *list) |
| Returns the head of the mmbuf list. More... | |
| static struct mmbuf * | mmbuf_list_peek_tail (struct mmbuf_list *list) |
| Returns the tail of the mmbuf list. More... | |
| void | mmbuf_list_clear (struct mmbuf_list *list) |
| Free all the packets in the given list and reset the list to empty state. More... | |
| #define MMBUF_LIST_INIT { NULL, NULL, 0 } |
Static initializer for mmbuf_list.
| struct mmbuf * mmbuf_alloc_on_heap | ( | uint32_t | space_at_start, |
| uint32_t | space_at_end | ||
| ) |
Allocate a new mmbuf on the heap (using mmosal_malloc()).
| space_at_start | Amount of space to reserve at start of buffer. |
| space_at_end | Amount of space to reserve at end of buffer. |
start_offset will be set to space_at_start, and buf_len will be the sum of space_at_start and space_at_end (rounded up to a multiple of 4).NULL on failure.
|
inlinestatic |
Reserves space immediately after the data currently in the given mmbuf and returns a pointer to this space.
For a function that also copies data in, see mmbuf_append_data().
len must be less than or equal to mmbuf_available_space_at_end().| mmbuf | The mmbuf to operate on. |
| len | Length of data to be append. |
|
inlinestatic |
Appends the given data to the data already in the mmbuf.
len must be less than or equal to mmbuf_available_space_at_start().| mmbuf | The mmbuf to operate on. |
| data | The data to be prepended. |
| len | Length of data to be prepended. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
| void mmbuf_list_append | ( | struct mmbuf_list * | list, |
| struct mmbuf * | mmbuf | ||
| ) |
Add an mmbuf to the end of an mmbuf list.
| list | The list to append to. |
| mmbuf | The mmbuf to append. |
| void mmbuf_list_clear | ( | struct mmbuf_list * | list | ) |
Free all the packets in the given list and reset the list to empty state.
| list | The list to clear. |
| struct mmbuf * mmbuf_list_dequeue | ( | struct mmbuf_list * | list | ) |
Remove the mmbuf at the head of the list and return it.
| list | The list to dequeue from. |
NULL if the list is empty.
|
inlinestatic |
| struct mmbuf * mmbuf_list_dequeue_tail | ( | struct mmbuf_list * | list | ) |
Remove the mmbuf at the tail of the list and return it.
| list | The list to dequeue from. |
NULL if the list is empty.
|
inlinestatic |
Initialization function for mmbuf_list, for cases where MMBUF_LIST_INIT cannot be used.
| list | The mmbuf_list to init. |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
| void mmbuf_list_prepend | ( | struct mmbuf_list * | list, |
| struct mmbuf * | mmbuf | ||
| ) |
Add an mmbuf to the start of an mmbuf list.
| list | The list to prepend to. |
| mmbuf | The mmbuf to prepend. |
| bool mmbuf_list_remove | ( | struct mmbuf_list * | list, |
| struct mmbuf * | mmbuf | ||
| ) |
Remove an mmbuf from an mmbuf list.
| list | The list to remove from. |
| mmbuf | The mmbuf to remove. |
true if the given mmbuf was present in list, else fase. Make a copy of the given mmbuf.
Note that regardless of the backend that allocated original, the newly allocated mmbuf will be allocated on the heap using mmbuf_alloc_on_heap().
| original | mmbuf to copy. |
NULL on failure.
|
inlinestatic |
Reserves space immediately before the data currently in the given mmbuf and returns a pointer to this space.
For a function that also copies data in, see mmbuf_prepend_data().
len must be less than or equal to mmbuf_available_space_at_start().| mmbuf | The mmbuf to operate on. |
| len | Length of data to be prepended. |
|
inlinestatic |
Prepends the given data to the data already in the mmbuf.
len must be less than or equal to mmbuf_available_space_at_start().| mmbuf | The mmbuf to operate on. |
| data | The data to be prepended. |
| len | Length of data to be prepended. |
| void mmbuf_release | ( | struct mmbuf * | mmbuf | ) |
Release a reference to the given mmbuf.
If this was the last reference (addition_ref_cnt was 0) then the mmbuf will be freed using the appropriate op callback.
| mmbuf | The mmbuf to release reference to. May be NULL. |
|
inlinestatic |
|
inlinestatic |