RTOS Abstraction Layer API#

The RTOS abstraction layer decouples Sound Open Firmware core logic from underlying real-time operating system primitives. It standardizes spinlocks, mutexes, task scheduling, high-resolution clocks, hardware timers, memory allocation pools, and cache coherency operations across supported DSP architectures.

group RTOS Abstraction Layer

RTOS primitives, synchronization (spinlocks, mutexes), memory allocation, clocks, and cache management.

Allocation flags

SOF_MEM_FLAG_DMA#

Allocate DMA-able memory.

SOF_MEM_FLAG_NO_COPY#

realloc() skips copying the original content.

SOF_MEM_FLAG_COHERENT#

Allocate uncached address.

SOF_MEM_FLAG_L3#

Allocate L3 address.

SOF_MEM_FLAG_LOW_POWER#

Allocate Low power memory address.

SOF_MEM_FLAG_KERNEL#

Allocate kernel memory address.

SOF_MEM_FLAG_USER#

Allocate user memory address.

SOF_MEM_FLAG_USER_SHARED_BUFFER#

Allocate shared user memory address.

SOF_MEM_FLAG_LARGE_BUFFER#

Use allocation method for large buffers.

Functions

void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment)#

Allocates memory block.

Parameters:
  • flags – Flags, see SOF_MEM_FLAG_….

  • bytes – Size in bytes.

  • alignment – Alignment in bytes.

Returns:

Pointer to the allocated memory or NULL if failed.

void *rmalloc(uint32_t flags, size_t bytes)#

Similar to rmalloc_align(), but no alignment can be specified.

void *rzalloc(uint32_t flags, size_t bytes)#

Similar to rmalloc(), guarantees that returned block is zeroed.

void *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment)#

Allocates memory block.

Parameters:
  • flags – Flags, see SOF_MEM_FLAG_…

  • bytes – Size in bytes.

  • alignment – Alignment in bytes.

Returns:

Pointer to the allocated memory or NULL if failed.

static inline void *rballoc(uint32_t flags, size_t bytes)#

Similar to rballoc_align(), returns buffer aligned to PLATFORM_DCACHE_ALIGN.

void rfree(void *ptr)#

Frees the memory block.

Parameters:
  • ptr – Pointer to the memory block.

void l3_heap_save(void)#

Save L3 heap over DSP reset.

void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes, size_t alignment)#

Allocate memory from a specified Zephyr heap or default system heap.

Parameters:
  • heap – Target Zephyr k_heap (or NULL to let implementation choose).

  • flags – Memory allocation flags (SOF_MEM_FLAG_…).

  • bytes – Size in bytes to allocate.

  • alignment – Required memory alignment in bytes.

Returns:

Pointer to allocated buffer, or NULL on allocation failure.

void sof_heap_free(struct k_heap *heap, void *addr)#

Free memory allocated via sof_heap_alloc().

Parameters:
  • heap – Target Zephyr k_heap.

  • addr – Address of allocated buffer to free.

static inline struct k_heap *sof_sys_heap_get(void)#

Get the system kernel heap descriptor.

Returns:

Pointer to the global system k_heap structure.

struct k_heap *sof_sys_user_heap_get(void)#

Returns heap object to use for SOF heap allocations for audio application code.

The returned value may be NULL. This matches with semantics of sof_heap_alloc() that allows passing NULL as the ‘heap’. In this case, the heap implementation will choose the heap to use.

The function should not be used for heap allocations for objects that are only used in SOF kernel space.

Note: audio modules should use mod_alloc() instead!

static inline void heap_trace_all(int force)#

Trace and log memory allocation statistics across all active heaps.

Parameters:
  • force – Force dumping heap trace even if logging threshold is not met.