diff --git a/libmetal/lib/CMakeLists.txt b/libmetal/lib/CMakeLists.txt index e9d5276..c8dd7d2 100644 --- a/libmetal/lib/CMakeLists.txt +++ b/libmetal/lib/CMakeLists.txt @@ -41,7 +41,9 @@ collect (PROJECT_LIB_SOURCES softirq.c) collect (PROJECT_LIB_SOURCES version.c) add_subdirectory (compiler) -add_subdirectory (processor) +if (NOT DEFINED METAL_PROCESSOR_HEADERS_ON_SYSTEM) + add_subdirectory (processor) +endif() add_subdirectory (system) collector_list (_inc_dirs PROJECT_INC_DIRS) @@ -72,6 +74,9 @@ if (WITH_ZEPHYR) add_dependencies(metal offsets_h) zephyr_library_sources(${_sources}) zephyr_include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) + if (DEFINED METAL_PROCESSOR_HEADERS_ON_SYSTEM) + zephyr_compile_definitions(METAL_PROCESSOR_HEADERS_ON_SYSTEM) + endif() else (WITH_ZEPHYR) # Build a shared library if so configured. if (WITH_SHARED_LIB) diff --git a/libmetal/lib/atomic.h b/libmetal/lib/atomic.h index 44d6b9a..e0f387a 100644 --- a/libmetal/lib/atomic.h +++ b/libmetal/lib/atomic.h @@ -101,7 +101,11 @@ using std::atomic_signal_fence; #elif defined(__GNUC__) # include #else +#if defined(METAL_PROCESSOR_HEADERS_ON_SYSTEM) +# include +#else # include #endif +#endif #endif /* __METAL_ATOMIC__H__ */ diff --git a/libmetal/lib/cpu.h b/libmetal/lib/cpu.h index 9deade6..2a94cdb 100644 --- a/libmetal/lib/cpu.h +++ b/libmetal/lib/cpu.h @@ -12,6 +12,10 @@ #ifndef __METAL_CPU__H__ #define __METAL_CPU__H__ +#if defined(METAL_PROCESSOR_HEADERS_ON_SYSTEM) +# include +#else # include +#endif #endif /* __METAL_CPU__H__ */ diff --git a/libmetal/lib/system/zephyr/CMakeLists.txt b/libmetal/lib/system/zephyr/CMakeLists.txt index 43cd1b6..6605b9a 100644 --- a/libmetal/lib/system/zephyr/CMakeLists.txt +++ b/libmetal/lib/system/zephyr/CMakeLists.txt @@ -8,6 +8,9 @@ collect (PROJECT_LIB_HEADERS log.h) collect (PROJECT_LIB_HEADERS mutex.h) collect (PROJECT_LIB_HEADERS sleep.h) collect (PROJECT_LIB_HEADERS sys.h) +if (DEFINED METAL_PROCESSOR_HEADERS_ON_SYSTEM) + collect (PROJECT_LIB_HEADERS cpu.h) +endif() collect (PROJECT_LIB_SOURCES alloc.c) collect (PROJECT_LIB_SOURCES condition.c) diff --git a/libmetal/lib/system/zephyr/cpu.h b/libmetal/lib/system/zephyr/cpu.h new file mode 100644 index 0000000..364557a --- /dev/null +++ b/libmetal/lib/system/zephyr/cpu.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2023 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * @file cpu.h + * @brief Zephyr native test environment CPU specific primitives + */ + +#ifndef __METAL_ZEPHYR_CPU__H__ +#define __METAL_ZEPHYR_CPU__H__ + +#include + +static inline void metal_cpu_yield(void) +{ + /* + * In Zephyr's native test environment let 1 microsecond pass + * to allow other threads to run + */ + k_busy_wait(1); +}; + +#endif /* __METAL_ZEPHYR_CPU__H__ */