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

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

sli_zigbee_message_buffer_queue_t#

typedef sli_buffer_manager_buffer_t sli_zigbee_message_buffer_queue_t

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

sli_zigbee_packet_header_t#

typedef sli_buffer_manager_buffer_t sli_zigbee_packet_header_t

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

Marker#

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

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

BufferMarker#

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

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

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

Definition at line 60 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (sli_buffer_manager_buffer_t buffer)

gets a pointer to the specified buffer

Parameters
N/Abuffer

Definition at line 71 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (sli_buffer_manager_buffer_t buffer)

gets the length of the specified buffer

Parameters
N/Abuffer

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

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

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


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

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
N/Acontents
N/Alength

Definition at line 88 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 99 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 103 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 107 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (sli_buffer_manager_buffer_t buffer)

returns whether the given buffer is valid

Parameters
N/Abuffer

Definition at line 138 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (sli_buffer_manager_buffer_t buffer, uint16_t length)

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

Parameters
N/Abuffer
N/Alength

Definition at line 172 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (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
N/Abuffer
N/Alength

Definition at line 177 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 218 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (sli_buffer_manager_buffer_t * root)

Marks the passed buffer. Called from Marker function.

Parameters
N/Aroot

Definition at line 222 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 (sli_buffer_manager_buffer_t * 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 231 of file /mnt/raid/workspaces/ws.J3v3YQgxI/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 51 of file /mnt/raid/workspaces/ws.J3v3YQgxI/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h