Simplified CRSF telemetry port handling since sharing not required

This commit is contained in:
Martin Budden 2016-11-18 15:04:13 +00:00
parent e58d4bc0ad
commit 01c272d0ef
7 changed files with 21 additions and 70 deletions

View File

@ -60,6 +60,5 @@ typedef enum {
DEBUG_DTERM_FILTER,
DEBUG_ANGLERATE,
DEBUG_ESC_TELEMETRY,
DEBUG_CRSF,
DEBUG_COUNT
} debugType_e;

View File

@ -39,8 +39,6 @@
#include "rx/rx.h"
#include "rx/crsf.h"
#include "telemetry/telemetry.h"
#define CRSF_TIME_NEEDED_PER_FRAME_US 1000
#define CRSF_TIME_BETWEEN_FRAMES_US 4000 // a frame is sent by the transmitter every 4 milliseconds
@ -235,19 +233,7 @@ bool crsfRxInit(const rxConfig_t *rxConfig, rxRuntimeConfig_t *rxRuntimeConfig)
return false;
}
#if defined(TELEMETRY) && defined(TELEMETRY_CRSF)
const bool portShared = telemetryCheckRxPortShared(portConfig);
#else
const bool portShared = false;
#endif
serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, CRSF_BAUDRATE, portShared ? MODE_RXTX : MODE_RX, CRSF_PORT_OPTIONS);
#if defined(TELEMETRY) && defined(TELEMETRY_CRSF)
if (portShared) {
telemetrySharedPort = serialPort;
}
#endif
serialPort = openSerialPort(portConfig->identifier, FUNCTION_RX_SERIAL, crsfDataReceive, CRSF_BAUDRATE, CRSF_PORT_MODE, CRSF_PORT_OPTIONS);
return serialPort != NULL;
}

View File

@ -19,6 +19,7 @@
#define CRSF_BAUDRATE 420000
#define CRSF_PORT_OPTIONS (SERIAL_STOPBITS_1 | SERIAL_PARITY_NO | SERIAL_BIDIR)
#define CRSF_PORT_MODE MODE_RXTX
#define CRSF_MAX_CHANNEL 16

View File

@ -111,7 +111,6 @@
#undef MAG
#ifdef CC3D_OPBL
#undef USE_SERIAL_4WAY_BLHELI_INTERFACE
#define SKIP_CLI_COMMAND_HELP
#undef BARO
#undef SONAR

View File

@ -108,7 +108,7 @@
#define USE_BARO_BMP085
#define USE_BARO_BMP280
//#define MAG
#define MAG
#define USE_MAG_HMC5883
#define MAG_HMC5883_ALIGN CW180_DEG

View File

@ -64,12 +64,8 @@
#include "fc/config.h"
#endif
#define TELEMETRY_CRSF_INITIAL_PORT_MODE MODE_RXTX
#define CRSF_CYCLETIME_US 100000
#define CRSF_CYCLETIME_US 100000 // 100ms, 10 Hz
static serialPort_t *serialPort;
static serialPortConfig_t *serialPortConfig;
static portSharing_e portSharing;
static bool crsfTelemetryEnabled;
static uint8_t crsfCrc;
static uint8_t crsfFrame[CRSF_FRAME_SIZE_MAX];
@ -351,52 +347,23 @@ static void processCrsf(void)
crsfScheduleIndex = (crsfScheduleIndex + 1) % CRSF_SCHEDULE_COUNT;
}
static void freeCrsfTelemetryPort(void)
{
closeSerialPort(serialPort);
serialPort = NULL;
crsfTelemetryEnabled = false;
}
static void configureCrsfTelemetryPort(void)
{
if (!serialPortConfig) {
return;
}
serialPort = openSerialPort(serialPortConfig->identifier, FUNCTION_TELEMETRY_CRSF, NULL, CRSF_BAUDRATE, TELEMETRY_CRSF_INITIAL_PORT_MODE, CRSF_PORT_OPTIONS);
if (!serialPort) {
return;
}
crsfTelemetryEnabled = true;
}
void initCrsfTelemetry(void)
{
serialPortConfig = findSerialPortConfig(FUNCTION_TELEMETRY_CRSF);
portSharing = determinePortSharing(serialPortConfig, FUNCTION_TELEMETRY_CRSF);
// check if there is a serial port open for CRSF telemetry (ie opened by the CRSF RX)
// if so, set CRSF telemetry enabled
crsfTelemetryEnabled = false;
const serialPortConfig_t *serialPortConfig = findSerialPortConfig(FUNCTION_TELEMETRY_CRSF);
if (serialPortConfig) {
const serialPort_t *serialPort = openSerialPort(serialPortConfig->identifier, FUNCTION_TELEMETRY_CRSF, NULL, CRSF_BAUDRATE, CRSF_PORT_MODE, CRSF_PORT_OPTIONS);
if (serialPort) {
crsfTelemetryEnabled = true;
}
}
}
bool checkCrsfTelemetryState(void)
{
if (serialPortConfig && telemetryCheckRxPortShared(serialPortConfig)) {
if (!crsfTelemetryEnabled && telemetrySharedPort != NULL) {
serialPort = telemetrySharedPort;
crsfTelemetryEnabled = true;
return true;
}
return false;
} else {
const bool newTelemetryEnabled = telemetryDetermineEnabledState(portSharing);
if (newTelemetryEnabled == crsfTelemetryEnabled) {
return false;
}
if (newTelemetryEnabled) {
configureCrsfTelemetryPort();
} else {
freeCrsfTelemetryPort();
}
return true;
}
return crsfTelemetryEnabled;
}
/*
@ -409,13 +376,12 @@ void handleCrsfTelemetry(uint32_t currentTime)
if (!crsfTelemetryEnabled) {
return;
}
if (!serialPort) {
return;
}
// give the receiver a change to send any outstanding telemetry data.
// Give the receiver a chance to send any outstanding telemetry data.
// This needs to be done at high frequency, to enable the RX to send the telemetry frame
// in between the RX frames.
crsfRxSendTelemetryData();
// Actual telemetry data only needs to be sent at a low frequency, ie 10Hz
if (currentTime >= crsfLastCycleTime + CRSF_CYCLETIME_US) {
crsfLastCycleTime = currentTime;
processCrsf();

View File

@ -59,4 +59,4 @@ bool telemetryDetermineEnabledState(portSharing_e portSharing);
void telemetryUseConfig(telemetryConfig_t *telemetryConfig);
#define TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK (FUNCTION_TELEMETRY_FRSKY | FUNCTION_TELEMETRY_LTM | FUNCTION_TELEMETRY_CRSF)
#define TELEMETRY_SHAREABLE_PORT_FUNCTIONS_MASK (FUNCTION_TELEMETRY_FRSKY | FUNCTION_TELEMETRY_LTM)