@@ -613,6 +613,53 @@ macro_rules! dma {
613
613
}
614
614
}
615
615
616
+ /// Check and clear the interrupt for the given event.
617
+ #[ inline]
618
+ pub fn check_interrupt( & mut self , event: Event ) -> bool {
619
+ match event {
620
+ Event :: HalfTransfer => {
621
+ self . check_half_transfer_interrupt( )
622
+ } ,
623
+ Event :: TransferComplete => {
624
+ self . check_transfer_complete_interrupt( )
625
+ } ,
626
+ }
627
+ }
628
+
629
+ /// Check and clear the half-transfer interrupt.
630
+ #[ inline]
631
+ pub fn check_half_transfer_interrupt( & mut self ) -> bool {
632
+ if self . isr( ) . $htifX( ) . bit_is_set( ) {
633
+ self . clear_half_transfer_interrupt( ) ;
634
+ return true
635
+ }
636
+
637
+ false
638
+ }
639
+
640
+ /// Clear the half-transfer interrupt.
641
+ #[ inline]
642
+ pub fn clear_half_transfer_interrupt( & mut self ) {
643
+ self . ifcr( ) . write( |w| w. $chtifX( ) . set_bit( ) )
644
+ }
645
+
646
+ /// Check and clear the transfer complete interrupt.
647
+ #[ inline]
648
+ pub fn check_transfer_complete_interrupt( & mut self ) -> bool {
649
+ if self . isr( ) . $tcifX( ) . bit_is_set( ) {
650
+ self . clear_transfer_complete_interrupt( ) ;
651
+ return true
652
+ }
653
+
654
+ false
655
+ }
656
+
657
+ /// Clear the transfer complete interrupt.
658
+ #[ inline]
659
+ pub fn clear_transfer_complete_interrupt( & mut self ) {
660
+ self . ifcr( ) . write( |w| w. $ctcifX( ) . set_bit( ) )
661
+ }
662
+
616
663
#[ inline]
617
664
pub ( crate ) fn isr( & self ) -> dma1:: isr:: R {
618
665
// NOTE(unsafe) atomic read with no side effects
@@ -680,7 +727,7 @@ macro_rules! dma {
680
727
681
728
// Clear ISR flag (Transfer Complete)
682
729
if !self . payload. channel. in_progress( ) {
683
- self . payload. channel. ifcr ( ) . write ( |w| w . $ctcifX ( ) . set_bit ( ) ) ;
730
+ self . payload. channel. clear_transfer_complete_interrupt ( ) ;
684
731
} else {
685
732
// The old transfer is not complete
686
733
return None ;
@@ -926,15 +973,8 @@ macro_rules! dma {
926
973
// We read the flags before reading the current write-index because if
927
974
// another word is written between those two accesses, this ordering
928
975
// prevents a false positive overrun error.
929
- let isr = self . payload. channel. isr( ) ;
930
- let half_complete_flag = isr. $htifX( ) . bit_is_set( ) ;
931
- if half_complete_flag {
932
- self . payload. channel. ifcr( ) . write( |w| w. $chtifX( ) . set_bit( ) ) ;
933
- }
934
- let transfer_complete_flag = isr. $tcifX( ) . bit_is_set( ) ;
935
- if transfer_complete_flag {
936
- self . payload. channel. ifcr( ) . write( |w| w. $ctcifX( ) . set_bit( ) ) ;
937
- }
976
+ let half_complete_flag = self . payload. channel. check_half_transfer_interrupt( ) ;
977
+ let transfer_complete_flag = self . payload. channel. check_transfer_complete_interrupt( ) ;
938
978
let write_current = capacity - self . payload. channel. get_cndtr( ) as usize ;
939
979
// Copy the data before examining the overrun conditions. If the
940
980
// overrun happens shortly after the flags and write-index were read,
0 commit comments