mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-24 23:08:08 +00:00
sketch
This commit is contained in:
parent
07cdaf5212
commit
71579aaa9f
1 changed files with 21 additions and 20 deletions
|
@ -192,32 +192,33 @@ fn notmain() -> Result<i32, anyhow::Error> {
|
||||||
// run
|
// run
|
||||||
|
|
||||||
let core = Rc::new(core);
|
let core = Rc::new(core);
|
||||||
let rtt_addr_result = rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?;
|
let rtt_addr_res = rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?;
|
||||||
let mut rtt: Result<Rtt, probe_rs_rtt::Error>;
|
let mut rtt_res: Result<Rtt, probe_rs_rtt::Error> =
|
||||||
let mut num_retries = 3; // picked at random, increase if necessary
|
Err(probe_rs_rtt::Error::ControlBlockNotFound);
|
||||||
|
const NUM_RETRIES: usize = 3; // picked at random, increase if necessary
|
||||||
|
|
||||||
loop {
|
for try_index in 0..NUM_RETRIES {
|
||||||
rtt = Rtt::attach_region(
|
rtt_res = Rtt::attach_region(core.clone(), &sess, &ScanRegion::Exact(rtt_addr_res));
|
||||||
core.clone(),
|
match rtt_res {
|
||||||
&sess,
|
Ok(_) => {
|
||||||
&ScanRegion::Exact(rtt_addr_result),
|
log::info!("Successfully attached RTT");
|
||||||
);
|
break;
|
||||||
|
}
|
||||||
match rtt {
|
Err(probe_rs_rtt::Error::ControlBlockNotFound) => {
|
||||||
Ok(_) => { break; }
|
if try_index < NUM_RETRIES {
|
||||||
Err(res) => {
|
log::info!("Attaching RTT failed. retrying");
|
||||||
num_retries -= 1;
|
} else {
|
||||||
if num_retries == 0 {
|
log::info!("Max number of retries exceeded. Giving up");
|
||||||
log::info!("Max number of retries exceeded. Giving up.");
|
return Err(anyhow!(probe_rs_rtt::Error::ControlBlockNotFound));
|
||||||
return Err(anyhow!(res));
|
|
||||||
}
|
}
|
||||||
log::info!("Attaching RTT failed. retrying");
|
}
|
||||||
|
Err(e) => {
|
||||||
|
return Err(anyhow!(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::info!("Successfully attached RTT");
|
|
||||||
|
|
||||||
let channel = rtt
|
let channel = rtt_res
|
||||||
.unwrap() // using ? instead wouldn't show the user any helpful error message
|
.unwrap() // using ? instead wouldn't show the user any helpful error message
|
||||||
.up_channels()
|
.up_channels()
|
||||||
.take(0)
|
.take(0)
|
||||||
|
|
Loading…
Reference in a new issue