checkpoint

This commit is contained in:
bunnie 2021-05-08 01:13:30 +08:00
parent ab67cf46b2
commit fe6b417643
8 changed files with 87 additions and 48 deletions

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2021-05-07 05:09:48]]></description>
<description><![CDATA[Litex SoC 2021-05-08 00:32:41]]></description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
@ -1070,10 +1070,10 @@ register to disable individual events.]]></description>
<register>
<name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``45bbf751``, so this value is 1169946449, which should be enough to check out
``c282333e``, so this value is 3263312702, which should be enough to check out
the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0x45bbf751</resetValue>
<resetValue>0xc282333e</resetValue>
<size>32</size>
<fields>
<field>
@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset>
<resetValue>0x0a</resetValue>
<resetValue>0x0c</resetValue>
<size>32</size>
<fields>
<field>
@ -3117,7 +3117,7 @@ inject too fast.]]></description>
<name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset>
<resetValue>0x1fda4c0d</resetValue>
<resetValue>0x4e4a385d</resetValue>
<size>32</size>
<fields>
<field>
@ -3132,7 +3132,7 @@ inject too fast.]]></description>
<name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset>
<resetValue>0x5bd9a073</resetValue>
<resetValue>0x67125561</resetValue>
<size>32</size>
<fields>
<field>

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2021-05-07 05:09:48]]></description>
<description><![CDATA[Litex SoC 2021-05-07 23:53:46]]></description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
@ -1070,10 +1070,10 @@ register to disable individual events.]]></description>
<register>
<name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``45bbf751``, so this value is 1169946449, which should be enough to check out
``c282333e``, so this value is 3263312702, which should be enough to check out
the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0x45bbf751</resetValue>
<resetValue>0xc282333e</resetValue>
<size>32</size>
<fields>
<field>
@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset>
<resetValue>0x0a</resetValue>
<resetValue>0x0c</resetValue>
<size>32</size>
<fields>
<field>
@ -3117,7 +3117,7 @@ inject too fast.]]></description>
<name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset>
<resetValue>0x1fda4c0d</resetValue>
<resetValue>0x4f6799cc</resetValue>
<size>32</size>
<fields>
<field>
@ -3132,7 +3132,7 @@ inject too fast.]]></description>
<name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset>
<resetValue>0x5bd9a073</resetValue>
<resetValue>0xd19cd8b</resetValue>
<size>32</size>
<fields>
<field>

Binary file not shown.

View file

@ -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
]);

View file

@ -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();

View file

@ -16,6 +16,10 @@ pub struct Audio {
framecount: u32,
callback_id: Option<u32>,
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)

View file

@ -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();

View file

@ -3,7 +3,7 @@
<device schemaVersion="1.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="CMSIS-SVD.xsd" >
<vendor>litex</vendor>
<name>SOC</name>
<description><![CDATA[Litex SoC 2021-05-07 05:09:48]]></description>
<description><![CDATA[Litex SoC 2021-05-08 00:32:41]]></description>
<addressUnitBits>8</addressUnitBits>
<width>32</width>
@ -1070,10 +1070,10 @@ register to disable individual events.]]></description>
<register>
<name>GIT_GITREV</name>
<description><![CDATA[First 32-bits of the git revision. This documentation was built from git rev
``45bbf751``, so this value is 1169946449, which should be enough to check out
``c282333e``, so this value is 3263312702, which should be enough to check out
the exact git version used to build this firmware.]]></description>
<addressOffset>0x0014</addressOffset>
<resetValue>0x45bbf751</resetValue>
<resetValue>0xc282333e</resetValue>
<size>32</size>
<fields>
<field>
@ -1090,7 +1090,7 @@ the exact git version used to build this firmware.]]></description>
is ``1``, then the repository this was built from has one additional commit
beyond the tag indicated in `MAJOR`, `MINOR`, and `REVISION`.]]></description>
<addressOffset>0x0018</addressOffset>
<resetValue>0x0a</resetValue>
<resetValue>0x0c</resetValue>
<size>32</size>
<fields>
<field>
@ -3117,7 +3117,7 @@ inject too fast.]]></description>
<name>SEED1</name>
<description><![CDATA[Bits 32-63 of `SEED_SEED`. Seed used for the build]]></description>
<addressOffset>0x0000</addressOffset>
<resetValue>0x1fda4c0d</resetValue>
<resetValue>0x4e4a385d</resetValue>
<size>32</size>
<fields>
<field>
@ -3132,7 +3132,7 @@ inject too fast.]]></description>
<name>SEED0</name>
<description><![CDATA[Bits 0-31 of `SEED_SEED`.]]></description>
<addressOffset>0x0004</addressOffset>
<resetValue>0x5bd9a073</resetValue>
<resetValue>0x67125561</resetValue>
<size>32</size>
<fields>
<field>