1 /*
2 * Copyright (c) 2018 Jan Van Winkel <jan.van_winkel@dxplore.eu>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "posix_board_if.h"
8 #include "soc.h"
9 #include <zephyr/arch/posix/posix_trace.h>
10 #include <zephyr/kernel.h>
11 #include "sdl_events_bottom.h"
12
sdl_handle_events(void * p1,void * p2,void * p3)13 static void sdl_handle_events(void *p1, void *p2, void *p3)
14 {
15 ARG_UNUSED(p1);
16 ARG_UNUSED(p2);
17 ARG_UNUSED(p3);
18
19 for (;;) {
20 int rc = sdl_handle_pending_events();
21
22 if (rc != 0) {
23 posix_exit(0);
24 }
25
26 k_msleep(CONFIG_SDL_THREAD_INTERVAL);
27 }
28 }
29
sdl_init(void)30 static void sdl_init(void)
31 {
32 if (sdl_init_video() != 0) {
33 posix_print_error_and_exit("Error on SDL_Init (%s)\n", sdl_get_error());
34 }
35 }
36
sdl_cleanup(void)37 static void sdl_cleanup(void)
38 {
39 sdl_quit();
40 }
41
42 NATIVE_TASK(sdl_init, PRE_BOOT_2, 1);
43 NATIVE_TASK(sdl_cleanup, ON_EXIT, 2);
44
45 K_THREAD_DEFINE(sdl, CONFIG_ARCH_POSIX_RECOMMENDED_STACK_SIZE,
46 sdl_handle_events, NULL, NULL, NULL,
47 CONFIG_SDL_THREAD_PRIORITY, K_ESSENTIAL, 0);
48