From 08a86749fe71e3bbba50e1d59362f54be07905e2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 9 May 2021 01:13:16 +0800 Subject: [PATCH] fix hosted mode bugs --- kernel/src/services.rs | 2 +- services/codec/src/backend/hostaudio.rs | 30 ++++++++++++--- services/codec/src/backend/mod.rs | 2 +- services/codec/src/backend/tlv320aic3100.rs | 41 --------------------- services/com/src/main.rs | 1 - services/gam/src/status.rs | 1 + services/llio/src/i2c/hardware.rs | 2 +- services/llio/src/i2c/hosted.rs | 16 +++++++- services/llio/src/i2c/mod.rs | 2 +- services/rtc/src/main.rs | 2 + services/shellchat/src/cmds/audio.rs | 9 +++++ 11 files changed, 56 insertions(+), 52 deletions(-) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index e6a74d8ea..f46e09d7c 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -217,7 +217,7 @@ std::thread_local!(static SYSTEM_SERVICES: core::cell::RefCell = }; MAX_PROCESS_COUNT], // Note we can't use MAX_SERVER_COUNT here because of how Rust's // macro tokenization works - servers: filled_array![None; 32], + servers: filled_array![None; 128], })); #[cfg(baremetal)] diff --git a/services/codec/src/backend/hostaudio.rs b/services/codec/src/backend/hostaudio.rs index 8723c2c45..91002bd2f 100644 --- a/services/codec/src/backend/hostaudio.rs +++ b/services/codec/src/backend/hostaudio.rs @@ -1,8 +1,10 @@ +use codec::FIFO_DEPTH; + pub struct Codec { } impl Codec { - pub fn new() -> Codec { + pub fn new(_conn: xous::CID, _xns: &xous_names::XousNames) -> Codec { Codec { } } @@ -10,15 +12,33 @@ impl Codec { } pub fn resume(&self) { } + pub fn init(&mut self) { + } + + pub fn nq_play_frame(&mut self, _frame: [u32; FIFO_DEPTH]) -> Result<(), [u32; FIFO_DEPTH]> { + Ok(()) + } + pub fn dq_rec_frame(&mut self) -> Option<[u32; FIFO_DEPTH]> { + None + } + pub fn free_play_frames(&self) -> usize { + 0 + } + pub fn available_rec_frames(&self) -> usize { + 0 + } pub fn power(&mut self, _state: bool) { } - pub fn nq_play_frame(&mut self, _frame: [u32; FIFO_DEPTH]) -> Result<(), [u32; DEPTH]> { - Ok(()) + pub fn is_on(&self) -> bool { + false } - pub fn dq_rec_frame(&mut self) -> Some([u32; FIFO_DEPTH]) { - None + pub fn is_init(&self) -> bool { + true + } + pub fn is_live(&self) -> bool { + false } pub fn get_headset_code(&mut self) -> u8 { diff --git a/services/codec/src/backend/mod.rs b/services/codec/src/backend/mod.rs index 33590e990..6c338ed3e 100644 --- a/services/codec/src/backend/mod.rs +++ b/services/codec/src/backend/mod.rs @@ -6,4 +6,4 @@ pub use crate::backend::hostaudio::*; #[cfg(target_os = "none")] mod tlv320aic3100; #[cfg(target_os = "none")] -pub use crate::backend::tlv320aic3100::*; +pub(crate) use crate::backend::tlv320aic3100::*; diff --git a/services/codec/src/backend/tlv320aic3100.rs b/services/codec/src/backend/tlv320aic3100.rs index 8bd6ad0c1..57ec01a91 100644 --- a/services/codec/src/backend/tlv320aic3100.rs +++ b/services/codec/src/backend/tlv320aic3100.rs @@ -493,44 +493,3 @@ impl Codec { } } } - -/* - -else if command.trim() == "aut" { // sample for 10 seconds and report # of samples seen -- for benchmarking sample rate - unsafe{ self.p.POWER.power.write(|w| w.audio().bit(false).self_().bit(true).state().bits(3)); } - delay_ms(&self.p, 50); // give it a moment to power on and initialize before blasting data in - self.audio.reset_fifos(); - unsafe{ self.p.POWER.power.write(|w| w.audio().bit(true).self_().bit(true).state().bits(3)); } - delay_ms(&self.p, 50); // give it a moment to power on and initialize before blasting data in - - self.audio.audio_clocks(); - self.audio.audio_ports(); - self.audio.audio_mixer(); - - self.audio.audio_i2s_start(); - self.audio_run = true; - - let mut samples: u32 = 0; - let start: u32 = get_time_ms(&self.p); - let mut toggle: bool = false; - let mut buf_a: [u32; AUDIO_FIFODEPTH] = [0; AUDIO_FIFODEPTH]; - let mut buf_b: [u32; AUDIO_FIFODEPTH] = [0; AUDIO_FIFODEPTH]; - loop { - if get_time_ms(&self.p) - start > 10_000 { - break; - } - if self.audio.audio_loopback_poll(&mut buf_a, &mut buf_b, toggle) { - samples = samples + 1; - toggle = !toggle; - } - } - - self.text.add_text(&mut format!("{} samples", samples)); - - self.audio.audio_i2s_stop(); - self.audio_run = false; - - unsafe{ self.p.POWER.power.write(|w| w.audio().bit(false).self_().bit(true).state().bits(3)); } - delay_ms(&self.p, 50); // give it a moment to power on and initialize before blasting data in - unsafe{ self.p.POWER.power.write(|w| w.audio().bit(true).self_().bit(true).state().bits(3)); } -*/ \ No newline at end of file diff --git a/services/com/src/main.rs b/services/com/src/main.rs index 2f7dfef49..b224e174c 100644 --- a/services/com/src/main.rs +++ b/services/com/src/main.rs @@ -205,7 +205,6 @@ mod implementation { use log::error; use heapless::Vec; - use heapless::consts::*; pub struct XousCom { pub workqueue: Vec, diff --git a/services/gam/src/status.rs b/services/gam/src/status.rs index 6f136640d..753862708 100644 --- a/services/gam/src/status.rs +++ b/services/gam/src/status.rs @@ -116,6 +116,7 @@ pub fn status_thread(canvas_gid_0: usize, canvas_gid_1: usize, canvas_gid_2: usi let mut rtc = rtc::Rtc::new(&xns).unwrap(); + #[cfg(target_os = "none")] rtc.clear_wakeup_alarm().unwrap(); // clear any wakeup alarm state, if it was set rtc.hook_rtc_callback(dt_callback).unwrap(); diff --git a/services/llio/src/i2c/hardware.rs b/services/llio/src/i2c/hardware.rs index 2e18ee915..4dc0a6830 100644 --- a/services/llio/src/i2c/hardware.rs +++ b/services/llio/src/i2c/hardware.rs @@ -275,7 +275,7 @@ impl I2cStateMachine { } // interrupt context-friendly handler - pub fn handler_i(&mut self) -> I2cHandlerReport { + pub(crate) fn handler_i(&mut self) -> I2cHandlerReport { let mut report = I2cHandlerReport::InProgress; match self.state { diff --git a/services/llio/src/i2c/hosted.rs b/services/llio/src/i2c/hosted.rs index 40f95b521..6e2f7d38a 100644 --- a/services/llio/src/i2c/hosted.rs +++ b/services/llio/src/i2c/hosted.rs @@ -1,9 +1,23 @@ +use crate::api::*; + pub(crate) struct I2cStateMachine { } impl I2cStateMachine { - pub fn new(ticktimer: ticktimer_server::Ticktimer, i2c_base: *mut u32) -> Self { + pub fn new(_handler_conn: xous::CID) -> Self { I2cStateMachine { } } + pub fn suspend(&mut self) {} + pub fn resume(&mut self) {} + pub fn initiate(&mut self, _transaction: I2cTransaction) -> I2cStatus { + I2cStatus::ResponseInProgress + } + pub fn report_write_done(&mut self) { + } + pub fn report_read_done(&mut self) { + } + pub fn is_busy(&self) -> bool { + false + } } diff --git a/services/llio/src/i2c/mod.rs b/services/llio/src/i2c/mod.rs index fcce8adb9..c26564bd4 100644 --- a/services/llio/src/i2c/mod.rs +++ b/services/llio/src/i2c/mod.rs @@ -1,7 +1,7 @@ #[cfg(not(target_os = "none"))] mod hosted; #[cfg(not(target_os = "none"))] -pub use crate::backend::hosted::*; +pub use crate::i2c::hosted::*; #[cfg(target_os = "none")] mod hardware; diff --git a/services/rtc/src/main.rs b/services/rtc/src/main.rs index 4d7c0c64c..38932be7c 100644 --- a/services/rtc/src/main.rs +++ b/services/rtc/src/main.rs @@ -512,6 +512,8 @@ mod implementation { pub fn clear_wakeup_alarm(&mut self) { } pub fn rtc_alarm(&mut self, _seconds: u8) { } pub fn clear_rtc_alarm(&mut self) { } + pub fn rtc_get_ack(&mut self) { + } } } diff --git a/services/shellchat/src/cmds/audio.rs b/services/shellchat/src/cmds/audio.rs index da891b147..1a8a480fa 100644 --- a/services/shellchat/src/cmds/audio.rs +++ b/services/shellchat/src/cmds/audio.rs @@ -23,6 +23,7 @@ pub struct Audio { } impl Audio { pub fn new(xns: &xous_names::XousNames) -> Self { + #[cfg(target_os = "none")] let sample = xous::syscall::map_memory( // 0x2634_0000 is the long sample. 0x2600_0000 is the short sample. Some(core::num::NonZeroUsize::new(0x2634_0000).unwrap()), // it's here, because we know it's here! @@ -30,6 +31,14 @@ impl Audio { 0x1c4_0000, // 0x8_0000 is length of short sample, 0x1C4_0000 is the long sample xous::MemoryFlags::R, ).expect("couldn't map in the audio sample"); + #[cfg(not(target_os = "none"))] // just make a dummy mapping to keep things from crashing in hosted mode + let sample = xous::syscall::map_memory( + None, + None, + 0x8_0000, + xous::MemoryFlags::R, + ).expect("couldn't map in the audio sample"); + let mut codec = codec::Codec::new(xns).unwrap(); let samples: *const [u8; 16] = unsafe{sample.as_ptr().add(20)} as *const [u8; 16]; let mut raw_header: [u8; 16] = [0; 16];