WIP: show recv_timeout API

TODO update text
This commit is contained in:
Jorge Aparicio 2020-06-17 18:51:52 +02:00
parent 806c4f09a0
commit 8140c7bba9
3 changed files with 33 additions and 11 deletions

View file

@ -122,7 +122,7 @@ checksum = "b1411551beb3c11dedfb0a90a0fa256b47d28b9ec2cdff34c25a2fa59e45dbdc"
[[package]]
name = "nrf-hal-common"
version = "0.10.0"
source = "git+https://github.com/japaric/nrf-hal?branch=radio#d624e80e5724e4709081ed65abaf63271fe1eca7"
source = "git+https://github.com/japaric/nrf-hal?branch=radio#7076639891fd2493e1c61a7aca71944b48ae0458"
dependencies = [
"cast",
"cortex-m",
@ -137,7 +137,7 @@ dependencies = [
[[package]]
name = "nrf52840-hal"
version = "0.10.0"
source = "git+https://github.com/japaric/nrf-hal?branch=radio#d624e80e5724e4709081ed65abaf63271fe1eca7"
source = "git+https://github.com/japaric/nrf-hal?branch=radio#7076639891fd2493e1c61a7aca71944b48ae0458"
dependencies = [
"cast",
"cortex-m",

View file

@ -4,9 +4,8 @@
use core::str;
use cortex_m::asm;
use cortex_m_rt::entry;
use dk::ieee802154::Packet;
use dk::ieee802154::{Error, Packet};
use panic_log as _; // the panicking behavior
#[entry]
@ -14,17 +13,27 @@ fn main() -> ! {
// initializes the peripherals
let board = dk::init().unwrap();
let mut radio = board.radio;
let mut timer = board.timer;
let mut packet = Packet::new();
let msg = b"olleh";
packet.copy_from_slice(msg);
radio.send(&packet);
log::info!("sent: {:?}", msg);
let crc = radio.recv(&mut packet);
let s = str::from_utf8(&*packet).expect("response is not valid UTF-8");
log::info!("received: {} (CRC={:?})", s, crc);
let timeout = 1_000;
let res = radio.recv_timeout(&mut packet, &mut timer, timeout);
loop {
asm::bkpt();
match res {
Ok(crc) => {
log::info!(
"received: {} (CRC={})",
str::from_utf8(&*packet).expect("response is not valid UTF-8"),
crc
);
}
Err(Error::Crc(crc)) => log::error!("invalid CRC: {:06x}", crc),
Err(Error::Timeout) => log::error!("no response within {} ms", timeout),
}
dk::exit()
}

View file

@ -5,6 +5,7 @@
#![no_std]
use core::{
ops,
sync::atomic::{AtomicU32, Ordering},
time::Duration,
};
@ -118,7 +119,7 @@ impl Led {
}
}
/// A timer for blocking delay
/// A timer for creating blocking delays
pub struct Timer {
inner: hal::Timer<hal::target::TIMER0, OneShot>,
}
@ -157,7 +158,19 @@ impl Timer {
}
}
// add Instant API
impl ops::Deref for Timer {
type Target = hal::Timer<hal::target::TIMER0, OneShot>;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl ops::DerefMut for Timer {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
/// Initializes the board
///