kopia lustrzana https://github.com/meshtastic/firmware
Encapsulate RadioLibInterface receive IRQ logic (#4866)
* Encapsulate RadioLibInterface receive IRQ logic * More concise * Trunkpull/4819/head
rodzic
51e4b364b0
commit
baf9cf5a59
|
@ -272,29 +272,8 @@ template <typename T> bool LR11x0Interface<T>::isActivelyReceiving()
|
||||||
{
|
{
|
||||||
// The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet
|
// The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet
|
||||||
// received and handled the interrupt for reading the packet/handling errors.
|
// received and handled the interrupt for reading the packet/handling errors.
|
||||||
|
return receiveDetected(lora.getIrqStatus(), RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID,
|
||||||
uint16_t irq = lora.getIrqStatus();
|
RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED);
|
||||||
bool detected = (irq & (RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID | RADIOLIB_LR11X0_IRQ_PREAMBLE_DETECTED));
|
|
||||||
// Handle false detections
|
|
||||||
if (detected) {
|
|
||||||
if (!activeReceiveStart) {
|
|
||||||
activeReceiveStart = millis();
|
|
||||||
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, 2 * preambleTimeMsec) &&
|
|
||||||
!(irq & RADIOLIB_LR11X0_IRQ_SYNC_WORD_HEADER_VALID)) {
|
|
||||||
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
|
|
||||||
activeReceiveStart = 0;
|
|
||||||
LOG_DEBUG("Ignore false preamble detection.\n");
|
|
||||||
return false;
|
|
||||||
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, maxPacketTimeMsec)) {
|
|
||||||
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
|
|
||||||
activeReceiveStart = 0;
|
|
||||||
LOG_DEBUG("Ignore false header detection.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (detected) LOG_DEBUG("rx detected\n");
|
|
||||||
return detected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool LR11x0Interface<T>::sleep()
|
template <typename T> bool LR11x0Interface<T>::sleep()
|
||||||
|
|
|
@ -65,7 +65,4 @@ template <class T> class LR11x0Interface : public RadioLibInterface
|
||||||
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
|
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
|
||||||
|
|
||||||
virtual void setStandby() override;
|
virtual void setStandby() override;
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t activeReceiveStart = 0;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -129,6 +129,28 @@ bool RadioLibInterface::canSendImmediately()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool RadioLibInterface::receiveDetected(uint16_t irq, ulong syncWordHeaderValidFlag, ulong preambleDetectedFlag)
|
||||||
|
{
|
||||||
|
bool detected = (irq & (syncWordHeaderValidFlag | preambleDetectedFlag));
|
||||||
|
// Handle false detections
|
||||||
|
if (detected) {
|
||||||
|
if (!activeReceiveStart) {
|
||||||
|
activeReceiveStart = millis();
|
||||||
|
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, 2 * preambleTimeMsec) && !(irq & syncWordHeaderValidFlag)) {
|
||||||
|
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
|
||||||
|
activeReceiveStart = 0;
|
||||||
|
LOG_DEBUG("Ignore false preamble detection.\n");
|
||||||
|
return false;
|
||||||
|
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, maxPacketTimeMsec)) {
|
||||||
|
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
|
||||||
|
activeReceiveStart = 0;
|
||||||
|
LOG_DEBUG("Ignore false header detection.\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return detected;
|
||||||
|
}
|
||||||
|
|
||||||
/// Send a packet (possibly by enquing in a private fifo). This routine will
|
/// Send a packet (possibly by enquing in a private fifo). This routine will
|
||||||
/// later free() the packet to pool. This routine is not allowed to stall because it is called from
|
/// later free() the packet to pool. This routine is not allowed to stall because it is called from
|
||||||
/// bluetooth comms code. If the txmit queue is empty it might return an error
|
/// bluetooth comms code. If the txmit queue is empty it might return an error
|
||||||
|
|
|
@ -167,6 +167,10 @@ class RadioLibInterface : public RadioInterface, protected concurrency::Notified
|
||||||
meshtastic_QueueStatus getQueueStatus();
|
meshtastic_QueueStatus getQueueStatus();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
uint32_t activeReceiveStart = 0;
|
||||||
|
|
||||||
|
bool receiveDetected(uint16_t irq, ulong syncWordHeaderValidFlag, ulong preambleDetectedFlag);
|
||||||
|
|
||||||
/** Do any hardware setup needed on entry into send configuration for the radio.
|
/** Do any hardware setup needed on entry into send configuration for the radio.
|
||||||
* Subclasses can customize, but must also call this base method */
|
* Subclasses can customize, but must also call this base method */
|
||||||
virtual void configHardwareForSend();
|
virtual void configHardwareForSend();
|
||||||
|
|
|
@ -316,29 +316,7 @@ template <typename T> bool SX126xInterface<T>::isActivelyReceiving()
|
||||||
{
|
{
|
||||||
// The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet
|
// The IRQ status will be cleared when we start our read operation. Check if we've started a header, but haven't yet
|
||||||
// received and handled the interrupt for reading the packet/handling errors.
|
// received and handled the interrupt for reading the packet/handling errors.
|
||||||
|
return receiveDetected(lora.getIrqFlags(), RADIOLIB_SX126X_IRQ_HEADER_VALID, RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED);
|
||||||
uint16_t irq = lora.getIrqFlags();
|
|
||||||
bool detected = (irq & (RADIOLIB_SX126X_IRQ_HEADER_VALID | RADIOLIB_SX126X_IRQ_PREAMBLE_DETECTED));
|
|
||||||
// Handle false detections
|
|
||||||
if (detected) {
|
|
||||||
if (!activeReceiveStart) {
|
|
||||||
activeReceiveStart = millis();
|
|
||||||
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, 2 * preambleTimeMsec) &&
|
|
||||||
!(irq & RADIOLIB_SX126X_IRQ_HEADER_VALID)) {
|
|
||||||
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
|
|
||||||
activeReceiveStart = 0;
|
|
||||||
LOG_DEBUG("Ignore false preamble detection.\n");
|
|
||||||
return false;
|
|
||||||
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, maxPacketTimeMsec)) {
|
|
||||||
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
|
|
||||||
activeReceiveStart = 0;
|
|
||||||
LOG_DEBUG("Ignore false header detection.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (detected) LOG_DEBUG("rx detected\n");
|
|
||||||
return detected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool SX126xInterface<T>::sleep()
|
template <typename T> bool SX126xInterface<T>::sleep()
|
||||||
|
|
|
@ -67,7 +67,4 @@ template <class T> class SX126xInterface : public RadioLibInterface
|
||||||
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
|
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
|
||||||
|
|
||||||
virtual void setStandby() override;
|
virtual void setStandby() override;
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t activeReceiveStart = 0;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -290,28 +290,7 @@ template <typename T> bool SX128xInterface<T>::isChannelActive()
|
||||||
/** Could we send right now (i.e. either not actively receiving or transmitting)? */
|
/** Could we send right now (i.e. either not actively receiving or transmitting)? */
|
||||||
template <typename T> bool SX128xInterface<T>::isActivelyReceiving()
|
template <typename T> bool SX128xInterface<T>::isActivelyReceiving()
|
||||||
{
|
{
|
||||||
uint16_t irq = lora.getIrqStatus();
|
return receiveDetected(lora.getIrqStatus(), RADIOLIB_SX128X_IRQ_HEADER_VALID, RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED);
|
||||||
bool detected = (irq & (RADIOLIB_SX128X_IRQ_HEADER_VALID | RADIOLIB_SX128X_IRQ_PREAMBLE_DETECTED));
|
|
||||||
|
|
||||||
// Handle false detections
|
|
||||||
if (detected) {
|
|
||||||
if (!activeReceiveStart) {
|
|
||||||
activeReceiveStart = millis();
|
|
||||||
} else if (!Throttle::isWithinTimespanMs(activeReceiveStart, 2 * preambleTimeMsec) &&
|
|
||||||
!(irq & RADIOLIB_SX128X_IRQ_HEADER_VALID)) {
|
|
||||||
// The HEADER_VALID flag should be set by now if it was really a packet, so ignore PREAMBLE_DETECTED flag
|
|
||||||
activeReceiveStart = 0;
|
|
||||||
LOG_DEBUG("Ignore false preamble detection.\n");
|
|
||||||
return false;
|
|
||||||
} else if (Throttle::isWithinTimespanMs(activeReceiveStart, maxPacketTimeMsec)) {
|
|
||||||
// We should have gotten an RX_DONE IRQ by now if it was really a packet, so ignore HEADER_VALID flag
|
|
||||||
activeReceiveStart = 0;
|
|
||||||
LOG_DEBUG("Ignore false header detection.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return detected;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> bool SX128xInterface<T>::sleep()
|
template <typename T> bool SX128xInterface<T>::sleep()
|
||||||
|
|
|
@ -67,7 +67,4 @@ template <class T> class SX128xInterface : public RadioLibInterface
|
||||||
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
|
virtual void addReceiveMetadata(meshtastic_MeshPacket *mp) override;
|
||||||
|
|
||||||
virtual void setStandby() override;
|
virtual void setStandby() override;
|
||||||
|
|
||||||
private:
|
|
||||||
uint32_t activeReceiveStart = 0;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -158,7 +158,6 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||||
result = bme680Sensor.runTrigger();
|
result = bme680Sensor.runTrigger();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t now = millis();
|
|
||||||
if (((lastSentToMesh == 0) ||
|
if (((lastSentToMesh == 0) ||
|
||||||
!Throttle::isWithinTimespanMs(lastSentToMesh, Default::getConfiguredOrDefaultMsScaled(
|
!Throttle::isWithinTimespanMs(lastSentToMesh, Default::getConfiguredOrDefaultMsScaled(
|
||||||
moduleConfig.telemetry.environment_update_interval,
|
moduleConfig.telemetry.environment_update_interval,
|
||||||
|
|
Ładowanie…
Reference in New Issue