|
1 | 1 | //! IEEE 802.15.4 radio
|
2 | 2 |
|
3 | 3 | use core::{
|
| 4 | + marker::PhantomData, |
4 | 5 | ops::{self, RangeFrom},
|
5 | 6 | sync::atomic::{self, Ordering},
|
6 |
| - marker::PhantomData, |
7 | 7 | };
|
8 | 8 |
|
9 | 9 | use embedded_hal::timer::CountDown as _;
|
@@ -380,7 +380,8 @@ impl<'c> Radio<'c> {
|
380 | 380 | }
|
381 | 381 |
|
382 | 382 | fn start_recv(&mut self, packet: &mut Packet) {
|
383 |
| - // NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details |
| 383 | + // NOTE we do NOT check the address of `packet` because the mutable reference ensures it's |
| 384 | + // allocated in RAM |
384 | 385 |
|
385 | 386 | // clear related events
|
386 | 387 | self.radio.events_phyend.reset();
|
@@ -413,8 +414,12 @@ impl<'c> Radio<'c> {
|
413 | 414 | /// This method performs Clear Channel Assessment (CCA) first and sends the `packet` only if the
|
414 | 415 | /// channel is observed to be *clear* (no transmission is currently ongoing), otherwise no
|
415 | 416 | /// packet is transmitted and the `Err` variant is returned
|
416 |
| - // NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details |
417 |
| - pub fn try_send(&mut self, packet: &Packet) -> Result<(), ()> { |
| 417 | + /// |
| 418 | + /// NOTE this method will *not* modify the `packet` argument. The mutable reference is used to |
| 419 | + /// ensure the `packet` buffer is allocated in RAM, which is required by the RADIO peripheral |
| 420 | + // NOTE we do NOT check the address of `packet` because the mutable reference ensures it's |
| 421 | + // allocated in RAM |
| 422 | + pub fn try_send(&mut self, packet: &mut Packet) -> Result<(), ()> { |
418 | 423 | // enable radio to perform cca
|
419 | 424 | self.put_in_rx_mode();
|
420 | 425 |
|
@@ -471,8 +476,12 @@ impl<'c> Radio<'c> {
|
471 | 476 | /// This is utility method that *consecutively* calls the `try_send` method until it succeeds.
|
472 | 477 | /// Note that this approach is *not* IEEE spec compliant -- there must be delay between failed
|
473 | 478 | /// CCA attempts to be spec compliant
|
474 |
| - // NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details |
475 |
| - pub fn send(&mut self, packet: &Packet) { |
| 479 | + /// |
| 480 | + /// NOTE this method will *not* modify the `packet` argument. The mutable reference is used to |
| 481 | + /// ensure the `packet` buffer is allocated in RAM, which is required by the RADIO peripheral |
| 482 | + // NOTE we do NOT check the address of `packet` because the mutable reference ensures it's |
| 483 | + // allocated in RAM |
| 484 | + pub fn send(&mut self, packet: &mut Packet) { |
476 | 485 | // enable radio to perform cca
|
477 | 486 | self.put_in_rx_mode();
|
478 | 487 |
|
@@ -529,8 +538,12 @@ impl<'c> Radio<'c> {
|
529 | 538 | /// Sends the specified `packet` without first performing CCA
|
530 | 539 | ///
|
531 | 540 | /// Acknowledgment packets must be sent using this method
|
532 |
| - // NOTE we do NOT check the address of `packet`; see comment in `Packet::new` for details |
533 |
| - pub fn send_no_cca(&mut self, packet: &Packet) { |
| 541 | + /// |
| 542 | + /// NOTE this method will *not* modify the `packet` argument. The mutable reference is used to |
| 543 | + /// ensure the `packet` buffer is allocated in RAM, which is required by the RADIO peripheral |
| 544 | + // NOTE we do NOT check the address of `packet` because the mutable reference ensures it's |
| 545 | + // allocated in RAM |
| 546 | + pub fn send_no_cca(&mut self, packet: &mut Packet) { |
534 | 547 | self.put_in_tx_mode();
|
535 | 548 |
|
536 | 549 | // clear related events
|
@@ -731,9 +744,6 @@ impl Packet {
|
731 | 744 | const SIZE: usize = 1 /* PHR */ + Self::MAX_PSDU_LEN as usize;
|
732 | 745 |
|
733 | 746 | /// Returns an empty packet (length = 0)
|
734 |
| - // XXX I believe that be making this *not* `const` it is not possible to place a `Packet` in |
735 |
| - // `.rodata` (modulo unsafe `#[link_section]` shenanigans) thus it is not necessary to check the |
736 |
| - // address of packet in `Radio.{send,recv}` (EasyDMA can only operate on RAM addresses) |
737 | 747 | pub fn new() -> Self {
|
738 | 748 | let mut packet = Self {
|
739 | 749 | buffer: [0; Self::SIZE],
|
|
0 commit comments