diff --git a/emulation/soc/renode.svd b/emulation/soc/renode.svd index d901a040c..6fb1ad2ad 100644 --- a/emulation/soc/renode.svd +++ b/emulation/soc/renode.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x45bbf751 + 0xc282333e 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x0a + 0x0c 32 @@ -3117,7 +3117,7 @@ inject too fast.]]> SEED1 0x0000 - 0x1fda4c0d + 0x4e4a385d 32 @@ -3132,7 +3132,7 @@ inject too fast.]]> SEED0 0x0004 - 0x5bd9a073 + 0x67125561 32 diff --git a/precursors/soc.svd b/precursors/soc.svd index d901a040c..b06f82cbd 100644 --- a/precursors/soc.svd +++ b/precursors/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x45bbf751 + 0xc282333e 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x0a + 0x0c 32 @@ -3117,7 +3117,7 @@ inject too fast.]]> SEED1 0x0000 - 0x1fda4c0d + 0x4f6799cc 32 @@ -3132,7 +3132,7 @@ inject too fast.]]> SEED0 0x0004 - 0x5bd9a073 + 0xd19cd8b 32 diff --git a/precursors/soc_csr.bin b/precursors/soc_csr.bin index edcb9cbf7..01c63ae53 100644 Binary files a/precursors/soc_csr.bin and b/precursors/soc_csr.bin differ diff --git a/services/codec/src/backend/tlv320aic3100.rs b/services/codec/src/backend/tlv320aic3100.rs index 9f85cb6dc..8b4d2815c 100644 --- a/services/codec/src/backend/tlv320aic3100.rs +++ b/services/codec/src/backend/tlv320aic3100.rs @@ -36,13 +36,17 @@ fn audio_handler(_irq_no: usize, arg: *mut usize) { // load the play buffer if let Some(frame) = codec.play_buffer.dq_frame() { - //assert!(codec.csr.rf(utra::audio::TX_STAT_FREE) == 1, "interrupt was called, but not enough space to receive!"); if codec.csr.rf(utra::audio::TX_STAT_FREE) != 1 { codec.tx_stat_errors += 1; } for &stereo_sample in frame.iter() { - unsafe { volatile_audio.write_volatile((stereo_sample & 0xFFFF_0000) | ((stereo_sample & 0xFFFF) >> 1)) }; -// unsafe { volatile_audio.write_volatile(stereo_sample) }; + if true { + //// TODO + // there is some bug which is causing the right channel to be frame shifted left by one, but not the left....could be a hardware bug. + unsafe { volatile_audio.write_volatile((stereo_sample & 0xFFFF_0000) | ((stereo_sample & 0xFFFF) >> 1)) }; + } else { + unsafe { volatile_audio.write_volatile(stereo_sample) }; + } } } else { codec.play_frames_dropped += 1; @@ -51,27 +55,12 @@ fn audio_handler(_irq_no: usize, arg: *mut usize) { } } // copy the record buffer - //assert!(codec.csr.rf(utra::audio::RX_STAT_DATAREADY) == 1, "interrupt was called, but not enough data to read!"); if codec.csr.rf(utra::audio::RX_STAT_DATAREADY) != 1 { codec.rx_stat_errors += 1; } let rx_rdcount = codec.csr.rf(utra::audio::RX_STAT_RDCOUNT) as usize; let rx_wrcount = codec.csr.rf(utra::audio::RX_STAT_WRCOUNT) as usize; - /* // this version saves on a useless initialization step - if codec.rec_buffer.is_full() { - codec.rec_frames_dropped += 1; - let mut _dummy = 0; - for _ in 0..codec::FIFO_DEPTH { - _dummy += unsafe{volatile_audio.read_volatile()}; // drain the record fifo to prevent interrupt from continuously firing - } - } else { - for _ in 0..codec::FIFO_DEPTH { - codec.rec_buffer.rec_sample(unsafe{volatile_audio.read_volatile()}); - } - codec.rec_buffer.rec_advance(); - }*/ - let mut rec_buf: [u32; FIFO_DEPTH] = [ZERO_PCM as u32 | (ZERO_PCM as u32) << 16; FIFO_DEPTH]; for stereo_sample in rec_buf.iter_mut() { unsafe{ *stereo_sample = volatile_audio.read_volatile(); } @@ -388,8 +377,8 @@ impl Codec { // driver PGA control self.w(40, &[ - 0b0_0000_111, // HPL driver PGA = 0dB, not muted, all gains applied - 0b0_0000_111, // HPR driver PGA = 0dB, not muted, all gains applied + 0b0_0011_111, // HPL driver PGA = 3dB, not muted, all gains applied + 0b0_0011_111, // HPR driver PGA = 3dB, not muted, all gains applied 0b000_01_1_0_1, // SPK gain = 12 dB, driver not muted, all gains applied ]); diff --git a/services/codec/src/main.rs b/services/codec/src/main.rs index 401965b0d..fce86eea0 100644 --- a/services/codec/src/main.rs +++ b/services/codec/src/main.rs @@ -97,7 +97,7 @@ fn xmain() -> ! { let mut printed = false; while codec.free_play_frames() == 0 { if !printed { - log::info!("swap overrun"); + log::debug!("swap overrun"); printed = true; } xous::yield_slice(); diff --git a/services/shellchat/src/cmds/audio.rs b/services/shellchat/src/cmds/audio.rs index 11079a7b4..d3ee26858 100644 --- a/services/shellchat/src/cmds/audio.rs +++ b/services/shellchat/src/cmds/audio.rs @@ -16,6 +16,10 @@ pub struct Audio { framecount: u32, callback_id: Option, callback_conn: u32, + recbuf: xous::MemoryRange, + rec_data: *mut u32, + rec_ptr_words: u32, + play_or_rec_n: bool, // true if play sample, false if play recorded data } impl Audio { pub fn new(xns: &xous_names::XousNames) -> Self { @@ -31,6 +35,12 @@ impl Audio { for i in 0..16 { unsafe{ raw_header[i] = (*samples)[i] }; } + let recbuf = xous::syscall::map_memory( + None, + None, + 0x8_0000, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ).expect("couldn't allocate record buffer"); log::trace!("setting up codec hardware parameters"); codec.setup_8k_stream().expect("couldn't set the CODEC to expected defaults"); @@ -45,7 +55,10 @@ impl Audio { framecount: 0, callback_id: None, callback_conn: xns.request_connection_blocking(crate::SERVER_NAME_SHELLCHAT).unwrap(), - + recbuf, + rec_data: recbuf.as_mut_ptr() as *mut u32, + rec_ptr_words: 0, + play_or_rec_n: true, }; audio } @@ -82,12 +95,20 @@ impl<'a> ShellCmdApi<'a> for Audio { } else { play_free }; - log::debug!("loading up {} frames", frames_to_push); - self.framecount += frames_to_push as u32; + log::info!("loading up {} frames", frames_to_push); + self.play_ptr_bytes = 0; + self.rec_ptr_words = 0; + self.framecount = frames_to_push as u32; for i in 0..frames_to_push { let mut frame: [u32; codec::FIFO_DEPTH] = [codec::ZERO_PCM as u32 | (codec::ZERO_PCM as u32) << 16; codec::FIFO_DEPTH]; - for sample in frame.iter_mut() { - *sample = unsafe{self.raw_data.add(i).read_volatile()}; + if self.play_or_rec_n { + for sample in frame.iter_mut() { + *sample = unsafe{self.raw_data.add(i).read_volatile()}; + } + } else { + for sample in frame.iter_mut() { + *sample = unsafe{self.rec_data.add(i).read_volatile()}; + } } self.play_ptr_bytes += codec::FIFO_DEPTH * 4; frames.nq_frame(frame).unwrap(); @@ -95,11 +116,19 @@ impl<'a> ShellCmdApi<'a> for Audio { log::debug!("pushing frames"); self.codec.swap_frames(&mut frames).unwrap(); // start the playing - log::debug!("starting playback"); + log::info!("starting playback"); self.codec.resume().unwrap(); // we'll get a callback that demands the next data... } + "fromrec" => { + self.play_or_rec_n = false; + write!(ret, "playing back from record buffer").unwrap(); + } + "fromsample" => { + self.play_or_rec_n = true; + write!(ret, "playing back from sample on FLASH").unwrap(); + } "dump" => { let mut temp = String::<9>::new(); for i in 0..8 { @@ -145,14 +174,34 @@ impl<'a> ShellCmdApi<'a> for Audio { log::debug!("f{} p{}", self.framecount, frames_to_push); for _ in 0..frames_to_push { let mut frame: [u32; codec::FIFO_DEPTH] = [ZERO_PCM as u32 | (ZERO_PCM as u32) << 16; codec::FIFO_DEPTH]; - for i in 0..codec::FIFO_DEPTH { - frame[i] = unsafe{*self.raw_data.add(i + self.play_ptr_bytes/4)}; + if self.play_or_rec_n { + for i in 0..codec::FIFO_DEPTH { + frame[i] = unsafe{*self.raw_data.add(i + self.play_ptr_bytes/4)}; + } + } else { + for i in 0..codec::FIFO_DEPTH { + frame[i] = unsafe{*self.rec_data.add(i + self.play_ptr_bytes/4)}; + } } self.play_ptr_bytes += codec::FIFO_DEPTH * 4; frames.nq_frame(frame).unwrap(); + } self.codec.swap_frames(&mut frames).unwrap(); + loop { + if let Some(frame) = frames.dq_frame() { + if self.rec_ptr_words < (0x8_0000 - codec::FIFO_DEPTH) as u32 { + for i in 0..codec::FIFO_DEPTH { + unsafe{*self.rec_data.add(i + self.rec_ptr_words as usize) = frame[i]}; + } + self.rec_ptr_words += codec::FIFO_DEPTH as u32; + } + } else { + break; + }; + } + return Ok(None) } else { log::debug!("stopping playback"); @@ -161,6 +210,7 @@ impl<'a> ShellCmdApi<'a> for Audio { write!(ret, "Playback of {} frames finished", self.framecount).unwrap(); self.framecount = 0; self.play_ptr_bytes = 0; + self.rec_ptr_words = 0; } else { // we will get extra callbacks as the pipe clears return Ok(None) diff --git a/services/shellchat/src/main.rs b/services/shellchat/src/main.rs index 6b43809d3..46325af05 100644 --- a/services/shellchat/src/main.rs +++ b/services/shellchat/src/main.rs @@ -258,7 +258,7 @@ pub(crate) const SERVER_NAME_SHELLCHAT: &str = "_Shell chat application_"; #[xous::xous_main] fn xmain() -> ! { log_server::init_wait().unwrap(); - log::set_max_level(log::LevelFilter::Debug); + log::set_max_level(log::LevelFilter::Info); info!("my PID is {}", xous::process::id()); let xns = xous_names::XousNames::new().unwrap(); diff --git a/svd2utra/examples/soc.svd b/svd2utra/examples/soc.svd index d901a040c..6fb1ad2ad 100644 --- a/svd2utra/examples/soc.svd +++ b/svd2utra/examples/soc.svd @@ -3,7 +3,7 @@ litex SOC - + 8 32 @@ -1070,10 +1070,10 @@ register to disable individual events.]]> GIT_GITREV 0x0014 - 0x45bbf751 + 0xc282333e 32 @@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]> is ``1``, then the repository this was built from has one additional commit beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]> 0x0018 - 0x0a + 0x0c 32 @@ -3117,7 +3117,7 @@ inject too fast.]]> SEED1 0x0000 - 0x1fda4c0d + 0x4e4a385d 32 @@ -3132,7 +3132,7 @@ inject too fast.]]> SEED0 0x0004 - 0x5bd9a073 + 0x67125561 32