MPM proto scan: use RTOS timers instead of polling for timeout
This commit is contained in:
committed by
Raphael Coeffic
parent
c413790892
commit
8f85097c90
@@ -32,6 +32,28 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
|
||||||
|
#include <FreeRTOS/include/FreeRTOS.h>
|
||||||
|
#include <FreeRTOS/include/timers.h>
|
||||||
|
|
||||||
|
struct ProtoScanTimer {
|
||||||
|
TimerHandle_t timer = nullptr;
|
||||||
|
StaticTimer_t timerBuffer;
|
||||||
|
};
|
||||||
|
|
||||||
|
static ProtoScanTimer _protoScanTimers[NUM_MODULES];
|
||||||
|
|
||||||
|
void MultiRfProtocols::timerCb(TimerHandle_t xTimer)
|
||||||
|
{
|
||||||
|
uint8_t moduleIdx = (uint8_t)(uintptr_t)pvTimerGetTimerID(xTimer);
|
||||||
|
auto instance = MultiRfProtocols::instance(moduleIdx);
|
||||||
|
if (instance->scanState == ScanBegin || instance->scanState == Scanning) {
|
||||||
|
instance->fillBuiltinProtos();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
MultiRfProtocols* MultiRfProtocols::_instance[NUM_MODULES] = {};
|
MultiRfProtocols* MultiRfProtocols::_instance[NUM_MODULES] = {};
|
||||||
|
|
||||||
// MPM telemetry packet format type = MultiProtoDef (0x11)
|
// MPM telemetry packet format type = MultiProtoDef (0x11)
|
||||||
@@ -231,6 +253,22 @@ bool MultiRfProtocols::triggerScan()
|
|||||||
currentProto = MULTI_INVALID_PROTO;
|
currentProto = MULTI_INVALID_PROTO;
|
||||||
moduleState[moduleIdx].mode = MODULE_MODE_GET_HARDWARE_INFO;
|
moduleState[moduleIdx].mode = MODULE_MODE_GET_HARDWARE_INFO;
|
||||||
scanStart = lastScan = RTOS_GET_MS();
|
scanStart = lastScan = RTOS_GET_MS();
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
auto scanTimer = &_protoScanTimers[moduleIdx];
|
||||||
|
if (!scanTimer->timer) {
|
||||||
|
scanTimer->timer = xTimerCreateStatic(
|
||||||
|
"MPM", MULTI_PROTOLIST_START_TIMEOUT / RTOS_MS_PER_TICK, pdTRUE,
|
||||||
|
(void*)moduleIdx, MultiRfProtocols::timerCb, &scanTimer->timerBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scanTimer->timer) {
|
||||||
|
if( xTimerStart( scanTimer->timer, 0 ) != pdPASS ) {
|
||||||
|
/* The timer could not be set into the Active state. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,11 +328,31 @@ bool MultiRfProtocols::scanReply(const uint8_t* packet, uint8_t len)
|
|||||||
|
|
||||||
currentProto++;
|
currentProto++;
|
||||||
lastScan = RTOS_GET_MS();
|
lastScan = RTOS_GET_MS();
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
auto scanTimer = &_protoScanTimers[moduleIdx];
|
||||||
|
if (scanTimer->timer) {
|
||||||
|
if (xTimerChangePeriod(scanTimer->timer,
|
||||||
|
MULTI_PROTOLIST_TIMEOUT / RTOS_MS_PER_TICK,
|
||||||
|
0) != pdPASS) {
|
||||||
|
/* The timer period could not be reset. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
scanState = ScanEnd;
|
scanState = ScanEnd;
|
||||||
setModuleMode(moduleIdx, MODULE_MODE_NORMAL);
|
setModuleMode(moduleIdx, MODULE_MODE_NORMAL);
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
auto scanTimer = &_protoScanTimers[moduleIdx];
|
||||||
|
if (scanTimer->timer) {
|
||||||
|
if (xTimerStop(scanTimer->timer, 0) != pdPASS) {
|
||||||
|
/* The timer period could not be stopped. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -27,6 +27,12 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
// Forward declare FreeRTOS timer
|
||||||
|
struct tmrTimerControl;
|
||||||
|
typedef struct tmrTimerControl * TimerHandle_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
class MultiRfProtocols
|
class MultiRfProtocols
|
||||||
{
|
{
|
||||||
static MultiRfProtocols* _instance[NUM_MODULES];
|
static MultiRfProtocols* _instance[NUM_MODULES];
|
||||||
@@ -45,6 +51,10 @@ class MultiRfProtocols
|
|||||||
MultiRfProtocols(unsigned int moduleIdx);
|
MultiRfProtocols(unsigned int moduleIdx);
|
||||||
void fillBuiltinProtos();
|
void fillBuiltinProtos();
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
static void timerCb(TimerHandle_t xTimer);
|
||||||
|
#endif
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
struct RfProto {
|
struct RfProto {
|
||||||
|
|||||||
@@ -223,17 +223,6 @@ inline bool isBadAntennaDetected()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MULTI_PROTOLIST)
|
|
||||||
// TODO: FreeRTOS timer instead...
|
|
||||||
static inline void pollMultiProtolist(uint8_t idx)
|
|
||||||
{
|
|
||||||
if ((moduleState[idx].protocol == PROTOCOL_CHANNELS_MULTIMODULE) &&
|
|
||||||
MultiRfProtocols::instance(idx)->isScanning()) {
|
|
||||||
MultiRfProtocols::instance(idx)->scanReply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline void pollTelemetry(uint8_t module, const etx_module_driver_t* drv, void* ctx)
|
static inline void pollTelemetry(uint8_t module, const etx_module_driver_t* drv, void* ctx)
|
||||||
{
|
{
|
||||||
if (!drv || !drv->getByte || !drv->processData) return;
|
if (!drv || !drv->getByte || !drv->processData) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user