EtherLib/dynmem.c
Epagris 0a6d007c73 - blocking FIFO name collision fixed, by prepending BlockingFifo function names with "eth_"
- CMake integration added
- OS calls got tailored to CMSIS OS2 interface
2024-04-13 16:57:21 +02:00

31 lines
804 B
C

#include "dynmem.h"
#include "global_state.h"
#include "utils.h"
#if !defined(ETHLIB_MEMORY_POOL_ATTRIBUTES)
static uint8_t sDynMemPool[ETHLIB_MEMORY_POOL_TOTAL_SIZE];
#else
static uint8_t sDynMemPool[ETHLIB_MEMORY_POOL_TOTAL_SIZE] __attribute__((ETHLIB_MEMORY_POOL_ATTRIBUTES));
#endif
static ETHLIB_OS_MTX_TYPE dynmem_mtx;
void dynmem_init() {
dynmem_mtx = ETHLIB_OS_MTX_CREATE();
E.mp = mp_init(sDynMemPool, ETHLIB_MEMORY_POOL_TOTAL_SIZE);
ASSERT_NULL(E.mp);
}
void *dynmem_alloc_(uint32_t size) {
ETHLIB_OS_MTX_LOCK(&dynmem_mtx);
void * p = mp_alloc(E.mp, size);
ETHLIB_OS_MTX_UNLOCK(&dynmem_mtx);
return p;
}
void dynmem_free_(const void *ptr) {
ETHLIB_OS_MTX_LOCK(&dynmem_mtx);
mp_free(E.mp, (const uint8_t *) ptr);
ETHLIB_OS_MTX_UNLOCK(&dynmem_mtx);
}