mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-08 19:07:26 +00:00
use my Timer class on all platforms, it works better than the freertos version
This commit is contained in:
@@ -11,12 +11,18 @@ static SPISettings spiSettings(4000000, MSBFIRST, SPI_MODE0);
|
||||
|
||||
RadioLibInterface::RadioLibInterface(RADIOLIB_PIN_TYPE cs, RADIOLIB_PIN_TYPE irq, RADIOLIB_PIN_TYPE rst, RADIOLIB_PIN_TYPE busy,
|
||||
SPIClass &spi, PhysicalLayer *_iface)
|
||||
: module(cs, irq, rst, busy, spi, spiSettings), iface(_iface)
|
||||
: PeriodicTask(0), module(cs, irq, rst, busy, spi, spiSettings), iface(_iface)
|
||||
{
|
||||
assert(!instance); // We assume only one for now
|
||||
instance = this;
|
||||
}
|
||||
|
||||
bool RadioLibInterface::init()
|
||||
{
|
||||
setup(); // init our timer
|
||||
return RadioInterface::init();
|
||||
}
|
||||
|
||||
#ifndef NO_ESP32
|
||||
// ESP32 doesn't use that flag
|
||||
#define YIELD_FROM_ISR(x) portYIELD_FROM_ISR()
|
||||
@@ -194,48 +200,25 @@ void RadioLibInterface::loop()
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#define USE_HW_TIMER
|
||||
#else
|
||||
// Not needed on NRF52
|
||||
#define IRAM_ATTR
|
||||
#endif
|
||||
|
||||
void IRAM_ATTR RadioLibInterface::timerCallback(void *p1, uint32_t p2)
|
||||
void RadioLibInterface::doTask()
|
||||
{
|
||||
RadioLibInterface *t = (RadioLibInterface *)p1;
|
||||
|
||||
t->timerRunning = false;
|
||||
disable(); // Don't call this callback again
|
||||
|
||||
// We use without overwrite, so that if there is already an interrupt pending to be handled, that gets handle properly (the
|
||||
// ISR handler will restart our timer)
|
||||
#ifndef USE_HW_TIMER
|
||||
t->notify(TRANSMIT_DELAY_COMPLETED, eSetValueWithoutOverwrite);
|
||||
#else
|
||||
BaseType_t xHigherPriorityTaskWoken;
|
||||
instance->notifyFromISR(&xHigherPriorityTaskWoken, TRANSMIT_DELAY_COMPLETED, eSetValueWithoutOverwrite);
|
||||
|
||||
/* Force a context switch if xHigherPriorityTaskWoken is now set to pdTRUE.
|
||||
The macro used to do this is dependent on the port and may be called
|
||||
portEND_SWITCHING_ISR. */
|
||||
YIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
#endif
|
||||
notify(TRANSMIT_DELAY_COMPLETED, eSetValueWithoutOverwrite);
|
||||
}
|
||||
|
||||
void RadioLibInterface::startTransmitTimer(bool withDelay)
|
||||
{
|
||||
// If we have work to do and the timer wasn't already scheduled, schedule it now
|
||||
if (!timerRunning && !txQueue.isEmpty()) {
|
||||
timerRunning = true;
|
||||
if (getPeriod() == 0 && !txQueue.isEmpty()) {
|
||||
uint32_t delay =
|
||||
!withDelay ? 0 : random(MIN_TX_WAIT_MSEC, MAX_TX_WAIT_MSEC); // See documentation for loop() wrt these values
|
||||
!withDelay ? 1 : random(MIN_TX_WAIT_MSEC, MAX_TX_WAIT_MSEC); // See documentation for loop() wrt these values
|
||||
// DEBUG_MSG("xmit timer %d\n", delay);
|
||||
#ifdef USE_HW_TIMER
|
||||
bool okay = scheduleHWCallback(timerCallback, this, 0, delay);
|
||||
#else
|
||||
bool okay = scheduleOSCallback(timerCallback, this, 0, delay);
|
||||
#endif
|
||||
assert(okay);
|
||||
|
||||
setPeriod(delay);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "PeriodicTask.h"
|
||||
#include "RadioInterface.h"
|
||||
|
||||
#include <RadioLib.h>
|
||||
@@ -11,13 +12,12 @@
|
||||
#define INTERRUPT_ATTR
|
||||
#endif
|
||||
|
||||
class RadioLibInterface : public RadioInterface
|
||||
class RadioLibInterface : public RadioInterface, private PeriodicTask
|
||||
{
|
||||
/// Used as our notification from the ISR
|
||||
enum PendingISR { ISR_NONE = 0, ISR_RX, ISR_TX, TRANSMIT_DELAY_COMPLETED };
|
||||
|
||||
volatile PendingISR pending = ISR_NONE;
|
||||
volatile bool timerRunning = false;
|
||||
|
||||
/**
|
||||
* Raw ISR handler that just calls our polymorphic method
|
||||
@@ -104,7 +104,14 @@ class RadioLibInterface : public RadioInterface
|
||||
|
||||
static void timerCallback(void *p1, uint32_t p2);
|
||||
|
||||
virtual void doTask();
|
||||
|
||||
protected:
|
||||
/// Initialise the Driver transport hardware and software.
|
||||
/// Make sure the Driver is properly configured before calling init().
|
||||
/// \return true if initialisation succeeded.
|
||||
virtual bool init();
|
||||
|
||||
/**
|
||||
* Convert our modemConfig enum into wf, sf, etc...
|
||||
*
|
||||
|
||||
@@ -113,9 +113,9 @@ void SX1262Interface::startReceive()
|
||||
/** Could we send right now (i.e. either not actively receving or transmitting)? */
|
||||
bool SX1262Interface::isActivelyReceiving()
|
||||
{
|
||||
return false; // FIXME
|
||||
// FIXME this is not correct - often always true - need to add an extra conditional
|
||||
// return lora.getPacketLength() > 0;
|
||||
// return false; // FIXME
|
||||
// FIXME this is not correct? - often always true - need to add an extra conditional
|
||||
return lora.getPacketLength() > 0;
|
||||
}
|
||||
|
||||
bool SX1262Interface::sleep()
|
||||
|
||||
Reference in New Issue
Block a user