From a2006940db5c7da3914f2dcfcbb8b7fb9f31afe8 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Fri, 7 Sep 2018 14:46:28 -0400 Subject: [PATCH 1/2] [simu] Refactor simu startup and shutdown handling (for 2.3 branch): * Use pwrCheck() as primary control point for shutdown, centralizes thread control in simpgmspace module; * Remove main_thread_running in favor of separate variables for startup mode and shutdown flag; * Don't start a thread for ARM startup, just run simuMain() directly (the thread just exits anyway); * Refactor SIMU_SLEEP() macro, and remove all unnecessary uses of it, also remove SIMU_SLEEP_NORET; * Add startType param to opentxStart() to control splash and startup checks; * Fixes backlight never turning off in simulator with "SWITCH" power button type (pwrPressed() was always true); * Fixes simu shutdown when model checklist is displayed at startup; * Adds stubs to possibly simulate a "soft" power button in the future. --- radio/src/definitions.h | 3 +- radio/src/gui/common/colorlcd/widgets.cpp | 2 +- radio/src/io/bootloader_flash.cpp | 3 +- radio/src/io/frsky_sport.cpp | 2 +- radio/src/keys.cpp | 5 -- radio/src/opentx.cpp | 48 ++++++++--------- radio/src/storage/eeprom_raw.cpp | 10 ++-- radio/src/storage/eeprom_rlc.cpp | 3 +- radio/src/targets/simu/opentxsimulator.cpp | 2 +- radio/src/targets/simu/simpgmspace.cpp | 63 +++++++++++++++++----- radio/src/targets/simu/simpgmspace.h | 11 ++-- radio/src/tasks_arm.cpp | 15 ++---- 12 files changed, 97 insertions(+), 70 deletions(-) diff --git a/radio/src/definitions.h b/radio/src/definitions.h index a2c31c38a..1eb4cf412 100644 --- a/radio/src/definitions.h +++ b/radio/src/definitions.h @@ -61,8 +61,7 @@ #define CONVERT_PTR_UINT(x) ((uint32_t)(uint64_t)(x)) #define CONVERT_UINT_PTR(x) ((uint32_t*)(uint64_t)(x)) #else - #define SIMU_SLEEP(x) - #define SIMU_SLEEP_NORET(x) + #define SIMU_SLEEP(x) true #define CONVERT_PTR_UINT(x) ((uint32_t)(x)) #define CONVERT_UINT_PTR(x) ((uint32_t *)(x)) #endif diff --git a/radio/src/gui/common/colorlcd/widgets.cpp b/radio/src/gui/common/colorlcd/widgets.cpp index 97446d88c..84f49e67d 100644 --- a/radio/src/gui/common/colorlcd/widgets.cpp +++ b/radio/src/gui/common/colorlcd/widgets.cpp @@ -82,6 +82,7 @@ void runFatalErrorScreen(const char * message) uint32_t pwr_check = pwrCheck(); if (pwr_check == e_power_off) { boardOff(); + return; // only happens in SIMU, required for proper shutdown } else if (pwr_check == e_power_press) { refresh = true; @@ -89,7 +90,6 @@ void runFatalErrorScreen(const char * message) else if (pwr_check == e_power_on && refresh) { break; } - SIMU_SLEEP_NORET(1); } } } diff --git a/radio/src/io/bootloader_flash.cpp b/radio/src/io/bootloader_flash.cpp index e7a947585..06fb3184c 100644 --- a/radio/src/io/bootloader_flash.cpp +++ b/radio/src/io/bootloader_flash.cpp @@ -61,7 +61,8 @@ void bootloaderFlash(const char * filename) flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j)); } drawProgressBar(STR_WRITING, i, BOOTLOADER_SIZE); - SIMU_SLEEP(30/*ms*/); + if (!SIMU_SLEEP(30/*ms*/)) + break; } if (unlocked) { diff --git a/radio/src/io/frsky_sport.cpp b/radio/src/io/frsky_sport.cpp index c7adfd162..f5b240495 100644 --- a/radio/src/io/frsky_sport.cpp +++ b/radio/src/io/frsky_sport.cpp @@ -123,7 +123,7 @@ void sportProcessUpdatePacket(uint8_t * packet) bool sportWaitState(SportUpdateState state, int timeout) { #if defined(SIMU) - SIMU_SLEEP_NORET(1); + SIMU_SLEEP(1); return true; #else watchdogSuspend(timeout / 10); diff --git a/radio/src/keys.cpp b/radio/src/keys.cpp index eb2d5a4de..cc28e02a2 100644 --- a/radio/src/keys.cpp +++ b/radio/src/keys.cpp @@ -188,12 +188,7 @@ bool clearKeyEvents() #endif while (keyDown()) { - -#if defined(SIMU) - SIMU_SLEEP_NORET(1/*ms*/); -#else wdt_reset(); -#endif #if !defined(BOOT) if ((get_tmr10ms() - start) >= 300) { // wait no more than 3 seconds diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index e46ad96fe..e45eb194c 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1019,18 +1019,20 @@ void alert(const char * title, const char * msg , uint8_t sound) while (1) { RTOS_WAIT_MS(10); - if (keyDown()) break; // wait for key release + if (keyDown()) // wait for key release + break; doLoopCommonActions(); wdt_reset(); -#if defined(PWR_BUTTON_PRESS) - uint32_t pwr_check = pwrCheck(); + const uint32_t pwr_check = pwrCheck(); if (pwr_check == e_power_off) { drawSleepBitmap(); boardOff(); + return; // only happens in SIMU, required for proper shutdown } +#if defined(PWR_BUTTON_PRESS) else if (pwr_check == e_power_press) { refresh = true; } @@ -1038,11 +1040,6 @@ void alert(const char * title, const char * msg , uint8_t sound) RAISE_ALERT(title, msg, STR_PRESSANYKEY, AU_NONE); refresh = false; } -#else - if (pwrCheck() == e_power_off) { - drawSleepBitmap(); - boardOff(); // turn power off now - } #endif } @@ -1506,20 +1503,26 @@ void doMixerCalculations() s_mixer_first_run_done = true; } -void opentxStart(uint8_t splash=true) -{ - TRACE("opentxStart"); -#if defined(SIMU) - if (main_thread_running == 2) { +#define OPENTX_START_NO_SPLASH 0x01 +#define OPENTX_START_NO_CHECKS 0x02 + +#if !defined(OPENTX_START_DEFAULT_ARGS) + #define OPENTX_START_DEFAULT_ARGS 0 +#endif + +void opentxStart(const uint8_t startType = OPENTX_START_DEFAULT_ARGS) +{ + TRACE("opentxStart(%u)", startType); + + if (startType & OPENTX_START_NO_CHECKS) { return; } -#endif uint8_t calibration_needed = (g_eeGeneral.chkSum != evalChkSum()); #if defined(GUI) - if (!calibration_needed && splash) { + if (!calibration_needed && !(startType & OPENTX_START_NO_SPLASH)) { doSplash(); } #endif @@ -1621,7 +1624,7 @@ void opentxResume() loadFontCache(); #endif - opentxStart(false); + opentxStart(OPENTX_START_NO_SPLASH); referenceSystemAudioFiles(); @@ -1907,7 +1910,7 @@ void opentxInit(OPENTX_INIT_ARGS) } #if defined(SIMU) -void * simuMain(void *) +void simuMain() #else int main() #endif @@ -1931,7 +1934,7 @@ int main() loadFonts(); #endif - + #if defined(GUI) && !defined(PCBTARANIS) && !defined(PCBHORUS) // TODO remove this lcdInit(); @@ -1970,13 +1973,9 @@ int main() #endif tasksStart(); - - -#if defined(SIMU) - return NULL; -#endif } +#if !defined(SIMU) #if defined(PWR_BUTTON_PRESS) uint32_t pwr_press_time = 0; @@ -2102,4 +2101,5 @@ uint32_t pwrCheck() return e_power_off; } -#endif +#endif // defined(PWR_BUTTON_PRESS) +#endif // !defined(SIMU) diff --git a/radio/src/storage/eeprom_raw.cpp b/radio/src/storage/eeprom_raw.cpp index ef3fe4c37..1bc299389 100644 --- a/radio/src/storage/eeprom_raw.cpp +++ b/radio/src/storage/eeprom_raw.cpp @@ -2,7 +2,7 @@ * Copyright (C) OpenTX * * Based on code named - * th9x - http://code.google.com/p/th9x + * th9x - http://code.google.com/p/th9x * er9x - http://code.google.com/p/er9x * gruvin9x - http://code.google.com/p/gruvin9x * @@ -63,16 +63,12 @@ uint8_t eepromWriteBuffer[EEPROM_BUFFER_SIZE] __DMA; void eepromWaitReadStatus() { - while (eepromReadStatus() == 0) { - SIMU_SLEEP(5/*ms*/); - } + while (eepromReadStatus() == 0 && SIMU_SLEEP(5/*ms*/)) { } } void eepromWaitTransferComplete() { - while (!eepromIsTransferComplete()) { - SIMU_SLEEP(5/*ms*/); - } + while (!eepromIsTransferComplete() && SIMU_SLEEP(5/*ms*/)) { } } void eepromEraseBlock(uint32_t address, bool blocking=true) diff --git a/radio/src/storage/eeprom_rlc.cpp b/radio/src/storage/eeprom_rlc.cpp index 8ee311473..b5608dfa1 100644 --- a/radio/src/storage/eeprom_rlc.cpp +++ b/radio/src/storage/eeprom_rlc.cpp @@ -911,7 +911,8 @@ void eepromBackup() eepromReadBlock(buffer, i, 1024); f_write(&file, buffer, 1024, &count); drawProgressBar(STR_WRITING, i, EEPROM_SIZE); - SIMU_SLEEP(100/*ms*/); + if (!SIMU_SLEEP(100/*ms*/)) + break; } f_close(&file); diff --git a/radio/src/targets/simu/opentxsimulator.cpp b/radio/src/targets/simu/opentxsimulator.cpp index 4d7f003d7..e7bbc8807 100644 --- a/radio/src/targets/simu/opentxsimulator.cpp +++ b/radio/src/targets/simu/opentxsimulator.cpp @@ -86,7 +86,7 @@ QString OpenTxSimulator::name() bool OpenTxSimulator::isRunning() { QMutexLocker lckr(&m_mtxSimuMain); - return (bool)main_thread_running; + return simuIsRunning(); } void OpenTxSimulator::init() diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index 99ca105a1..d73afbec9 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -40,10 +40,12 @@ uint8_t portb, portc, porth=0, dummyport; uint16_t dummyport16; int g_snapshot_idx = 0; -pthread_t main_thread_pid; -uint8_t main_thread_running = 0; +uint8_t simu_start_mode = 0; char * main_thread_error = NULL; +bool simu_shutdown = false; +bool simu_running = false; + #if defined(STM32) uint32_t Peri1_frequency, Peri2_frequency; GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj; @@ -132,6 +134,13 @@ void simuInit() RCC->CSR = 0; #endif + // set power button to "not pressed" +#if defined(PWR_SWITCH_GPIO) // STM32 + GPIO_SetBits(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN); +#elif defined(PIO_PC17) // AT91SAM3 + PIOC->PIO_PDSR &= ~PIO_PC17; +#endif + for (int i = 0; i <= 17; i++) { simuSetSwitch(i, 0); simuSetKey(i, false); // a little dirty, but setting keys that don't exist is perfectly OK here @@ -315,13 +324,14 @@ void simuSetSwitch(uint8_t swtch, int8_t state) void StartSimu(bool tests, const char * sdPath, const char * settingsPath) { - if (main_thread_running) + if (simu_running) return; s_current_protocol[0] = 255; menuLevel = 0; - main_thread_running = (tests ? 1 : 2); // TODO rename to simu_run_mode with #define + simu_start_mode = (tests ? 0 : 0x02 /* OPENTX_START_NO_CHECKS */); + simu_shutdown = false; simuFatfsSetPaths(sdPath, settingsPath); @@ -350,7 +360,9 @@ void StartSimu(bool tests, const char * sdPath, const char * settingsPath) try { #endif - pthread_create(&main_thread_pid, NULL, &simuMain, NULL); + simuMain(); + + simu_running = true; #if defined(SIMU_EXCEPTIONS) } @@ -361,14 +373,15 @@ void StartSimu(bool tests, const char * sdPath, const char * settingsPath) void StopSimu() { - if (!main_thread_running) + if (!simu_running) return; - main_thread_running = 0; + simu_shutdown = true; pthread_join(mixerTaskId, NULL); pthread_join(menusTaskId, NULL); - pthread_join(main_thread_pid, NULL); + + simu_running = false; } struct SimulatorAudio { @@ -380,6 +393,21 @@ struct SimulatorAudio { pthread_t threadPid; } simuAudio; +bool simuIsRunning() +{ + return simu_running; +} + +bool simuSleep(uint32_t ms) +{ + for (uint32_t i = 0; i < ms; ++i){ + if (simu_shutdown || !simu_running) + return false; + sleep(1); + } + return true; +} + void audioConsumeCurrentBuffer() { } @@ -572,16 +600,25 @@ int lcdRestoreBackupBuffer() return 1; } +uint32_t pwrCheck() +{ + // TODO: ability to simulate shutdown warning for a "soft" simulator restart + return simu_shutdown ? e_power_off : e_power_on; +} void pwrOff() { } + uint32_t pwrPressed() { -#if defined(PWR_BUTTON_PRESS) - return false; + // TODO: simulate power button +#if defined(PWR_SWITCH_GPIO) // STM32 + return GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET; +#elif defined(PIO_PC17) // AT91SAM3 + return PIOC->PIO_PDSR & PIO_PC17; #else - return true; + return false; #endif } @@ -648,9 +685,9 @@ FlagStatus RCC_GetFlagStatus(uint8_t RCC_FLAG) { return SET; } ErrorStatus RTC_WaitForSynchro(void) { return SUCCESS; } void unlockFlash() { } void lockFlash() { } -void flashWrite(uint32_t *address, uint32_t *buffer) { SIMU_SLEEP(100); } +void flashWrite(uint32_t *address, uint32_t *buffer) { simuSleep(100); } uint32_t isBootloaderStart(const uint8_t * block) { return 1; } -#endif // defined(PCBTARANIS) +#endif // defined(STM32) #if defined(PCBHORUS) void LCD_ControlLight(uint16_t dutyCycle) { } diff --git a/radio/src/targets/simu/simpgmspace.h b/radio/src/targets/simu/simpgmspace.h index 56b244467..3e2529d6c 100644 --- a/radio/src/targets/simu/simpgmspace.h +++ b/radio/src/targets/simu/simpgmspace.h @@ -227,21 +227,24 @@ extern uint32_t Master_frequency; #define __disable_irq() #define __enable_irq() -extern uint8_t main_thread_running; +extern uint8_t simu_start_mode; extern char * main_thread_error; +#define OPENTX_START_DEFAULT_ARGS simu_start_mode + static inline void getADC() { } -#define SIMU_SLEEP(x) do { if (!main_thread_running) return; sleep(x/*ms*/); } while (0) -#define SIMU_SLEEP_NORET(x) do { sleep(x/*ms*/); } while (0) +#define SIMU_SLEEP(x) simuSleep(x) uint64_t simuTimerMicros(void); void simuInit(); void StartSimu(bool tests=true, const char * sdPath = 0, const char * settingsPath = 0); void StopSimu(); +bool simuIsRunning(); +bool simuSleep(uint32_t ms); void simuSetKey(uint8_t key, bool state); void simuSetTrim(uint8_t trim, bool state); @@ -257,7 +260,7 @@ void StopEepromThread(); #define StopAudioThread() #endif -void * simuMain(void * args = NULL); +void simuMain(); #define UART_Stop(...) #define UART3_Stop(...) diff --git a/radio/src/tasks_arm.cpp b/radio/src/tasks_arm.cpp index 27190c576..fecc02333 100644 --- a/radio/src/tasks_arm.cpp +++ b/radio/src/tasks_arm.cpp @@ -82,20 +82,20 @@ TASK_FUNCTION(mixerTask) while(1) { -#if defined(SIMU) - if (main_thread_running == 0) - TASK_RETURN(); -#endif - #if defined(SBUS) processSbusInput(); #endif RTOS_WAIT_TICKS(1); +#if defined(SIMU) + if (pwrCheck() == e_power_off) + TASK_RETURN(); +#else if (isForcePowerOffRequested()) { pwrOff(); } +#endif uint32_t now = RTOS_GET_TIME(); bool run = false; @@ -208,11 +208,6 @@ TASK_FUNCTION(menusTask) } resetForcePowerOffRequest(); - -#if defined(SIMU) - if (main_thread_running == 0) - break; -#endif } #if defined(PCBX9E) From 66cd99bf6beda9dbc7994f20f9b03b5d549f017f Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sat, 8 Sep 2018 21:56:41 -0400 Subject: [PATCH 2/2] [simu] Updates for RTOS abstraction layer; Remove further SIMU_SLEEP usages. --- radio/src/definitions.h | 1 - radio/src/io/bootloader_flash.cpp | 5 +++- radio/src/io/frsky_sport.cpp | 3 ++- radio/src/rtos.h | 32 +++++++++----------------- radio/src/storage/eeprom_raw.cpp | 4 ++-- radio/src/storage/eeprom_rlc.cpp | 5 +++- radio/src/targets/simu/simpgmspace.cpp | 6 ++--- radio/src/targets/simu/simpgmspace.h | 8 ++----- 8 files changed, 28 insertions(+), 36 deletions(-) diff --git a/radio/src/definitions.h b/radio/src/definitions.h index 1eb4cf412..e921389f9 100644 --- a/radio/src/definitions.h +++ b/radio/src/definitions.h @@ -61,7 +61,6 @@ #define CONVERT_PTR_UINT(x) ((uint32_t)(uint64_t)(x)) #define CONVERT_UINT_PTR(x) ((uint32_t*)(uint64_t)(x)) #else - #define SIMU_SLEEP(x) true #define CONVERT_PTR_UINT(x) ((uint32_t)(x)) #define CONVERT_UINT_PTR(x) ((uint32_t *)(x)) #endif diff --git a/radio/src/io/bootloader_flash.cpp b/radio/src/io/bootloader_flash.cpp index 06fb3184c..612fe4e88 100644 --- a/radio/src/io/bootloader_flash.cpp +++ b/radio/src/io/bootloader_flash.cpp @@ -61,8 +61,11 @@ void bootloaderFlash(const char * filename) flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j)); } drawProgressBar(STR_WRITING, i, BOOTLOADER_SIZE); - if (!SIMU_SLEEP(30/*ms*/)) +#if defined(SIMU) + // add an artificial delay and check for simu quit + if (SIMU_SLEEP_OR_EXIT_MS(30)) break; +#endif } if (unlocked) { diff --git a/radio/src/io/frsky_sport.cpp b/radio/src/io/frsky_sport.cpp index f5b240495..a65de6159 100644 --- a/radio/src/io/frsky_sport.cpp +++ b/radio/src/io/frsky_sport.cpp @@ -123,7 +123,8 @@ void sportProcessUpdatePacket(uint8_t * packet) bool sportWaitState(SportUpdateState state, int timeout) { #if defined(SIMU) - SIMU_SLEEP(1); + UNUSED(state); + UNUSED(timeout); return true; #else watchdogSuspend(timeout / 10); diff --git a/radio/src/rtos.h b/radio/src/rtos.h index 36f08b337..1478b778a 100644 --- a/radio/src/rtos.h +++ b/radio/src/rtos.h @@ -33,19 +33,8 @@ extern "C++" { #include #include - #if __GNUC__ - #include - static inline void msleep(unsigned x) - { - usleep(1000 * x); - } - #else - #include - inline void msleep(unsigned x) - { - Sleep(x); - } - #endif + + #define SIMU_SLEEP_OR_EXIT_MS(x) simuSleep(x) typedef pthread_t RTOS_TASK_HANDLE; typedef pthread_mutex_t RTOS_MUTEX_HANDLE; @@ -53,6 +42,7 @@ extern "C++" { typedef sem_t * RTOS_EVENT_HANDLE; extern uint64_t simuTimerMicros(void); + extern uint8_t simuSleep(uint32_t ms); static inline void RTOS_INIT() { @@ -62,14 +52,14 @@ extern "C++" { { } - static inline void RTOS_WAIT_MS(unsigned x) + static inline void RTOS_WAIT_MS(uint32_t x) { - msleep(x); + simuSleep(x); } - static inline void RTOS_WAIT_TICKS(unsigned x) + static inline void RTOS_WAIT_TICKS(uint32_t x) { - msleep(x * 2); + RTOS_WAIT_MS(x * 2); } #ifdef __cplusplus @@ -125,7 +115,7 @@ extern "C++" { #define TASK_FUNCTION(task) void * task(void * pdata) template - inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char * name, FakeTaskStack &stack, unsigned stackSize, unsigned priority) + inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char *, FakeTaskStack &, unsigned, unsigned) { pthread_create(&taskId, nullptr, task, nullptr); } @@ -159,7 +149,7 @@ extern "C++" { } #endif - #define RTOS_MS_PER_TICK (CFG_CPU_FREQ / CFG_SYSTICK_FREQ / (CFG_CPU_FREQ / 1000)) // RTOS timer tick length in ms (currently 2) + #define RTOS_MS_PER_TICK (CFG_CPU_FREQ / CFG_SYSTICK_FREQ / (CFG_CPU_FREQ / 1000)) // RTOS timer tick length in ms (currently 2) typedef OS_TID RTOS_TASK_HANDLE; typedef OS_MutexID RTOS_MUTEX_HANDLE; @@ -176,7 +166,7 @@ extern "C++" { CoStartOS(); } - static inline void RTOS_WAIT_MS(unsigned x) + static inline void RTOS_WAIT_MS(uint32_t x) { if (!x) return; @@ -185,7 +175,7 @@ extern "C++" { CoTickDelay(x); } - static inline void RTOS_WAIT_TICKS(unsigned x) + static inline void RTOS_WAIT_TICKS(uint32_t x) { CoTickDelay(x); } diff --git a/radio/src/storage/eeprom_raw.cpp b/radio/src/storage/eeprom_raw.cpp index 1bc299389..78ec6f677 100644 --- a/radio/src/storage/eeprom_raw.cpp +++ b/radio/src/storage/eeprom_raw.cpp @@ -63,12 +63,12 @@ uint8_t eepromWriteBuffer[EEPROM_BUFFER_SIZE] __DMA; void eepromWaitReadStatus() { - while (eepromReadStatus() == 0 && SIMU_SLEEP(5/*ms*/)) { } + while (!eepromReadStatus()) { } } void eepromWaitTransferComplete() { - while (!eepromIsTransferComplete() && SIMU_SLEEP(5/*ms*/)) { } + while (!eepromIsTransferComplete()) { } } void eepromEraseBlock(uint32_t address, bool blocking=true) diff --git a/radio/src/storage/eeprom_rlc.cpp b/radio/src/storage/eeprom_rlc.cpp index b5608dfa1..81a621790 100644 --- a/radio/src/storage/eeprom_rlc.cpp +++ b/radio/src/storage/eeprom_rlc.cpp @@ -911,8 +911,11 @@ void eepromBackup() eepromReadBlock(buffer, i, 1024); f_write(&file, buffer, 1024, &count); drawProgressBar(STR_WRITING, i, EEPROM_SIZE); - if (!SIMU_SLEEP(100/*ms*/)) +#if defined(SIMU) + // add an artificial delay and check for simu quit + if (SIMU_SLEEP_OR_EXIT_MS(100)) break; +#endif } f_close(&file); diff --git a/radio/src/targets/simu/simpgmspace.cpp b/radio/src/targets/simu/simpgmspace.cpp index d73afbec9..dedbaec25 100644 --- a/radio/src/targets/simu/simpgmspace.cpp +++ b/radio/src/targets/simu/simpgmspace.cpp @@ -398,14 +398,14 @@ bool simuIsRunning() return simu_running; } -bool simuSleep(uint32_t ms) +uint8_t simuSleep(uint32_t ms) { for (uint32_t i = 0; i < ms; ++i){ if (simu_shutdown || !simu_running) - return false; + return 1; sleep(1); } - return true; + return 0; } void audioConsumeCurrentBuffer() diff --git a/radio/src/targets/simu/simpgmspace.h b/radio/src/targets/simu/simpgmspace.h index 3e2529d6c..f99e08faf 100644 --- a/radio/src/targets/simu/simpgmspace.h +++ b/radio/src/targets/simu/simpgmspace.h @@ -232,11 +232,7 @@ extern char * main_thread_error; #define OPENTX_START_DEFAULT_ARGS simu_start_mode -static inline void getADC() -{ -} - -#define SIMU_SLEEP(x) simuSleep(x) +static inline void getADC() { } uint64_t simuTimerMicros(void); @@ -244,7 +240,7 @@ void simuInit(); void StartSimu(bool tests=true, const char * sdPath = 0, const char * settingsPath = 0); void StopSimu(); bool simuIsRunning(); -bool simuSleep(uint32_t ms); +uint8_t simuSleep(uint32_t ms); // returns true if thread shutdown requested void simuSetKey(uint8_t key, bool state); void simuSetTrim(uint8_t trim, bool state);