@@ -80,34 +80,39 @@ impl<T: Sized> BufferExt for T {}
80
80
/// }
81
81
///
82
82
/// impl<Buf: WriteBuffer> DmaTransfer<Buf> {
83
+ /// /// stars the DMA transfer
83
84
/// fn start(buf: Buf) -> Self {
84
- /// // DMA logic
85
+ /// // DMA logic would go here
85
86
/// Self { buf }
86
87
/// }
87
88
///
88
- /// async fn wait_until_done(&self) {
89
- /// // to implement
89
+ /// /// returns if DMA transaction is done.
90
+ /// /// this could be called in a polling loop in order to be non-blocking
91
+ /// fn is_done(&self) -> bool {
92
+ /// true
90
93
/// }
91
94
///
95
+ /// /// returns resources held by the DMA transfer.
92
96
/// fn free(self) -> Buf {
93
97
/// // busy loop which waits until DMA is done to ensure safety
98
+ /// while !self.is_done() {}
94
99
/// self.buf
95
100
/// }
96
101
/// }
97
102
///
98
103
/// /// This function is bad because we cannot obtain the original slice—just a subset of it.
99
- /// async fn dma_transfer_bad1(buffer: &'static mut [u8], length: usize) -> &'static [u8] {
104
+ /// fn dma_transfer_bad1(buffer: &'static mut [u8], length: usize) -> &'static [u8] {
100
105
/// let sub_slice = &mut buffer[..length];
101
106
/// let transfer = DmaTransfer::start(sub_slice);
102
- /// transfer.wait_until_done().await;
107
+ /// while ! transfer.is_done() {}
103
108
/// transfer.free()
104
109
/// }
105
110
///
106
111
/// /// This function is bad because we cannot unsplit the slice.
107
- /// async fn dma_transfer_bad2(buffer: &'static mut [u8], length: usize) -> &'static [u8] {
112
+ /// fn dma_transfer_bad2(buffer: &'static mut [u8], length: usize) -> &'static [u8] {
108
113
/// let (slice_a, slice_b) = buffer.split_at_mut(length);
109
114
/// let transfer = DmaTransfer::start(slice_a);
110
- /// transfer.wait_until_done().await;
115
+ /// while ! transfer.is_done() {}
111
116
/// let slice_a = transfer.free();
112
117
/// // can't unsplit!!!
113
118
/// slice_a
@@ -117,8 +122,7 @@ impl<T: Sized> BufferExt for T {}
117
122
/// fn dma_transfer(buffer: &'static mut [u8], length: usize) -> &'static [u8] {
118
123
/// let buffer_slice = buffer.into_buffer_slice(..length);
119
124
/// let transfer = DmaTransfer::start(buffer_slice);
120
- /// // we are commenting this out so we can actually test it without an async runtime
121
- /// // transfer.wait_until_done().await;
125
+ /// while !transfer.is_done() {}
122
126
/// let buffer_slice = transfer.free();
123
127
/// buffer_slice.inner()
124
128
/// }
0 commit comments