mirror of
https://github.com/opentx/opentx.git
synced 2025-07-26 01:35:21 +03:00
[simu] Updates for RTOS abstraction layer; Remove further SIMU_SLEEP usages.
This commit is contained in:
parent
a2006940db
commit
66cd99bf6b
8 changed files with 28 additions and 36 deletions
|
@ -61,7 +61,6 @@
|
||||||
#define CONVERT_PTR_UINT(x) ((uint32_t)(uint64_t)(x))
|
#define CONVERT_PTR_UINT(x) ((uint32_t)(uint64_t)(x))
|
||||||
#define CONVERT_UINT_PTR(x) ((uint32_t*)(uint64_t)(x))
|
#define CONVERT_UINT_PTR(x) ((uint32_t*)(uint64_t)(x))
|
||||||
#else
|
#else
|
||||||
#define SIMU_SLEEP(x) true
|
|
||||||
#define CONVERT_PTR_UINT(x) ((uint32_t)(x))
|
#define CONVERT_PTR_UINT(x) ((uint32_t)(x))
|
||||||
#define CONVERT_UINT_PTR(x) ((uint32_t *)(x))
|
#define CONVERT_UINT_PTR(x) ((uint32_t *)(x))
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -61,8 +61,11 @@ void bootloaderFlash(const char * filename)
|
||||||
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
|
flashWrite(CONVERT_UINT_PTR(FIRMWARE_ADDRESS+i+j), (uint32_t *)(buffer+j));
|
||||||
}
|
}
|
||||||
drawProgressBar(STR_WRITING, i, BOOTLOADER_SIZE);
|
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;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlocked) {
|
if (unlocked) {
|
||||||
|
|
|
@ -123,7 +123,8 @@ void sportProcessUpdatePacket(uint8_t * packet)
|
||||||
bool sportWaitState(SportUpdateState state, int timeout)
|
bool sportWaitState(SportUpdateState state, int timeout)
|
||||||
{
|
{
|
||||||
#if defined(SIMU)
|
#if defined(SIMU)
|
||||||
SIMU_SLEEP(1);
|
UNUSED(state);
|
||||||
|
UNUSED(timeout);
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
watchdogSuspend(timeout / 10);
|
watchdogSuspend(timeout / 10);
|
||||||
|
|
|
@ -33,19 +33,8 @@ extern "C++" {
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#if __GNUC__
|
|
||||||
#include <unistd.h>
|
#define SIMU_SLEEP_OR_EXIT_MS(x) simuSleep(x)
|
||||||
static inline void msleep(unsigned x)
|
|
||||||
{
|
|
||||||
usleep(1000 * x);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#include <windows.h>
|
|
||||||
inline void msleep(unsigned x)
|
|
||||||
{
|
|
||||||
Sleep(x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef pthread_t RTOS_TASK_HANDLE;
|
typedef pthread_t RTOS_TASK_HANDLE;
|
||||||
typedef pthread_mutex_t RTOS_MUTEX_HANDLE;
|
typedef pthread_mutex_t RTOS_MUTEX_HANDLE;
|
||||||
|
@ -53,6 +42,7 @@ extern "C++" {
|
||||||
typedef sem_t * RTOS_EVENT_HANDLE;
|
typedef sem_t * RTOS_EVENT_HANDLE;
|
||||||
|
|
||||||
extern uint64_t simuTimerMicros(void);
|
extern uint64_t simuTimerMicros(void);
|
||||||
|
extern uint8_t simuSleep(uint32_t ms);
|
||||||
|
|
||||||
static inline void RTOS_INIT()
|
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
|
#ifdef __cplusplus
|
||||||
|
@ -125,7 +115,7 @@ extern "C++" {
|
||||||
#define TASK_FUNCTION(task) void * task(void * pdata)
|
#define TASK_FUNCTION(task) void * task(void * pdata)
|
||||||
|
|
||||||
template<int SIZE>
|
template<int SIZE>
|
||||||
inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char * name, FakeTaskStack<SIZE> &stack, unsigned stackSize, unsigned priority)
|
inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char *, FakeTaskStack<SIZE> &, unsigned, unsigned)
|
||||||
{
|
{
|
||||||
pthread_create(&taskId, nullptr, task, nullptr);
|
pthread_create(&taskId, nullptr, task, nullptr);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +149,7 @@ extern "C++" {
|
||||||
}
|
}
|
||||||
#endif
|
#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_TID RTOS_TASK_HANDLE;
|
||||||
typedef OS_MutexID RTOS_MUTEX_HANDLE;
|
typedef OS_MutexID RTOS_MUTEX_HANDLE;
|
||||||
|
@ -176,7 +166,7 @@ extern "C++" {
|
||||||
CoStartOS();
|
CoStartOS();
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void RTOS_WAIT_MS(unsigned x)
|
static inline void RTOS_WAIT_MS(uint32_t x)
|
||||||
{
|
{
|
||||||
if (!x)
|
if (!x)
|
||||||
return;
|
return;
|
||||||
|
@ -185,7 +175,7 @@ extern "C++" {
|
||||||
CoTickDelay(x);
|
CoTickDelay(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void RTOS_WAIT_TICKS(unsigned x)
|
static inline void RTOS_WAIT_TICKS(uint32_t x)
|
||||||
{
|
{
|
||||||
CoTickDelay(x);
|
CoTickDelay(x);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,12 +63,12 @@ uint8_t eepromWriteBuffer[EEPROM_BUFFER_SIZE] __DMA;
|
||||||
|
|
||||||
void eepromWaitReadStatus()
|
void eepromWaitReadStatus()
|
||||||
{
|
{
|
||||||
while (eepromReadStatus() == 0 && SIMU_SLEEP(5/*ms*/)) { }
|
while (!eepromReadStatus()) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
void eepromWaitTransferComplete()
|
void eepromWaitTransferComplete()
|
||||||
{
|
{
|
||||||
while (!eepromIsTransferComplete() && SIMU_SLEEP(5/*ms*/)) { }
|
while (!eepromIsTransferComplete()) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
void eepromEraseBlock(uint32_t address, bool blocking=true)
|
void eepromEraseBlock(uint32_t address, bool blocking=true)
|
||||||
|
|
|
@ -911,8 +911,11 @@ void eepromBackup()
|
||||||
eepromReadBlock(buffer, i, 1024);
|
eepromReadBlock(buffer, i, 1024);
|
||||||
f_write(&file, buffer, 1024, &count);
|
f_write(&file, buffer, 1024, &count);
|
||||||
drawProgressBar(STR_WRITING, i, EEPROM_SIZE);
|
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;
|
break;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
f_close(&file);
|
f_close(&file);
|
||||||
|
|
|
@ -398,14 +398,14 @@ bool simuIsRunning()
|
||||||
return simu_running;
|
return simu_running;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool simuSleep(uint32_t ms)
|
uint8_t simuSleep(uint32_t ms)
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < ms; ++i){
|
for (uint32_t i = 0; i < ms; ++i){
|
||||||
if (simu_shutdown || !simu_running)
|
if (simu_shutdown || !simu_running)
|
||||||
return false;
|
return 1;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void audioConsumeCurrentBuffer()
|
void audioConsumeCurrentBuffer()
|
||||||
|
|
|
@ -232,11 +232,7 @@ extern char * main_thread_error;
|
||||||
|
|
||||||
#define OPENTX_START_DEFAULT_ARGS simu_start_mode
|
#define OPENTX_START_DEFAULT_ARGS simu_start_mode
|
||||||
|
|
||||||
static inline void getADC()
|
static inline void getADC() { }
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
#define SIMU_SLEEP(x) simuSleep(x)
|
|
||||||
|
|
||||||
uint64_t simuTimerMicros(void);
|
uint64_t simuTimerMicros(void);
|
||||||
|
|
||||||
|
@ -244,7 +240,7 @@ void simuInit();
|
||||||
void StartSimu(bool tests=true, const char * sdPath = 0, const char * settingsPath = 0);
|
void StartSimu(bool tests=true, const char * sdPath = 0, const char * settingsPath = 0);
|
||||||
void StopSimu();
|
void StopSimu();
|
||||||
bool simuIsRunning();
|
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 simuSetKey(uint8_t key, bool state);
|
||||||
void simuSetTrim(uint8_t trim, bool state);
|
void simuSetTrim(uint8_t trim, bool state);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue