mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 00:05:45 +00:00
control flow cleanup
This commit is contained in:
parent
3fac13606e
commit
b65b432762
1 changed files with 14 additions and 13 deletions
|
@ -192,29 +192,30 @@ fn notmain() -> Result<i32, anyhow::Error> {
|
||||||
// run
|
// run
|
||||||
|
|
||||||
let core = Rc::new(core);
|
let core = Rc::new(core);
|
||||||
let mut num_retries = 5;
|
let rtt_addr_result = rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?;
|
||||||
|
|
||||||
let mut rtt: Result<Rtt, probe_rs_rtt::Error>;
|
let mut rtt: Result<Rtt, probe_rs_rtt::Error>;
|
||||||
|
let mut num_retries = 3; // picked at random, increase if necessary
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
rtt = Rtt::attach_region(
|
rtt = Rtt::attach_region(
|
||||||
core.clone(),
|
core.clone(),
|
||||||
&sess,
|
&sess,
|
||||||
&ScanRegion::Exact(rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?), // todo only do this once?
|
&ScanRegion::Exact(rtt_addr_result),
|
||||||
);
|
);
|
||||||
|
|
||||||
// todo clean up control flow
|
match rtt {
|
||||||
if rtt.is_ok() {
|
Ok(_) => { break; }
|
||||||
log::info!("Successfully attached RTT");
|
Err(res) => {
|
||||||
break;
|
num_retries -= 1;
|
||||||
|
if num_retries == 0 {
|
||||||
|
log::info!("Max number of retries exceeded. Giving up.");
|
||||||
|
return Err(anyhow!(res));
|
||||||
|
}
|
||||||
|
log::info!("Attaching RTT failed. retrying");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
num_retries -= 1;
|
|
||||||
if num_retries == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
log::info!("Attaching RTT failed. retrying");
|
|
||||||
}
|
}
|
||||||
|
log::info!("Successfully attached RTT");
|
||||||
|
|
||||||
let channel = rtt
|
let channel = rtt
|
||||||
.unwrap() // using ? instead wouldn't show the user any helpful error message
|
.unwrap() // using ? instead wouldn't show the user any helpful error message
|
||||||
|
|
Loading…
Reference in a new issue