Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions cmake/Generic.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#********************************************************************
# _ _ _
# _ __ | |_ _ | | __ _ | |__ ___
# | '__|| __|(_)| | / _` || '_ \ / __|
# | | | |_ _ | || (_| || |_) |\__ \
# |_| \__|(_)|_| \__,_||_.__/ |___/
#
# www.rt-labs.com
# Copyright 2026 rt-labs AB, Sweden.
#
# This software is licensed under the terms of the BSD 3-clause
# license. See the file LICENSE distributed with this software for
# full license information.
#*******************************************************************/

if(ZEPHYR_BASE)
include(${CMAKE_CURRENT_LIST_DIR}/Zephyr.cmake)
endif()
20 changes: 20 additions & 0 deletions cmake/Zephyr.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#********************************************************************
# _ _ _
# _ __ | |_ _ | | __ _ | |__ ___
# | '__|| __|(_)| | / _` || '_ \ / __|
# | | | |_ _ | || (_| || |_) |\__ \
# |_| \__|(_)|_| \__,_||_.__/ |___/
#
# www.rt-labs.com
# Copyright 2026 rt-labs AB, Sweden.
#
# This software is licensed under the terms of the BSD 3-clause
# license. See the file LICENSE distributed with this software for
# full license information.
#*******************************************************************/

add_subdirectory(src/zephyr)

set (OSAL_DEFAULT_SYSTEM
osal-zephyr
CACHE STRING ${OSAL_DEFAULT_SYSTEM_HELP_STRING})
56 changes: 56 additions & 0 deletions src/zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#********************************************************************
# _ _ _
# _ __ | |_ _ | | __ _ | |__ ___
# | '__|| __|(_)| | / _` || '_ \ / __|
# | | | |_ _ | || (_| || |_) |\__ \
# |_| \__|(_)|_| \__,_||_.__/ |___/
#
# www.rt-labs.com
# Copyright 2017 rt-labs AB, Sweden.
#
# This software is licensed under the terms of the BSD 3-clause
# license. See the file LICENSE distributed with this software for
# full license information.
#*******************************************************************/

set(_osal_sys osal-zephyr)
add_library(${_osal_sys})

add_dependencies(${_osal_sys} zephyr_generated_headers)

target_compile_features(${_osal_sys}
PUBLIC
c_std_99
)

target_sources(${_osal_sys}
PRIVATE
osal.c
osal_log.c
)

target_compile_options(${_osal_sys}
PRIVATE
-Wall
-Wextra
-Werror
-Wno-unused-parameter
)

target_link_libraries(${_osal_sys}
PUBLIC
osal-interface
PRIVATE
$<BUILD_INTERFACE:zephyr_interface>
$<BUILD_INTERFACE:kernel>
)

target_include_directories(${_osal_sys}
PRIVATE
sys
)

install(
TARGETS ${_osal_sys}
EXPORT OsalTargets
)
35 changes: 35 additions & 0 deletions src/zephyr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# OSAL Zephyr backend

## Required Kconfig options

Applications linking against `osal` on Zephyr need the following in
their `prj.conf`:

```
CONFIG_HEAP_MEM_POOL_SIZE=<size>
CONFIG_THREAD_STACK_INFO=y
CONFIG_DYNAMIC_THREAD=y
CONFIG_DYNAMIC_THREAD_ALLOC=y
CONFIG_EVENTS=y
CONFIG_THREAD_NAME=y
CONFIG_LOG=y
```

- `HEAP_MEM_POOL_SIZE`: backs `k_malloc`/`k_free`, used throughout `osal.c`.
- `THREAD_STACK_INFO`: required by `DYNAMIC_THREAD`.
- `DYNAMIC_THREAD` + `DYNAMIC_THREAD_ALLOC`: `os_thread_create()` takes a
runtime stack size, so stacks are heap-allocated via
`k_thread_stack_alloc()` rather than declared statically.
- `EVENTS`: backs `os_event_*()` (`k_event`).
- `THREAD_NAME`: `os_thread_create()` sets the Zephyr thread name from
its `name` argument.
- `LOG`: backs `os_log()` (`osal_log.c`). Without it, log calls compile
down to no-ops.

## Linking

Link against `osal` normally:

```cmake
target_link_libraries(app PRIVATE osal)
```
Loading
Loading