MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
memoria_externa — external memory

Data Structures

struct  PingPong
 A pair of buffers, one under fill while the other is under drain. More...
struct  ExternaCfg
 Arguments for every exter call, where each call reads only the members it needs. More...
struct  MemoriaExternaNs
 Type of the exter dispatch table. More...

Enumerations

enum  mmgr_place {
  PLACE_DRAM ,
  PLACE_PSRAM ,
  PLACE_FAIL
}
 Where a request should go. More...

Functions

EMBED_HOST_DEVICE mmgr_place mmgr_extern_place (const ExternaCfg *args)
 Decides whether a request belongs in internal or external memory.
EMBED_HOST_DEVICE void mmgr_pingpong_init (const ExternaCfg *args)
 Points the pair at buffer 0.
EMBED_HOST_DEVICE uint8_t mmgr_pingpong_fill_index (const ExternaCfg *args)
 Returns the index of the buffer under fill.
EMBED_HOST_DEVICE uint8_t mmgr_pingpong_drain_index (const ExternaCfg *args)
 Returns the index of the buffer under drain.
EMBED_HOST_DEVICE uint8_t mmgr_pingpong_swap (const ExternaCfg *args)
 Swaps which buffer takes the fill and which the drain.

Variables

static const MemoriaExternaNs exter
 Dispatch table instance named exter.

Detailed Description

Enumeration Type Documentation

◆ mmgr_place

enum mmgr_place

Where a request should go.

Note
One byte on every compiler, through EMBED_ENUM_BYTE.
Enumerator
PLACE_DRAM 

Internal memory.

PLACE_PSRAM 

External memory.

PLACE_FAIL 

Neither will take it.

Definition at line 35 of file memoria_externa.h.

Function Documentation

◆ mmgr_extern_place()

EMBED_HOST_DEVICE mmgr_place mmgr_extern_place ( const ExternaCfg * args)

Decides whether a request belongs in internal or external memory.

Parameters
[in]argsRequest size, the DMA requirement and both memory figures [BORROWS].
Returns
PLACE_DRAM, PLACE_PSRAM, or PLACE_FAIL when neither will take it.
Note
A size of 0 gives PLACE_FAIL.
A DMA request only ever gives PLACE_DRAM or PLACE_FAIL, never external memory.
At or above psram_threshold external memory comes first, below it internal does.
Warning
The two tests are not the same shape. Internal placement must also leave dram_reserve free, where the external one is a size comparison alone.

References mmgr_extern_place().

Referenced by mmgr_extern_place().

◆ mmgr_pingpong_init()

EMBED_HOST_DEVICE void mmgr_pingpong_init ( const ExternaCfg * args)

Points the pair at buffer 0.

Parameters
[in,out]argsPair to reset, as args->pingpong [BORROWS].
Note
The other three pingpong entries read a pair this call set.
Warning
args->pingpong must not be null. Nothing checks it and no assertion covers it, and this call writes through it at once.

References mmgr_pingpong_init().

Referenced by mmgr_pingpong_init().

◆ mmgr_pingpong_fill_index()

EMBED_HOST_DEVICE uint8_t mmgr_pingpong_fill_index ( const ExternaCfg * args)

Returns the index of the buffer under fill.

Parameters
[in]argsPair to read, as args->pingpong [BORROWS].
Returns
0 or 1.
Note
Does not modify args->pingpong.
Warning
args->pingpong must not be null. Nothing checks it and no assertion covers it.
Reports fill_index as it is. On a pair that has not been through mmgr_pingpong_init that is whatever its storage contained, and this call does not bound it to 0 or 1.

References mmgr_pingpong_fill_index().

Referenced by mmgr_pingpong_fill_index().

◆ mmgr_pingpong_drain_index()

EMBED_HOST_DEVICE uint8_t mmgr_pingpong_drain_index ( const ExternaCfg * args)

Returns the index of the buffer under drain.

Parameters
[in]argsPair to read, as args->pingpong [BORROWS].
Returns
The other index, 0 or 1.
Note
The answer is fill_index with its low bit flipped, and so the two indexes always disagree.
Does not modify args->pingpong.
Warning
args->pingpong must not be null. Nothing checks it and no assertion covers it.
The answer is an index only while fill_index is 0 or 1. On a pair that has not been through mmgr_pingpong_init it is the flip of whatever its storage contained.

References mmgr_pingpong_drain_index().

Referenced by mmgr_pingpong_drain_index().

◆ mmgr_pingpong_swap()

EMBED_HOST_DEVICE uint8_t mmgr_pingpong_swap ( const ExternaCfg * args)

Swaps which buffer takes the fill and which the drain.

Parameters
[in,out]argsPair to flip, as args->pingpong [BORROWS].
Returns
The index now under fill, 0 or 1.
Note
Flips the low bit. A swap of a swap is where it started.
Warning
args->pingpong must not be null. Nothing checks it and no assertion covers it.
One caller at a time. The flip and the read that follows it are two steps on a plain byte, with no atomic and no lock. So two callers that swap the same pair can come away with the same index.

References mmgr_pingpong_swap().

Referenced by mmgr_pingpong_swap().

Variable Documentation

◆ exter

const MemoriaExternaNs exter
static

Dispatch table instance named exter.

Note
pingpong_fill calls mmgr_pingpong_fill_index and pingpong_drain calls mmgr_pingpong_drain_index.

Definition at line 152 of file memoria_externa.h.