All processing moved from ISR to main loop

This commit is contained in:
Pawel Spychalski (DzikuVx)
2017-11-11 16:51:00 +01:00
parent 6082f7f4a7
commit 8fc8c20697
3 changed files with 18 additions and 32 deletions

View File

@@ -12,7 +12,7 @@
#include "variables.h" #include "variables.h"
#include "qsp.h" #include "qsp.h"
volatile int ppm[16] = {0}; int ppm[16] = {0};
// LoRa32u4 ports // LoRa32u4 ports
#define LORA32U4_SS_PIN 8 #define LORA32U4_SS_PIN 8
@@ -56,10 +56,11 @@ uint32_t lastOledTaskTime = 0;
/* /*
* Start of QSP protocol implementation * Start of QSP protocol implementation
*/ */
volatile QspConfiguration_t qsp = {}; QspConfiguration_t qsp = {};
volatile RxDeviceState_t rxDeviceState = {}; RxDeviceState_t rxDeviceState = {};
volatile TxDeviceState_t txDeviceState = {}; TxDeviceState_t txDeviceState = {};
volatile bool doReadPacket = false;
uint8_t getRadioRssi(void) uint8_t getRadioRssi(void)
{ {
@@ -270,22 +271,25 @@ int8_t getFrameToTransmit(QspConfiguration_t *qsp) {
void loop(void) void loop(void)
{ {
#ifdef DEVICE_MODE_TX if (doReadPacket) {
if (txDeviceState.readPacket) {
int incomingByte; int incomingByte;
while (incomingByte = LoRa.read(), incomingByte > -1) while (incomingByte = LoRa.read(), incomingByte > -1)
{ {
qspDecodeIncomingFrame(&qsp, incomingByte, ppm, &rxDeviceState, &txDeviceState); qspDecodeIncomingFrame(&qsp, incomingByte, ppm, &rxDeviceState, &txDeviceState);
} }
#ifdef DEVICE_MODE_TX
txDeviceState.rssi = getRadioRssi(); txDeviceState.rssi = getRadioRssi();
txDeviceState.snr = getRadioSnr(); txDeviceState.snr = getRadioSnr();
txDeviceState.readPacket = false; #endif
#ifdef DEVICE_MODE_RX
rxDeviceState.rssi = getRadioRssi();
rxDeviceState.snr = getRadioSnr();
#endif
doReadPacket = false;
} }
#endif
uint32_t currentMillis = millis(); uint32_t currentMillis = millis();
bool transmitPayload = false; bool transmitPayload = false;
static uint32_t previousAnyFrameReceivedAt = 0;
/* /*
* Watchdog for frame decoding stuck somewhere in the middle of a process * Watchdog for frame decoding stuck somewhere in the middle of a process
@@ -307,7 +311,7 @@ void loop(void)
int8_t frameToSend = getFrameToTransmit(&qsp); int8_t frameToSend = getFrameToTransmit(&qsp);
if (frameToSend == QSP_FRAME_RC_DATA && !ppmReader.isReceiving()) { if (frameToSend == QSP_FRAME_RC_DATA && !ppmReader.isReceiving()) {
frameToSend = -1; // frameToSend = -1;
//FIXME uncomment to enable full Failsafe //FIXME uncomment to enable full Failsafe
} }
@@ -492,20 +496,5 @@ void onReceive(int packetSize)
if (packetSize == 0) if (packetSize == 0)
return; return;
#ifdef DEVICE_MODE_TX doReadPacket = true;
txDeviceState.readPacket = true;
#endif
#ifdef DEVICE_MODE_RX
int incomingByte;
while (incomingByte = LoRa.read(), incomingByte > -1)
{
qspDecodeIncomingFrame(&qsp, incomingByte, ppm, &rxDeviceState, &txDeviceState);
}
rxDeviceState.rssi = getRadioRssi();
rxDeviceState.snr = getRadioSnr();
#endif
} }

View File

@@ -213,7 +213,6 @@ void qspDecodeIncomingFrame(
qsp->lastFrameReceivedAt[frameId] = millis(); qsp->lastFrameReceivedAt[frameId] = millis();
} }
qsp->anyFrameRecivedAt = millis(); qsp->anyFrameRecivedAt = millis();
switch (frameId) { switch (frameId) {
case QSP_FRAME_RC_DATA: case QSP_FRAME_RC_DATA:
qspDecodeRcDataFrame(qsp, ppm); qspDecodeRcDataFrame(qsp, ppm);
@@ -234,7 +233,6 @@ void qspDecodeIncomingFrame(
txDeviceState->roundtrip += (uint32_t) qsp->payload[3] << 24; txDeviceState->roundtrip += (uint32_t) qsp->payload[3] << 24;
txDeviceState->roundtrip = (micros() - txDeviceState->roundtrip) / 1000; txDeviceState->roundtrip = (micros() - txDeviceState->roundtrip) / 1000;
break; break;
default: default:

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#define OLED_UPDATE_RATE 500 #define OLED_UPDATE_RATE 750
#define SBUS_UPDATE_RATE 15 //ms #define SBUS_UPDATE_RATE 15 //ms
#define SBUS_PACKET_LENGTH 25 #define SBUS_PACKET_LENGTH 25
@@ -18,7 +18,7 @@
#define CHANNEL_ID 0x01 #define CHANNEL_ID 0x01
#define QSP_PAYLOAD_LENGTH 32 #define QSP_PAYLOAD_LENGTH 32
#define QSP_MAX_FRAME_DECODE_TIME 5 //max time that frame can be decoded in ms #define QSP_MAX_FRAME_DECODE_TIME 10 //max time that frame can be decoded in ms
#define QSP_FRAME_RC_DATA 0x0 #define QSP_FRAME_RC_DATA 0x0
#define QSP_FRAME_RX_HEALTH 0x1 #define QSP_FRAME_RX_HEALTH 0x1
@@ -90,7 +90,6 @@ struct TxDeviceState_t {
uint8_t snr = 0; uint8_t snr = 0;
uint8_t flags = 0; uint8_t flags = 0;
uint32_t roundtrip = 0; uint32_t roundtrip = 0;
bool readPacket = false;
bool isReceiving = false; //Indicates that TX module is receiving frames from RX module bool isReceiving = false; //Indicates that TX module is receiving frames from RX module
}; };