diff --git a/boards/posix/native_posix/Kconfig b/boards/posix/native_posix/Kconfig index 807fa5b4fedd9..da782b928643a 100644 --- a/boards/posix/native_posix/Kconfig +++ b/boards/posix/native_posix/Kconfig @@ -26,4 +26,18 @@ config HAS_SDL help This option specifies that the target board has SDL support -endif +config SDL_THREAD_INTERVAL + int "SDL thread sleep interval" + default 10 + depends on HAS_SDL + help + Sleep interval time of SDL thread to handle events in milliseconds. + +config SDL_THREAD_PRIORITY + int "SDL thread priority" + default 0 + depends on HAS_SDL + help + Priority of SDL thread to handle events. + +endif # BOARD_NATIVE_POSIX diff --git a/boards/posix/native_posix/hw_models_top.c b/boards/posix/native_posix/hw_models_top.c index 5632ff3c96180..ebd582fb0b932 100644 --- a/boards/posix/native_posix/hw_models_top.c +++ b/boards/posix/native_posix/hw_models_top.c @@ -21,7 +21,6 @@ #include "hw_counter.h" #include #include "posix_arch_internal.h" -#include "sdl_events.h" #include @@ -32,17 +31,11 @@ static uint64_t end_of_time = NEVER; /* When will this device stop */ extern uint64_t hw_timer_timer; /* When should this timer_model be called */ extern uint64_t irq_ctrl_timer; extern uint64_t hw_counter_timer; -#ifdef CONFIG_HAS_SDL -extern uint64_t sdl_event_timer; -#endif static enum { HWTIMER = 0, IRQCNT, HW_COUNTER, -#ifdef CONFIG_HAS_SDL - SDLEVENTTIMER, -#endif NUMBER_OF_TIMERS, NONE } next_timer_index = NONE; @@ -51,9 +44,6 @@ static uint64_t *Timer_list[NUMBER_OF_TIMERS] = { &hw_timer_timer, &irq_ctrl_timer, &hw_counter_timer, -#ifdef CONFIG_HAS_SDL - &sdl_event_timer, -#endif }; static uint64_t next_timer_time; @@ -154,11 +144,6 @@ void hwm_one_event(void) case HW_COUNTER: hw_counter_triggered(); break; -#ifdef CONFIG_HAS_SDL - case SDLEVENTTIMER: - sdl_handle_events(); - break; -#endif default: /* LCOV_EXCL_START */ posix_print_error_and_exit( diff --git a/boards/posix/native_posix/sdl_events.c b/boards/posix/native_posix/sdl_events.c index 7fc3f11dba579..e2cb2042d7bd5 100644 --- a/boards/posix/native_posix/sdl_events.c +++ b/boards/posix/native_posix/sdl_events.c @@ -4,14 +4,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include "posix_board_if.h" -#include -#include "posix_arch_internal.h" #include "soc.h" -#include "hw_models_top.h" +#include +#include -uint64_t sdl_event_timer; +#include static void sdl_handle_window_event(const SDL_Event *event) { @@ -37,25 +35,30 @@ static void sdl_handle_window_event(const SDL_Event *event) } } -void sdl_handle_events(void) +static void sdl_handle_events(void *p1, void *p2, void *p3) { SDL_Event event; - sdl_event_timer = hwm_get_time() + 10000; + ARG_UNUSED(p1); + ARG_UNUSED(p2); + ARG_UNUSED(p3); - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_WINDOWEVENT: - sdl_handle_window_event(&event); - break; - case SDL_QUIT: - posix_exit(0); - break; - default: - break; + for (;;) { + while (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_WINDOWEVENT: + sdl_handle_window_event(&event); + break; + case SDL_QUIT: + posix_exit(0); + break; + default: + break; + } } - } + k_msleep(CONFIG_SDL_THREAD_INTERVAL); + } } static void sdl_init(void) @@ -73,3 +76,7 @@ static void sdl_cleanup(void) NATIVE_TASK(sdl_init, PRE_BOOT_2, 1); NATIVE_TASK(sdl_cleanup, ON_EXIT, 2); + +K_THREAD_DEFINE(sdl, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE, + sdl_handle_events, NULL, NULL, NULL, + CONFIG_SDL_THREAD_PRIORITY, K_ESSENTIAL, 0); diff --git a/boards/posix/native_posix/sdl_events.h b/boards/posix/native_posix/sdl_events.h deleted file mode 100644 index fe0a69cbed56a..0000000000000 --- a/boards/posix/native_posix/sdl_events.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright (c) 2018 Jan Van Winkel - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_BOARD_POSIX_NATIVE_POSIX_SDL_EVENTS_H -#define ZEPHYR_BOARD_POSIX_NATIVE_POSIX_SDL_EVENTS_H - -#include - -void sdl_handle_events(void); - -#endif /* ZEPHYR_BOARD_POSIX_NATIVE_POSIX_SDL_EVENTS_H */