diff options
| author | Mathias <[email protected]> | 2022-08-23 12:28:17 +0200 |
|---|---|---|
| committer | Mathias <[email protected]> | 2022-08-23 12:28:17 +0200 |
| commit | f6c2e26372961747a0bc148d1675b1bc5dfb7e75 (patch) | |
| tree | ec72b7f61e206f04a8287fe125f4ca77d68e041c | |
| parent | 295af2a057beec74bb765f6e3dad28b44e30cb19 (diff) | |
Address code review comments
| -rw-r--r-- | embassy-rp/src/dma.rs | 50 | ||||
| -rw-r--r-- | embassy-rp/src/lib.rs | 1 | ||||
| -rw-r--r-- | embassy-rp/src/uart.rs | 34 |
3 files changed, 47 insertions, 38 deletions
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index 75ad640ca..25e3ec8fc 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs | |||
| @@ -15,27 +15,47 @@ use crate::{interrupt, pac, peripherals}; | |||
| 15 | unsafe fn DMA_IRQ_0() { | 15 | unsafe fn DMA_IRQ_0() { |
| 16 | let ints0 = pac::DMA.ints0().read().ints0(); | 16 | let ints0 = pac::DMA.ints0().read().ints0(); |
| 17 | 17 | ||
| 18 | critical_section::with(|_| { | 18 | for channel in 0..CHANNEL_COUNT { |
| 19 | for channel in 0..CHANNEL_COUNT { | 19 | if ints0 & (1 << channel) == (1 << channel) { |
| 20 | if ints0 & (1 << channel) == (1 << channel) { | 20 | CHANNEL_WAKERS[channel].wake(); |
| 21 | CHANNEL_WAKERS[channel].wake(); | ||
| 22 | } | ||
| 23 | } | 21 | } |
| 24 | pac::DMA.ints0().write(|w| w.set_ints0(ints0)); | 22 | } |
| 25 | }); | 23 | pac::DMA.ints0().write(|w| w.set_ints0(ints0)); |
| 26 | } | 24 | } |
| 27 | 25 | ||
| 28 | pub fn read<'a, C: Channel, W: Word>(ch: impl Peripheral<P = C> + 'a, from: *const W, to: &mut [W]) -> Transfer<'a, C> { | 26 | pub(crate) unsafe fn init() { |
| 27 | let irq = interrupt::DMA_IRQ_0::steal(); | ||
| 28 | irq.disable(); | ||
| 29 | irq.set_priority(interrupt::Priority::P6); | ||
| 30 | |||
| 31 | pac::DMA.inte0().write(|w| w.set_inte0(0xFFFF)); | ||
| 32 | |||
| 33 | irq.enable(); | ||
| 34 | } | ||
| 35 | |||
| 36 | pub unsafe fn read<'a, C: Channel, W: Word>( | ||
| 37 | ch: impl Peripheral<P = C> + 'a, | ||
| 38 | from: *const W, | ||
| 39 | to: &mut [W], | ||
| 40 | ) -> Transfer<'a, C> { | ||
| 29 | let (ptr, len) = crate::dma::slice_ptr_parts_mut(to); | 41 | let (ptr, len) = crate::dma::slice_ptr_parts_mut(to); |
| 30 | copy_inner(ch, from as *const u32, ptr as *mut u32, len, W::size(), false, true) | 42 | copy_inner(ch, from as *const u32, ptr as *mut u32, len, W::size(), false, true) |
| 31 | } | 43 | } |
| 32 | 44 | ||
| 33 | pub fn write<'a, C: Channel, W: Word>(ch: impl Peripheral<P = C> + 'a, from: &[W], to: *mut W) -> Transfer<'a, C> { | 45 | pub unsafe fn write<'a, C: Channel, W: Word>( |
| 46 | ch: impl Peripheral<P = C> + 'a, | ||
| 47 | from: &[W], | ||
| 48 | to: *mut W, | ||
| 49 | ) -> Transfer<'a, C> { | ||
| 34 | let (from_ptr, len) = crate::dma::slice_ptr_parts(from); | 50 | let (from_ptr, len) = crate::dma::slice_ptr_parts(from); |
| 35 | copy_inner(ch, from_ptr as *const u32, to as *mut u32, len, W::size(), true, false) | 51 | copy_inner(ch, from_ptr as *const u32, to as *mut u32, len, W::size(), true, false) |
| 36 | } | 52 | } |
| 37 | 53 | ||
| 38 | pub fn copy<'a, C: Channel, W: Word>(ch: impl Peripheral<P = C> + 'a, from: &[W], to: &mut [W]) -> Transfer<'a, C> { | 54 | pub unsafe fn copy<'a, C: Channel, W: Word>( |
| 55 | ch: impl Peripheral<P = C> + 'a, | ||
| 56 | from: &[W], | ||
| 57 | to: &mut [W], | ||
| 58 | ) -> Transfer<'a, C> { | ||
| 39 | let (from_ptr, from_len) = crate::dma::slice_ptr_parts(from); | 59 | let (from_ptr, from_len) = crate::dma::slice_ptr_parts(from); |
| 40 | let (to_ptr, to_len) = crate::dma::slice_ptr_parts_mut(to); | 60 | let (to_ptr, to_len) = crate::dma::slice_ptr_parts_mut(to); |
| 41 | assert_eq!(from_len, to_len); | 61 | assert_eq!(from_len, to_len); |
| @@ -91,16 +111,6 @@ impl<'a, C: Channel> Transfer<'a, C> { | |||
| 91 | pub(crate) fn new(channel: impl Peripheral<P = C> + 'a) -> Self { | 111 | pub(crate) fn new(channel: impl Peripheral<P = C> + 'a) -> Self { |
| 92 | into_ref!(channel); | 112 | into_ref!(channel); |
| 93 | 113 | ||
| 94 | unsafe { | ||
| 95 | let irq = interrupt::DMA_IRQ_0::steal(); | ||
| 96 | irq.disable(); | ||
| 97 | irq.set_priority(interrupt::Priority::P6); | ||
| 98 | |||
| 99 | pac::DMA.inte0().write(|w| w.set_inte0(1 << channel.number())); | ||
| 100 | |||
| 101 | irq.enable(); | ||
| 102 | } | ||
| 103 | |||
| 104 | Self { channel } | 114 | Self { channel } |
| 105 | } | 115 | } |
| 106 | } | 116 | } |
diff --git a/embassy-rp/src/lib.rs b/embassy-rp/src/lib.rs index 8c053a4f7..6db77b8cd 100644 --- a/embassy-rp/src/lib.rs +++ b/embassy-rp/src/lib.rs | |||
| @@ -105,6 +105,7 @@ pub fn init(_config: config::Config) -> Peripherals { | |||
| 105 | unsafe { | 105 | unsafe { |
| 106 | clocks::init(); | 106 | clocks::init(); |
| 107 | timer::init(); | 107 | timer::init(); |
| 108 | dma::init(); | ||
| 108 | } | 109 | } |
| 109 | 110 | ||
| 110 | peripherals | 111 | peripherals |
diff --git a/embassy-rp/src/uart.rs b/embassy-rp/src/uart.rs index 03623a9f8..9d94dcf21 100644 --- a/embassy-rp/src/uart.rs +++ b/embassy-rp/src/uart.rs | |||
| @@ -120,17 +120,16 @@ impl<'d, T: Instance, M: Mode> UartTx<'d, T, M> { | |||
| 120 | 120 | ||
| 121 | impl<'d, T: Instance> UartTx<'d, T, Async> { | 121 | impl<'d, T: Instance> UartTx<'d, T, Async> { |
| 122 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { | 122 | pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error> { |
| 123 | if let Some(ch) = &mut self.tx_dma { | 123 | let ch = self.tx_dma.as_mut().unwrap(); |
| 124 | unsafe { | 124 | let transfer = unsafe { |
| 125 | T::regs().uartdmacr().modify(|reg| { | 125 | T::regs().uartdmacr().modify(|reg| { |
| 126 | reg.set_txdmae(true); | 126 | reg.set_txdmae(true); |
| 127 | }); | 127 | }); |
| 128 | } | ||
| 129 | // If we don't assign future to a variable, the data register pointer | 128 | // If we don't assign future to a variable, the data register pointer |
| 130 | // is held across an await and makes the future non-Send. | 129 | // is held across an await and makes the future non-Send. |
| 131 | let transfer = crate::dma::write(ch, buffer, T::regs().uartdr().ptr() as *mut _); | 130 | crate::dma::write(ch, buffer, T::regs().uartdr().ptr() as *mut _) |
| 132 | transfer.await; | 131 | }; |
| 133 | } | 132 | transfer.await; |
| 134 | Ok(()) | 133 | Ok(()) |
| 135 | } | 134 | } |
| 136 | } | 135 | } |
| @@ -170,17 +169,16 @@ impl<'d, T: Instance, M: Mode> UartRx<'d, T, M> { | |||
| 170 | 169 | ||
| 171 | impl<'d, T: Instance> UartRx<'d, T, Async> { | 170 | impl<'d, T: Instance> UartRx<'d, T, Async> { |
| 172 | pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { | 171 | pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error> { |
| 173 | if let Some(ch) = &mut self.rx_dma { | 172 | let ch = self.rx_dma.as_mut().unwrap(); |
| 174 | unsafe { | 173 | let transfer = unsafe { |
| 175 | T::regs().uartdmacr().modify(|reg| { | 174 | T::regs().uartdmacr().modify(|reg| { |
| 176 | reg.set_rxdmae(true); | 175 | reg.set_rxdmae(true); |
| 177 | }); | 176 | }); |
| 178 | } | ||
| 179 | // If we don't assign future to a variable, the data register pointer | 177 | // If we don't assign future to a variable, the data register pointer |
| 180 | // is held across an await and makes the future non-Send. | 178 | // is held across an await and makes the future non-Send. |
| 181 | let transfer = crate::dma::read(ch, T::regs().uartdr().ptr() as *const _, buffer); | 179 | crate::dma::read(ch, T::regs().uartdr().ptr() as *const _, buffer) |
| 182 | transfer.await; | 180 | }; |
| 183 | } | 181 | transfer.await; |
| 184 | Ok(()) | 182 | Ok(()) |
| 185 | } | 183 | } |
| 186 | } | 184 | } |
