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 uint16_t
typedef void(*
Marker)(Buffer *buffer)
typedef void(*

Functions#

Allocates a buffer.

uint8_t *

gets a pointer to the specified buffer

uint16_t

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

returns whether the given buffer is valid

void
sli_legacy_buffer_manager_set_buffer_length(Buffer buffer, uint16_t length)

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

void

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

Marks the passed buffer. Called from Marker function.

void

weakly mark buffer

Macros#

#define
NULL_BUFFER 0x0000u

Typedef Documentation#

Buffer#

typedef uint16_t Buffer

Definition at line 47 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

MessageBufferQueue#

typedef Buffer MessageBufferQueue

Definition at line 50 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

PacketHeader#

typedef Buffer PacketHeader

Definition at line 51 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

EmberMessageBuffer#

typedef Buffer EmberMessageBuffer

Definition at line 52 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

Marker#

typedef void(* Marker) (Buffer *buffer) )(Buffer *buffer)

Definition at line 177 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

BufferMarker#

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

Definition at line 178 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

Function Documentation#

sli_legacy_buffer_manager_allocate_buffer#

Buffer sli_legacy_buffer_manager_allocate_buffer (uint16_t dataSizeInBytes)

Allocates a buffer.

Parameters
N/AdataSizeInBytes

Definition at line 58 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_get_buffer_pointer#

uint8_t * sli_legacy_buffer_manager_get_buffer_pointer (Buffer buffer)

gets a pointer to the specified buffer

Parameters
N/Abuffer

Definition at line 69 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_get_buffer_length#

uint16_t sli_legacy_buffer_manager_get_buffer_length (Buffer buffer)

gets the length of the specified buffer

Parameters
N/Abuffer

Definition at line 74 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_fill_string_buffer#

Buffer sli_legacy_buffer_manager_fill_string_buffer (const uint8_t * contents)

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

Parameters
N/Acontents

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


Definition at line 80 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_fill_buffer#

Buffer sli_legacy_buffer_manager_fill_buffer (const uint8_t * contents, uint16_t length)

Allocates a buffer and fills with length bytes of contents.

Parameters
N/Acontents
N/Alength

Definition at line 86 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

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
N/A

Definition at line 97 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

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
N/A

Definition at line 101 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

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
N/A

Definition at line 105 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_is_valid_buffer#

bool sli_legacy_buffer_manager_is_valid_buffer (Buffer buffer)

returns whether the given buffer is valid

Parameters
N/Abuffer

Definition at line 136 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_set_buffer_length#

void sli_legacy_buffer_manager_set_buffer_length (Buffer buffer, uint16_t length)

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

Parameters
N/Abuffer
N/Alength

Definition at line 170 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_set_buffer_length_from_end#

void sli_legacy_buffer_manager_set_buffer_length_from_end (Buffer buffer, uint16_t length)

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

Parameters
N/Abuffer
N/Alength

Definition at line 175 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

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
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 ... }


Definition at line 216 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_mark_buffer#

void sli_legacy_buffer_manager_mark_buffer (Buffer * root)

Marks the passed buffer. Called from Marker function.

Parameters
N/Aroot

Definition at line 220 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

sli_legacy_buffer_manager_mark_buffer_weak#

void sli_legacy_buffer_manager_mark_buffer_weak (Buffer * root)

weakly mark buffer

Parameters
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


Definition at line 229 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h

Macro Definition Documentation#

NULL_BUFFER#

#define NULL_BUFFER
Value:
0x0000u

Definition at line 48 of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h