Fixes after review
- rename tx_seq_max to sdpcm_seq_max - make sure we have credit for each packet we send
This commit is contained in:
parent
95f3484b87
commit
5c4d6232ae
29
src/lib.rs
29
src/lib.rs
@ -526,7 +526,7 @@ pub struct Runner<'a, PWR, SPI> {
|
|||||||
sdpcm_seq: u8,
|
sdpcm_seq: u8,
|
||||||
backplane_window: u32,
|
backplane_window: u32,
|
||||||
|
|
||||||
tx_seq_max: u8,
|
sdpcm_seq_max: u8,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn new<'a, PWR, SPI>(
|
pub async fn new<'a, PWR, SPI>(
|
||||||
@ -549,7 +549,7 @@ where
|
|||||||
sdpcm_seq: 0,
|
sdpcm_seq: 0,
|
||||||
backplane_window: 0xAAAA_AAAA,
|
backplane_window: 0xAAAA_AAAA,
|
||||||
|
|
||||||
tx_seq_max: 1,
|
sdpcm_seq_max: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
runner.init(firmware).await;
|
runner.init(firmware).await;
|
||||||
@ -673,17 +673,20 @@ where
|
|||||||
let mut buf = [0; 512];
|
let mut buf = [0; 512];
|
||||||
loop {
|
loop {
|
||||||
// Send stuff
|
// Send stuff
|
||||||
// TODO flow control
|
// TODO flow control not yet complete
|
||||||
if self.sdpcm_seq == self.tx_seq_max || self.tx_seq_max.wrapping_sub(self.sdpcm_seq) & 0x80 != 0 {
|
if !self.has_credit() {
|
||||||
warn!("TX stalled");
|
warn!("TX stalled");
|
||||||
} else {
|
} else {
|
||||||
if let IoctlState::Pending { kind, cmd, iface, buf } = self.state.ioctl_state.get() {
|
if let IoctlState::Pending { kind, cmd, iface, buf } = self.state.ioctl_state.get() {
|
||||||
self.send_ioctl(kind, cmd, iface, unsafe { &*buf }).await;
|
self.send_ioctl(kind, cmd, iface, unsafe { &*buf }).await;
|
||||||
self.state.ioctl_state.set(IoctlState::Sent { buf });
|
self.state.ioctl_state.set(IoctlState::Sent { buf });
|
||||||
}
|
}
|
||||||
|
if !self.has_credit() {
|
||||||
if let Ok(p) = self.state.tx_channel.try_recv() {
|
warn!("TX stalled");
|
||||||
self.send_packet(&p).await;
|
} else {
|
||||||
|
if let Ok(p) = self.state.tx_channel.try_recv() {
|
||||||
|
self.send_packet(&p).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -906,14 +909,18 @@ where
|
|||||||
|
|
||||||
fn update_credit(&mut self, sdpcm_header: &SdpcmHeader) {
|
fn update_credit(&mut self, sdpcm_header: &SdpcmHeader) {
|
||||||
if sdpcm_header.channel_and_flags & 0xf < 3 {
|
if sdpcm_header.channel_and_flags & 0xf < 3 {
|
||||||
let mut tx_seq_max = sdpcm_header.bus_data_credit;
|
let mut sdpcm_seq_max = sdpcm_header.bus_data_credit;
|
||||||
if tx_seq_max - self.sdpcm_seq > 0x40 {
|
if sdpcm_seq_max - self.sdpcm_seq > 0x40 {
|
||||||
tx_seq_max = self.sdpcm_seq + 2;
|
sdpcm_seq_max = self.sdpcm_seq + 2;
|
||||||
}
|
}
|
||||||
self.tx_seq_max = tx_seq_max;
|
self.sdpcm_seq_max = sdpcm_seq_max;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn has_credit(&mut self) -> bool {
|
||||||
|
self.sdpcm_seq != self.sdpcm_seq_max && self.sdpcm_seq_max.wrapping_sub(self.sdpcm_seq) & 0x80 == 0
|
||||||
|
}
|
||||||
|
|
||||||
async fn send_ioctl(&mut self, kind: u32, cmd: u32, iface: u32, data: &[u8]) {
|
async fn send_ioctl(&mut self, kind: u32, cmd: u32, iface: u32, data: &[u8]) {
|
||||||
let mut buf = [0; 512];
|
let mut buf = [0; 512];
|
||||||
let buf8 = slice8_mut(&mut buf);
|
let buf8 = slice8_mut(&mut buf);
|
||||||
|
Loading…
Reference in New Issue
Block a user