Morse Micro IoT SDK  2.9.7

Detailed Description

Read-only buffer data structure.

The design of this data structure allows the buffer to exist either in statically or dynamically allocated memory.

For statically allocated memory, the field free_cb may be set to NULL and free_arg ignored. For example:

const uint8_t some_data[] = { 0x00, 0x01, 0x02 };
void put_some_data_into_buf(struct mmhal_robuf *robuf)
{
robuf->buf = some_data;
robuf->len = sizeof(some_data);
robuf->free_cb = NULL;
}
Read-only buffer data structure.
Definition: mmhal_wlan.h:162
const uint8_t * buf
Pointer to the start of the read-only buffer.
Definition: mmhal_wlan.h:164
uint32_t len
Length of the buffer contents.
Definition: mmhal_wlan.h:166
void(* free_cb)(void *arg)
Optional callback to be invoked by the consumer to release the buffer when it is no longer required.
Definition: mmhal_wlan.h:175

For dynamically allocated memory, the field free_cb is set to the appropriate function to free the buffer and free_arg is an opaque argument to the free function. This approach might be used, for example, when reading into a temporary buffer from storage that is not memory mapped. For example:

#define SOME_DATA_MAXLEN (64)
void put_some_data_into_buf(struct mmhal_robuf *robuf)
{
uint8_t *buf = malloc(SOME_DATA_MAXLEN);
robuf->buf = buf;
if (robuf->buf == NULL)
return;
// HERE: copy data into buf and set robuf->len as appropriate
robuf->free_cb = free;
robuf->free_arg = buf;
}
void * free_arg
Optional argument to free_cb.
Definition: mmhal_wlan.h:177

Definition at line 161 of file mmhal_wlan.h.

#include <mmhal_wlan.h>

Data Fields

const uint8_t * buf
 Pointer to the start of the read-only buffer. More...
 
uint32_t len
 Length of the buffer contents. More...
 
void(* free_cb )(void *arg)
 Optional callback to be invoked by the consumer to release the buffer when it is no longer required. More...
 
void * free_arg
 Optional argument to free_cb. More...
 

Field Documentation

◆ buf

const uint8_t* mmhal_robuf::buf

Pointer to the start of the read-only buffer.

May be NULL only if len is zero.

Definition at line 164 of file mmhal_wlan.h.

◆ free_arg

void* mmhal_robuf::free_arg

Optional argument to free_cb.

Ignored if free_cb is NULL.

Definition at line 177 of file mmhal_wlan.h.

◆ free_cb

void(* mmhal_robuf::free_cb) (void *arg)

Optional callback to be invoked by the consumer to release the buffer when it is no longer required.

If not required, set to NULL.

Note
The values of buf and len in this structure may be modified before free_cb() is invoked. However, the value of free_arg will be passed to free_cb().

Definition at line 175 of file mmhal_wlan.h.

◆ len

uint32_t mmhal_robuf::len

Length of the buffer contents.

Definition at line 166 of file mmhal_wlan.h.


The documentation for this struct was generated from the following file: