Skip to content

Commit fd94f25

Browse files
authored
Add POSIX and Zephyr platform support for Ocre runtime (#70)
- Introduced core internal headers and source files for both POSIX and Zephyr platforms, including memory management, threading, mutexes, message queues, timers, and miscellaneous utilities. - Implemented core functions for memory allocation and deallocation using `malloc` and `free` for POSIX, and `k_malloc` and `k_free` for Zephyr. - Developed message queue functionalities with initialization, sending, and receiving capabilities for both platforms. - Created thread management functions to handle thread creation, destruction, and execution for both environments. - Added timer functionalities to support periodic and one-shot timers in the Ocre runtime. - Implemented filesystem operations for Zephyr, including file opening, reading, and directory listing. - Configured CMake build scripts for both platforms, ensuring proper linking and compilation of the Ocre runtime components. - Integrated WAMR (WebAssembly Micro Runtime) support for both platforms, allowing for enhanced execution of WebAssembly modules. Signed-off-by: Krisztian Szilvasi <34309983+kr-t@users.noreply.github.com>
1 parent 52461d7 commit fd94f25

76 files changed

Lines changed: 5654 additions & 2461 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ Thumbs.db
5757
*.mov
5858
*.wmv
5959

60+
# VS Code IDE
61+
.vscode/

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "wasm-micro-runtime"]
2+
path = wasm-micro-runtime
3+
url = https://github.com/bytecodealliance/wasm-micro-runtime.git

CMakeLists.txt

Lines changed: 45 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,52 @@
11
cmake_minimum_required(VERSION 3.20.0)
22

3-
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
3+
# Allow user to set CMAKE_SYSTEM_NAME via -DCMAKE_SYSTEM_NAME=Zephyr or Linux
4+
if(NOT DEFINED TARGET_PLATFORM_NAME)
5+
set(TARGET_PLATFORM_NAME "Zephyr")
6+
endif()
47

5-
project(ocre VERSION ${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_PATCHLEVEL}.${APP_VERSION_TWEAK} LANGUAGES C ASM)
8+
if(TARGET_PLATFORM_NAME STREQUAL "Linux")
9+
project(ocre LANGUAGES C ASM)
10+
elseif(TARGET_PLATFORM_NAME STREQUAL "Zephyr")
11+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
12+
project(ocre VERSION ${APP_VERSION_MAJOR}.${APP_VERSION_MINOR}.${APP_PATCHLEVEL}.${APP_VERSION_TWEAK} LANGUAGES C ASM)
13+
else()
14+
message(FATAL_ERROR "Unsupported TARGET_PLATFORM_NAME: ${TARGET_PLATFORM_NAME}")
15+
endif()
616

17+
# ----------- COMMON SECTION -----------
718
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
19+
set(CMAKE_C_STANDARD 99)
20+
set(CMAKE_CXX_STANDARD 17)
821

22+
# Version and build info (common)
923
execute_process(
10-
COMMAND git describe --long --dirty --always
11-
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
12-
OUTPUT_VARIABLE RAW_GIT_VERSION
13-
OUTPUT_STRIP_TRAILING_WHITESPACE
14-
)
15-
24+
COMMAND git describe --long --dirty --always
25+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
26+
OUTPUT_VARIABLE RAW_GIT_VERSION
27+
OUTPUT_STRIP_TRAILING_WHITESPACE
28+
)
1629
string(REPLACE "-dirty" "+" BUILD_INFO ${RAW_GIT_VERSION})
17-
1830
string(TIMESTAMP BUILD_DATE "%d-%m-%Y, %H:%M" UTC )
19-
2031
cmake_host_system_information(RESULT BUILD_MACHINE QUERY HOSTNAME)
21-
2232
string(PREPEND BUILD_INFO dev-)
23-
2433
string(REPLACE "-" ";" GIT_INFO_LIST ${RAW_GIT_VERSION})
2534
list(GET GIT_INFO_LIST 0 VERSION_NUMBER)
26-
message("VERSION NUMBER: ${VERSION_NUMBER}")
27-
zephyr_compile_options(-DVERSION_INFO="${VERSION_NUMBER}")
28-
message("BUILD DATE: ${BUILD_DATE}")
29-
zephyr_compile_options(-DVERSION_BUILD_DATE="${BUILD_DATE}")
30-
message("BUILD MACHINE: ${BUILD_MACHINE}")
31-
zephyr_compile_options(-DVERSION_BUILD_MACHINE="${BUILD_MACHINE}")
32-
message("BUILD_INFO: ${BUILD_INFO}")
33-
zephyr_compile_options(-DVERSION_BUILD_INFO="${BUILD_INFO}")
34-
35-
# Determine the ISA of the target and set appropriately
36-
if (DEFINED CONFIG_ISA_THUMB2)
37-
set (TARGET_ISA THUMB)
38-
elseif (DEFINED CONFIG_ISA_ARM)
39-
set (TARGET_ISA ARM)
40-
elseif (DEFINED CONFIG_X86)
41-
set (TARGET_ISA X86_32)
42-
elseif (DEFINED CONFIG_XTENSA)
43-
set (TARGET_ISA XTENSA)
44-
elseif (DEFINED CONFIG_RISCV)
45-
set (TARGET_ISA RISCV32)
46-
elseif (DEFINED CONFIG_ARCH_POSIX)
47-
# Technically, this is not correct as the CPU architecture is not set. This assumes POSIX is x86 32-bit
48-
set (TARGET_ISA X86_32)
49-
else ()
50-
message (FATAL_ERROR "Unsupported ISA: ${CONFIG_ARCH}")
51-
endif ()
52-
message("TARGET ISA: ${TARGET_ISA}")
53-
54-
add_compile_options(-O0 -Wno-unknown-attributes)
55-
56-
57-
##################
58-
# WAMR Options #
59-
##################
60-
set (WAMR_BUILD_PLATFORM "zephyr")
61-
set (WAMR_BUILD_TARGET ${TARGET_ISA})
62-
set (WAMR_BUILD_INTERP 1)
63-
set (WAMR_BUILD_FAST_INTERP 0)
64-
set (WAMR_BUILD_AOT 0)
65-
set (WAMR_BUILD_JIT 0)
66-
set (WAMR_BUILD_LIBC_BUILTIN 0)
67-
set (WAMR_BUILD_LIBC_WASI 1)
68-
set (WAMR_BUILD_LIB_PTHREAD 1)
69-
set (WAMR_BUILD_REF_TYPES 1)
70-
set (WASM_ENABLE_LOG 1)
71-
72-
# Override the global heap usage
73-
if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL)
74-
set (WAMR_BUILD_GLOBAL_HEAP_POOL 1)
75-
endif ()
76-
77-
# Override the global heap size for small devices
78-
if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE)
79-
#set (WAMR_BUILD_GLOBAL_HEAP_SIZE 131072) # 128 KB
80-
set (WAMR_BUILD_GLOBAL_HEAP_SIZE 32767) # 32 KB
81-
endif ()
82-
83-
# Include WAMR build script
84-
set (WAMR_ROOT_DIR ${ZEPHYR_WASM_MICRO_RUNTIME_MODULE_DIR})
85-
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
8635

87-
# Generate the messages header file
36+
# Message generation (common)
8837
set(OCRE_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
8938
set(MSG_INPUT_FILES ${OCRE_ROOT_DIR}/src/ocre/components/container_supervisor/component_supervisor.yaml )
9039
set(MSG_GENERATED_FILE ${CMAKE_CURRENT_LIST_DIR}/src/messaging/messages.g)
9140

41+
# Zephyr toolchain usually provides PYTHON_EXECUTABLE
42+
if(NOT DEFINED PYTHON_EXECUTABLE)
43+
find_package(Python3 QUIET REQUIRED Interpreter Development)
44+
if(NOT Python3_FOUND)
45+
message(FATAL_ERROR "Python3 interpreter not found. Please install Python3 or set PYTHON_EXECUTABLE to the path of your Python interpreter.")
46+
endif()
47+
set(PYTHON_EXECUTABLE ${Python3_EXECUTABLE})
48+
endif()
49+
9250
add_custom_command(
9351
OUTPUT ${MSG_GENERATED_FILE}
9452
COMMAND ${PYTHON_EXECUTABLE} ${OCRE_ROOT_DIR}/tools/automsg ${MSG_INPUT_FILES} ${MSG_GENERATED_FILE}
@@ -97,53 +55,22 @@ add_custom_command(
9755
)
9856
add_custom_target(generate_messages DEPENDS ${MSG_GENERATED_FILE})
9957

100-
zephyr_include_directories(
101-
src/
102-
src/ocre
103-
)
104-
105-
set(lib_sources
106-
# Libraries
107-
src/ocre/sm/sm.c
108-
src/ocre/fs/fs.c
109-
src/ocre/ocre_timers/ocre_timer.c
110-
src/ocre/container_healthcheck/ocre_container_healthcheck.c
111-
112-
# Ocre APIs
113-
src/ocre/api/ocre_api.c
114-
)
115-
116-
# Compile in sensors framework if enabled.
117-
if(CONFIG_OCRE_SENSORS)
118-
set(ocre_sources ${ocre_sources} ${OCRE_ROOT_DIR}/src/ocre/ocre_sensors/ocre_sensors.c)
119-
endif()
58+
if(NOT "${OCRE_INPUT_FILE}" STREQUAL "")
59+
message("Using input file: ${OCRE_INPUT_FILE}")
60+
add_custom_command(
61+
OUTPUT ${CMAKE_CURRENT_LIST_DIR}/src/ocre/ocre_input_file.g
62+
COMMAND xxd -n wasm_binary -i ${OCRE_INPUT_FILE} > ${CMAKE_CURRENT_LIST_DIR}/src/ocre/ocre_input_file.g
63+
DEPENDS ${OCRE_INPUT_FILE}
64+
COMMENT "Generating C header from ${OCRE_INPUT_FILE}"
65+
)
12066

121-
# Compile random sensor if enabled.
122-
if(CONFIG_RNG_SENSOR)
123-
set(ocre_sources ${ocre_sources} ${OCRE_ROOT_DIR}/src/ocre/ocre_sensors/rng_sensor.c)
124-
endif()
67+
add_definitions(-DHAS_GENERATED_INPUT)
12568

126-
if(DEFINED CONFIG_OCRE_GPIO)
127-
set(lib_sources ${lib_sources}
128-
src/ocre/ocre_gpio/ocre_gpio.c
129-
)
69+
add_custom_target(generate_ocre_file DEPENDS ${CMAKE_CURRENT_LIST_DIR}/src/ocre/ocre_input_file.g)
13070
endif()
13171

132-
# Compile container messaging if enabled.
133-
if(CONFIG_OCRE_CONTAINER_MESSAGING)
134-
set(lib_sources ${lib_sources} src/ocre/container_messaging/messaging.c)
72+
if(TARGET_PLATFORM_NAME STREQUAL "Linux")
73+
include(${CMAKE_CURRENT_LIST_DIR}/src/shared/platform/posix/ocre_internal.cmake)
74+
elseif(TARGET_PLATFORM_NAME STREQUAL "Zephyr")
75+
include(${CMAKE_CURRENT_LIST_DIR}/src/shared/platform/zephyr/ocre_internal.cmake)
13576
endif()
136-
137-
set(component_sources
138-
# Component support
139-
src/ocre/component/component.c
140-
141-
# Components
142-
src/ocre/ocre_container_runtime/ocre_container_runtime.c
143-
src/ocre/components/container_supervisor/cs_main.c
144-
src/ocre/components/container_supervisor/cs_sm.c
145-
src/ocre/components/container_supervisor/cs_sm_impl.c
146-
)
147-
148-
target_sources(app PRIVATE ${WAMR_RUNTIME_LIB_SOURCE} ${lib_sources} ${component_sources} src/main.c)
149-
add_dependencies(app generate_messages)

Kconfig

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ config OCRE_CONTAINER_DEFAULT_STACK_SIZE
115115
help
116116
The default value used for a container's stack size.
117117

118+
config MAX_CONTAINERS
119+
int "Maximum concurrent containers"
120+
default 10
121+
help
122+
The default value for maximum number of container's.
123+
118124
config MAX_TIMERS
119125
int "Maximum number of timers"
120126
default 5
@@ -146,6 +152,14 @@ config OCRE_GPIO
146152
help
147153
Enable the OCRE GPIO driver that provides a portable API layer
148154
for GPIO operations across different hardware platforms.
155+
156+
157+
config OCRE_TIMER
158+
bool "OCRE Timer Driver"
159+
default y
160+
help
161+
Enable the OCRE Timer driver that provides a portable API layer
162+
for Timer operations across different hardware platforms.
149163

150164
config OCRE_GPIO_MAX_PINS
151165
int "Maximum number of GPIO pins"
@@ -179,4 +193,17 @@ config MESSAGING_MAX_SUBSCRIPTIONS
179193
help
180194
Number of maximum subscriptions for Container Messaging
181195

196+
config OCRE_SHELL
197+
bool "Enable OCRE Shell"
198+
default y
199+
help
200+
Enable the OCRE Shell for dynamic configuration management.
201+
202+
config IMU_SENSOR
203+
bool "IMU Sensor"
204+
default n
205+
depends on OCRE_SENSORS
206+
help
207+
Enable support for the custom IMU sensor.
208+
182209
endmenu

0 commit comments

Comments
 (0)