arch POSIX: provide a bottom which uses natsim's thread emul

This allows building with embedded libCs in the Zephyr side,
as the POSIX arch bottom is not anymore built in Zephyr context.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
Alberto Escolar Piedras 2023-06-07 10:42:23 +02:00 committed by Chris Friedt
commit 945429e8c3
2 changed files with 73 additions and 6 deletions

View file

@ -6,13 +6,21 @@ zephyr_library_sources(
cpuhalt.c
fatal.c
irq.c
nsi_compat/nsi_compat.c
nsi_compat/nce.c
posix_core.c
swap.c
thread.c
)
zephyr_include_directories(
nsi_compat/
)
if(CONFIG_NATIVE_APPLICATION)
zephyr_include_directories(
nsi_compat/
)
zephyr_library_sources(
posix_core.c
nsi_compat/nsi_compat.c
nsi_compat/nce.c
)
else()
zephyr_library_sources(
posix_core_nsi.c
)
endif()

View file

@ -0,0 +1,59 @@
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Interfacing between the POSIX arch and the Native Simulator (nsi) CPU thread emulator
*
* This posix architecture "bottom" will be used when building with the native simulator.
*/
#include "nct_if.h"
static void *te_state;
/*
* Initialize the posix architecture
*/
void posix_arch_init(void)
{
extern void posix_arch_thread_entry(void *pa_thread_status);
te_state = nct_init(posix_arch_thread_entry);
}
/*
* Clear the state of the POSIX architecture
* free whatever memory it may have allocated, etc.
*/
void posix_arch_clean_up(void)
{
nct_clean_up(te_state);
}
void posix_swap(int next_allowed_thread_nbr, int this_th_nbr)
{
(void) this_th_nbr;
nct_swap_threads(te_state, next_allowed_thread_nbr);
}
void posix_main_thread_start(int next_allowed_thread_nbr)
{
nct_first_thread_start(te_state, next_allowed_thread_nbr);
}
int posix_new_thread(void *payload)
{
return nct_new_thread(te_state, payload);
}
void posix_abort_thread(int thread_idx)
{
nct_abort_thread(te_state, thread_idx);
}
int posix_arch_get_unique_thread_id(int thread_idx)
{
return nct_get_unique_thread_id(te_state, thread_idx);
}