Skip to content
Draft
22 changes: 4 additions & 18 deletions posix/include/rtos/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,18 @@
#ifndef __SOF_ATOMIC_H__
#define __SOF_ATOMIC_H__

#include <arch/atomic.h>
#include <zephyr/sys/atomic.h>
#include <stdint.h>

/* SOF names for atomic_set() and atomic_get(), as in zephyr/include/rtos/atomic.h */
static inline void atomic_init(atomic_t *a, int32_t value)
{
arch_atomic_init(a, value);
atomic_set(a, value);
}

static inline int32_t atomic_read(const atomic_t *a)
{
return arch_atomic_read(a);
}

static inline void atomic_set(atomic_t *a, int32_t value)
{
arch_atomic_set(a, value);
}

static inline int32_t atomic_add(atomic_t *a, int32_t value)
{
return arch_atomic_add(a, value);
}

static inline int32_t atomic_sub(atomic_t *a, int32_t value)
{
return arch_atomic_sub(a, value);
return atomic_get(a);
}

#endif /* __SOF_ATOMIC_H__ */
12 changes: 12 additions & 0 deletions posix/include/rtos/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,21 @@ void __panic(uint32_t p, const char *filename, uint32_t linenum) SOF_NORETURN;

#define sof_panic(x) __panic((x), (RELATIVE_FILE), (__LINE__))

/*
* Zephyr k_panic() takes no panic code. Report SOF_IPC_PANIC_ASSERT, the code
* of a failed assert(): Zephyr also ends a failed assertion with k_panic().
*/
#define k_panic() sof_panic(SOF_IPC_PANIC_ASSERT)

/* runtime assertion */
#ifndef assert
#define assert(cond) (void)((cond) || (sof_panic(SOF_IPC_PANIC_ASSERT), 0))
#endif

/*
* The Zephyr assert macros. On Zephyr, rtos/panic.h provides them through
* <zephyr/kernel.h>.
*/
#include <zephyr/sys/__assert.h>

#endif /* __POSIX_RTOS_PANIC_H__ */
47 changes: 47 additions & 0 deletions posix/include/zephyr/cache.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Stub for <zephyr/cache.h> used by the non-Zephyr host builds (the host
* library and the testbench), which compile the shared code against
* posix/include. Zephyr builds, native_sim included, use the Zephyr header.
*
* The host has no cache to maintain, so these return -ENOTSUP, like Zephyr
* built without CONFIG_CACHE_MANAGEMENT.
*/

#ifndef __POSIX_ZEPHYR_CACHE_H__
#define __POSIX_ZEPHYR_CACHE_H__

#include <errno.h>
#include <stddef.h>

static inline int sys_cache_data_flush_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

static inline int sys_cache_data_invd_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

static inline int sys_cache_data_flush_and_invd_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

static inline int sys_cache_instr_invd_range(void *addr, size_t size)
{
(void)addr;
(void)size;
return -ENOTSUP;
}

#endif /* __POSIX_ZEPHYR_CACHE_H__ */
54 changes: 54 additions & 0 deletions posix/include/zephyr/sys/__assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Stub for <zephyr/sys/__assert.h> used by the non-Zephyr host builds (the host
* library and the testbench), which compile the shared code against
* posix/include. Zephyr builds, native_sim included, use the Zephyr header.
*
* The host checks its assertions in every build, as assert() does: a failed
* assertion prints the condition and any message, then panics with
* SOF_IPC_PANIC_ASSERT.
*/

#ifndef __POSIX_ZEPHYR_SYS___ASSERT_H__
#define __POSIX_ZEPHYR_SYS___ASSERT_H__

#include <rtos/panic.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>

/*
* Print a failed assertion. The variable arguments are the optional message
* format and its arguments, then NULL: NULL alone means there is no message.
*/
static inline void posix_assert_print(const char *test, const char *file, int line, ...)
{
const char *fmt;
va_list ap;

fprintf(stderr, "ASSERTION FAIL [%s] @ %s:%d\n", test, file, line);
va_start(ap, line);
fmt = va_arg(ap, const char *);
if (fmt) {
fprintf(stderr, "\t");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
}
va_end(ap);
}

/* as in Zephyr, the message format and its arguments are optional */
#define __ASSERT(test, ...) \
do { \
if (!(test)) { \
posix_assert_print(#test, RELATIVE_FILE, __LINE__, \
##__VA_ARGS__, NULL); \
sof_panic(SOF_IPC_PANIC_ASSERT); \
} \
} while (0)

#define __ASSERT_NO_MSG(test) __ASSERT(test)

#endif /* __POSIX_ZEPHYR_SYS___ASSERT_H__ */
41 changes: 41 additions & 0 deletions posix/include/zephyr/sys/atomic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/*
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*
* Stub for <zephyr/sys/atomic.h> used by the non-Zephyr host builds (the host
* library and the testbench), which compile the shared code against
* posix/include. Zephyr builds, native_sim included, use the Zephyr header.
*
* The functions have the Zephyr names and return values: atomic_set(),
* atomic_add() and atomic_sub() return the previous value.
*/

#ifndef __POSIX_ZEPHYR_SYS_ATOMIC_H__
#define __POSIX_ZEPHYR_SYS_ATOMIC_H__

#include <arch/atomic.h>
#include <stdint.h>

typedef int32_t atomic_val_t;

static inline atomic_val_t atomic_get(const atomic_t *target)
{
return arch_atomic_read(target);
}

static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value)
{
return arch_atomic_swap(target, value);
}

static inline atomic_val_t atomic_add(atomic_t *target, atomic_val_t value)
{
return arch_atomic_add(target, value);
}

static inline atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value)
{
return arch_atomic_sub(target, value);
}

#endif /* __POSIX_ZEPHYR_SYS_ATOMIC_H__ */
4 changes: 2 additions & 2 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void src_copy_s16(struct processing_module *mod,
n_copy = (n < n_wrap_src) ? n : n_wrap_src;
s_copy = n_copy * sizeof(int16_t);
ret = memcpy_s(buf, s_copy, src, s_copy);
assert(!ret);
__ASSERT_NO_MSG(!ret);

/* Update and check both source and destination for wrap */
n -= n_copy;
Expand Down Expand Up @@ -172,7 +172,7 @@ static void src_copy_s16(struct processing_module *mod,
n_copy = (n < n_wrap_snk) ? n : n_wrap_snk;
s_copy = n_copy * sizeof(int16_t);
ret = memcpy_s(snk, s_copy, buf, s_copy);
assert(!ret);
__ASSERT_NO_MSG(!ret);

/* Update and check both source and destination for wrap */
n -= n_copy;
Expand Down
2 changes: 1 addition & 1 deletion src/audio/buffers/audio_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void audio_buffer_init(struct sof_audio_buffer *buffer, uint32_t buffer_type, bo
CORE_CHECK_STRUCT_INIT(buffer, is_shared);
buffer->buffer_type = buffer_type;
buffer->ops = audio_buffer_ops;
assert(audio_buffer_ops->free);
__ASSERT_NO_MSG(audio_buffer_ops->free);
buffer->audio_stream_params = audio_stream_params;
buffer->is_shared = is_shared;

Expand Down
12 changes: 6 additions & 6 deletions src/audio/buffers/comp_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void comp_buffer_free(struct sof_audio_buffer *audio_buffer)

struct mod_alloc_ctx *alloc = buffer->audio_buffer.alloc;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
sof_ctx_free(alloc, buffer->stream.addr);
Expand Down Expand Up @@ -292,7 +292,7 @@ struct comp_buffer *buffer_alloc(struct mod_alloc_ctx *alloc, size_t size, uint3
return NULL;
}

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
stream_addr = sof_ctx_alloc(alloc, flags, size, align);
Expand Down Expand Up @@ -340,7 +340,7 @@ struct comp_buffer *buffer_alloc_range(struct mod_alloc_ctx *alloc, size_t prefe
if (preferred_size % minimum_size)
preferred_size += minimum_size - preferred_size % minimum_size;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (size = preferred_size; size >= minimum_size; size -= minimum_size) {
if (alloc)
Expand Down Expand Up @@ -403,7 +403,7 @@ int buffer_set_size(struct comp_buffer *buffer, uint32_t size, uint32_t alignmen
if (size == audio_stream_get_size(&buffer->stream))
return 0;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

if (alloc)
new_ptr = sof_ctx_alloc(alloc, buffer->flags, size, alignment);
Expand Down Expand Up @@ -458,7 +458,7 @@ int buffer_set_size_range(struct comp_buffer *buffer, size_t preferred_size, siz
if (preferred_size == actual_size)
return 0;

assert(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);
__ASSERT_NO_MSG(!IS_ENABLED(CONFIG_SOF_USERSPACE_LL) || alloc);

for (new_size = preferred_size; new_size >= minimum_size;
new_size -= minimum_size) {
Expand Down Expand Up @@ -530,7 +530,7 @@ EXPORT_SYMBOL(buffer_set_params);
bool buffer_params_match(struct comp_buffer *buffer,
struct sof_ipc_stream_params *params, uint32_t flag)
{
assert(params);
__ASSERT_NO_MSG(params);
CORE_CHECK_STRUCT(&buffer->audio_buffer);

if ((flag & BUFF_PARAMS_FRAME_FMT) &&
Expand Down
2 changes: 1 addition & 1 deletion src/audio/buffers/ring_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ uint8_t __sparse_cache *ring_buffer_get_pointer(struct ring_buffer *ring_buffer,
static inline
size_t ring_buffer_inc_offset(struct ring_buffer *ring_buffer, size_t offset, size_t inc)
{
assert(inc <= ring_buffer->data_buffer_size);
__ASSERT_NO_MSG(inc <= ring_buffer->data_buffer_size);
offset += inc;
/* wrap around ? 2*size because of "double area" */
if (offset >= 2 * ring_buffer->data_buffer_size)
Expand Down
4 changes: 2 additions & 2 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static APP_SYSUSER_BSS struct comp_driver_list cd;
#ifdef CONFIG_SOF_USERSPACE_LL
struct comp_driver_list *comp_drivers_get(void)
{
assert(!ll_sch_is_current());
__ASSERT_NO_MSG(!ll_sch_is_current());
return &cd;
}
#endif
Expand Down Expand Up @@ -586,7 +586,7 @@ int comp_copy(struct comp_dev *dev)
{
int ret = 0;

assert(dev->drv->ops.copy);
__ASSERT_NO_MSG(dev->drv->ops.copy);

/* copy only if we are the owner of component OR this is DP component
*
Expand Down
2 changes: 1 addition & 1 deletion src/audio/copier/copier_dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void copier_dai_adjust_params(const struct copier_data *cd,
int dma_buf_container_bits, dma_buf_valid_bits;

/* Call this func only for DAI gateway with already setup DMA buffer */
assert(cd->dd[0] && cd->dd[0]->dma_buffer);
__ASSERT_NO_MSG(cd->dd[0] && cd->dd[0]->dma_buffer);
dma_buf = cd->dd[0]->dma_buffer;

/* Unfortunately, configuring the gateway DMA buffer format is somewhat confusing.
Expand Down
2 changes: 1 addition & 1 deletion src/audio/copier/copier_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ static bool is_remapping_chmap(uint32_t chmap, size_t out_channel_count)
{
size_t i;

assert(out_channel_count <= 8);
__ASSERT_NO_MSG(out_channel_count <= 8);

for (i = 0; i < out_channel_count; i++) {
if ((chmap & 0xf) != i)
Expand Down
4 changes: 2 additions & 2 deletions src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ static int crossover_init_coef_lr4(struct processing_module *mod,
/* coefficients of the first biquad */
ret = memcpy_s(lr4->coef, sizeof(struct sof_eq_iir_biquad),
coef, sizeof(struct sof_eq_iir_biquad));
assert(!ret);
__ASSERT_NO_MSG(!ret);

/* coefficients of the second biquad */
ret = memcpy_s(lr4->coef + SOF_EQ_IIR_NBIQUAD,
sizeof(struct sof_eq_iir_biquad),
coef, sizeof(struct sof_eq_iir_biquad));
assert(!ret);
__ASSERT_NO_MSG(!ret);

/* LR4 filters are two 2nd order filters, so only need 4 delay slots
* delay[0..1] -> state for first biquad
Expand Down
6 changes: 3 additions & 3 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ dai_dma_multi_endpoint_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t fr
if (dev->direction == SOF_IPC_STREAM_CAPTURE)
audio_stream_invalidate(&dd->dma_buffer->stream, bytes);

assert(dd->channel_copy);
__ASSERT_NO_MSG(dd->channel_copy);

/* copy all channels one by one */
for (i = 0; i < audio_stream_get_channels(&dd->dma_buffer->stream); i++) {
Expand Down Expand Up @@ -1948,8 +1948,8 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
}
}

assert(audio_stream_get_channels(&dd->dma_buffer->stream));
assert(audio_stream_get_channels(&dd->local_buffer->stream));
__ASSERT_NO_MSG(audio_stream_get_channels(&dd->dma_buffer->stream));
__ASSERT_NO_MSG(audio_stream_get_channels(&dd->local_buffer->stream));

/* calculate minimum size to copy */
if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
Expand Down
Loading
Loading