Skip to content

Commit 977c6ac

Browse files
committed
Testing I3C 1p5
1 parent 7d3e39a commit 977c6ac

1 file changed

Lines changed: 38 additions & 2 deletions

File tree

hw-model/src/xi3c/controller.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,27 @@ impl Controller {
205205
byte_count: 0,
206206
tid: 0,
207207
};
208-
// Disable Target Events
208+
// Disable Target Events — retry with escalating delay up to 10 seconds
209+
// in case the device is not ready yet (NACK).
210+
println!("XI3C: Waiting 10s before DISEC to allow device to become ready");
211+
std::thread::sleep(Duration::from_secs(10));
209212
println!("XI3C: Broadcast CCC DISEC");
210213
let result = self.send_transfer_cmd(&cmd, Ccc::Byte(XI3C_CCC_BRDCAST_DISEC));
214+
/*
215+
let result = {
216+
let deadline = Instant::now() + Duration::from_secs(10);
217+
let mut delay = Duration::from_millis(10);
218+
loop {
219+
let r = self.send_transfer_cmd(&cmd, Ccc::Byte(XI3C_CCC_BRDCAST_DISEC));
220+
if r.is_ok() || Instant::now() >= deadline {
221+
break r;
222+
}
223+
println!("XI3C: DISEC failed, retrying after {:?}", delay);
224+
self.reset();
225+
std::thread::sleep(delay);
226+
delay = (delay * 2).min(Duration::from_secs(1));
227+
}
228+
};*/
211229
if result.is_ok() {
212230
println!("XI3C: Acknowledge received");
213231
}
@@ -540,6 +558,9 @@ impl Controller {
540558
} else {
541559
t_hold = if t_hold < 6 { 6 } else { t_hold };
542560
}
561+
println!("scl_high_time: {}", t_high.wrapping_sub(2) & 0x3ffff);
562+
println!("scl_low_time: {}", t_low.wrapping_sub(2) & 0x3ffff);
563+
println!("sda_hold_time: {}", t_hold.wrapping_sub(2) & 0x3ffff);
543564
self.regs()
544565
.scl_high_time
545566
.set(t_high.wrapping_sub(2) & 0x3ffff);
@@ -578,6 +599,12 @@ impl Controller {
578599
} else {
579600
t_high
580601
};
602+
println!("Forcing od_scl_high_time to be the same as scl_high_time");
603+
od_t_high = t_high;
604+
//println!("Forcing od_scl_low_time to be the same as scl_low_time");
605+
//od_t_low = t_low;
606+
println!("od_scl_high_time: {}", od_t_high.wrapping_sub(2) & 0x3ffff);
607+
println!("od_scl_low_time: {}", od_t_low.wrapping_sub(2) & 0x3ffff);
581608
self.regs()
582609
.od_scl_high_time
583610
.set(od_t_high.wrapping_sub(2) & 0x3ffff);
@@ -592,6 +619,9 @@ impl Controller {
592619
let thd_start = if t_high > tcas_min { t_high } else { tcas_min };
593620
let tsu_start = if t_low > tcas_min { t_low } else { tcas_min };
594621
let tsu_stop = if t_low > tcas_min { t_low } else { tcas_min };
622+
println!("tsu_start: {}", tsu_start.wrapping_sub(2) & 0x3ffff);
623+
println!("thd_start: {}", thd_start.wrapping_sub(2) & 0x3ffff);
624+
println!("tsu_stop: {}", tsu_stop.wrapping_sub(2) & 0x3ffff);
595625
self.regs()
596626
.tsu_start
597627
.set(tsu_start.wrapping_sub(2) & 0x3ffff);
@@ -600,7 +630,13 @@ impl Controller {
600630
.set(thd_start.wrapping_sub(2) & 0x3ffff);
601631
self.regs()
602632
.tsu_stop
603-
.set(tsu_stop.wrapping_sub(2) & (0x3ffff + 5));
633+
.set(tsu_stop.wrapping_sub(2) & 0x3ffff);
634+
635+
let bus_idle = input_clock_hz/769230;
636+
println!("bus_idle: {}", bus_idle);
637+
self.regs()
638+
.bus_idle
639+
.set(bus_idle);
604640
}
605641

606642
fn get_response(&self) -> Result<(), XI3cError> {

0 commit comments

Comments
 (0)