Skip to content

Commit

Permalink
Make the M cores only poll the state on first construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Yatekii committed May 6, 2020
1 parent 1da8e45 commit a485eb4
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 57 deletions.
38 changes: 19 additions & 19 deletions probe-rs/src/architecture/arm/core/m0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,34 +285,34 @@ impl<'probe> M0<'probe> {
mut memory: Memory<'probe>,
state: &'probe mut CortexState,
) -> Result<Self, Error> {
// determine current state
let dhcsr = Dhcsr(memory.read_word_32(Dhcsr::ADDRESS)?);
if !state.initialized() {
// determine current state
let dhcsr = Dhcsr(memory.read_word_32(Dhcsr::ADDRESS)?);

let core_state = if dhcsr.s_sleep() {
CoreStatus::Sleeping
} else if dhcsr.s_halt() {
log::debug!("Core was halted when connecting");
let core_state = if dhcsr.s_sleep() {
CoreStatus::Sleeping
} else if dhcsr.s_halt() {
log::debug!("Core was halted when connecting");

let dfsr = Dfsr(memory.read_word_32(Dfsr::ADDRESS)?);
let dfsr = Dfsr(memory.read_word_32(Dfsr::ADDRESS)?);

let reason = dfsr.halt_reason();
let reason = dfsr.halt_reason();

CoreStatus::Halted(reason)
} else {
CoreStatus::Running
};
CoreStatus::Halted(reason)
} else {
CoreStatus::Running
};

// Clear DFSR register. The bits in the register are sticky,
// so we clear them here to ensure that that none are set.
let dfsr_clear = Dfsr::clear_all();

memory.write_word_32(Dfsr::ADDRESS, dfsr_clear.into())?;

if !state.initialized() {
state.current_state = core_state;
state.initialize();
}

// Clear DFSR register. The bits in the register are sticky,
// so we clear them here to ensure that that none are set.
let dfsr_clear = Dfsr::clear_all();

memory.write_word_32(Dfsr::ADDRESS, dfsr_clear.into())?;

Ok(Self { memory, state })
}

Expand Down
38 changes: 19 additions & 19 deletions probe-rs/src/architecture/arm/core/m33.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,34 @@ impl<'probe> M33<'probe> {
mut memory: Memory<'probe>,
state: &'probe mut CortexState,
) -> Result<Self, Error> {
// determine current state
let dhcsr = Dhcsr(memory.read_word_32(Dhcsr::ADDRESS)?);
if !state.initialized() {
// determine current state
let dhcsr = Dhcsr(memory.read_word_32(Dhcsr::ADDRESS)?);

let core_state = if dhcsr.s_sleep() {
CoreStatus::Sleeping
} else if dhcsr.s_halt() {
log::debug!("Core was halted when connecting");
let core_state = if dhcsr.s_sleep() {
CoreStatus::Sleeping
} else if dhcsr.s_halt() {
log::debug!("Core was halted when connecting");

let dfsr = Dfsr(memory.read_word_32(Dfsr::ADDRESS)?);
let dfsr = Dfsr(memory.read_word_32(Dfsr::ADDRESS)?);

let reason = dfsr.halt_reason();
let reason = dfsr.halt_reason();

CoreStatus::Halted(reason)
} else {
CoreStatus::Running
};
CoreStatus::Halted(reason)
} else {
CoreStatus::Running
};

// Clear DFSR register. The bits in the register are sticky,
// so we clear them here to ensure that that none are set.
let dfsr_clear = Dfsr::clear_all();

memory.write_word_32(Dfsr::ADDRESS, dfsr_clear.into())?;

if !state.initialized() {
state.current_state = core_state;
state.initialize();
}

// Clear DFSR register. The bits in the register are sticky,
// so we clear them here to ensure that that none are set.
let dfsr_clear = Dfsr::clear_all();

memory.write_word_32(Dfsr::ADDRESS, dfsr_clear.into())?;

Ok(Self { memory, state })
}

Expand Down
38 changes: 19 additions & 19 deletions probe-rs/src/architecture/arm/core/m4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,34 +338,34 @@ impl<'probe> M4<'probe> {
mut memory: Memory<'probe>,
state: &'probe mut CortexState,
) -> Result<M4<'probe>, Error> {
// determine current state
let dhcsr = Dhcsr(memory.read_word_32(Dhcsr::ADDRESS)?);
if !state.initialized() {
// determine current state
let dhcsr = Dhcsr(memory.read_word_32(Dhcsr::ADDRESS)?);

let core_state = if dhcsr.s_sleep() {
CoreStatus::Sleeping
} else if dhcsr.s_halt() {
log::debug!("Core was halted when connecting");
let core_state = if dhcsr.s_sleep() {
CoreStatus::Sleeping
} else if dhcsr.s_halt() {
log::debug!("Core was halted when connecting");

let dfsr = Dfsr(memory.read_word_32(Dfsr::ADDRESS)?);
let dfsr = Dfsr(memory.read_word_32(Dfsr::ADDRESS)?);

let reason = dfsr.halt_reason();
let reason = dfsr.halt_reason();

CoreStatus::Halted(reason)
} else {
CoreStatus::Running
};
CoreStatus::Halted(reason)
} else {
CoreStatus::Running
};

// Clear DFSR register. The bits in the register are sticky,
// so we clear them here to ensure that that none are set.
let dfsr_clear = Dfsr::clear_all();

memory.write_word_32(Dfsr::ADDRESS, dfsr_clear.into())?;

if !state.initialized() {
state.current_state = core_state;
state.initialize();
}

// Clear DFSR register. The bits in the register are sticky,
// so we clear them here to ensure that that none are set.
let dfsr_clear = Dfsr::clear_all();

memory.write_word_32(Dfsr::ADDRESS, dfsr_clear.into())?;

Ok(Self { memory, state })
}

Expand Down

0 comments on commit a485eb4

Please sign in to comment.