mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-07 01:13:18 +00:00
start/stopEvent bodies should be in atomic blocks
This commit is contained in:
+10
-6
@@ -176,8 +176,9 @@ constexpr uint16_t mic_quiet_ticks = (uint16_t)((F_CPU / 1024UL) / 2UL);
|
|||||||
/* Disable non-read related interrupts (USART RX, PIT, TCA) during AVCLAN reads.
|
/* Disable non-read related interrupts (USART RX, PIT, TCA) during AVCLAN reads.
|
||||||
*/
|
*/
|
||||||
static inline void stopEvent() {
|
static inline void stopEvent() {
|
||||||
RTC.PITINTCTRL &= ~(1 << RTC_PI_bp);
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||||
USART0.CTRLA &= ~(1 << USART_RXCIE_bp);
|
RTC.PITINTCTRL &= ~RTC_PI_bm;
|
||||||
|
USART0.CTRLA &= ~USART_RXCIE_bm;
|
||||||
|
|
||||||
// WO1 toggles don't depend on OVF interrupt, but the OVF interrupt *DOES*
|
// WO1 toggles don't depend on OVF interrupt, but the OVF interrupt *DOES*
|
||||||
// count the toggles So, disabling the OVF interrupt alone is insufficient,
|
// count the toggles So, disabling the OVF interrupt alone is insufficient,
|
||||||
@@ -190,20 +191,23 @@ static inline void stopEvent() {
|
|||||||
// (high/low) won't exceed the allowable ranges for pulses (high) or
|
// (high/low) won't exceed the allowable ranges for pulses (high) or
|
||||||
// intervals (low)
|
// intervals (low)
|
||||||
TCA0.SINGLE.CTRLA &= ~TCA_SINGLE_ENABLE_bm;
|
TCA0.SINGLE.CTRLA &= ~TCA_SINGLE_ENABLE_bm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-enable serial and periodic interrupts.
|
// Re-enable serial and periodic interrupts.
|
||||||
static inline void startEvent() {
|
static inline void startEvent() {
|
||||||
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||||
if (AVCLAN_isPlaying()) // Reenable PIT interrupt if currently playing
|
if (AVCLAN_isPlaying()) // Reenable PIT interrupt if currently playing
|
||||||
RTC.PITINTCTRL |= (1 << RTC_PI_bp);
|
RTC.PITINTCTRL |= RTC_PI_bm;
|
||||||
USART0.CTRLA |= (1 << USART_RXCIE_bp);
|
USART0.CTRLA |= USART_RXCIE_bm;
|
||||||
// Resume/re-arm mic-press timer only while a press is in progress.
|
// Resume/re-arm mic-press timer only while a press is in progress.
|
||||||
// Enable before unmasking so a pending final-phase OVF lands after re-enable
|
// Enable before unmasking so a pending final-phase OVF lands after
|
||||||
// and the ISR's own ENABLE clear wins (no spurious extra period).
|
// re-enable and the ISR's own ENABLE clear wins (no spurious extra period).
|
||||||
if (mic_ntoggles) {
|
if (mic_ntoggles) {
|
||||||
TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;
|
TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;
|
||||||
TCA0.SINGLE.INTCTRL |= TCA_SINGLE_OVF_bm;
|
TCA0.SINGLE.INTCTRL |= TCA_SINGLE_OVF_bm;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|||||||
Reference in New Issue
Block a user