chore: Introduce FreeRTOS Software timers
Introduce FreeRTOS Software timers
This commit is contained in:
@@ -42,7 +42,7 @@
|
|||||||
#define configUSE_APPLICATION_TASK_TAG 0
|
#define configUSE_APPLICATION_TASK_TAG 0
|
||||||
#define configUSE_COUNTING_SEMAPHORES 0
|
#define configUSE_COUNTING_SEMAPHORES 0
|
||||||
#define configGENERATE_RUN_TIME_STATS 0
|
#define configGENERATE_RUN_TIME_STATS 0
|
||||||
#define configUSE_TIMERS 0
|
#define configUSE_TIMERS 1
|
||||||
|
|
||||||
#if !defined(DEBUG)
|
#if !defined(DEBUG)
|
||||||
#define configMAX_TASK_NAME_LEN 4
|
#define configMAX_TASK_NAME_LEN 4
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
/* Software timer definitions. */
|
/* Software timer definitions. */
|
||||||
#define configTIMER_TASK_PRIORITY ( 2 )
|
#define configTIMER_TASK_PRIORITY ( 2 )
|
||||||
#define configTIMER_QUEUE_LENGTH 10
|
#define configTIMER_QUEUE_LENGTH 10
|
||||||
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
|
#define configTIMER_TASK_STACK_DEPTH ( 512 )
|
||||||
|
|
||||||
/* Set the following definitions to 1 to include the API function, or zero
|
/* Set the following definitions to 1 to include the API function, or zero
|
||||||
to exclude the API function. */
|
to exclude the API function. */
|
||||||
@@ -73,6 +73,7 @@ to exclude the API function. */
|
|||||||
#define INCLUDE_vTaskSuspend 1
|
#define INCLUDE_vTaskSuspend 1
|
||||||
#define INCLUDE_vTaskDelayUntil 1
|
#define INCLUDE_vTaskDelayUntil 1
|
||||||
#define INCLUDE_vTaskDelay 1
|
#define INCLUDE_vTaskDelay 1
|
||||||
|
#define INCLUDE_xTimerPendFunctionCall 1
|
||||||
|
|
||||||
#if defined(THREADSAFE_MALLOC)
|
#if defined(THREADSAFE_MALLOC)
|
||||||
#define INCLUDE_xTaskGetSchedulerState 1
|
#define INCLUDE_xTaskGetSchedulerState 1
|
||||||
|
|||||||
@@ -1059,8 +1059,6 @@ static const etx_serial_init spIntmoduleSerialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void spInternalModuleSetBaudRate(uint32_t baud)
|
static void spInternalModuleSetBaudRate(uint32_t baud)
|
||||||
|
|||||||
@@ -47,8 +47,6 @@ typedef struct {
|
|||||||
uint8_t word_length; // = ETX_WordLength_8;
|
uint8_t word_length; // = ETX_WordLength_8;
|
||||||
uint8_t rx_enable; // = false;
|
uint8_t rx_enable; // = false;
|
||||||
|
|
||||||
void (*on_receive)(uint8_t data); // = nullptr;
|
|
||||||
void (*on_error)(); // = nullptr;
|
|
||||||
} etx_serial_init;
|
} etx_serial_init;
|
||||||
|
|
||||||
struct etx_serial_callbacks_t {
|
struct etx_serial_callbacks_t {
|
||||||
|
|||||||
@@ -316,8 +316,6 @@ static const etx_serial_init serialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -22,10 +22,12 @@
|
|||||||
#ifndef _IO_PXX2_H_
|
#ifndef _IO_PXX2_H_
|
||||||
#define _IO_PXX2_H_
|
#define _IO_PXX2_H_
|
||||||
|
|
||||||
#include "../fifo.h"
|
#include "fifo.h"
|
||||||
#include "../pulses/pxx.h"
|
#include "pulses/pxx.h"
|
||||||
|
|
||||||
class ModuleFifo : public Fifo<uint8_t, PXX2_FRAME_MAXLENGTH> {
|
#include "board.h"
|
||||||
|
|
||||||
|
class ModuleFifo : public Fifo<uint8_t, INTMODULE_FIFO_SIZE> {
|
||||||
public:
|
public:
|
||||||
bool getFrame(uint8_t * frame)
|
bool getFrame(uint8_t * frame)
|
||||||
{
|
{
|
||||||
@@ -74,7 +76,6 @@ class ModuleFifo : public Fifo<uint8_t, PXX2_FRAME_MAXLENGTH> {
|
|||||||
return ((crc >> 8) == crcLow) && ((crc & 0xFF) == crcHigh);
|
return ((crc >> 8) == crcLow) && ((crc & 0xFF) == crcHigh);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t errors;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -82,8 +82,6 @@ static const etx_serial_init serialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
|
class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
|
||||||
@@ -130,6 +128,7 @@ class MultiInternalUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||||
class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
|
class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -143,15 +142,7 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
|
|
||||||
void init(bool inverted) override
|
void init(bool inverted) override
|
||||||
{
|
{
|
||||||
#if !defined(EXTMODULE_USART)
|
extmoduleInitTxPin();
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
|
||||||
GPIO_InitStructure.GPIO_Pin = EXTMODULE_TX_GPIO_PIN;
|
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
||||||
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
||||||
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
|
|
||||||
GPIO_Init(EXTMODULE_TX_GPIO, &GPIO_InitStructure);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (inverted)
|
if (inverted)
|
||||||
telemetryPortInvertedInit(57600);
|
telemetryPortInvertedInit(57600);
|
||||||
@@ -166,9 +157,7 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
|
|
||||||
void sendByte(uint8_t byte) const override
|
void sendByte(uint8_t byte) const override
|
||||||
{
|
{
|
||||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
|
||||||
extmoduleSendInvertedByte(byte);
|
extmoduleSendInvertedByte(byte);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() const override
|
void clear() const override
|
||||||
@@ -186,6 +175,7 @@ class MultiExternalUpdateDriver: public MultiFirmwareUpdateDriver
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
class MultiExtSportUpdateDriver: public MultiFirmwareUpdateDriver
|
class MultiExtSportUpdateDriver: public MultiFirmwareUpdateDriver
|
||||||
{
|
{
|
||||||
@@ -618,14 +608,16 @@ bool MultiDeviceFirmwareUpdate::flashFirmware(const char * filename, ProgressHan
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<MultiFirmwareUpdateDriver> driver;
|
std::unique_ptr<MultiFirmwareUpdateDriver> driver;
|
||||||
if (module == EXTERNAL_MODULE)
|
|
||||||
driver.reset(new MultiExternalUpdateDriver());
|
|
||||||
#if defined(INTERNAL_MODULE_MULTI)
|
#if defined(INTERNAL_MODULE_MULTI)
|
||||||
else if (module == INTERNAL_MODULE)
|
if (type == MULTI_TYPE_MULTIMODULE && module == INTERNAL_MODULE)
|
||||||
driver.reset(new MultiInternalUpdateDriver());
|
driver.reset(new MultiInternalUpdateDriver());
|
||||||
#endif
|
#endif
|
||||||
else if (type == MULTI_TYPE_ELRS)
|
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||||
|
if (type == MULTI_TYPE_MULTIMODULE && module == EXTERNAL_MODULE)
|
||||||
|
driver.reset(new MultiExternalUpdateDriver());
|
||||||
|
if (type == MULTI_TYPE_ELRS && module == EXTERNAL_MODULE)
|
||||||
driver.reset(new MultiExtSportUpdateDriver());
|
driver.reset(new MultiExtSportUpdateDriver());
|
||||||
|
#endif
|
||||||
|
|
||||||
pausePulses();
|
pausePulses();
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,6 @@ const etx_serial_init afhds2SerialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* afhds2Init(uint8_t module)
|
static void* afhds2Init(uint8_t module)
|
||||||
|
|||||||
@@ -111,31 +111,12 @@ static void crossfireSetupMixerScheduler(uint8_t module)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(INTERNAL_MODULE_CRSF)
|
#if defined(INTERNAL_MODULE_CRSF)
|
||||||
static void intmoduleCRSF_rx(uint8_t data)
|
|
||||||
{
|
|
||||||
intmoduleFifo.push(data);
|
|
||||||
|
|
||||||
#if !defined(SIMU)
|
|
||||||
// wakeup mixer when rx buffer is quarter full (16 bytes)
|
|
||||||
if (intmoduleFifo.size() >= 16) {
|
|
||||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
|
||||||
xTaskNotifyFromISR(mixerTaskId.rtos_handle, 0, eNoAction,
|
|
||||||
&xHigherPriorityTaskWoken);
|
|
||||||
|
|
||||||
// might effect a context switch on ISR exit
|
|
||||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static const etx_serial_init intmoduleCrossfireInitParams = {
|
static const etx_serial_init intmoduleCrossfireInitParams = {
|
||||||
.baudrate = 0,
|
.baudrate = 0,
|
||||||
.parity = ETX_Parity_None,
|
.parity = ETX_Parity_None,
|
||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleCRSF_rx,
|
|
||||||
.on_error = nullptr,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* crossfireInitInternal(uint8_t module)
|
static void* crossfireInitInternal(uint8_t module)
|
||||||
@@ -146,9 +127,6 @@ static void* crossfireInitInternal(uint8_t module)
|
|||||||
etx_serial_init params(intmoduleCrossfireInitParams);
|
etx_serial_init params(intmoduleCrossfireInitParams);
|
||||||
params.baudrate = INT_CROSSFIRE_BAUDRATE;
|
params.baudrate = INT_CROSSFIRE_BAUDRATE;
|
||||||
|
|
||||||
// wakeup mixer when rx buffer is quarter full (16 bytes)
|
|
||||||
params.on_receive = intmoduleCRSF_rx;
|
|
||||||
|
|
||||||
intmoduleFifo.clear();
|
intmoduleFifo.clear();
|
||||||
IntmoduleSerialDriver.init(¶ms);
|
IntmoduleSerialDriver.init(¶ms);
|
||||||
INTERNAL_MODULE_ON();
|
INTERNAL_MODULE_ON();
|
||||||
|
|||||||
@@ -60,8 +60,6 @@ etx_serial_init multiSerialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_Two,
|
.stop_bits = ETX_StopBits_Two,
|
||||||
.word_length = ETX_WordLength_9,
|
.word_length = ETX_WordLength_9,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -49,12 +49,42 @@
|
|||||||
#include "pulses/afhds2.h"
|
#include "pulses/afhds2.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <FreeRTOS.h>
|
||||||
|
#include <timers.h>
|
||||||
|
|
||||||
uint8_t s_pulses_paused = 0;
|
uint8_t s_pulses_paused = 0;
|
||||||
ModuleState moduleState[NUM_MODULES];
|
ModuleState moduleState[NUM_MODULES];
|
||||||
InternalModulePulsesData intmodulePulsesData __DMA;
|
InternalModulePulsesData intmodulePulsesData __DMA;
|
||||||
ExternalModulePulsesData extmodulePulsesData __DMA;
|
ExternalModulePulsesData extmodulePulsesData __DMA;
|
||||||
TrainerPulsesData trainerPulsesData __DMA;
|
TrainerPulsesData trainerPulsesData __DMA;
|
||||||
|
|
||||||
|
void startPulses()
|
||||||
|
{
|
||||||
|
telemetryStart();
|
||||||
|
s_pulses_paused = false;
|
||||||
|
|
||||||
|
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||||
|
setupPulsesInternalModule();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HARDWARE_EXTERNAL_MODULE)
|
||||||
|
setupPulsesExternalModule();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HARDWARE_EXTRA_MODULE)
|
||||||
|
extramodulePpmStart();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopPulses()
|
||||||
|
{
|
||||||
|
telemetryStop();
|
||||||
|
s_pulses_paused = true;
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < NUM_MODULES; i++)
|
||||||
|
moduleState[i].protocol = PROTOCOL_CHANNELS_UNINITIALIZED;
|
||||||
|
}
|
||||||
|
|
||||||
void restartModule(uint8_t idx)
|
void restartModule(uint8_t idx)
|
||||||
{
|
{
|
||||||
if (idx == INTERNAL_MODULE) {
|
if (idx == INTERNAL_MODULE) {
|
||||||
|
|||||||
@@ -262,29 +262,8 @@ uint8_t actualAfhdsRunPower(int moduleIndex);
|
|||||||
#endif
|
#endif
|
||||||
void extramodulePpmStart();
|
void extramodulePpmStart();
|
||||||
|
|
||||||
inline void startPulses()
|
void startPulses();
|
||||||
{
|
void stopPulses();
|
||||||
s_pulses_paused = false;
|
|
||||||
|
|
||||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
|
||||||
setupPulsesInternalModule();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HARDWARE_EXTERNAL_MODULE)
|
|
||||||
setupPulsesExternalModule();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HARDWARE_EXTRA_MODULE)
|
|
||||||
extramodulePpmStart();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void stopPulses()
|
|
||||||
{
|
|
||||||
s_pulses_paused = true;
|
|
||||||
for (uint8_t i = 0; i < NUM_MODULES; i++)
|
|
||||||
moduleState[i].protocol = PROTOCOL_CHANNELS_UNINITIALIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool pulsesStarted()
|
inline bool pulsesStarted()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -231,8 +231,6 @@ static const etx_serial_init pxx1SerialInit = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = false,
|
.rx_enable = false,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* pxx1InitInternal(uint8_t module)
|
static void* pxx1InitInternal(uint8_t module)
|
||||||
@@ -293,8 +291,6 @@ static const etx_serial_init pxx1ExtSerialInit = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = false,
|
.rx_enable = false,
|
||||||
.on_receive = extmoduleFifoReceive,
|
|
||||||
.on_error = extmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* pxx1InitExternal(uint8_t module)
|
static void* pxx1InitExternal(uint8_t module)
|
||||||
|
|||||||
@@ -36,8 +36,6 @@ const etx_serial_init pxx2SerialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -717,8 +715,6 @@ static const etx_serial_init pxx2ExtSerialInitParams = {
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = extmoduleFifoReceive,
|
|
||||||
.on_error = extmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void* pxx2InitLowSpeed(uint8_t module)
|
static void* pxx2InitLowSpeed(uint8_t module)
|
||||||
|
|||||||
@@ -290,8 +290,6 @@ void serialInit(uint8_t port_nr, int mode)
|
|||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = false,
|
.rx_enable = false,
|
||||||
.on_receive = nullptr,
|
|
||||||
.on_error = nullptr,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool power_required = false;
|
bool power_required = false;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ static void* aux_serial_init(const SerialState* st, const etx_serial_init* param
|
|||||||
{
|
{
|
||||||
stm32_usart_init(st->usart, params);
|
stm32_usart_init(st->usart, params);
|
||||||
|
|
||||||
if (params->rx_enable && st->usart->rxDMA && !params->on_receive) {
|
if (params->rx_enable && st->usart->rxDMA) {
|
||||||
st->rxFifo->clear();
|
st->rxFifo->clear();
|
||||||
stm32_usart_init_rx_dma(st->usart, st->rxFifo->buffer(), st->rxFifo->size());
|
stm32_usart_init_rx_dma(st->usart, st->rxFifo->buffer(), st->rxFifo->size());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,17 @@ void extmoduleSendNextFrameSoftSerial(const void* pulses, uint16_t length, bool
|
|||||||
stm32_pulse_start_dma_req(&extmoduleTimer, pulses, length, LL_TIM_OCMODE_TOGGLE, 0);
|
stm32_pulse_start_dma_req(&extmoduleTimer, pulses, length, LL_TIM_OCMODE_TOGGLE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void extmoduleInitTxPin()
|
||||||
|
{
|
||||||
|
LL_GPIO_InitTypeDef pinInit;
|
||||||
|
LL_GPIO_StructInit(&pinInit);
|
||||||
|
pinInit.Pin = extmoduleTimer.GPIO_Pin;
|
||||||
|
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
||||||
|
pinInit.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
|
||||||
|
pinInit.Pull = LL_GPIO_PULL_UP;
|
||||||
|
LL_GPIO_Init(extmoduleTimer.GPIOx, &pinInit);
|
||||||
|
}
|
||||||
|
|
||||||
// Delay based byte sending @ 57600 bps
|
// Delay based byte sending @ 57600 bps
|
||||||
void extmoduleSendInvertedByte(uint8_t byte)
|
void extmoduleSendInvertedByte(uint8_t byte)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -41,4 +41,5 @@ void extmoduleSendNextFrameSoftSerial(const void* pulses, uint16_t length,
|
|||||||
bool polarity = true);
|
bool polarity = true);
|
||||||
|
|
||||||
// Bitbang serial
|
// Bitbang serial
|
||||||
|
void extmoduleInitTxPin();
|
||||||
void extmoduleSendInvertedByte(uint8_t byte);
|
void extmoduleSendInvertedByte(uint8_t byte);
|
||||||
|
|||||||
@@ -38,19 +38,12 @@ void extmoduleFifoReceive(uint8_t data)
|
|||||||
extmoduleFifo.push(data);
|
extmoduleFifo.push(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void extmoduleFifoError()
|
|
||||||
{
|
|
||||||
extmoduleFifo.errors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const etx_serial_init extmoduleSerialParams = {
|
static const etx_serial_init extmoduleSerialParams = {
|
||||||
.baudrate = 0,
|
.baudrate = 0,
|
||||||
.parity = ETX_Parity_None,
|
.parity = ETX_Parity_None,
|
||||||
.stop_bits = ETX_StopBits_One,
|
.stop_bits = ETX_StopBits_One,
|
||||||
.word_length = ETX_WordLength_8,
|
.word_length = ETX_WordLength_8,
|
||||||
.rx_enable = true,
|
.rx_enable = true,
|
||||||
.on_receive = extmoduleFifoReceive,
|
|
||||||
.on_error = extmoduleFifoError,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const LL_GPIO_InitTypeDef extmoduleUSART_PinDef = {
|
static const LL_GPIO_InitTypeDef extmoduleUSART_PinDef = {
|
||||||
@@ -80,8 +73,8 @@ static void* extmoduleSerialStart(const etx_serial_init* params)
|
|||||||
{
|
{
|
||||||
if (!params) return nullptr;
|
if (!params) return nullptr;
|
||||||
|
|
||||||
extmodule_driver.on_receive = params->on_receive;
|
extmodule_driver.on_receive = extmoduleFifoReceive;
|
||||||
extmodule_driver.on_error = params->on_error;
|
extmodule_driver.on_error = nullptr;
|
||||||
|
|
||||||
// UART config
|
// UART config
|
||||||
stm32_usart_init(&extmoduleUSART, params);
|
stm32_usart_init(&extmoduleUSART, params);
|
||||||
|
|||||||
@@ -23,9 +23,9 @@
|
|||||||
#include "intmodule_serial_driver.h"
|
#include "intmodule_serial_driver.h"
|
||||||
#include "stm32_usart_driver.h"
|
#include "stm32_usart_driver.h"
|
||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
#include "fifo.h"
|
||||||
|
|
||||||
#include "io/frsky_pxx2.h"
|
Fifo<uint8_t, INTMODULE_FIFO_SIZE> intmoduleFifo;
|
||||||
ModuleFifo intmoduleFifo;
|
|
||||||
|
|
||||||
#if !defined(INTMODULE_DMA_STREAM)
|
#if !defined(INTMODULE_DMA_STREAM)
|
||||||
static uint8_t * intmoduleTxBufferData;
|
static uint8_t * intmoduleTxBufferData;
|
||||||
@@ -54,16 +54,11 @@ static etx_serial_callbacks_t intmodule_driver = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// TODO: move this somewhere else
|
// TODO: move this somewhere else
|
||||||
void intmoduleFifoReceive(uint8_t data)
|
static void intmoduleFifoReceive(uint8_t data)
|
||||||
{
|
{
|
||||||
intmoduleFifo.push(data);
|
intmoduleFifo.push(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void intmoduleFifoError()
|
|
||||||
{
|
|
||||||
intmoduleFifo.errors++;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const LL_GPIO_InitTypeDef intmoduleUSART_PinDef = {
|
static const LL_GPIO_InitTypeDef intmoduleUSART_PinDef = {
|
||||||
.Pin = INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN,
|
.Pin = INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN,
|
||||||
.Mode = LL_GPIO_MODE_ALTERNATE,
|
.Mode = LL_GPIO_MODE_ALTERNATE,
|
||||||
@@ -110,8 +105,8 @@ void* intmoduleSerialStart(const etx_serial_init* params)
|
|||||||
// - the UART seems to block when initialised with baudrate = 0
|
// - the UART seems to block when initialised with baudrate = 0
|
||||||
|
|
||||||
// init callbacks
|
// init callbacks
|
||||||
intmodule_driver.on_receive = params->on_receive;
|
intmodule_driver.on_receive = intmoduleFifoReceive;
|
||||||
intmodule_driver.on_error = params->on_error;
|
intmodule_driver.on_error = nullptr;
|
||||||
|
|
||||||
stm32_usart_init(&intmoduleUSART, params);
|
stm32_usart_init(&intmoduleUSART, params);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|||||||
@@ -26,8 +26,4 @@
|
|||||||
|
|
||||||
#define INTMODULE_USART_IRQ_PRIORITY 6
|
#define INTMODULE_USART_IRQ_PRIORITY 6
|
||||||
|
|
||||||
// Callbacks using intmoduleFifo
|
|
||||||
void intmoduleFifoReceive(uint8_t data);
|
|
||||||
void intmoduleFifoError();
|
|
||||||
|
|
||||||
extern const etx_serial_driver_t IntmoduleSerialDriver;
|
extern const etx_serial_driver_t IntmoduleSerialDriver;
|
||||||
|
|||||||
@@ -67,8 +67,7 @@ static void interrupt1ms()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// 5ms loop
|
// 5ms loop
|
||||||
if (pre_scale == 5 || pre_scale == 10)
|
if (pre_scale == 5 || pre_scale == 10) {
|
||||||
{
|
|
||||||
#if defined(HAPTIC)
|
#if defined(HAPTIC)
|
||||||
DEBUG_TIMER_START(debugTimerHaptic);
|
DEBUG_TIMER_START(debugTimerHaptic);
|
||||||
HAPTIC_HEARTBEAT();
|
HAPTIC_HEARTBEAT();
|
||||||
@@ -77,8 +76,7 @@ static void interrupt1ms()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 10ms loop
|
// 10ms loop
|
||||||
if (pre_scale == 10)
|
if (pre_scale == 10) {
|
||||||
{
|
|
||||||
pre_scale = 0;
|
pre_scale = 0;
|
||||||
DEBUG_TIMER_START(debugTimerPer10ms);
|
DEBUG_TIMER_START(debugTimerPer10ms);
|
||||||
DEBUG_TIMER_SAMPLE(debugTimerPer10msPeriod);
|
DEBUG_TIMER_SAMPLE(debugTimerPer10msPeriod);
|
||||||
|
|||||||
@@ -615,6 +615,7 @@ int32_t getVolume();
|
|||||||
#define VOLUME_LEVEL_DEF 12
|
#define VOLUME_LEVEL_DEF 12
|
||||||
|
|
||||||
// Telemetry driver
|
// Telemetry driver
|
||||||
|
#define INTMODULE_FIFO_SIZE 512
|
||||||
#define TELEMETRY_FIFO_SIZE 512
|
#define TELEMETRY_FIFO_SIZE 512
|
||||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
||||||
void telemetryPortSetDirectionInput();
|
void telemetryPortSetDirectionInput();
|
||||||
|
|||||||
@@ -478,6 +478,7 @@ int32_t getVolume();
|
|||||||
#define VOLUME_LEVEL_DEF 12
|
#define VOLUME_LEVEL_DEF 12
|
||||||
|
|
||||||
// Telemetry driver
|
// Telemetry driver
|
||||||
|
#define INTMODULE_FIFO_SIZE 512
|
||||||
#define TELEMETRY_FIFO_SIZE 512
|
#define TELEMETRY_FIFO_SIZE 512
|
||||||
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
void telemetryPortInit(uint32_t baudrate, uint8_t mode);
|
||||||
void telemetryPortSetDirectionOutput();
|
void telemetryPortSetDirectionOutput();
|
||||||
|
|||||||
@@ -42,16 +42,18 @@ void extmodulePpmStart(unsigned short, bool) {}
|
|||||||
void extmoduleSerialStart() {}
|
void extmoduleSerialStart() {}
|
||||||
void extmodulePxx1SerialStart() {}
|
void extmodulePxx1SerialStart() {}
|
||||||
void extmodulePxx1PulsesStart() {}
|
void extmodulePxx1PulsesStart() {}
|
||||||
|
void extmoduleInitTxPin() {}
|
||||||
void extmoduleSendInvertedByte(uint8_t) {}
|
void extmoduleSendInvertedByte(uint8_t) {}
|
||||||
void extmoduleSendNextFramePxx1(void const*, unsigned short) {}
|
void extmoduleSendNextFramePxx1(void const*, unsigned short) {}
|
||||||
void extmoduleSendNextFrameSoftSerial(void const*, unsigned short, bool) {}
|
void extmoduleSendNextFrameSoftSerial(void const*, unsigned short, bool) {}
|
||||||
void extmoduleSendNextFramePpm(void*, unsigned short, unsigned short, bool) {}
|
void extmoduleSendNextFramePpm(void*, unsigned short, unsigned short, bool) {}
|
||||||
|
|
||||||
|
#if defined(TRAINER_GPIO)
|
||||||
void init_trainer_ppm() {}
|
void init_trainer_ppm() {}
|
||||||
void stop_trainer_ppm() {}
|
void stop_trainer_ppm() {}
|
||||||
|
|
||||||
void init_trainer_capture() {}
|
void init_trainer_capture() {}
|
||||||
void stop_trainer_capture() {}
|
void stop_trainer_capture() {}
|
||||||
|
#endif
|
||||||
|
|
||||||
void init_trainer_module_cppm() {}
|
void init_trainer_module_cppm() {}
|
||||||
void stop_trainer_module_cppm() {}
|
void stop_trainer_module_cppm() {}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpio
|
|||||||
USART_TypeDef Usart0, Usart1, Usart2, Usart3, Usart4;
|
USART_TypeDef Usart0, Usart1, Usart2, Usart3, Usart4;
|
||||||
ADC_Common_TypeDef adc;
|
ADC_Common_TypeDef adc;
|
||||||
RTC_TypeDef rtc;
|
RTC_TypeDef rtc;
|
||||||
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct) { }
|
|
||||||
void lcdCopy(void * dest, void * src);
|
void lcdCopy(void * dest, void * src);
|
||||||
|
|
||||||
FATFS g_FATFS_Obj;
|
FATFS g_FATFS_Obj;
|
||||||
@@ -802,3 +802,6 @@ struct TouchState getInternalTouchState()
|
|||||||
return simTouchState;
|
return simTouchState;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void telemetryStart() {}
|
||||||
|
void telemetryStop() {}
|
||||||
|
|||||||
@@ -976,6 +976,8 @@ void setTopBatteryValue(uint32_t volts);
|
|||||||
extern Fifo<uint8_t, TELEMETRY_FIFO_SIZE> telemetryFifo;
|
extern Fifo<uint8_t, TELEMETRY_FIFO_SIZE> telemetryFifo;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define INTMODULE_FIFO_SIZE 128
|
||||||
|
|
||||||
// Gyro driver
|
// Gyro driver
|
||||||
#define GYRO_VALUES_COUNT 6
|
#define GYRO_VALUES_COUNT 6
|
||||||
#define GYRO_BUFFER_LENGTH (GYRO_VALUES_COUNT * sizeof(int16_t))
|
#define GYRO_BUFFER_LENGTH (GYRO_VALUES_COUNT * sizeof(int16_t))
|
||||||
|
|||||||
@@ -100,12 +100,6 @@ void execMixerFrequentActions()
|
|||||||
#if defined(BLUETOOTH)
|
#if defined(BLUETOOTH)
|
||||||
bluetooth.wakeup();
|
bluetooth.wakeup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!s_pulses_paused) {
|
|
||||||
DEBUG_TIMER_START(debugTimerTelemetryWakeup);
|
|
||||||
telemetryWakeup();
|
|
||||||
DEBUG_TIMER_STOP(debugTimerTelemetryWakeup);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TASK_FUNCTION(mixerTask)
|
TASK_FUNCTION(mixerTask)
|
||||||
|
|||||||
@@ -283,14 +283,6 @@ void sportProcessTelemetryPacket(uint16_t id, uint8_t subId, uint8_t instance,
|
|||||||
uint32_t data, TelemetryUnit unit = UNIT_RAW);
|
uint32_t data, TelemetryUnit unit = UNIT_RAW);
|
||||||
void sportProcessTelemetryPacketWithoutCrc(uint8_t origin, const uint8_t *packet);
|
void sportProcessTelemetryPacketWithoutCrc(uint8_t origin, const uint8_t *packet);
|
||||||
|
|
||||||
void telemetryWakeup();
|
|
||||||
void telemetryReset();
|
|
||||||
|
|
||||||
extern uint8_t telemetryProtocol;
|
|
||||||
void telemetryInit(uint8_t protocol);
|
|
||||||
|
|
||||||
void telemetryInterrupt10ms();
|
|
||||||
|
|
||||||
bool pushFrskyTelemetryData(uint8_t data); // returns true when end of frame detected
|
bool pushFrskyTelemetryData(uint8_t data); // returns true when end of frame detected
|
||||||
void processFrskyTelemetryData(uint8_t data);
|
void processFrskyTelemetryData(uint8_t data);
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,8 @@
|
|||||||
#include "intmodule_serial_driver.h"
|
#include "intmodule_serial_driver.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static_assert(PXX2_FRAME_MAXLENGTH <= INTMODULE_FIFO_SIZE);
|
||||||
|
|
||||||
void processGetHardwareInfoFrame(uint8_t module, const uint8_t * frame)
|
void processGetHardwareInfoFrame(uint8_t module, const uint8_t * frame)
|
||||||
{
|
{
|
||||||
if (moduleState[module].mode != MODULE_MODE_GET_HARDWARE_INFO) {
|
if (moduleState[module].mode != MODULE_MODE_GET_HARDWARE_INFO) {
|
||||||
|
|||||||
@@ -31,6 +31,9 @@
|
|||||||
#include "libopenui.h"
|
#include "libopenui.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <FreeRTOS.h>
|
||||||
|
#include <timers.h>
|
||||||
|
|
||||||
uint8_t telemetryStreaming = 0;
|
uint8_t telemetryStreaming = 0;
|
||||||
uint8_t telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE]; // Receive buffer. 9 bytes (full packet), worst case 18 bytes with byte-stuffing (+1)
|
uint8_t telemetryRxBuffer[TELEMETRY_RX_PACKET_SIZE]; // Receive buffer. 9 bytes (full packet), worst case 18 bytes with byte-stuffing (+1)
|
||||||
uint8_t telemetryRxBufferCount = 0;
|
uint8_t telemetryRxBufferCount = 0;
|
||||||
@@ -106,6 +109,45 @@ void telemetryMirrorSend(uint8_t data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !defined(SIMU)
|
||||||
|
static TimerHandle_t telemetryTimer = nullptr;
|
||||||
|
static StaticTimer_t telemetryTimerBuffer;
|
||||||
|
|
||||||
|
static void telemetryTimerCb(TimerHandle_t xTimer)
|
||||||
|
{
|
||||||
|
(void)xTimer;
|
||||||
|
if (!s_pulses_paused) {
|
||||||
|
DEBUG_TIMER_START(debugTimerTelemetryWakeup);
|
||||||
|
telemetryWakeup();
|
||||||
|
DEBUG_TIMER_STOP(debugTimerTelemetryWakeup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void telemetryStart()
|
||||||
|
{
|
||||||
|
if (!telemetryTimer) {
|
||||||
|
telemetryTimer =
|
||||||
|
xTimerCreateStatic("Telem", 4 / RTOS_MS_PER_TICK, pdTRUE, (void*)0,
|
||||||
|
telemetryTimerCb, &telemetryTimerBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (telemetryTimer) {
|
||||||
|
if( xTimerStart( telemetryTimer, 0 ) != pdPASS ) {
|
||||||
|
/* The timer could not be set into the Active state. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void telemetryStop()
|
||||||
|
{
|
||||||
|
if (telemetryTimer) {
|
||||||
|
if( xTimerStop( telemetryTimer, 5 / RTOS_MS_PER_TICK ) != pdPASS ) {
|
||||||
|
/* The timer could not be set into the Active state. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void processTelemetryData(uint8_t data)
|
void processTelemetryData(uint8_t data)
|
||||||
{
|
{
|
||||||
#if defined(CROSSFIRE)
|
#if defined(CROSSFIRE)
|
||||||
@@ -275,6 +317,9 @@ void telemetryWakeup()
|
|||||||
{
|
{
|
||||||
uint8_t requiredTelemetryProtocol = modelTelemetryProtocol();
|
uint8_t requiredTelemetryProtocol = modelTelemetryProtocol();
|
||||||
|
|
||||||
|
// TODO: needs to be moved to protocol/module init
|
||||||
|
// as-is, it implies only ONE telemetry protocol
|
||||||
|
// enabled at the same time
|
||||||
if (telemetryProtocol != requiredTelemetryProtocol) {
|
if (telemetryProtocol != requiredTelemetryProtocol) {
|
||||||
telemetryInit(requiredTelemetryProtocol);
|
telemetryInit(requiredTelemetryProtocol);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,17 @@ void telemetrySetMirrorCb(void* ctx, void (*fct)(void*, uint8_t));
|
|||||||
// Mirror telemetry byte
|
// Mirror telemetry byte
|
||||||
void telemetryMirrorSend(uint8_t data);
|
void telemetryMirrorSend(uint8_t data);
|
||||||
|
|
||||||
|
void telemetryWakeup();
|
||||||
|
void telemetryReset();
|
||||||
|
|
||||||
|
extern uint8_t telemetryProtocol;
|
||||||
|
void telemetryInit(uint8_t protocol);
|
||||||
|
|
||||||
|
void telemetryInterrupt10ms();
|
||||||
|
|
||||||
|
void telemetryStart();
|
||||||
|
void telemetryStop();
|
||||||
|
|
||||||
#define TELEMETRY_AVERAGE_COUNT 3
|
#define TELEMETRY_AVERAGE_COUNT 3
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
|||||||
Reference in New Issue
Block a user