From 66cd99bf6beda9dbc7994f20f9b03b5d549f017f Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sat, 8 Sep 2018 21:56:41 -0400 Subject: [PATCH] [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);