diff --git a/meson.build b/meson.build
index ebea3c74..e46c4e9e 100644
--- a/meson.build
+++ b/meson.build
@@ -31,6 +31,7 @@ openrtx_src = ['openrtx/src/core/state.c',
'openrtx/src/core/dsp.cpp',
'openrtx/src/core/cps.c',
'openrtx/src/core/crc.c',
+ 'openrtx/src/core/openrtx.c',
'openrtx/src/core/audio_codec.c',
'openrtx/src/core/data_conversion.c',
'openrtx/src/core/memory_profiling.cpp',
diff --git a/openrtx/include/core/openrtx.h b/openrtx/include/core/openrtx.h
new file mode 100644
index 00000000..4fe2f1c0
--- /dev/null
+++ b/openrtx/include/core/openrtx.h
@@ -0,0 +1,39 @@
+/***************************************************************************
+ * Copyright (C) 2022 by Federico Amedeo Izzo IU2NUO, *
+ * Niccolò Izzo IU2KIN *
+ * Frederik Saraci IU2NRO *
+ * Silvano Seva IU2KWO *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, see *
+ ***************************************************************************/
+
+#ifndef OPENRTX_H
+#define OPENRTX_H
+
+#include
+
+/**
+ * Initialisation of all the OpenRTX components, to be called before the main
+ * entrypoint.
+ */
+void openrtx_init();
+
+/**
+ * Entrypoint of the OpenRTX firmware.
+ * This function returns only on linux emulator, when the main program terminates.
+ * Return type is void* to make this function be used as a pthread thread body.
+ */
+void *openrtx_run();
+
+#endif /* OPENRTX_H */
diff --git a/openrtx/src/core/openrtx.c b/openrtx/src/core/openrtx.c
new file mode 100644
index 00000000..aace4a97
--- /dev/null
+++ b/openrtx/src/core/openrtx.c
@@ -0,0 +1,65 @@
+/***************************************************************************
+ * Copyright (C) 2022 by Federico Amedeo Izzo IU2NUO, *
+ * Niccolò Izzo IU2KIN *
+ * Frederik Saraci IU2NRO *
+ * Silvano Seva IU2KWO *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 3 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, see *
+ ***************************************************************************/
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+extern void *ui_task(void *arg);
+
+void openrtx_init()
+{
+ // Initialize platform drivers
+ platform_init();
+
+ // Initialize radio state
+ state_init();
+
+ // Initialize display and graphics driver
+ gfx_init();
+
+ // Set default contrast
+ display_setContrast(state.settings.contrast);
+
+ // Initialize user interface
+ ui_init();
+}
+
+void *openrtx_run()
+{
+ // Display splash screen
+ ui_drawSplashScreen(true);
+ gfx_render();
+
+ // Wait 30ms before turning on backlight to hide random pixels on screen
+ sleepFor(0u, 30u);
+ platform_setBacklightLevel(state.settings.brightness);
+
+ // Start the OpenRTX threads
+ create_threads();
+
+ // Jump to the UI task
+ ui_task(NULL);
+
+ return NULL;
+}
diff --git a/openrtx/src/core/threads.c b/openrtx/src/core/threads.c
index 574ead2d..c72e9a78 100644
--- a/openrtx/src/core/threads.c
+++ b/openrtx/src/core/threads.c
@@ -69,6 +69,9 @@ void *ui_task(void *arg)
ui_saveState();
pthread_mutex_unlock(&state_mutex);
+ // Keep the splash screen for 1 second
+ sleepFor(1u, 0u);
+
// Initial GUI draw
ui_updateGUI();
gfx_render();
diff --git a/openrtx/src/main.c b/openrtx/src/main.c
index 69d4b2d9..a0da6604 100644
--- a/openrtx/src/main.c
+++ b/openrtx/src/main.c
@@ -18,15 +18,8 @@
* along with this program; if not, see *
***************************************************************************/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
+#include
+
#ifdef PLATFORM_LINUX
#include
#endif
@@ -48,46 +41,18 @@ int main(void)
while(!platform_pwrButtonStatus());
#endif
- // Initialize platform drivers
- platform_init();
-
- // Initialize radio state
- state_init();
-
- // Initialize display and graphics driver
- gfx_init();
-
- // Set default contrast
- display_setContrast(state.settings.contrast);
-
- // Initialize user interface
- ui_init();
-
- // Display splash screen
- ui_drawSplashScreen(true);
- gfx_render();
-
- // Wait 30ms before turning on backlight to hide random pixels on screen
- sleepFor(0u, 30u);
- platform_setBacklightLevel(state.settings.brightness);
-
- // Keep the splash screen for 1 second
- sleepFor(1u, 0u);
-
- // Create OpenRTX threads
- create_threads();
+ openrtx_init();
#ifndef PLATFORM_LINUX
- // Jump to the UI task
- ui_task(NULL);
+ openrtx_run();
#else
// macOS requires SDL main loop to run on the main thread.
- // Here we create a new thread for ui_task and utilize the masin thread for
- // the SDL main loop.
- pthread_t ui_thread;
- pthread_create(&ui_thread, NULL, ui_task, NULL);
+ // Here we create a new thread for OpenRTX main program and utilize the main
+ // thread for the SDL main loop.
+ pthread_t openrtx_thread;
+ pthread_create(&openrtx_thread, NULL, openrtx_run, NULL);
sdl_task();
- pthread_join(ui_thread, NULL);
+ pthread_join(openrtx_thread, NULL);
#endif
}