Return Duration for delay calculation

Additionally, we were waiting 2x as long as necessary because
each trip through the TX state machine was waiting two full
character delays.
This commit is contained in:
Seth Morabito 2022-09-10 20:07:27 -07:00
parent 0e8f46ca1a
commit 8ba2b44919
1 changed files with 5 additions and 5 deletions

View File

@ -374,8 +374,8 @@ impl Default for Duart {
}
/// Compute the delay rate to wait for the next transmit or receive
fn delay_rate(csr_bits: u8, acr_bits: u8) -> u32 {
const NS_PER_SEC: u32 = 1_100_000_000;
fn delay_rate(csr_bits: u8, acr_bits: u8) -> Duration {
const NS_PER_SEC: u32 = 1_000_000_000;
const BITS_PER_CHAR: u32 = 7;
let baud_bits: usize = ((csr_bits >> 4) & 0xf) as usize;
@ -385,7 +385,7 @@ fn delay_rate(csr_bits: u8, acr_bits: u8) -> u32 {
BAUD_RATES_B[baud_bits]
};
NS_PER_SEC / (baud_rate / BITS_PER_CHAR)
Duration::new(0, (NS_PER_SEC / (baud_rate / BITS_PER_CHAR)) / 2)
}
impl Duart {
@ -735,7 +735,7 @@ impl Device for Duart {
CSRA => {
debug!("WRITE: CSRA, val={:02x}", val);
let mut ctx = &mut self.ports[PORT_0];
ctx.char_delay = Duration::new(0, delay_rate(val, self.acr));
ctx.char_delay = delay_rate(val, self.acr);
}
CRA => {
debug!("WRITE: CRA, val={:02x}", val);
@ -771,7 +771,7 @@ impl Device for Duart {
CSRB => {
debug!("WRITE: CSRB, val={:02x}", val);
let mut ctx = &mut self.ports[PORT_1];
ctx.char_delay = Duration::new(0, delay_rate(val, self.acr));
ctx.char_delay = delay_rate(val, self.acr);
}
CRB => {
debug!("WRITE: CRB, val={:02x}", val);