cortex-m icon indicating copy to clipboard operation
cortex-m copied to clipboard

Differentiate comparator 0 as the only one capable of cycle compare

Open TDHolmes opened this issue 3 years ago • 15 comments

Statically enforces that only comparator 0 on armv7m can be configured for cycle comparison by introducing a marker trait differentiating comparator 0 and the rest of them, and only implementing the ability for this configuration on comparator 0.

Closes #376

TDHolmes avatar Jan 02 '22 00:01 TDHolmes

r? @adamgreig

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Jan 02 '22 00:01 rust-highfive

🏷️ @tmplt

TDHolmes avatar Jan 02 '22 00:01 TDHolmes

I tested the cycle count comparison functionality on HW to make sure this all worked as expected. I'm not sure how to test the address compare functionality on HW so didn't check that.

TDHolmes avatar Jan 02 '22 00:01 TDHolmes

I don't see any outstanding issues reviewing from a phone at the moment. I'll go over it in detail when I'm back in my office next week.

tmplt avatar Jan 02 '22 06:01 tmplt

Thoughts @tmplt ?

TDHolmes avatar Jan 05 '22 19:01 TDHolmes

I'll go over it tomorrow.

tmplt avatar Jan 05 '22 19:01 tmplt

I made all of the DWT::has_* implementation feature checks associated functions instead of methods (they no longer take &self) per this comment as it allows me to check has_cycle_counter in configure.

edit: Looks like this was originally how it was implemented, but then you changed it in #342. Let me know if there was a good reason, but I think it makes sense to go back to associated functions.

TDHolmes avatar Jan 06 '22 22:01 TDHolmes

I also tried to be fancy by wrapping these two slightly different comparators in a unified struct which then vended the right one by implementing the Index trait, however it requires GATs to work :( it would've been cool because then we could've also checked DWT::num_comp to see if the comparator you're trying to access is even implemented. Oh well...

TDHolmes avatar Jan 06 '22 22:01 TDHolmes

Actually.. I suppose I could still implement Index where I return the type Result<ComparatorTypes, DwtError> where ComparatorTypes is an enum:

enum ComparatorTypes {
    NoCycleCount(Comparator<NoCycleCompare>),
    WithCycleCount(Comparator<HasCycleCompare>),

thoughts?

TDHolmes avatar Jan 06 '22 23:01 TDHolmes

Let me know if there was a good reason

At the time I thought it was relics from an older implementation which I refactored just to remove the unsafe usage.

As for Index I suggest limiting this PR to its namesake and create another one for the comparator implementation check.

tmplt avatar Jan 07 '22 10:01 tmplt

In that case this should be ready to review and merge

TDHolmes avatar Jan 07 '22 16:01 TDHolmes

I want to try this out on hardware before I sign off on it. Hopefully I'll have it done by next week.

tmplt avatar Jan 08 '22 01:01 tmplt

Sounds good, thanks!

TDHolmes avatar Jan 08 '22 02:01 TDHolmes

I've been testing this PR with a in cortex-m-rtic-trace branch, based on an rtic-scope-dw0 branch of cortex-m that contains this PR, for use with cargo-rtic-scope. Without the patch I see

hardware task - enter
software task - enter
software task - exit
hardware task - exit / overflow

With the patch I get a very confusing trace. I doubt this PR is at fault, but to make sure I need to handle #392 and #383 first.

tmplt avatar Jan 13 '22 15:01 tmplt

rebased onto latest master

TDHolmes avatar Oct 08 '22 18:10 TDHolmes