aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias <[email protected]>2022-08-18 21:27:37 +0200
committerMathias <[email protected]>2022-08-18 21:27:37 +0200
commitaa586fe1dee309808fca34500812bf33f2a5c558 (patch)
treed4e7ddd3288167d16380d46a8c5053d263fa1b95
parentdebff0980d6a4c5527ebdaea6f91f32b63477bc5 (diff)
Simplify waker storage for DMA state
-rw-r--r--embassy-rp/src/dma.rs45
1 files changed, 6 insertions, 39 deletions
diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs
index 8cf8c394d..a56d77c12 100644
--- a/embassy-rp/src/dma.rs
+++ b/embassy-rp/src/dma.rs
@@ -1,6 +1,6 @@
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, Waker}; 3use core::task::{Context, Poll};
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 embassy_util::waitqueue::AtomicWaker;
@@ -84,9 +84,9 @@ impl<'a, C: Channel> Unpin for Transfer<'a, C> {}
84impl<'a, C: Channel> Future for Transfer<'a, C> { 84impl<'a, C: Channel> Future for Transfer<'a, C> {
85 type Output = (); 85 type Output = ();
86 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { 86 fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
87 self.channel.set_waker(cx.waker()); 87 CHANNEL_WAKERS[self.channel.number() as usize].register(cx.waker());
88 88
89 if self.channel.is_running() { 89 if unsafe { self.channel.regs().ctrl_trig().read().en() } {
90 Poll::Pending 90 Poll::Pending
91 } else { 91 } else {
92 Poll::Ready(()) 92 Poll::Ready(())
@@ -94,30 +94,9 @@ impl<'a, C: Channel> Future for Transfer<'a, C> {
94 } 94 }
95} 95}
96 96
97struct ChannelState { 97const CHANNEL_COUNT: usize = 12;
98 waker: AtomicWaker, 98const NEW_AW: AtomicWaker = AtomicWaker::new();
99} 99static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
100
101impl ChannelState {
102 const fn new() -> Self {
103 Self {
104 waker: AtomicWaker::new(),
105 }
106 }
107}
108
109struct State {
110 channels: [ChannelState; 12],
111}
112
113impl State {
114 const fn new() -> Self {
115 const CH: ChannelState = ChannelState::new();
116 Self { channels: [CH; 12] }
117 }
118}
119
120static STATE: State = State::new();
121 100
122mod sealed { 101mod sealed {
123 pub trait Channel {} 102 pub trait Channel {}
@@ -132,18 +111,6 @@ pub trait Channel: Peripheral<P = Self> + sealed::Channel + Into<AnyChannel> + S
132 pac::DMA.ch(self.number() as _) 111 pac::DMA.ch(self.number() as _)
133 } 112 }
134 113
135 fn is_running(&self) -> bool {
136 unsafe { self.regs().ctrl_trig().read().en() }
137 }
138
139 fn set_waker(&self, waker: &Waker) {
140 STATE.channels[self.number() as usize].waker.register(waker);
141 }
142
143 fn on_irq() {
144 // FIXME:
145 }
146
147 fn degrade(self) -> AnyChannel { 114 fn degrade(self) -> AnyChannel {
148 AnyChannel { number: self.number() } 115 AnyChannel { number: self.number() }
149 } 116 }