@@ -15,6 +15,47 @@ use crate::{
15
15
timer:: { self , Timer } ,
16
16
} ;
17
17
18
+ pub enum RecvStatus {
19
+ NotDone ,
20
+ Success ( u16 ) ,
21
+ CrcFailure ( u16 ) ,
22
+ }
23
+
24
+ /// Non-blocking receive
25
+ pub struct Recv < ' a , ' c > {
26
+ radio : & ' a mut Radio < ' c > ,
27
+ }
28
+
29
+ impl < ' a , ' c > Recv < ' a , ' c > {
30
+ fn new ( radio : & ' a mut Radio < ' c > ) -> Self {
31
+ Self { radio }
32
+ }
33
+
34
+ pub fn is_done ( & mut self ) -> RecvStatus {
35
+ if self . radio . radio . events_end . read ( ) . events_end ( ) . bit_is_set ( ) {
36
+ self . radio . radio . events_end . reset ( ) ;
37
+
38
+ dma_end_fence ( ) ;
39
+
40
+ let crc = self . radio . radio . rxcrc . read ( ) . rxcrc ( ) . bits ( ) as u16 ;
41
+
42
+ if self . radio . radio . crcstatus . read ( ) . crcstatus ( ) . bit_is_set ( ) {
43
+ RecvStatus :: Success ( crc)
44
+ } else {
45
+ RecvStatus :: CrcFailure ( crc)
46
+ }
47
+ } else {
48
+ RecvStatus :: NotDone
49
+ }
50
+ }
51
+ }
52
+
53
+ impl < ' a , ' c > Drop for Recv < ' a , ' c > {
54
+ fn drop ( & mut self ) {
55
+ self . radio . cancel_recv ( ) ;
56
+ }
57
+ }
58
+
18
59
/// IEEE 802.15.4 radio
19
60
pub struct Radio < ' c > {
20
61
radio : RADIO ,
@@ -323,6 +364,19 @@ impl<'c> Radio<'c> {
323
364
}
324
365
}
325
366
367
+ /// Receives one radio packet and copies its contents into the given `packet` buffer
368
+ ///
369
+ /// This method is non-blocking
370
+ pub fn recv_non_blocking ( & mut self , packet : & mut Packet ) -> Recv < ' _ , ' c > {
371
+ // Start the read
372
+ // NOTE(unsafe) We block until reception completes or errors
373
+ unsafe {
374
+ self . start_recv ( packet) ;
375
+ }
376
+
377
+ Recv :: new ( self )
378
+ }
379
+
326
380
/// Listens for a packet for no longer than the specified amount of microseconds
327
381
/// and copies its contents into the given `packet` buffer
328
382
///
0 commit comments