Packet Buffers#

These buffers are contiguous blocks of bytes. Buffers are allocated linearly from a single chunk of memory. When space gets short any buffers still in use can be moved to the beginning of buffer memory, which consolidates any unused space.

'Buffer' values are actually offsets from the beginning of buffer memory. Using uint8_ts would require additional memory for the mapping between the uint8_ts and memory locations.

In fact, Buffers are offsets from one before the beginning of buffer memory. The first buffer is thus 0x0001. This allows us to use 0x0000 as the null buffer, just as C uses zero for the null pointer.

In general the buffer functions are not safe for use in ISRs. The one exception is the PHY->MAC queue, which is handled specially. It is safe for an ISR to allocate a new buffer and put it on the PHY->MAC queue.

Any code which holds on to buffers beyond the context in which they are allocated must provide a marking function to prevent them from being garbage collected. See sli_legacy_buffer_manager_reclaim_unused_buffers for details.

Typedefs#

typedef void(*
Marker)(sli_buffer_manager_buffer_t *buffer)
typedef void(*

Functions#

Allocates a buffer.

uint8_t *
sli_legacy_buffer_manager_get_buffer_pointer(sli_buffer_manager_buffer_t buffer)

gets a pointer to the specified buffer

uint16_t
sli_legacy_buffer_manager_get_buffer_length(sli_buffer_manager_buffer_t buffer)

gets the length of the specified buffer

allocates a buffer and fills it with the given null terminated string

sli_legacy_buffer_manager_fill_buffer(const uint8_t *contents, uint16_t length)

Allocates a buffer and fills with length bytes of contents.

uint16_t

returns the number of bytes of buffer space currently in use

uint16_t

returns the number of available bytes remaining in the buffer system

uint16_t

returns the number of bytes allocated to the buffer system

bool
sli_legacy_buffer_manager_is_valid_buffer(sli_buffer_manager_buffer_t buffer)

returns whether the given buffer is valid

void
sli_legacy_buffer_manager_set_buffer_length(sli_buffer_manager_buffer_t buffer, uint16_t length)

Truncates the buffer. New length cannot be longer than the old length.

void
sli_legacy_buffer_manager_set_buffer_length_from_end(sli_buffer_manager_buffer_t buffer, uint16_t length)

Truncates the buffer, removing bytes from the front. New length cannot be longer than the old length.

void

Reclaims unused buffers and compacts the heap.

void
sli_legacy_buffer_manager_mark_buffer(sli_buffer_manager_buffer_t *root)

Marks the passed buffer. Called from Marker function.

void
sli_legacy_buffer_manager_mark_buffer_weak(sli_buffer_manager_buffer_t *root)

weakly mark buffer

Macros#

#define
NULL_BUFFER 0x0000u

Typedef Documentation#

sli_buffer_manager_buffer_t#

typedef uint16_t sli_buffer_manager_buffer_t

sli_zigbee_message_buffer_queue_t#

typedef sli_buffer_manager_buffer_t sli_zigbee_message_buffer_queue_t

sli_zigbee_packet_header_t#

typedef sli_buffer_manager_buffer_t sli_zigbee_packet_header_t

Marker#

typedef void(* Marker) (sli_buffer_manager_buffer_t *buffer) )(sli_buffer_manager_buffer_t *buffer)

BufferMarker#

typedef void(* BufferMarker) (void) )(void)

Function Documentation#

sli_legacy_buffer_manager_allocate_buffer#

sli_buffer_manager_buffer_t sli_legacy_buffer_manager_allocate_buffer (uint16_t dataSizeInBytes)

Allocates a buffer.

Parameters
TypeDirectionArgument NameDescription
uint16_tN/AdataSizeInBytes

sli_legacy_buffer_manager_get_buffer_pointer#

uint8_t * sli_legacy_buffer_manager_get_buffer_pointer (sli_buffer_manager_buffer_t buffer)

gets a pointer to the specified buffer

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_tN/Abuffer

sli_legacy_buffer_manager_get_buffer_length#

uint16_t sli_legacy_buffer_manager_get_buffer_length (sli_buffer_manager_buffer_t buffer)

gets the length of the specified buffer

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_tN/Abuffer

sli_legacy_buffer_manager_fill_string_buffer#

sli_buffer_manager_buffer_t sli_legacy_buffer_manager_fill_string_buffer (const uint8_t * contents)

allocates a buffer and fills it with the given null terminated string

Parameters
TypeDirectionArgument NameDescription
const uint8_t *N/Acontents

'contents' may be NULL, in which case NULL_BUFFER is returned.


sli_legacy_buffer_manager_fill_buffer#

sli_buffer_manager_buffer_t sli_legacy_buffer_manager_fill_buffer (const uint8_t * contents, uint16_t length)

Allocates a buffer and fills with length bytes of contents.

Parameters
TypeDirectionArgument NameDescription
const uint8_t *N/Acontents
uint16_tN/Alength

sli_legacy_buffer_manager_buffer_bytes_used#

uint16_t sli_legacy_buffer_manager_buffer_bytes_used (void )

returns the number of bytes of buffer space currently in use

Parameters
TypeDirectionArgument NameDescription
voidN/A

sli_legacy_buffer_manager_buffer_bytes_remaining#

uint16_t sli_legacy_buffer_manager_buffer_bytes_remaining (void )

returns the number of available bytes remaining in the buffer system

Parameters
TypeDirectionArgument NameDescription
voidN/A

sli_legacy_buffer_manager_buffer_bytes_total#

uint16_t sli_legacy_buffer_manager_buffer_bytes_total (void )

returns the number of bytes allocated to the buffer system

Parameters
TypeDirectionArgument NameDescription
voidN/A

sli_legacy_buffer_manager_is_valid_buffer#

bool sli_legacy_buffer_manager_is_valid_buffer (sli_buffer_manager_buffer_t buffer)

returns whether the given buffer is valid

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_tN/Abuffer

sli_legacy_buffer_manager_set_buffer_length#

void sli_legacy_buffer_manager_set_buffer_length (sli_buffer_manager_buffer_t buffer, uint16_t length)

Truncates the buffer. New length cannot be longer than the old length.

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_tN/Abuffer
uint16_tN/Alength

sli_legacy_buffer_manager_set_buffer_length_from_end#

void sli_legacy_buffer_manager_set_buffer_length_from_end (sli_buffer_manager_buffer_t buffer, uint16_t length)

Truncates the buffer, removing bytes from the front. New length cannot be longer than the old length.

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_tN/Abuffer
uint16_tN/Alength

sli_legacy_buffer_manager_reclaim_unused_buffers#

void sli_legacy_buffer_manager_reclaim_unused_buffers (const BufferMarker * markers)

Reclaims unused buffers and compacts the heap.

Parameters
TypeDirectionArgument NameDescription
const BufferMarker *N/Amarkers

Reclaims all buffers not reachable from 'roots', the PHY->MAC queue, by one of marker functions. The marker functions should call their argument on all known buffer references.

The idea is that single top level references, such as a queue, can be put in 'roots', whereas buffers stored in data structures, such as the retry table, are handled by marker functions.

Surviving buffers moved to the beginning of the heap, which amalgamates the free memory into a single contiguous block. This should only be called when there are no references to buffers outside of 'roots', the PHY->MAC queue, and the locations passed to the marker functions.

IMPORTANT: BufferMarker routines should not reference buffers after they have been marked. The buffers may be in an inconsistent state until the reclaimation has completed.

Right: void myBufferMarker(void) { ... myBuffer ... sli_legacy_buffer_manager_mark_buffer(&myBuffer); }

Wrong: void myBufferMarker(void) { sli_legacy_buffer_manager_mark_buffer(&myBuffer); ... myBuffer ... }


sli_legacy_buffer_manager_mark_buffer#

void sli_legacy_buffer_manager_mark_buffer (sli_buffer_manager_buffer_t * root)

Marks the passed buffer. Called from Marker function.

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_t *N/Aroot

sli_legacy_buffer_manager_mark_buffer_weak#

void sli_legacy_buffer_manager_mark_buffer_weak (sli_buffer_manager_buffer_t * root)

weakly mark buffer

Parameters
TypeDirectionArgument NameDescription
sli_buffer_manager_buffer_t *N/Aroot

sli_legacy_buffer_manager_mark_buffer_weak only operates during the update references phase if emMark Buffer is called on the same buffer elsewhere, the weak reference will be updated. If a buffer is only weakly marked, the update phase will replace it with NULL_BUFFER