Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Zephyr's POSIX architecture #19

Merged
merged 3 commits into from
Oct 24, 2023
Merged
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
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,13 @@ set(WITH_ZEPHYR_LIB 1)
set(WITH_DOC OFF CACHE BOOL "" FORCE)
set(WITH_DEFAULT_LOGGER OFF CACHE BOOL "" FORCE)

if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "posix")
# When building Zephyr for the POSIX architecture
# CMAKE_SYSTEM_PROCESSOR is set to POSIX. We need
# to set it instead to "hosted" which is what the
# libmetal build specs for such a target.
set(CMAKE_SYSTEM_PROCESSOR "hosted")
endif()

add_subdirectory(${CONFIG_LIBMETAL_SRC_PATH} libmetal)
endif()
2 changes: 2 additions & 0 deletions libmetal/lib/processor/hosted/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collect (PROJECT_LIB_HEADERS atomic.h)
collect (PROJECT_LIB_HEADERS cpu.h)
15 changes: 15 additions & 0 deletions libmetal/lib/processor/hosted/atomic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/*
* @file hosted/atomic.h
aescolar marked this conversation as resolved.
Show resolved Hide resolved
* @brief Hosted environment atomic primitives for libmetal.
*/

#ifndef __METAL_HOSTED_ATOMIC__H__
#define __METAL_HOSTED_ATOMIC__H__

#endif /* __METAL_HOSTED_ATOMIC__H__ */
22 changes: 22 additions & 0 deletions libmetal/lib/processor/hosted/cpu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: BSD-3-Clause
*/

/*
* @file hosted/cpu.h
* @brief Hosted environment CPU specific primitives
*/

#include <metal/sys.h>

#ifndef __METAL_HOSTED_CPU__H__
#define __METAL_HOSTED_CPU__H__

static inline void metal_cpu_yield(void)
{
metal_wait_usec(1);
}

#endif /* __METAL_HOSTED_CPU__H__ */
6 changes: 6 additions & 0 deletions libmetal/lib/system/zephyr/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define __METAL_ZEPHYR_SYS__H__

#include <stdlib.h>
#include <zephyr/kernel.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -39,6 +40,11 @@ struct metal_state {
struct metal_common_state common;
};

static inline void metal_wait_usec(uint32_t usec_to_wait)
{
k_busy_wait(usec_to_wait);
}

#ifdef __cplusplus
}
#endif
Expand Down