Moved OpenRTX startup code from main.c to dedicated openrtx_init() and openrtx_run() functions in a separate source file.
This commit is contained in:
parent
316e588bc3
commit
8b5b6ed571
|
|
@ -31,6 +31,7 @@ openrtx_src = ['openrtx/src/core/state.c',
|
||||||
'openrtx/src/core/dsp.cpp',
|
'openrtx/src/core/dsp.cpp',
|
||||||
'openrtx/src/core/cps.c',
|
'openrtx/src/core/cps.c',
|
||||||
'openrtx/src/core/crc.c',
|
'openrtx/src/core/crc.c',
|
||||||
|
'openrtx/src/core/openrtx.c',
|
||||||
'openrtx/src/core/audio_codec.c',
|
'openrtx/src/core/audio_codec.c',
|
||||||
'openrtx/src/core/data_conversion.c',
|
'openrtx/src/core/data_conversion.c',
|
||||||
'openrtx/src/core/memory_profiling.cpp',
|
'openrtx/src/core/memory_profiling.cpp',
|
||||||
|
|
|
||||||
|
|
@ -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 <http://www.gnu.org/licenses/> *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef OPENRTX_H
|
||||||
|
#define OPENRTX_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 */
|
||||||
|
|
@ -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 <http://www.gnu.org/licenses/> *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <interfaces/platform.h>
|
||||||
|
#include <interfaces/graphics.h>
|
||||||
|
#include <interfaces/delays.h>
|
||||||
|
#include <threads.h>
|
||||||
|
#include <openrtx.h>
|
||||||
|
#include <ui.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,9 @@ void *ui_task(void *arg)
|
||||||
ui_saveState();
|
ui_saveState();
|
||||||
pthread_mutex_unlock(&state_mutex);
|
pthread_mutex_unlock(&state_mutex);
|
||||||
|
|
||||||
|
// Keep the splash screen for 1 second
|
||||||
|
sleepFor(1u, 0u);
|
||||||
|
|
||||||
// Initial GUI draw
|
// Initial GUI draw
|
||||||
ui_updateGUI();
|
ui_updateGUI();
|
||||||
gfx_render();
|
gfx_render();
|
||||||
|
|
|
||||||
|
|
@ -18,15 +18,8 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <ui.h>
|
#include <openrtx.h>
|
||||||
#include <stdlib.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <threads.h>
|
|
||||||
#include <interfaces/platform.h>
|
|
||||||
#include <battery.h>
|
|
||||||
#include <interfaces/graphics.h>
|
|
||||||
#include <interfaces/delays.h>
|
|
||||||
#include <hwconfig.h>
|
|
||||||
#ifdef PLATFORM_LINUX
|
#ifdef PLATFORM_LINUX
|
||||||
#include <emulator/sdl_engine.h>
|
#include <emulator/sdl_engine.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -48,46 +41,18 @@ int main(void)
|
||||||
while(!platform_pwrButtonStatus());
|
while(!platform_pwrButtonStatus());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Initialize platform drivers
|
openrtx_init();
|
||||||
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();
|
|
||||||
|
|
||||||
#ifndef PLATFORM_LINUX
|
#ifndef PLATFORM_LINUX
|
||||||
// Jump to the UI task
|
openrtx_run();
|
||||||
ui_task(NULL);
|
|
||||||
#else
|
#else
|
||||||
// macOS requires SDL main loop to run on the main thread.
|
// 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
|
// Here we create a new thread for OpenRTX main program and utilize the main
|
||||||
// the SDL main loop.
|
// thread for the SDL main loop.
|
||||||
pthread_t ui_thread;
|
pthread_t openrtx_thread;
|
||||||
pthread_create(&ui_thread, NULL, ui_task, NULL);
|
pthread_create(&openrtx_thread, NULL, openrtx_run, NULL);
|
||||||
|
|
||||||
sdl_task();
|
sdl_task();
|
||||||
pthread_join(ui_thread, NULL);
|
pthread_join(openrtx_thread, NULL);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue