diff --git a/arch/sim/src/sim/up_idle.c b/arch/sim/src/sim/up_idle.c index 0dedbce8440..7e4a4d62088 100644 --- a/arch/sim/src/sim/up_idle.c +++ b/arch/sim/src/sim/up_idle.c @@ -26,7 +26,6 @@ #include #include #include -#include #include "up_internal.h" @@ -74,48 +73,9 @@ void up_idle(void) } #endif - /* Handle UART data availability */ - - up_uartloop(); - -#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) || \ - defined(CONFIG_SIM_BUTTONS) - /* Drive the X11 event loop */ - - up_x11events(); -#endif - -#ifdef CONFIG_SIM_NETDEV - /* Run the network if enabled */ - - netdriver_loop(); -#endif - -#ifdef CONFIG_SIM_NETUSRSOCK - usrsock_loop(); -#endif - -#ifdef CONFIG_RPTUN - up_rptun_loop(); -#endif - -#ifdef CONFIG_SIM_HCISOCKET - bthcisock_loop(); -#endif - -#ifdef CONFIG_SIM_SOUND - sim_audio_loop(); -#endif - #ifdef CONFIG_ONESHOT /* Driver the simulated interval timer */ up_timer_update(); #endif - -#ifdef CONFIG_MOTOR_FOC_DUMMY - /* Update simulated FOC device */ - - foc_dummy_update(); -#endif } diff --git a/arch/sim/src/sim/up_initialize.c b/arch/sim/src/sim/up_initialize.c index 0e7fe717fc2..1d32e124db7 100644 --- a/arch/sim/src/sim/up_initialize.c +++ b/arch/sim/src/sim/up_initialize.c @@ -24,13 +24,17 @@ #include +#include #include #include #include +#include #include #include #include +#include +#include #include #include #include @@ -151,6 +155,70 @@ static void up_init_smartfs(void) } #endif +static int up_loop_task(int argc, FAR char **argv) +{ + while (1) + { + /* Handle UART data availability */ + + up_uartloop(); + +#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) || \ + defined(CONFIG_SIM_BUTTONS) + /* Drive the X11 event loop */ + + up_x11events(); +#endif + +#ifdef CONFIG_SIM_NETDEV + /* Run the network if enabled */ + + netdriver_loop(); +#endif + +#ifdef CONFIG_SIM_NETUSRSOCK + usrsock_loop(); +#endif + +#ifdef CONFIG_RPTUN + up_rptun_loop(); +#endif + +#ifdef CONFIG_SIM_HCISOCKET + bthcisock_loop(); +#endif + +#ifdef CONFIG_SIM_SOUND + sim_audio_loop(); +#endif + +#ifdef CONFIG_MOTOR_FOC_DUMMY + /* Update simulated FOC device */ + + foc_dummy_update(); +#endif + + /* Sleep minimal time, let the idle run */ + + usleep(USEC_PER_TICK); + } + + return 0; +} + +static void up_loop_init(void) +{ + int ret; + + /* Use loop_task to simulate the IRQ */ + + ret = kthread_create("loop_task", 1, + CONFIG_DEFAULT_TASK_STACKSIZE, + up_loop_task, NULL); + + DEBUGASSERT(ret > 0); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -282,4 +350,6 @@ void up_initialize(void) audio_register("pcm0p", sim_audio_initialize(true)); audio_register("pcm0c", sim_audio_initialize(false)); #endif + + up_loop_init(); } diff --git a/sched/init/nx_start.c b/sched/init/nx_start.c index 74473e8f7a3..a17b97b2e11 100644 --- a/sched/init/nx_start.c +++ b/sched/init/nx_start.c @@ -609,6 +609,13 @@ void nx_start(void) } #endif + /* Disables context switching beacuse we need take the memory manager + * semaphore on this CPU so that it will not be available on the other + * CPUs until we have finished initialization. + */ + + sched_lock(); + /* Initialize the file system (needed to support device drivers) */ fs_initialize(); @@ -746,13 +753,6 @@ void nx_start(void) syslog_initialize(); - /* Disables context switching beacuse we need take the memory manager - * semaphore on this CPU so that it will not be available on the other - * CPUs until we have finished initialization. - */ - - sched_lock(); - #ifdef CONFIG_SMP /* Start all CPUs *********************************************************/