Skip to content

Commit d624e80

Browse files
committed
once more event handling
the previous version result in `recv` resuming immediately after issuing a `*send`
1 parent 4c46534 commit d624e80

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

nrf52840-hal/src/ieee802154.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ impl<'c> Radio<'c> {
250250
pub fn recv(&mut self, packet: &mut Packet) -> Result<u16, u16> {
251251
// NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details
252252

253+
// clear related events
254+
self.radio.events_phyend.reset();
255+
self.radio.events_end.reset();
256+
253257
// go to the RXIDLE state
254258
self.enable_rx();
255259

@@ -268,8 +272,6 @@ impl<'c> Radio<'c> {
268272
// wait until we have received something
269273
self.wait_for_event(Event::End);
270274
dma_end_fence();
271-
// also clear the PHYEND event
272-
self.radio.events_phyend.reset();
273275

274276
let crc = self.radio.rxcrc.read().rxcrc().bits() as u16;
275277
if self.radio.crcstatus.read().crcstatus().bit_is_set() {
@@ -285,6 +287,10 @@ impl<'c> Radio<'c> {
285287
/// channel is observed to be *clear* (no transmission is currently ongoing), otherwise no
286288
/// packet is transmitted and the `Err` variant is returned
287289
pub fn try_send(&mut self, packet: &Packet) -> Result<(), ()> {
290+
// clear related events
291+
self.radio.events_phyend.reset();
292+
self.radio.events_end.reset();
293+
288294
// NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details
289295
// go to the RXIDLE state
290296
self.enable_rx();
@@ -337,8 +343,6 @@ impl<'c> Radio<'c> {
337343
// until the PHYEND event is raised
338344
self.wait_for_event(Event::PhyEnd);
339345
dma_end_fence();
340-
// also clear the END event
341-
self.radio.events_end.reset();
342346

343347
Ok(())
344348
}
@@ -351,6 +355,10 @@ impl<'c> Radio<'c> {
351355
pub fn send(&mut self, packet: &Packet) {
352356
// NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details
353357

358+
// clear related events
359+
self.radio.events_phyend.reset();
360+
self.radio.events_end.reset();
361+
354362
self.radio.shorts.modify(|_, w| w.ccaidle_txen().set_bit());
355363

356364
// go to the RXIDLE state
@@ -403,8 +411,6 @@ impl<'c> Radio<'c> {
403411
// until the PHYEND event is raised
404412
self.wait_for_event(Event::PhyEnd);
405413
dma_end_fence();
406-
// also clear the END event
407-
self.radio.events_end.reset();
408414

409415
self.radio
410416
.shorts

0 commit comments

Comments
 (0)