Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differentiate comparator 0 as the only one capable of cycle compare #377

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
check DWT::has_cycle_counter when configuring a comparator for that f…
…unction & some cleanup
TDHolmes committed Oct 8, 2022
commit ffa638c71c451719e4a25a295199af0bce7ba4e9
11 changes: 9 additions & 2 deletions src/peripheral/dwt.rs
Original file line number Diff line number Diff line change
@@ -452,7 +452,7 @@ pub enum DwtError {

impl<SupportedFunctions: ComparatorSupportedFunctions> Comparator<SupportedFunctions> {
/// Private function for configuring address compare on any [`Comparator`] since they all support this.
/// Utilized publicly through [`Comparator::configure`]
/// Utilized publicly through [`Comparator::configure`].
fn configure_address_compare(
&self,
settings: ComparatorAddressSettings,
@@ -522,12 +522,19 @@ impl Comparator<NoCycleCompare> {
}

impl Comparator<HasCycleCompare> {
/// Configure the function of the [`Comparator`]. Has support for cycle count comparison.
/// Configure the function of the [`Comparator`]. Has support for cycle count comparison
/// and checks [`DWT::has_cycle_counter`] for hardware support if
/// [`CycleCount`](ComparatorFunction::CycleCount) is requested.
#[allow(clippy::missing_inline_in_public_items)]
pub fn configure(&self, settings: ComparatorFunction) -> Result<(), DwtError> {
match settings {
ComparatorFunction::Address(settings) => self.configure_address_compare(settings),
ComparatorFunction::CycleCount(settings) => {
// Check if the HW advertises that it has the cycle counter or not
if !DWT::has_cycle_counter() {
return Err(DwtError::UnsupportedFunction);
}

let function = match &settings.emit {
EmitOption::PCData => 0b0001,
EmitOption::WatchpointDebugEvent => 0b0100,