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

View File

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

View File

@@ -1,6 +1,6 @@
#pragma once
#define OLED_UPDATE_RATE 500
#define OLED_UPDATE_RATE 750
#define SBUS_UPDATE_RATE 15 //ms
#define SBUS_PACKET_LENGTH 25
@@ -18,7 +18,7 @@
#define CHANNEL_ID 0x01
#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_RX_HEALTH 0x1
@@ -90,7 +90,6 @@ struct TxDeviceState_t {
uint8_t snr = 0;
uint8_t flags = 0;
uint32_t roundtrip = 0;
bool readPacket = false;
bool isReceiving = false; //Indicates that TX module is receiving frames from RX module
};