From af982aef30221af7343a9592989f3239c7bf02ea Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 16 Jul 2023 22:07:09 +0800 Subject: [PATCH] add a static flag for interrupt hooking of the codec object the init() function on this object may actually be called several times within a single boot context because the codec is powered down as a separate subsystem from the rest. however, the interrupt should still only be hooked exactly once. This flag tracks that state. --- services/codec/src/backend/tlv320aic3100.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/services/codec/src/backend/tlv320aic3100.rs b/services/codec/src/backend/tlv320aic3100.rs index 5a541e5df..7bd2dd62d 100644 --- a/services/codec/src/backend/tlv320aic3100.rs +++ b/services/codec/src/backend/tlv320aic3100.rs @@ -6,6 +6,9 @@ use susres::{RegManager, RegOrField, SuspendResume}; use llio::I2cStatus; use crate::api::*; use num_traits::*; +use core::sync::atomic::{AtomicBool, Ordering::SeqCst}; + +static INTERRUPT_HOOKED: AtomicBool = AtomicBool::new(false); pub const TLV320AIC3100_I2C_ADR: u8 = 0b0011_000; const I2C_TIMEOUT: u32 = 50; @@ -181,7 +184,8 @@ impl Codec { } pub fn init(&mut self) { - if ! self.initialized { + // this should only be called once per reboot + if !INTERRUPT_HOOKED.swap(true, SeqCst) { xous::claim_interrupt( utra::audio::AUDIO_IRQ, audio_handler, @@ -196,6 +200,7 @@ impl Codec { self.susres_manager.push(RegOrField::Reg(utra::audio::EV_ENABLE), None); } + // this may be called repeatedly, e.g if the code was put through suspend/resume log::trace!("audio_clocks"); self.audio_clocks(); log::trace!("audio_ports");