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 native test environment #260

Merged
merged 3 commits into from
Nov 10, 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
4 changes: 4 additions & 0 deletions lib/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,11 @@ using std::atomic_signal_fence;
#elif defined(__GNUC__)
# include <metal/compiler/gcc/atomic.h>
#else
#if defined(HAVE_PROCESSOR_ATOMIC_H)
# include <metal/processor/@PROJECT_PROCESSOR@/atomic.h>
#else
# include <metal/processor/generic/atomic.h>
#endif /* defined(HAVE_PROCESSOR_ATOMIC_H) */
#endif

#endif /* __METAL_ATOMIC__H__ */
2 changes: 2 additions & 0 deletions lib/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern "C" {

#cmakedefine HAVE_STDATOMIC_H
#cmakedefine HAVE_FUTEX_H
#cmakedefine HAVE_PROCESSOR_ATOMIC_H
#cmakedefine HAVE_PROCESSOR_CPU_H

#ifdef __cplusplus
}
Expand Down
6 changes: 6 additions & 0 deletions lib/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#ifndef __METAL_CPU__H__
#define __METAL_CPU__H__

#include <metal/config.h>

#if defined(HAVE_PROCESSOR_CPU_H)
# include <metal/processor/@PROJECT_PROCESSOR@/cpu.h>
#else
# include <metal/processor/generic/cpu.h>
#endif

#endif /* __METAL_CPU__H__ */
14 changes: 13 additions & 1 deletion lib/processor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
add_subdirectory (${PROJECT_PROCESSOR})
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_PROCESSOR}/cpu.h")
collect (PROJECT_LIB_HEADERS ${PROJECT_PROCESSOR}/cpu.h)
set(HAVE_PROCESSOR_CPU_H 1 CACHE INTERNAL "Have include ${PROJECT_PROCESSOR}/cpu.h")
else()
collect (PROJECT_LIB_HEADERS generic/cpu.h)
endif()

if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_PROCESSOR}/atomic.h")
collect (PROJECT_LIB_HEADERS ${PROJECT_PROCESSOR}/atomic.h)
set(HAVE_PROCESSOR_ATOMIC_H 1 CACHE INTERNAL "Have include ${PROJECT_PROCESSOR}/atomic.h")
else()
collect (PROJECT_LIB_HEADERS generic/atomic.h)
endif()

3 changes: 0 additions & 3 deletions lib/processor/aarch64/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions lib/processor/aarch64/atomic.h

This file was deleted.

3 changes: 0 additions & 3 deletions lib/processor/arm/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions lib/processor/arm/atomic.h

This file was deleted.

17 changes: 0 additions & 17 deletions lib/processor/arm/cpu.h

This file was deleted.

2 changes: 0 additions & 2 deletions lib/processor/ceva/CMakeLists.txt

This file was deleted.

2 changes: 0 additions & 2 deletions lib/processor/csky/CMakeLists.txt

This file was deleted.

17 changes: 0 additions & 17 deletions lib/processor/csky/cpu.h

This file was deleted.

15 changes: 15 additions & 0 deletions lib/processor/generic/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 generic/atomic.h
* @brief Generic environment atomic primitives for libmetal.
*/

#ifndef __METAL_GENERIC_ATOMIC__H__
#define __METAL_GENERIC_ATOMIC__H__

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

/*
* @file generic/cpu.h
* @brief Generic CPU specific primitives
*/

#ifndef __METAL_GENERIC_CPU__H__
#define __METAL_GENERIC_CPU__H__

#define metal_cpu_yield()

#endif /* __METAL_GENERIC_CPU__H__ */
22 changes: 22 additions & 0 deletions 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(10);
}

#endif /* __METAL_HOSTED_CPU__H__ */
3 changes: 0 additions & 3 deletions lib/processor/microblaze/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions lib/processor/microblaze/atomic.h

This file was deleted.

20 changes: 0 additions & 20 deletions lib/processor/microblaze/cpu.h

This file was deleted.

2 changes: 0 additions & 2 deletions lib/processor/riscv/CMakeLists.txt

This file was deleted.

17 changes: 0 additions & 17 deletions lib/processor/riscv/cpu.h

This file was deleted.

3 changes: 0 additions & 3 deletions lib/processor/x86/CMakeLists.txt

This file was deleted.

16 changes: 0 additions & 16 deletions lib/processor/x86/atomic.h

This file was deleted.

3 changes: 0 additions & 3 deletions lib/processor/x86_64/CMakeLists.txt

This file was deleted.

16 changes: 0 additions & 16 deletions lib/processor/x86_64/atomic.h

This file was deleted.

2 changes: 0 additions & 2 deletions lib/processor/xtensa/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions lib/processor/xtensa/atomic.h

This file was deleted.

6 changes: 6 additions & 0 deletions 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>
aescolar marked this conversation as resolved.
Show resolved Hide resolved

#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