From e77c0edcdc65b656b676cf42ab59c2386f36c7a6 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 1 Jun 2021 11:27:04 -0700 Subject: [PATCH] if pkt too large, ignore, restart rx on err/timeout, loop processing schedule.. The first one is just more defensive programming, not sure if I'd seen this failure.. The middle one did fix some hangs... Last one is to ensure that the schedule processes more quickly and not enforce each command to take one ms... --- irr_main.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/irr_main.c b/irr_main.c index 9d4787b..a1028f2 100644 --- a/irr_main.c +++ b/irr_main.c @@ -82,25 +82,29 @@ void rxdone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { - if (rxpktavail) { - memcpy(rxpkt, payload, MIN(sizeof rxpkt, size)); + if (rxpktavail && size <= sizeof rxpkt) { + memcpy(rxpkt, payload, size); rxpktbuf = (struct pktbuf){ .pkt = rxpkt, .pktlen = size, }; rxpktavail = false; } + Radio.Rx(0); } void rxtimeout(void) { + Radio.Rx(0); } void rxerr(void) { + + Radio.Rx(0); } RadioEvents_t revents = { @@ -225,16 +229,26 @@ start_sched(struct sched *sched) set_chan(sched->chan, 1); } -static void -process_sched() +static bool +canproc_sched() { /* nothing to do? */ if (schedcnt == 0) - return; + return false; /* not yet expired */ if (uwTick < SCHED_HEAD.end_wait_tick) + return false; + + return true; +} + +static void +process_sched() +{ + + if (!canproc_sched()) return; if (SCHED_HEAD.cmd == CMD_RUNFOR) @@ -390,7 +404,8 @@ main() //Radio.Rx(0); loop: - process_sched(); + while (canproc_sched()) + process_sched(); BoardLowPowerHandler(); if (Radio.IrqProcess != NULL)