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)