mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-05 05:04:46 +00:00
SX1262 approximately works top-to-bottom, but need to add sleep modes
This commit is contained in:
parent
a2ba9d3c44
commit
62a893c760
@ -73,8 +73,8 @@ ErrorCode RadioLibInterface::send(MeshPacket *p)
|
|||||||
// we almost certainly guarantee no one outside will like the packet we are sending.
|
// we almost certainly guarantee no one outside will like the packet we are sending.
|
||||||
if (canSendImmediately()) {
|
if (canSendImmediately()) {
|
||||||
// if the radio is idle, we can send right away
|
// if the radio is idle, we can send right away
|
||||||
DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id, -1,
|
DEBUG_MSG("immediate send on mesh fr=0x%x,to=0x%x,id=%d\n (txGood=%d,rxGood=%d,rxBad=%d)\n", p->from, p->to, p->id,
|
||||||
-1, -1);
|
txGood, rxGood, rxBad);
|
||||||
|
|
||||||
startSend(p);
|
startSend(p);
|
||||||
return ERRNO_OK;
|
return ERRNO_OK;
|
||||||
@ -95,8 +95,6 @@ void RadioLibInterface::loop()
|
|||||||
if (wasPending) {
|
if (wasPending) {
|
||||||
pending = ISR_NONE; // If the flag was set, it is _guaranteed_ the ISR won't be running, because it masked itself
|
pending = ISR_NONE; // If the flag was set, it is _guaranteed_ the ISR won't be running, because it masked itself
|
||||||
|
|
||||||
DEBUG_MSG("Handling a LORA interrupt %d!\n", wasPending);
|
|
||||||
|
|
||||||
if (wasPending == ISR_TX)
|
if (wasPending == ISR_TX)
|
||||||
handleTransmitInterrupt();
|
handleTransmitInterrupt();
|
||||||
else if (wasPending == ISR_RX)
|
else if (wasPending == ISR_RX)
|
||||||
@ -122,6 +120,7 @@ void RadioLibInterface::startNextWork()
|
|||||||
|
|
||||||
void RadioLibInterface::handleTransmitInterrupt()
|
void RadioLibInterface::handleTransmitInterrupt()
|
||||||
{
|
{
|
||||||
|
DEBUG_MSG("handling lora TX interrupt\n");
|
||||||
assert(sendingPacket); // Were we sending?
|
assert(sendingPacket); // Were we sending?
|
||||||
|
|
||||||
completeSending();
|
completeSending();
|
||||||
@ -130,6 +129,8 @@ void RadioLibInterface::handleTransmitInterrupt()
|
|||||||
void RadioLibInterface::completeSending()
|
void RadioLibInterface::completeSending()
|
||||||
{
|
{
|
||||||
if (sendingPacket) {
|
if (sendingPacket) {
|
||||||
|
txGood++;
|
||||||
|
|
||||||
// We are done sending that packet, release it
|
// We are done sending that packet, release it
|
||||||
packetPool.release(sendingPacket);
|
packetPool.release(sendingPacket);
|
||||||
sendingPacket = NULL;
|
sendingPacket = NULL;
|
||||||
@ -142,12 +143,15 @@ void RadioLibInterface::handleReceiveInterrupt()
|
|||||||
assert(isReceiving);
|
assert(isReceiving);
|
||||||
isReceiving = false;
|
isReceiving = false;
|
||||||
|
|
||||||
|
DEBUG_MSG("handling lora RX interrupt\n");
|
||||||
|
|
||||||
// read the number of actually received bytes
|
// read the number of actually received bytes
|
||||||
size_t length = iface.getPacketLength();
|
size_t length = iface.getPacketLength();
|
||||||
|
|
||||||
int state = iface.readData(radiobuf, length);
|
int state = iface.readData(radiobuf, length);
|
||||||
if (state != ERR_NONE) {
|
if (state != ERR_NONE) {
|
||||||
DEBUG_MSG("ignoring received packet due to error=%d\n", state);
|
DEBUG_MSG("ignoring received packet due to error=%d\n", state);
|
||||||
|
rxBad++;
|
||||||
} else {
|
} else {
|
||||||
// Skip the 4 headers that are at the beginning of the rxBuf
|
// Skip the 4 headers that are at the beginning of the rxBuf
|
||||||
int32_t payloadLen = length - sizeof(PacketHeader);
|
int32_t payloadLen = length - sizeof(PacketHeader);
|
||||||
@ -167,9 +171,11 @@ void RadioLibInterface::handleReceiveInterrupt()
|
|||||||
if (!pb_decode_from_bytes(payload, payloadLen, SubPacket_fields, p)) {
|
if (!pb_decode_from_bytes(payload, payloadLen, SubPacket_fields, p)) {
|
||||||
DEBUG_MSG("Invalid protobufs in received mesh packet, discarding.\n");
|
DEBUG_MSG("Invalid protobufs in received mesh packet, discarding.\n");
|
||||||
packetPool.release(mp);
|
packetPool.release(mp);
|
||||||
|
// rxBad++; not really a hw errpr
|
||||||
} else {
|
} else {
|
||||||
// parsing was successful, queue for our recipient
|
// parsing was successful, queue for our recipient
|
||||||
mp->has_payload = true;
|
mp->has_payload = true;
|
||||||
|
txGood++;
|
||||||
|
|
||||||
deliverToReceiver(mp);
|
deliverToReceiver(mp);
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class RadioLibInterface : public RadioInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* What sort of interrupt do we expect our helper thread to now handle */
|
* What sort of interrupt do we expect our helper thread to now handle */
|
||||||
volatile PendingISR pending;
|
volatile PendingISR pending = ISR_NONE;
|
||||||
|
|
||||||
/** Our ISR code currently needs this to find our active instance
|
/** Our ISR code currently needs this to find our active instance
|
||||||
*/
|
*/
|
||||||
@ -28,6 +28,11 @@ class RadioLibInterface : public RadioInterface
|
|||||||
*/
|
*/
|
||||||
static void isrTxLevel0();
|
static void isrTxLevel0();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Debugging counts
|
||||||
|
*/
|
||||||
|
uint32_t rxBad = 0, rxGood = 0, txGood = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
float bw = 125;
|
float bw = 125;
|
||||||
uint8_t sf = 9;
|
uint8_t sf = 9;
|
||||||
|
@ -100,7 +100,11 @@ bool SX1262Interface::canSendImmediately()
|
|||||||
// We wait _if_ we are partially though receiving a packet (rather than just merely waiting for one).
|
// We wait _if_ we are partially though receiving a packet (rather than just merely waiting for one).
|
||||||
// To do otherwise would be doubly bad because not only would we drop the packet that was on the way in,
|
// To do otherwise would be doubly bad because not only would we drop the packet that was on the way in,
|
||||||
// we almost certainly guarantee no one outside will like the packet we are sending.
|
// we almost certainly guarantee no one outside will like the packet we are sending.
|
||||||
bool busy = sendingPacket != NULL || (isReceiving && lora.getPacketLength() > 0);
|
bool busyTx = sendingPacket != NULL;
|
||||||
|
bool busyRx = isReceiving && lora.getPacketLength() > 0;
|
||||||
|
|
||||||
return !busy;
|
if (busyTx || busyRx)
|
||||||
|
DEBUG_MSG("Can not set now, busyTx=%d, busyRx=%d\n", busyTx, busyRx);
|
||||||
|
|
||||||
|
return !busyTx && !busyRx;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user