[Taranis] Telemetry serial interrupt fix
[Taranis] CRC check on telemetry data [all] Mixer bug on recursive channels
This commit is contained in:
@@ -36,7 +36,6 @@
|
|||||||
|
|
||||||
#include "../opentx.h"
|
#include "../opentx.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include "fifo.h"
|
|
||||||
|
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
|
|
||||||
|
|||||||
@@ -466,6 +466,34 @@ TEST(Mixer, RecursiveAddChannel)
|
|||||||
EXPECT_EQ(chans[1], 0);
|
EXPECT_EQ(chans[1], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Mixer, RecursiveAddChannelAfterInactivePhase)
|
||||||
|
{
|
||||||
|
MODEL_RESET();
|
||||||
|
MIXER_RESET();
|
||||||
|
g_model.phaseData[1].swtch = SWSRC_ID1;
|
||||||
|
g_model.mixData[0].destCh = 0;
|
||||||
|
g_model.mixData[0].mltpx = MLTPX_ADD;
|
||||||
|
g_model.mixData[0].srcRaw = MIXSRC_CH2;
|
||||||
|
g_model.mixData[0].phases = 0b11110;
|
||||||
|
g_model.mixData[0].weight = 50;
|
||||||
|
g_model.mixData[1].destCh = 0;
|
||||||
|
g_model.mixData[1].mltpx = MLTPX_ADD;
|
||||||
|
g_model.mixData[1].srcRaw = MIXSRC_MAX;
|
||||||
|
g_model.mixData[1].phases = 0b11101;
|
||||||
|
g_model.mixData[1].weight = 50;
|
||||||
|
g_model.mixData[2].destCh = 1;
|
||||||
|
g_model.mixData[2].srcRaw = MIXSRC_MAX;
|
||||||
|
g_model.mixData[2].weight = 100;
|
||||||
|
simuSetSwitch(3, -1);
|
||||||
|
perMain();
|
||||||
|
EXPECT_EQ(chans[0], CHANNEL_MAX/2);
|
||||||
|
EXPECT_EQ(chans[1], CHANNEL_MAX);
|
||||||
|
simuSetSwitch(3, 0);
|
||||||
|
perMain();
|
||||||
|
EXPECT_EQ(chans[0], CHANNEL_MAX/2);
|
||||||
|
EXPECT_EQ(chans[1], CHANNEL_MAX);
|
||||||
|
}
|
||||||
|
|
||||||
#define CHECK_SLOW_MOVEMENT(channel, sign, duration) \
|
#define CHECK_SLOW_MOVEMENT(channel, sign, duration) \
|
||||||
do { \
|
do { \
|
||||||
for (int i=1; i<=(duration); i++) { \
|
for (int i=1; i<=(duration); i++) { \
|
||||||
|
|||||||
+13
-12
@@ -2834,11 +2834,11 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
||||||
// printf("[pass %d]\n", pass); fflush(stdout);
|
// TRACE("[pass %d]", pass);
|
||||||
|
|
||||||
bitfield_channels_t passDirtyChannels = 0;
|
bitfield_channels_t passDirtyChannels = 0;
|
||||||
|
|
||||||
for (uint8_t i = 0; i < MAX_MIXERS; i++) {
|
for (uint8_t i=0; i<MAX_MIXERS; i++) {
|
||||||
|
|
||||||
#if defined(BOLD_FONT)
|
#if defined(BOLD_FONT)
|
||||||
if (mode==e_perout_mode_normal && pass==0) swOn[i].activeMix = 0;
|
if (mode==e_perout_mode_normal && pass==0) swOn[i].activeMix = 0;
|
||||||
@@ -2852,6 +2852,11 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
|
|
||||||
if (!(dirtyChannels & ((bitfield_channels_t)1 << md->destCh))) continue;
|
if (!(dirtyChannels & ((bitfield_channels_t)1 << md->destCh))) continue;
|
||||||
|
|
||||||
|
// if this is the first calculation for the destination channel, initialize it with 0 (otherwise would be random)
|
||||||
|
if (i == 0 || md->destCh != (md-1)->destCh) {
|
||||||
|
chans[md->destCh] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//========== PHASE && SWITCH =====
|
//========== PHASE && SWITCH =====
|
||||||
bool mixCondition = (md->phases != 0 || md->swtch);
|
bool mixCondition = (md->phases != 0 || md->swtch);
|
||||||
delayval_t mixEnabled = !(md->phases & (1 << s_perout_flight_phase)) && getSwitch(md->swtch);
|
delayval_t mixEnabled = !(md->phases & (1 << s_perout_flight_phase)) && getSwitch(md->swtch);
|
||||||
@@ -2873,7 +2878,7 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
else {
|
else {
|
||||||
v = getValue(k);
|
v = getValue(k);
|
||||||
if (k>=MIXSRC_CH1-1 && k<=MIXSRC_LAST_CH-1 && md->destCh != k-MIXSRC_CH1+1) {
|
if (k>=MIXSRC_CH1-1 && k<=MIXSRC_LAST_CH-1 && md->destCh != k-MIXSRC_CH1+1) {
|
||||||
if (dirtyChannels & ((bitfield_channels_t)1 << (k-MIXSRC_CH1+1)) & (passDirtyChannels|~(((bitfield_channels_t) 1 << md->destCh)-1)))
|
if (dirtyChannels & ((bitfield_channels_t)1 << (k-MIXSRC_CH1+1)))
|
||||||
passDirtyChannels |= (bitfield_channels_t) 1 << md->destCh;
|
passDirtyChannels |= (bitfield_channels_t) 1 << md->destCh;
|
||||||
if (k-MIXSRC_CH1+1 < md->destCh || pass > 0)
|
if (k-MIXSRC_CH1+1 < md->destCh || pass > 0)
|
||||||
v = chans[k-MIXSRC_CH1+1] >> 8;
|
v = chans[k-MIXSRC_CH1+1] >> 8;
|
||||||
@@ -2886,7 +2891,7 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
|
|
||||||
bool apply_offset_and_curve = true;
|
bool apply_offset_and_curve = true;
|
||||||
|
|
||||||
// ========== DELAYS ===============
|
//========== DELAYS ===============
|
||||||
delayval_t _swOn = swOn[i].now;
|
delayval_t _swOn = swOn[i].now;
|
||||||
delayval_t _swPrev = swOn[i].prev;
|
delayval_t _swPrev = swOn[i].prev;
|
||||||
bool swTog = (mixEnabled != _swOn);
|
bool swTog = (mixEnabled != _swOn);
|
||||||
@@ -2927,7 +2932,7 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
int16_t offset = GET_GVAR(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, s_perout_flight_phase);
|
int16_t offset = GET_GVAR(MD_OFFSET(md), GV_RANGELARGE_NEG, GV_RANGELARGE, s_perout_flight_phase);
|
||||||
if (offset) v += calc100toRESX_16Bits(offset);
|
if (offset) v += calc100toRESX_16Bits(offset);
|
||||||
|
|
||||||
//========== TRIMS ===============
|
//========== TRIMS ================
|
||||||
if (!(mode & e_perout_mode_notrims)) {
|
if (!(mode & e_perout_mode_notrims)) {
|
||||||
int8_t mix_trim = md->carryTrim;
|
int8_t mix_trim = md->carryTrim;
|
||||||
if (mix_trim < TRIM_ON)
|
if (mix_trim < TRIM_ON)
|
||||||
@@ -2976,13 +2981,13 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown);
|
int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown);
|
||||||
if (newValue>currentValue) currentValue = newValue; // Endposition; prevent toggling around the destination
|
if (newValue>currentValue) currentValue = newValue; // Endposition; prevent toggling around the destination
|
||||||
}
|
}
|
||||||
} //endif diff>0
|
}
|
||||||
act[i] = tact = currentValue;
|
act[i] = tact = currentValue;
|
||||||
// open.20.fsguruh: this implementation would save about 50 bytes code
|
// open.20.fsguruh: this implementation would save about 50 bytes code
|
||||||
} // endif tick10ms ; in case no time passed assign the old value, not the current value from source
|
} // endif tick10ms ; in case no time passed assign the old value, not the current value from source
|
||||||
v = (tact >> DEL_MULT_SHIFT);
|
v = (tact >> DEL_MULT_SHIFT);
|
||||||
} //endif diff
|
}
|
||||||
} //endif speed
|
}
|
||||||
|
|
||||||
//========== CURVES ===============
|
//========== CURVES ===============
|
||||||
if (apply_offset_and_curve && md->curveParam && md->curveMode == MODE_CURVE) {
|
if (apply_offset_and_curve && md->curveParam && md->curveMode == MODE_CURVE) {
|
||||||
@@ -3004,10 +3009,6 @@ void perOut(uint8_t mode, uint8_t tick10ms)
|
|||||||
|
|
||||||
int32_t *ptr = &chans[md->destCh]; // Save calculating address several times
|
int32_t *ptr = &chans[md->destCh]; // Save calculating address several times
|
||||||
|
|
||||||
if (i == 0 || md->destCh != (md - 1)->destCh)
|
|
||||||
*ptr = 0;
|
|
||||||
// if this is the first calculation for the destination channel, initialize it with 0 (otherwise would be random)
|
|
||||||
|
|
||||||
switch (md->mltpx) {
|
switch (md->mltpx) {
|
||||||
case MLTPX_REP:
|
case MLTPX_REP:
|
||||||
*ptr = dv;
|
*ptr = dv;
|
||||||
|
|||||||
@@ -407,6 +407,7 @@ enum EnumKeys {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CPUARM)
|
#if defined(CPUARM)
|
||||||
|
#include "fifo.h"
|
||||||
// This doesn't need protection on this processor
|
// This doesn't need protection on this processor
|
||||||
#define tmr10ms_t uint32_t
|
#define tmr10ms_t uint32_t
|
||||||
extern volatile tmr10ms_t g_tmr10ms;
|
extern volatile tmr10ms_t g_tmr10ms;
|
||||||
|
|||||||
@@ -35,7 +35,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "../opentx.h"
|
#include "../opentx.h"
|
||||||
#include "../fifo.h"
|
|
||||||
|
|
||||||
void btSetBaudrate(uint32_t index)
|
void btSetBaudrate(uint32_t index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -466,7 +466,7 @@ static void init_pa7_dsm2()
|
|||||||
|
|
||||||
TIM8->CR1 &= ~TIM_CR1_CEN ;
|
TIM8->CR1 &= ~TIM_CR1_CEN ;
|
||||||
TIM8->ARR = 44000 ; // 22mS
|
TIM8->ARR = 44000 ; // 22mS
|
||||||
TIM8->CCR2 = 30000 ; // Update time
|
TIM8->CCR2 = 40000 ; // Update time
|
||||||
TIM8->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
TIM8->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 2000000 - 1 ; // 0.5uS from 30MHz
|
||||||
#if defined(REV3)
|
#if defined(REV3)
|
||||||
TIM8->CCER = TIM_CCER_CC1E | TIM_CCER_CC1P ;
|
TIM8->CCER = TIM_CCER_CC1E | TIM_CCER_CC1P ;
|
||||||
@@ -608,8 +608,7 @@ extern "C" void TIM8_UP_TIM13_IRQHandler()
|
|||||||
TIM8->SR &= ~TIM_SR_UIF ; // Clear flag
|
TIM8->SR &= ~TIM_SR_UIF ; // Clear flag
|
||||||
|
|
||||||
TIM8->ARR = *ppmStreamPtr[EXTERNAL_MODULE]++ ;
|
TIM8->ARR = *ppmStreamPtr[EXTERNAL_MODULE]++ ;
|
||||||
if (*ppmStreamPtr[EXTERNAL_MODULE] == 0)
|
if (*ppmStreamPtr[EXTERNAL_MODULE] == 0) {
|
||||||
{
|
|
||||||
TIM8->SR &= ~TIM_SR_CC2IF ; // Clear this flag
|
TIM8->SR &= ~TIM_SR_CC2IF ; // Clear this flag
|
||||||
TIM8->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
TIM8->DIER |= TIM_DIER_CC2IE ; // Enable this interrupt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#include "../opentx.h"
|
#include "../opentx.h"
|
||||||
|
|
||||||
|
extern Fifo<512> telemetryFifo;
|
||||||
|
|
||||||
void sportInit(void)
|
void sportInit(void)
|
||||||
{
|
{
|
||||||
USART_InitTypeDef USART_InitStructure;
|
USART_InitTypeDef USART_InitStructure;
|
||||||
@@ -85,16 +87,25 @@ void sportPutc(const char c)
|
|||||||
GPIO_ResetBits(GPIO_PIN_SPORT_ON, PIN_SPORT_ON);
|
GPIO_ResetBits(GPIO_PIN_SPORT_ON, PIN_SPORT_ON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void processSerialData(uint8_t data);
|
|
||||||
|
|
||||||
#if !defined(SIMU)
|
#if !defined(SIMU)
|
||||||
|
|
||||||
|
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||||
|
|
||||||
extern "C" void USART2_IRQHandler()
|
extern "C" void USART2_IRQHandler()
|
||||||
{
|
{
|
||||||
uint16_t data;
|
uint32_t status;
|
||||||
|
uint8_t data;
|
||||||
|
|
||||||
if (USART_GetFlagStatus(SPORT, USART_FLAG_RXNE) || USART_GetFlagStatus(SPORT, USART_FLAG_ORE)) {
|
status = SPORT->SR;
|
||||||
data = USART_ReceiveData(SPORT);
|
|
||||||
processSerialData((uint8_t) data);
|
while (status & (USART_FLAG_RXNE | USART_FLAG_ERRORS)) {
|
||||||
|
data = SPORT->DR;
|
||||||
|
|
||||||
|
if (!(status & USART_FLAG_ERRORS))
|
||||||
|
telemetryFifo.push(data);
|
||||||
|
|
||||||
|
status = SPORT->SR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ void uartInit(uint32_t baudrate)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(DEBUG)
|
#if defined(DEBUG)
|
||||||
#include "../../fifo.h"
|
|
||||||
Fifo<512> debugTxFifo;
|
Fifo<512> debugTxFifo;
|
||||||
void debugPutc(const char c)
|
void debugPutc(const char c)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -125,11 +125,11 @@ uint8_t link_counter = 0;
|
|||||||
FrskyData frskyData;
|
FrskyData frskyData;
|
||||||
|
|
||||||
#if defined(DEBUG) && !defined(SIMU)
|
#if defined(DEBUG) && !defined(SIMU)
|
||||||
#include "../fifo.h"
|
|
||||||
extern FIL g_telemetryFile;
|
extern FIL g_telemetryFile;
|
||||||
Fifo<512> debugTelemetryFifo;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Fifo<512> telemetryFifo;
|
||||||
|
|
||||||
void setBaroAltitude(int32_t baroAltitude)
|
void setBaroAltitude(int32_t baroAltitude)
|
||||||
{
|
{
|
||||||
// First received barometer altitude => Altitude offset
|
// First received barometer altitude => Altitude offset
|
||||||
@@ -266,6 +266,19 @@ void processHubPacket(uint8_t id, uint16_t value)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool checkSportPacket(uint8_t *packet)
|
||||||
|
{
|
||||||
|
short t_short =0;
|
||||||
|
for (int i=0; i<FRSKY_RX_PACKET_SIZE-1; i++) {
|
||||||
|
t_short += *packet++; //0-1FF
|
||||||
|
t_short += t_short >> 8; //0-100
|
||||||
|
t_short &= 0x00ff;
|
||||||
|
t_short += t_short >> 8; //0-0FF
|
||||||
|
t_short &= 0x00ff;
|
||||||
|
}
|
||||||
|
return packet[FRSKY_RX_PACKET_SIZE-1] == (uint8_t)t_short;
|
||||||
|
}
|
||||||
|
|
||||||
#define SPORT_DATA_U8(packet) (packet[4])
|
#define SPORT_DATA_U8(packet) (packet[4])
|
||||||
#define SPORT_DATA_S32(packet) (*((int32_t *)(packet+4)))
|
#define SPORT_DATA_S32(packet) (*((int32_t *)(packet+4)))
|
||||||
#define SPORT_DATA_U32(packet) (*((uint32_t *)(packet+4)))
|
#define SPORT_DATA_U32(packet) (*((uint32_t *)(packet+4)))
|
||||||
@@ -277,6 +290,9 @@ void processSportPacket(uint8_t *packet)
|
|||||||
uint8_t prim = packet[1];
|
uint8_t prim = packet[1];
|
||||||
uint16_t appId = *((uint16_t *)(packet+2));
|
uint16_t appId = *((uint16_t *)(packet+2));
|
||||||
|
|
||||||
|
if (!checkSportPacket(packet))
|
||||||
|
return;
|
||||||
|
|
||||||
switch (prim)
|
switch (prim)
|
||||||
{
|
{
|
||||||
case DATA_FRAME:
|
case DATA_FRAME:
|
||||||
@@ -404,10 +420,6 @@ void processSerialData(uint8_t data)
|
|||||||
btPushByte(data);
|
btPushByte(data);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG) && !defined(SIMU)
|
|
||||||
debugTelemetryFifo.push(data);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (data == START_STOP) {
|
if (data == START_STOP) {
|
||||||
dataState = STATE_DATA_IN_FRAME;
|
dataState = STATE_DATA_IN_FRAME;
|
||||||
numPktBytes = 0;
|
numPktBytes = 0;
|
||||||
@@ -489,7 +501,27 @@ inline bool alarmRaised(uint8_t channel, uint8_t idx)
|
|||||||
|
|
||||||
void telemetryWakeup()
|
void telemetryWakeup()
|
||||||
{
|
{
|
||||||
#if defined(PCBSKY9X)
|
#if defined(PCBTARANIS)
|
||||||
|
uint8_t data;
|
||||||
|
#if defined(DEBUG) && !defined(SIMU)
|
||||||
|
static tmr10ms_t lastTime = 0;
|
||||||
|
tmr10ms_t newTime = get_tmr10ms();
|
||||||
|
struct gtm utm;
|
||||||
|
gettime(&utm);
|
||||||
|
#endif
|
||||||
|
while (telemetryFifo.pop(data)) {
|
||||||
|
processSerialData(data);
|
||||||
|
#if defined(DEBUG) && !defined(SIMU)
|
||||||
|
if (lastTime != newTime) {
|
||||||
|
f_printf(&g_telemetryFile, "\r\n%4d-%02d-%02d,%02d:%02d:%02d.%02d0: %02X", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100, data);
|
||||||
|
lastTime = newTime;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
f_printf(&g_telemetryFile, " %02X", data);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#elif defined(PCBSKY9X)
|
||||||
rxPdcUsart(processSerialData); // Receive serial data here
|
rxPdcUsart(processSerialData); // Receive serial data here
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -507,24 +539,6 @@ void telemetryWakeup()
|
|||||||
varioWakeup();
|
varioWakeup();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG) && !defined(SIMU)
|
|
||||||
static tmr10ms_t lastTime = 0;
|
|
||||||
tmr10ms_t newTime = get_tmr10ms();
|
|
||||||
uint8_t data;
|
|
||||||
struct gtm utm;
|
|
||||||
gettime(&utm);
|
|
||||||
|
|
||||||
while (debugTelemetryFifo.pop(data)) {
|
|
||||||
if (lastTime != newTime) {
|
|
||||||
f_printf(&g_telemetryFile, "\r\n%4d-%02d-%02d,%02d:%02d:%02d.%02d0: %02X", utm.tm_year+1900, utm.tm_mon+1, utm.tm_mday, utm.tm_hour, utm.tm_min, utm.tm_sec, g_ms100, data);
|
|
||||||
lastTime = newTime;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
f_printf(&g_telemetryFile, " %02X", data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static tmr10ms_t alarmsCheckTime = 0;
|
static tmr10ms_t alarmsCheckTime = 0;
|
||||||
static uint8_t alarmsCheckStep = 0;
|
static uint8_t alarmsCheckStep = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user