2017-12-21 21:14:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Oticon A/S
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The basic principle of operation is:
|
2017-12-30 22:20:08 +08:00
|
|
|
* No asynchronous behavior, no indeterminism.
|
2017-12-21 21:14:19 +08:00
|
|
|
* If you run the same thing 20 times, you get exactly the same result 20
|
|
|
|
* times.
|
|
|
|
* It does not matter if you are running from console, or in a debugger
|
|
|
|
* and you go for lunch in the middle of the debug session.
|
|
|
|
*
|
|
|
|
* This is achieved as follows:
|
2018-07-15 22:22:45 +08:00
|
|
|
* The execution of native_posix is decoupled from the underlying host and its
|
|
|
|
* peripherals (unless set otherwise).
|
|
|
|
* In general, time in native_posix is simulated.
|
|
|
|
*
|
|
|
|
* But, native_posix can also be linked if desired to the underlying host,
|
|
|
|
* e.g.:You can use the provided Ethernet TAP driver, or a host BLE controller.
|
|
|
|
*
|
|
|
|
* In this case, the no-indeterminism principle is lost. Runs of native_posix
|
|
|
|
* will depend on the host load and the interactions with those real host
|
|
|
|
* peripherals.
|
|
|
|
*
|
2017-12-21 21:14:19 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <soc.h>
|
|
|
|
#include "hw_models_top.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "misc/util.h"
|
2018-01-09 21:20:49 +08:00
|
|
|
#include "cmdline.h"
|
2017-12-21 21:14:19 +08:00
|
|
|
|
2018-01-28 23:18:06 +08:00
|
|
|
void posix_exit(int exit_code)
|
2017-12-21 21:14:19 +08:00
|
|
|
{
|
|
|
|
static int max_exit_code;
|
|
|
|
|
2019-02-12 01:14:19 +08:00
|
|
|
max_exit_code = MAX(exit_code, max_exit_code);
|
2017-12-21 21:14:19 +08:00
|
|
|
/*
|
|
|
|
* posix_soc_clean_up may not return if this is called from a SW thread,
|
2018-01-28 23:18:06 +08:00
|
|
|
* but instead it would get posix_exit() recalled again
|
2017-12-21 21:14:19 +08:00
|
|
|
* ASAP from the HW thread
|
|
|
|
*/
|
|
|
|
posix_soc_clean_up();
|
|
|
|
hwm_cleanup();
|
2018-07-29 20:38:49 +08:00
|
|
|
native_cleanup_cmd_line();
|
2018-07-10 15:17:39 +08:00
|
|
|
exit(max_exit_code);
|
2017-12-21 21:14:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the actual main for the Linux process,
|
|
|
|
* the Zephyr application main is renamed something else thru a define.
|
|
|
|
*/
|
2018-01-09 21:20:49 +08:00
|
|
|
int main(int argc, char *argv[])
|
2017-12-21 21:14:19 +08:00
|
|
|
{
|
2018-07-29 02:42:06 +08:00
|
|
|
run_native_tasks(_NATIVE_PRE_BOOT_1_LEVEL);
|
2017-12-21 21:14:19 +08:00
|
|
|
|
2018-01-09 21:20:49 +08:00
|
|
|
native_handle_cmd_line(argc, argv);
|
|
|
|
|
2018-07-29 02:42:06 +08:00
|
|
|
run_native_tasks(_NATIVE_PRE_BOOT_2_LEVEL);
|
|
|
|
|
2017-12-21 21:14:19 +08:00
|
|
|
hwm_init();
|
|
|
|
|
2018-07-29 02:42:06 +08:00
|
|
|
run_native_tasks(_NATIVE_PRE_BOOT_3_LEVEL);
|
|
|
|
|
2017-12-21 21:14:19 +08:00
|
|
|
posix_boot_cpu();
|
|
|
|
|
2018-07-29 02:42:06 +08:00
|
|
|
run_native_tasks(_NATIVE_FIRST_SLEEP_LEVEL);
|
2017-12-21 21:14:19 +08:00
|
|
|
|
2018-07-29 02:42:06 +08:00
|
|
|
hwm_main_loop();
|
2017-12-21 21:14:19 +08:00
|
|
|
|
2018-07-29 02:42:06 +08:00
|
|
|
/* This line should be unreachable */
|
|
|
|
return 1; /* LCOV_EXCL_LINE */
|
2017-12-21 21:14:19 +08:00
|
|
|
}
|