Skip to content

Commit 1c803af

Browse files
authored
Add methods for checking/clearing DMA channel interrupts. (#319)
1 parent e64497b commit 1c803af

File tree

1 file changed

+50
-10
lines changed

1 file changed

+50
-10
lines changed

src/dma.rs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,53 @@ macro_rules! dma {
613613
}
614614
}
615615

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+
616663
#[inline]
617664
pub(crate) fn isr(&self) -> dma1::isr::R {
618665
// NOTE(unsafe) atomic read with no side effects
@@ -680,7 +727,7 @@ macro_rules! dma {
680727

681728
// Clear ISR flag (Transfer Complete)
682729
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();
684731
} else {
685732
// The old transfer is not complete
686733
return None;
@@ -926,15 +973,8 @@ macro_rules! dma {
926973
// We read the flags before reading the current write-index because if
927974
// another word is written between those two accesses, this ordering
928975
// 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();
938978
let write_current = capacity - self.payload.channel.get_cndtr() as usize;
939979
// Copy the data before examining the overrun conditions. If the
940980
// overrun happens shortly after the flags and write-index were read,

0 commit comments

Comments
 (0)