1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /*
8  * Interfacing between the POSIX arch and the Native Simulator (nsi) CPU thread emulator
9  *
10  * This posix architecture "bottom" will be used when building with the native simulator.
11  */
12 
13 #include "nct_if.h"
14 
15 static void *te_state;
16 
17 /*
18  * Initialize the posix architecture
19  */
posix_arch_init(void)20 void posix_arch_init(void)
21 {
22 	extern void posix_arch_thread_entry(void *pa_thread_status);
23 	te_state = nct_init(posix_arch_thread_entry);
24 }
25 
26 /*
27  * Clear the state of the POSIX architecture
28  * free whatever memory it may have allocated, etc.
29  */
posix_arch_clean_up(void)30 void posix_arch_clean_up(void)
31 {
32 	nct_clean_up(te_state);
33 }
34 
posix_swap(int next_allowed_thread_nbr,int this_th_nbr)35 void posix_swap(int next_allowed_thread_nbr, int this_th_nbr)
36 {
37 	(void) this_th_nbr;
38 	nct_swap_threads(te_state, next_allowed_thread_nbr);
39 }
40 
posix_main_thread_start(int next_allowed_thread_nbr)41 void posix_main_thread_start(int next_allowed_thread_nbr)
42 {
43 	nct_first_thread_start(te_state, next_allowed_thread_nbr);
44 }
45 
posix_new_thread(void * payload)46 int posix_new_thread(void *payload)
47 {
48 	return nct_new_thread(te_state, payload);
49 }
50 
posix_abort_thread(int thread_idx)51 void posix_abort_thread(int thread_idx)
52 {
53 	nct_abort_thread(te_state, thread_idx);
54 }
55 
posix_arch_get_unique_thread_id(int thread_idx)56 int posix_arch_get_unique_thread_id(int thread_idx)
57 {
58 	return nct_get_unique_thread_id(te_state, thread_idx);
59 }
60