Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion boards/posix/native_posix/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 0 additions & 15 deletions boards/posix/native_posix/hw_models_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#include "hw_counter.h"
#include <zephyr/arch/posix/posix_soc_if.h>
#include "posix_arch_internal.h"
#include "sdl_events.h"
#include <zephyr/sys/util.h>


Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
43 changes: 25 additions & 18 deletions boards/posix/native_posix/sdl_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <SDL.h>
#include "posix_board_if.h"
#include <zephyr/arch/posix/posix_trace.h>
#include "posix_arch_internal.h"
#include "soc.h"
#include "hw_models_top.h"
#include <zephyr/arch/posix/posix_trace.h>
#include <zephyr/kernel.h>

uint64_t sdl_event_timer;
#include <SDL.h>

static void sdl_handle_window_event(const SDL_Event *event)
{
Expand All @@ -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)
Expand All @@ -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);
13 changes: 0 additions & 13 deletions boards/posix/native_posix/sdl_events.h

This file was deleted.