MEMORY API

[中文]

  • The OS abstraction layer encapsulates all memory application and release interfaces.

Header File

Functions

void *os_memcpy(void *out, const void *in, UINT32 n)

copies data from one memory location to another memory location with specified length

Note

this function is a wrapper for memcpy

Parameters
  • out – : the pointer of source memory location

  • in – : the pointer of destinated memory location

  • n – : the specified length

static inline void os_memcpy_word(uint32_t *out, const uint32_t *in, uint32_t n)
static inline void os_memset_word(uint32_t *b, int32_t c, uint32_t n)
INT32 os_memcmp(const void *s1, const void *s2, UINT32 n)

comparing the size of two memory blocks by specified length

Note

this function is a wrapper for memcmp

Parameters
  • s1 – : the pointer of a memory block

  • s2 – : the pointer of other memory block

  • n – : the specified length

Returns

the comarison results

void *os_memmove(void *out, const void *in, UINT32 n)

move data from one memory location to another memory location with specified length

Note

this function is a wrapper for memmove

Parameters
  • out – : the pointer of source memory location

  • in – : the pointer of destinated memory location

  • n – : the specified length

int os_memcmp_const(const void *a, const void *b, size_t len)

copies data from one memory location to another memory location with specified length

Note

this function is a wrapper for memcpy

Parameters
  • a – : the pointer of source memory location

  • b – : the pointer of destinated memory location

  • len – : the specified length

void *os_memset(void *b, int c, UINT32 len)

fill or copy a given value into the specified len bytes of the specified memory

Note

this function is a wrapper for memset

Parameters
  • b – : the pointer of the specified memory

  • c – : the given value

  • len – : the specified length

void *os_realloc(void *ptr, size_t size)

reallocate memory

Note

this API cannot be called in interrupt context

Parameters
  • ptr – : the pointer of the specified memory

  • size – : the reallocate memory length

void *bk_psram_realloc(void *ptr, size_t size)

reallocate memory in psram

Note

this API cannot be called in interrupt context

Parameters
  • ptr – : the pointer of the specified memory

  • size – : the reallocate memory length

void *psram_realloc(void *ptr, size_t size)
void *os_malloc(size_t size)

request memory according to the specified size

Note

This API cannot be called in interrupt context. When macro CONFIG_USE_PSRAM_HEAP_AT_SRAM_OOM is configured, if sram is insufficient,the system will try to request memory form psram

Parameters

size – : requested memory size

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void *os_sram_malloc(size_t size)

request memory according to the specified size

Note

This API cannot be called in interrupt context. and only request memory in sram when call this API

Parameters

size – : requested memory size

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void os_free(void *ptr)

release preciously reuqested memory

Note

This API cannot be called in interrupt context.

Parameters

ptr – : the pointer of the handle previously requested

void *os_zalloc(size_t size)

request memory of a specified size and auotmatically initializes the allocated memory to zero

Note

This API cannot be called in interrupt context. and this function is a wrapper for memset and malloc

Parameters

size – : requested memory size

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void *psram_malloc(size_t size)

request memory in psram according to the specified size

Note

This API cannot be called in interrupt context.

Parameters

size – : requested pspram memory size

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void *psram_zalloc(size_t size)

request psram memory of a specified size and auotmatically initializes the allocated memory to zero

Note

This API cannot be called in interrupt context. and this function is a wrapper for psram_malloc and memset

Parameters

size – : requested psram memory size

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void *os_sram_calloc(size_t a, size_t b)

request memory in sram of a specified size and auotmatically initializes the allocated memory to zero

Note

This API cannot be called in interrupt context. and this function is a wrapper for os_sram_malloc and memset

Parameters
  • a – : the number of elements to allocate

  • b – : the size of each element in bytes

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void *os_sram_zalloc(size_t size)

request memory in sram of a specified size and auotmatically initializes the allocated memory to zero

Note

This API cannot be called in interrupt context. and this function is a wrapper for os_sram_malloc and memset

Parameters

size – : requested memory size in sram

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

uint32_t bk_psram_heap_get_used_count(void)

get the current used psram size

Returns

psram size has been used

void bk_psram_heap_get_used_state(void)

get detailed information about the current psram in use

void bk_psram_heap_dump_data(void)
void *os_malloc_wifi_buffer(size_t size)

request memory according to the specified size

Parameters

size – : requested memory size

Returns

if request success, return the pointer of the memory, otherwise NULL is returned

void os_show_memory_config_info(void)

show current system memory information

Macros

os_write_word(addr, val)

write value by word size

os_read_word(addr, val)

read value by word size

os_get_word(addr)

get value by word size

psram_free

Enumerations

enum beken_mem_type_t

Memory type for mempool.

Values:

enumerator HEAP_MEM_TYPE_DEFAULT

Default heap memory type

enumerator HEAP_MEM_TYPE_SRAM

SRAM heap memory type

enumerator HEAP_MEM_TYPE_PSRAM

PSRAM heap memory type

enumerator MEM_TYPE_MAX