Prusa MINI Firmware overview
memp.h File Reference
#include "lwip/opt.h"
#include "lwip/priv/memp_std.h"
#include "lwip/priv/memp_priv.h"
#include "lwip/stats.h"

Go to the source code of this file.

Macros

#define LWIP_MEMPOOL(name, num, size, desc)
 
#define LWIP_MEMPOOL(name, num, size, desc)   MEMP_##name,
 
#define LWIP_MEMPOOL_PROTOTYPE(name)   extern const struct memp_desc memp_ ## name
 
#define LWIP_MEMPOOL_DECLARE(name, num, size, desc)
 
#define LWIP_MEMPOOL_INIT(name)   memp_init_pool(&memp_ ## name)
 
#define LWIP_MEMPOOL_ALLOC(name)   memp_malloc_pool(&memp_ ## name)
 
#define LWIP_MEMPOOL_FREE(name, x)   memp_free_pool(&memp_ ## name, (x))
 

Enumerations

enum  memp_t { MEMP_MAX }
 

Functions

void memp_init (void)
 
voidmemp_malloc (memp_t type)
 
void memp_free (memp_t type, void *mem)
 

Variables

const struct memp_desc *const memp_pools [MEMP_MAX]
 

Detailed Description

Memory pool API

Macro Definition Documentation

◆ LWIP_MEMPOOL [1/2]

#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)

◆ LWIP_MEMPOOL [2/2]

#define LWIP_MEMPOOL (   name,
  num,
  size,
  desc 
)    MEMP_##name,

Enumeration Type Documentation

◆ memp_t

enum memp_t

Create the list of all memory pools managed by memp. MEMP_MAX represents a NULL pool at the end

Enumerator
MEMP_MAX 
52  {
53 #define LWIP_MEMPOOL(name,num,size,desc) MEMP_##name,
54 #include "lwip/priv/memp_std.h"
55  MEMP_MAX
56 } memp_t;

Function Documentation

◆ memp_init()

void memp_init ( void  )

Initializes lwIP built-in pools. Related functions: memp_malloc, memp_free

Carves out memp_memory into linked lists for each pool-type.

272 {
273  u16_t i;
274 
275  /* for every pool: */
276  for (i = 0; i < LWIP_ARRAYSIZE(memp_pools); i++) {
278 
279 #if LWIP_STATS && MEMP_STATS
280  lwip_stats.memp[i] = memp_pools[i]->stats;
281 #endif
282  }
283 
284 #if MEMP_OVERFLOW_CHECK >= 2
285  /* check everything a first time to see if it worked */
286  memp_overflow_check_all();
287 #endif /* MEMP_OVERFLOW_CHECK >= 2 */
288 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ memp_malloc()

void* memp_malloc ( memp_t  type)

Get an element from a specific pool.

Parameters
typethe pool to get an element from
Returns
a pointer to the allocated memory or a NULL pointer on error
389 {
390  void *memp;
391  LWIP_ERROR("memp_malloc: type < MEMP_MAX", (type < MEMP_MAX), return NULL;);
392 
393 #if MEMP_OVERFLOW_CHECK >= 2
394  memp_overflow_check_all();
395 #endif /* MEMP_OVERFLOW_CHECK >= 2 */
396 
397 #if !MEMP_OVERFLOW_CHECK
399 #else
400  memp = do_memp_malloc_pool_fn(memp_pools[type], file, line);
401 #endif
402 
403  return memp;
404 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ memp_free()

void memp_free ( memp_t  type,
void mem 
)

Put an element back into its pool.

Parameters
typethe pool where to put mem
memthe memp element to free
470 {
471 #ifdef LWIP_HOOK_MEMP_AVAILABLE
472  struct memp *old_first;
473 #endif
474 
475  LWIP_ERROR("memp_free: type < MEMP_MAX", (type < MEMP_MAX), return;);
476 
477  if (mem == NULL) {
478  return;
479  }
480 
481 #if MEMP_OVERFLOW_CHECK >= 2
482  memp_overflow_check_all();
483 #endif /* MEMP_OVERFLOW_CHECK >= 2 */
484 
485 #ifdef LWIP_HOOK_MEMP_AVAILABLE
486  old_first = *memp_pools[type]->tab;
487 #endif
488 
490 
491 #ifdef LWIP_HOOK_MEMP_AVAILABLE
492  if (old_first == NULL) {
493  LWIP_HOOK_MEMP_AVAILABLE(type);
494  }
495 #endif
496 }
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ memp_pools

const struct memp_desc* const memp_pools[MEMP_MAX]
do_memp_malloc_pool
static void * do_memp_malloc_pool(const struct memp_desc *desc)
Definition: memp.c:292
mem
Definition: mem.c:264
memp_init_pool
void memp_init_pool(const struct memp_desc *desc)
Definition: memp.c:230
u16_t
uint16_t u16_t
Definition: arch.h:121
LWIP_ARRAYSIZE
#define LWIP_ARRAYSIZE(x)
Definition: def.h:58
MEMP_MAX
Definition: memp.h:55
type
uint8_t type
Definition: UsbCore.h:184
i
uint8_t i
Definition: screen_test_graph.c:72
NULL
#define NULL
Definition: usbd_def.h:53
LWIP_ERROR
#define LWIP_ERROR(message, expression, handler)
Definition: debug.h:135
do_memp_free_pool
static void do_memp_free_pool(const struct memp_desc *desc, void *mem)
Definition: memp.c:407
memp_std.h
memp_desc::tab
struct memp ** tab
Definition: memp_priv.h:151
memp
Definition: memp_priv.h:91
memp_t
memp_t
Definition: memp.h:52
memp_pools
const struct memp_desc *const memp_pools[MEMP_MAX]
Definition: memp.c:81