Mbed OS Reference
Loading...
Searching...
No Matches
EMACMemoryManager Class Referenceabstract
Inheritance diagram for EMACMemoryManager:
NetStackMemoryManager NanostackMemoryManager

Public Types

enum class  Lifetime { POOL_ALLOCATED , HEAP_ALLOCATED , CONSTANT , VOLATILE }
 

Public Member Functions

virtual net_stack_mem_buf_t * alloc_heap (uint32_t size, uint32_t align)=0
 Allocates memory buffer from the heap.
 
virtual net_stack_mem_buf_t * alloc_pool (uint32_t size, uint32_t align)=0
 Allocates memory buffer chain from a pool.
 
virtual uint32_t get_pool_alloc_unit (uint32_t align) const =0
 Get memory buffer pool allocation unit.
 
virtual uint32_t get_pool_size () const =0
 Get memory buffer pool size.
 
virtual void free (net_stack_mem_buf_t *buf)=0
 Free memory buffer chain.
 
virtual uint32_t get_total_len (const net_stack_mem_buf_t *buf) const =0
 Return total length of a memory buffer chain.
 
virtual void copy (net_stack_mem_buf_t *to_buf, const net_stack_mem_buf_t *from_buf)=0
 Copy a memory buffer chain.
 
virtual void copy_to_buf (net_stack_mem_buf_t *to_buf, const void *ptr, uint32_t len)
 Copy to a memory buffer chain.
 
virtual uint32_t copy_from_buf (void *ptr, uint32_t len, const net_stack_mem_buf_t *from_buf) const
 Copy from a memory buffer chain.
 
virtual void cat (net_stack_mem_buf_t *to_buf, net_stack_mem_buf_t *cat_buf)=0
 Concatenate two memory buffer chains.
 
virtual net_stack_mem_buf_t * get_next (const net_stack_mem_buf_t *buf) const =0
 Returns the next buffer.
 
size_t count_buffers (const net_stack_mem_buf_t *buf)
 Count the number of buffers in a buffer chain.
 
virtual void * get_ptr (const net_stack_mem_buf_t *buf) const =0
 Return pointer to the payload of the buffer.
 
virtual uint32_t get_len (const net_stack_mem_buf_t *buf) const =0
 Return payload size of this individual buffer (NOT including any chained buffers)
 
virtual void set_len (net_stack_mem_buf_t *buf, uint32_t len)=0
 Sets the payload size of the buffer.
 
virtual Lifetime get_lifetime (net_stack_mem_buf_t const *buf) const =0
 Gets the lifetime of the buffer.
 
void set_on_pool_space_avail_cb (mbed::Callback< void()> cb)
 Set callback which will be called when pool space becomes available.
 

Protected Attributes

mbed::Callback< void()> onPoolSpaceAvailCallback
 Callback which shall be called (if set) by the implementation after one or more buffer spaces become free in the pool.
 

Detailed Description

Definition at line 45 of file EMACMemoryManager.h.

Member Enumeration Documentation

◆ Lifetime

enum class Lifetime
stronginherited
Enumerator
POOL_ALLOCATED 

Allocated from the memory manager's pool.

HEAP_ALLOCATED 

Allocated from the memory manager's heap.

CONSTANT 

Buffer points to constant data (e.g. in ROM) that will live forever.

VOLATILE 

Buffer points to data from the application that will not live past the current network stack call.

Definition at line 235 of file NetStackMemoryManager.h.

Member Function Documentation

◆ alloc_heap()

virtual net_stack_mem_buf_t * alloc_heap ( uint32_t  size,
uint32_t  align 
)
pure virtualinherited

Allocates memory buffer from the heap.

Memory buffer allocated from heap is always contiguous and can be arbitrary size.

Parameters
sizeSize of the memory to allocate in bytes
alignMemory alignment requirement in bytes
Returns
Allocated memory buffer, or NULL in case of error

Implemented in NanostackMemoryManager.

◆ alloc_pool()

virtual net_stack_mem_buf_t * alloc_pool ( uint32_t  size,
uint32_t  align 
)
pure virtualinherited

Allocates memory buffer chain from a pool.

Memory allocated from pool is contiguous if size is equal or less than (aligned) allocation unit, otherwise may be chained. Will typically come from fixed-size packet pool memory.

Parameters
sizeTotal size of the memory to allocate in bytes
alignMemory alignment requirement for each buffer in bytes
Returns
Allocated memory buffer chain, or NULL in case of error

Implemented in NanostackMemoryManager.

◆ get_pool_alloc_unit()

virtual uint32_t get_pool_alloc_unit ( uint32_t  align) const
pure virtualinherited

Get memory buffer pool allocation unit.

Returns the maximum size of contiguous memory that can be allocated from a pool.

Parameters
alignMemory alignment requirement in bytes
Returns
Contiguous memory size

Implemented in NanostackMemoryManager.

◆ get_pool_size()

virtual uint32_t get_pool_size ( ) const
pure virtualinherited

Get memory buffer pool size.

Returns
The maximum size of contiguous memory that can be allocated from a pool.

Implemented in NanostackMemoryManager.

◆ free()

virtual void free ( net_stack_mem_buf_t *  buf)
pure virtualinherited

Free memory buffer chain.

Frees all buffers from the chained list.

Parameters
bufMemory buffer chain to be freed.

Implemented in NanostackMemoryManager.

◆ get_total_len()

virtual uint32_t get_total_len ( const net_stack_mem_buf_t *  buf) const
pure virtualinherited

Return total length of a memory buffer chain.

Returns a total length of this buffer and any following buffers in the chain.

Parameters
bufMemory buffer chain
Returns
Total length in bytes

Implemented in NanostackMemoryManager.

◆ copy()

virtual void copy ( net_stack_mem_buf_t *  to_buf,
const net_stack_mem_buf_t *  from_buf 
)
pure virtualinherited

Copy a memory buffer chain.

Copies data from one buffer chain to another. Copy operation does not adjust the lengths of the copied-to memory buffer chain, so chain total lengths must be the same.

Parameters
to_bufMemory buffer chain to copy to
from_bufMemory buffer chain to copy from

Implemented in NanostackMemoryManager.

◆ copy_to_buf()

virtual void copy_to_buf ( net_stack_mem_buf_t *  to_buf,
const void *  ptr,
uint32_t  len 
)
virtualinherited

Copy to a memory buffer chain.

Copies data to a buffer chain. Copy operation does not adjust the lengths of the copied-to memory buffer chain, so chain total length must match the copied length.

Parameters
to_bufMemory buffer chain to copy to
ptrPointer to data
lenData length

◆ copy_from_buf()

virtual uint32_t copy_from_buf ( void *  ptr,
uint32_t  len,
const net_stack_mem_buf_t *  from_buf 
) const
virtualinherited

Copy from a memory buffer chain.

Copies data from a memory buffer chain.

Parameters
lenData length
ptrPointer to data
from_bufMemory buffer chain to copy from
Returns
Length of the data that was copied

◆ cat()

virtual void cat ( net_stack_mem_buf_t *  to_buf,
net_stack_mem_buf_t *  cat_buf 
)
pure virtualinherited

Concatenate two memory buffer chains.

Concatenates buffer chain to end of the other buffer chain. Concatenated-to buffer total length is adjusted accordingly. cat_buf must point to the start of a the chain. After concatenation to_buf's chain now owns those buffers, and they will be freed when the to_buf chain is freed.

Parameters
to_bufMemory buffer chain to concatenate to
cat_bufMemory buffer chain to concatenate

Implemented in NanostackMemoryManager.

◆ get_next()

virtual net_stack_mem_buf_t * get_next ( const net_stack_mem_buf_t *  buf) const
pure virtualinherited

Returns the next buffer.

Returns the next buffer from the memory buffer chain.

Parameters
bufMemory buffer
Returns
The next memory buffer, or NULL if last

Implemented in NanostackMemoryManager.

◆ count_buffers()

size_t count_buffers ( const net_stack_mem_buf_t *  buf)
inherited

Count the number of buffers in a buffer chain.

Parameters
bufMemory buffer
Returns
The number of buffers in the chain

Definition at line 190 of file NetStackMemoryManager.h.

◆ get_ptr()

virtual void * get_ptr ( const net_stack_mem_buf_t *  buf) const
pure virtualinherited

Return pointer to the payload of the buffer.

Parameters
bufMemory buffer
Returns
Pointer to the payload

Implemented in NanostackMemoryManager.

◆ get_len()

virtual uint32_t get_len ( const net_stack_mem_buf_t *  buf) const
pure virtualinherited

Return payload size of this individual buffer (NOT including any chained buffers)

Parameters
bufMemory buffer
Returns
Size in bytes

Implemented in NanostackMemoryManager.

◆ set_len()

virtual void set_len ( net_stack_mem_buf_t *  buf,
uint32_t  len 
)
pure virtualinherited

Sets the payload size of the buffer.

The allocated payload size will not change. It is not permitted to change the length of a buffer that is not the first (or only) in a chain.

*Note as of Dec 2024: Different implementations (Nanostack vs LwIP) disagree about how to implement this operation. Specifically, if called on the head of a buffer chain, the LwIP implementation allows changing the length of the chain as a whole. However, the Nanostack implementation does not and only can change the length of the head buffer. For fear of breaking existing code, I do not want to change this behavior. So, if constructing a buffer chain, it is safest to set the buffer lengths first before building the chain.

Parameters
bufMemory buffer
lenPayload size, must be less or equal to the allocated size

Implemented in NanostackMemoryManager.

◆ get_lifetime()

virtual Lifetime get_lifetime ( net_stack_mem_buf_t const *  buf) const
pure virtualinherited

Gets the lifetime of the buffer.

Parameters
bufMemory buffer

Implemented in NanostackMemoryManager.

◆ set_on_pool_space_avail_cb()

void set_on_pool_space_avail_cb ( mbed::Callback< void()>  cb)
inherited

Set callback which will be called when pool space becomes available.

Warning
The callback could be called from any thread, and should make no assumptions about being in the same thread as anything else.
Parameters
cbCallback to call

Definition at line 257 of file NetStackMemoryManager.h.

Field Documentation

◆ onPoolSpaceAvailCallback

mbed::Callback<void()> onPoolSpaceAvailCallback
protectedinherited

Callback which shall be called (if set) by the implementation after one or more buffer spaces become free in the pool.

This is used by zero-copy Ethernet MACs as a hint that now is a good time to allocate fresh buffers off the pool into Ethernet descriptors. It is legal to call this function if you aren't totally sure new memory is available – the mac will try to allocate more buffers, and if it can't, oh well. However, it is not legal for memory to become available without a call to this function. Such a situation might lead to a lockup of the MAC due to not having memory allocated for Rx.

Definition at line 62 of file NetStackMemoryManager.h.