aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias <[email protected]>2022-08-18 20:30:50 +0200
committerMathias <[email protected]>2022-08-18 20:30:50 +0200
commit55a63a5417ccfd2ca2792215920de14519a3d27b (patch)
tree5fb7b7b971969ce32d2e841a1af4ffb8cbbeeb3b
parent3bbfc11f45149c5624e2ff6370f8e71b956402af (diff)
Attempt to implement future for DMA transfer
-rw-r--r--embassy-rp/src/dma.rs49
1 files changed, 42 insertions, 7 deletions
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs
index bf15e1f4e..ec09a7699 100644
--- a/embassy-rp/src/dma.rs
+++ b/embassy-rp/src/dma.rs
@@ -1,8 +1,9 @@
1use core::pin::Pin; 1use core::pin::Pin;
2use core::sync::atomic::{compiler_fence, Ordering}; 2use core::sync::atomic::{compiler_fence, Ordering};
3use core::task::{Context, Poll}; 3use core::task::{Context, Poll, Waker};
4 4
5use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef}; 5use embassy_hal_common::{impl_peripheral, into_ref, Peripheral, PeripheralRef};
6use embassy_util::waitqueue::AtomicWaker;
6use futures::Future; 7use futures::Future;
7 8
8use crate::pac::dma::vals; 9use crate::pac::dma::vals;
@@ -60,15 +61,41 @@ impl<'a, C: Channel> Unpin for Transfer<'a, C> {}
60impl<'a, C: Channel> Future for Transfer<'a, C> { 61impl<'a, C: Channel> Future for Transfer<'a, C> {
61 type Output = (); 62 type Output = ();
62 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 63 fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
63 // self.channel.set_waker(cx.waker()); 64 self.channel.set_waker(cx.waker());
64 // if self.channel.is_running() { 65
65 // Poll::Pending 66 if self.channel.is_running() {
66 // } else { 67 Poll::Pending
67 Poll::Ready(()) 68 } else {
68 // } 69 Poll::Ready(())
70 }
71 }
72}
73
74struct ChannelState {
75 waker: AtomicWaker,
76}
77
78impl ChannelState {
79 const fn new() -> Self {
80 Self {
81 waker: AtomicWaker::new(),
82 }
83 }
84}
85
86struct State {
87 channels: [ChannelState; 12],
88}
89
90impl State {
91 const fn new() -> Self {
92 const CH: ChannelState = ChannelState::new();
93 Self { channels: [CH; 12] }
69 } 94 }
70} 95}
71 96
97static STATE: State = State::new();
98
72pub struct NoDma; 99pub struct NoDma;
73 100
74impl_peripheral!(NoDma); 101impl_peripheral!(NoDma);
@@ -86,6 +113,14 @@ pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + S
86 pac::DMA.ch(self.number() as _) 113 pac::DMA.ch(self.number() as _)
87 } 114 }
88 115
116 fn is_running(&self) -> bool {
117 self.regs().ctrl_trig().read().en()
118 }
119
120 fn set_waker(&self, waker: &Waker) {
121 STATE.channels[self.number() as usize].waker.register(waker);
122 }
123
89 fn degrade(self) -> AnyChannel { 124 fn degrade(self) -> AnyChannel {
90 AnyChannel { number: self.number() } 125 AnyChannel { number: self.number() }
91 } 126 }