feat(radio): OS compatibility layer (#5840)

This commit is contained in:
Raphael Coeffic
2025-05-03 19:07:49 +10:00
committed by GitHub
parent c996612b0a
commit ab2a19e153
92 changed files with 1740 additions and 896 deletions
+30 -28
View File
@@ -32,6 +32,9 @@
#include "hal/watchdog_driver.h"
#include "edgetx.h"
#include "os/sleep.h"
#include "os/time.h"
#include "os/task.h"
#include "timers_driver.h"
#if defined(BLUETOOTH)
@@ -58,8 +61,8 @@
#define CLI_PRINT_BUFFER_SIZE 128
RTOS_TASK_HANDLE cliTaskId;
RTOS_DEFINE_STACK(cliTaskId, cliStack, CLI_STACK_SIZE);
task_handle_t cliTaskId;
TASK_DEFINE_STACK(cliStack, CLI_STACK_SIZE);
static uint8_t cliRxBufferStorage[CLI_RX_BUFFER_SIZE];
static StaticStreamBuffer_t cliRxBufferStatic;
@@ -188,9 +191,9 @@ static uint32_t cliGetBaudRate()
char cliLastLine[CLI_COMMAND_MAX_LEN+1];
typedef int (* CliFunction) (const char ** args);
int cliExecLine(char * line);
int cliExecCommand(const char ** argv);
int cliHelp(const char ** argv);
static int cliExecLine(char * line);
static int cliExecCommand(const char ** argv);
static int cliHelp(const char ** argv);
struct CliCommand
{
@@ -466,7 +469,7 @@ int cliTestNew()
{
char * tmp = nullptr;
cliSerialPrint("Allocating 1kB with new()");
RTOS_WAIT_MS(200);
sleep_ms(200);
tmp = new char[1024];
if (tmp) {
cliSerialPrint("\tsuccess");
@@ -478,7 +481,7 @@ int cliTestNew()
}
cliSerialPrint("Allocating 10MB with (std::nothrow) new()");
RTOS_WAIT_MS(200);
sleep_ms(200);
tmp = new (std::nothrow) char[1024*1024*10];
if (tmp) {
cliSerialPrint("\tFAILURE, tmp = %p", tmp);
@@ -490,7 +493,7 @@ int cliTestNew()
}
cliSerialPrint("Allocating 10MB with new()");
RTOS_WAIT_MS(200);
sleep_ms(200);
tmp = new char[1024*1024*10];
if (tmp) {
cliSerialPrint("\tFAILURE, tmp = %p", tmp);
@@ -569,10 +572,10 @@ void testClear() { lcdClear(); }
float runTimedFunctionTest(timedTestFunc_t func, const char *name,
uint32_t runtime, uint16_t step)
{
const uint32_t start = RTOS_GET_MS();
const uint32_t start = time_get_ms();
uint32_t noRuns = 0;
uint32_t actualRuntime = 0;
while ((actualRuntime = RTOS_GET_MS() - start) < runtime) {
while ((actualRuntime = time_get_ms() - start) < runtime) {
for (uint16_t n = 0; n < step; n++) {
func();
}
@@ -583,14 +586,14 @@ float runTimedFunctionTest(timedTestFunc_t func, const char *name,
cliSerialPrint("Test %s speed: %lu.%02u, (%lu runs in %lu ms)", name,
uint32_t(result), uint16_t((result - uint32_t(result)) * 100.0f),
noRuns, actualRuntime);
RTOS_WAIT_MS(200);
sleep_ms(200);
return result;
}
int cliTestGraphics()
{
cliSerialPrint("Starting graphics performance test...");
RTOS_WAIT_MS(200);
sleep_ms(200);
watchdogSuspend(6000 /*60s*/);
if (pulsesStarted()) {
@@ -723,7 +726,7 @@ void testMemoryCopyFrom_SDRAM_to_SDRAM_8bit()
int cliTestMemorySpeed()
{
cliSerialPrint("Starting memory speed test...");
RTOS_WAIT_MS(200);
sleep_ms(200);
watchdogSuspend(6000 /*60s*/);
if (pulsesStarted()) {
@@ -744,7 +747,7 @@ int cliTestMemorySpeed()
LTDC_Cmd(DISABLE);
cliSerialPrint("Disabling LCD...");
RTOS_WAIT_MS(200);
sleep_ms(200);
result += RUN_MEMORY_TEST(testMemoryReadFrom_RAM_8bit, 200);
result += RUN_MEMORY_TEST(testMemoryReadFrom_RAM_32bit, 200);
@@ -783,7 +786,7 @@ int cliTestModelsList()
int count = 0;
cliSerialPrint("Starting fetching RF data 100x...");
const uint32_t start = RTOS_GET_MS();
const uint32_t start = time_get_ms();
const list<ModelsCategory *> &cats = modList.getCategories();
while (1) {
@@ -803,7 +806,7 @@ int cliTestModelsList()
done:
cliSerialPrint("Done fetching %ix RF data: %lu ms", count,
(RTOS_GET_MS() - start));
(time_get_ms() - start));
return 0;
}
@@ -1474,7 +1477,7 @@ int cliRepeat(const char ** argv)
counter = interval;
uint8_t c;
const TickType_t xTimeout = 20 / RTOS_MS_PER_TICK;
const TickType_t xTimeout = 20 / portTICK_PERIOD_MS;
while (!xStreamBufferReceive(cliRxBuffer, &c, 1, xTimeout)
|| !(c == '\r' || c == '\n' || c == ' ')) {
@@ -1610,9 +1613,9 @@ int cliCrypt(const char ** argv)
mixerTaskStop();
perMainEnabled = false;
uint32_t startMs = RTOS_GET_MS();
uint32_t startMs = time_get_ms();
testAccessDenied(100000);
cliSerialPrintf("access_denied: %f us/run\r\n", (RTOS_GET_MS() - startMs)*1000.0f / 100000.0f);
cliSerialPrintf("access_denied: %f us/run\r\n", (time_get_ms() - startMs)*1000.0f / 100000.0f);
cliSerialPrint("Decrypted (SW):");
dumpBody(cryptOutput, sizeof(cryptOutput));
@@ -1706,7 +1709,7 @@ const CliCommand cliCommands[] = {
{ nullptr, nullptr, nullptr } /* sentinel */
};
int cliHelp(const char ** argv)
static int cliHelp(const char ** argv)
{
for (const CliCommand * command = cliCommands; command->name != nullptr; command++) {
if (argv[1][0] == '\0' || !strcmp(command->name, argv[0])) {
@@ -1722,7 +1725,7 @@ int cliHelp(const char ** argv)
return -1;
}
int cliExecCommand(const char ** argv)
static int cliExecCommand(const char ** argv)
{
if (argv[0][0] == '\0')
return 0;
@@ -1736,7 +1739,7 @@ int cliExecCommand(const char ** argv)
return -1;
}
int cliExecLine(char * line)
static int cliExecLine(char * line)
{
int len = strlen(line);
const char * argv[CLI_COMMAND_MAX_ARGS];
@@ -1759,7 +1762,7 @@ int cliExecLine(char * line)
#define CHAR_CR 0x0D
#define CHAR_DEL 0x7F
void cliTask(void * pdata)
static void cliTask()
{
char line[CLI_COMMAND_MAX_LEN+1];
int pos = 0;
@@ -1773,7 +1776,7 @@ void cliTask(void * pdata)
// of going byte-by-byte.
/* Block for max 100ms. */
const TickType_t xTimeout = 100 / RTOS_MS_PER_TICK;
const TickType_t xTimeout = 100 / portTICK_PERIOD_MS;
size_t xReceivedBytes = xStreamBufferReceive(cliRxBuffer, &c, 1, xTimeout);
if (!mixerTaskRunning()) {
@@ -1811,8 +1814,7 @@ void cliTask(void * pdata)
if (pos == 0 && cliLastLine[0]) {
// execute (repeat) last command
strcpy(line, cliLastLine);
}
else {
} else {
// save new command
strcpy(cliLastLine, line);
}
@@ -1843,6 +1845,6 @@ void cliStart()
// Setup consumer callback
cliReceiveCallBack = cliDefaultRx;
RTOS_CREATE_TASK(cliTaskId, cliTask, "CLI", cliStack, CLI_STACK_SIZE,
CLI_TASK_PRIO);
task_create(&cliTaskId, cliTask, "CLI", cliStack, CLI_STACK_SIZE,
CLI_TASK_PRIO);
}