WiP internal module buffer
This commit is contained in:
@@ -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,8 +22,10 @@
|
|||||||
#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"
|
||||||
|
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
class ModuleFifo : public Fifo<uint8_t, INTMODULE_FIFO_SIZE> {
|
class ModuleFifo : public Fifo<uint8_t, INTMODULE_FIFO_SIZE> {
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -275,6 +275,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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user