@@ -203,6 +203,22 @@ impl<T, C, B> Transfer<T, C, B, Started>
203
203
204
204
Ok ( self . res )
205
205
}
206
+
207
+ /// Returns some transfer state
208
+ ///
209
+ /// The number of items to transfer, the half transfer flag, and the
210
+ /// transfer completed flag.
211
+ pub ( crate ) fn state ( & self ) -> ( u16 , bool , bool ) {
212
+ self . res . channel . transfer_state ( )
213
+ }
214
+
215
+ /// Clears the half transfer and transfer complete flags
216
+ ///
217
+ /// Be careful when calling this, as it can confuse the other methods. This
218
+ /// method is designed to manage circular transfers only.
219
+ pub ( crate ) fn clear_flags ( & self ) {
220
+ self . res . channel . clear_flags ( )
221
+ }
206
222
}
207
223
208
224
@@ -280,6 +296,8 @@ pub trait Channel: Sized {
280
296
fn is_active ( & self ) -> bool ;
281
297
fn clear_complete_flag ( & self ) ;
282
298
fn error_occured ( & self ) -> bool ;
299
+ fn transfer_state ( & self ) -> ( u16 , bool , bool ) ;
300
+ fn clear_flags ( & self ) ;
283
301
}
284
302
285
303
macro_rules! impl_channel {
@@ -289,8 +307,10 @@ macro_rules! impl_channel {
289
307
$field: ident,
290
308
$chfield: ident,
291
309
$cxs: ident,
310
+ $htif: ident,
292
311
$tcif: ident,
293
312
$teif: ident,
313
+ $chtif: ident,
294
314
$ctcif: ident,
295
315
$cteif: ident;
296
316
) *
@@ -433,26 +453,52 @@ macro_rules! impl_channel {
433
453
false
434
454
}
435
455
}
456
+
457
+ fn transfer_state( & self ) -> ( u16 , bool , bool ) {
458
+ // Safe, as we're only doing atomic reads.
459
+ let dma = unsafe { & * pac:: DMA1 :: ptr( ) } ;
460
+
461
+ let isr = dma. isr. read( ) ;
462
+
463
+ let data_remaining = dma. $chfield. ndtr. read( ) . ndt( ) . bits( ) ;
464
+
465
+ let half_transfer = isr. $htif( ) . is_half( ) ;
466
+ let transfer_complete = isr. $tcif( ) . is_complete( ) ;
467
+
468
+ ( data_remaining, half_transfer, transfer_complete)
469
+ }
470
+
471
+ fn clear_flags( & self ) {
472
+ // Safe, as we're only doing an atomic write to a stateless
473
+ // register.
474
+ let dma = unsafe { & * pac:: DMA1 :: ptr( ) } ;
475
+
476
+ dma. ifcr. write( |w|
477
+ w
478
+ . $chtif( ) . clear( )
479
+ . $ctcif( ) . clear( )
480
+ ) ;
481
+ }
436
482
}
437
483
) *
438
484
}
439
485
}
440
486
441
487
impl_channel ! (
442
488
Channel1 , channel1, ch1,
443
- c1s, tcif1, teif1, ctcif1, cteif1;
489
+ c1s, htif1 , tcif1, teif1, chtif1 , ctcif1, cteif1;
444
490
Channel2 , channel2, ch2,
445
- c2s, tcif2, teif2, ctcif2, cteif2;
491
+ c2s, htif2 , tcif2, teif2, chtif2 , ctcif2, cteif2;
446
492
Channel3 , channel3, ch3,
447
- c3s, tcif3, teif3, ctcif3, cteif3;
493
+ c3s, htif3 , tcif3, teif3, chtif3 , ctcif3, cteif3;
448
494
Channel4 , channel4, ch4,
449
- c4s, tcif4, teif4, ctcif4, cteif4;
495
+ c4s, htif4 , tcif4, teif4, chtif4 , ctcif4, cteif4;
450
496
Channel5 , channel5, ch5,
451
- c5s, tcif5, teif5, ctcif5, cteif5;
497
+ c5s, htif5 , tcif5, teif5, chtif5 , ctcif5, cteif5;
452
498
Channel6 , channel6, ch6,
453
- c6s, tcif6, teif6, ctcif6, cteif6;
499
+ c6s, htif6 , tcif6, teif6, chtif6 , ctcif6, cteif6;
454
500
Channel7 , channel7, ch7,
455
- c7s, tcif7, teif7, ctcif7, cteif7;
501
+ c7s, htif7 , tcif7, teif7, chtif7 , ctcif7, cteif7;
456
502
) ;
457
503
458
504
0 commit comments