add buffer input on transmit/receive

This commit is contained in:
Guilherme S. Salustiano 2024-02-10 08:49:14 +01:00
parent 3773928425
commit 40282c2666

View file

@ -316,7 +316,7 @@ impl<'d, T: Instance> Radio<'d, T> {
/// for the life time of the transmission or if the buffer will be modified. /// for the life time of the transmission or if the buffer will be modified.
/// Also if the buffer is smaller than the packet length, the radio will /// Also if the buffer is smaller than the packet length, the radio will
/// read/write memory out of the buffer bounds. /// read/write memory out of the buffer bounds.
pub fn set_buffer(&mut self, buffer: &[u8]) -> Result<(), Error> { fn set_buffer(&mut self, buffer: &[u8]) -> Result<(), Error> {
// Because we are serializing the buffer, we should always have the buffer in RAM // Because we are serializing the buffer, we should always have the buffer in RAM
slice_in_ram_or(buffer, Error::BufferNotInRAM)?; slice_in_ram_or(buffer, Error::BufferNotInRAM)?;
@ -334,27 +334,33 @@ impl<'d, T: Instance> Radio<'d, T> {
} }
/// Send packet /// Send packet
pub async fn transmit(&mut self) { pub async fn transmit(&mut self, buffer: &[u8]) -> Result<(), Error> {
let r = T::regs(); self.set_buffer(buffer)?;
let r = T::regs();
self.trigger_and_wait_end(move || { self.trigger_and_wait_end(move || {
// Initialize the transmission // Initialize the transmission
// trace!("txen"); // trace!("txen");
r.tasks_txen.write(|w| w.tasks_txen().set_bit()); r.tasks_txen.write(|w| w.tasks_txen().set_bit());
}) })
.await; .await;
Ok(())
} }
/// Receive packet /// Receive packet
pub async fn receive(&mut self) { pub async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
let r = T::regs(); self.set_buffer(buffer)?;
let r = T::regs();
self.trigger_and_wait_end(move || { self.trigger_and_wait_end(move || {
// Initialize the transmission // Initialize the transmission
// trace!("rxen"); // trace!("rxen");
r.tasks_rxen.write(|w| w.tasks_rxen().set_bit()); r.tasks_rxen.write(|w| w.tasks_rxen().set_bit());
}) })
.await; .await;
Ok(())
} }
async fn trigger_and_wait_end(&mut self, trigger: impl FnOnce()) { async fn trigger_and_wait_end(&mut self, trigger: impl FnOnce()) {