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#
Functions#
Allocates a buffer.
gets a pointer to the specified buffer
gets the length of the specified buffer
allocates a buffer and fills it with the given null terminated string
Allocates a buffer and fills with length bytes of contents.
returns the number of bytes of buffer space currently in use
returns the number of available bytes remaining in the buffer system
returns the number of bytes allocated to the buffer system
returns whether the given buffer is valid
Truncates the buffer. New length cannot be longer than the old length.
Truncates the buffer, removing bytes from the front. New length cannot be longer than the old length.
Reclaims unused buffers and compacts the heap.
Marks the passed buffer. Called from Marker function.
weakly mark buffer
Macros#
Typedef Documentation#
Buffer#
typedef uint16_t Buffer
47
of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h
MessageBufferQueue#
typedef Buffer MessageBufferQueue
50
of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h
PacketHeader#
typedef Buffer PacketHeader
51
of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h
EmberMessageBuffer#
typedef Buffer EmberMessageBuffer
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)
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)
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.
N/A | dataSizeInBytes |
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
N/A | buffer |
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
N/A | buffer |
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
N/A | contents |
'contents' may be NULL, in which case NULL_BUFFER is returned.
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.
N/A | contents | |
N/A | length |
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
N/A |
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
N/A |
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
N/A |
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
N/A | buffer |
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.
N/A | buffer | |
N/A | length |
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.
N/A | buffer | |
N/A | length |
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.
N/A | markers |
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 ... }
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.
N/A | root |
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
N/A | root |
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
229
of file /mnt/raid/workspaces/ws.aPtlWsFtZ/overlay/gsdk/util/silicon_labs/silabs_core/buffer_manager/buffer-management.h