-
Notifications
You must be signed in to change notification settings - Fork 150
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
Add SCB methods to enable/disable exceptions #205
Conversation
r? @ithinuel (rust_highfive has picked a reviewer for you, use r? to override) |
One comment, otherwise I'm happy with this. Thank you for the PR! |
Some exceptions might be disabled by default which means that the HardFault handler will be called instead of the exception handler. This commit adds methods on the SCB peripheral that use the SHCSR register to enable/disable exceptions. Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
This was ready to be merged, any updates? |
Sorry for the wait! On the whole I think this is good. I had a few thoughts as I looked over it...
|
Thanks for the review 😃
I would think so too because these methods do not enable/disable interrupts per say, but only modify their routing to the specific handler or
I was not sure of what was the idiomatic thing to do! It is indeed easier to use static methods. I now realise that I used
I don't think there are any requirements ; it was done for performance to avoid going through a critical-section set-up if it is actually not needed! If you think this is not needed, I can remove it indeed. |
Out of your three points, I think we agreed on the first one that
|
Sorry for the wait (again!). We had a chat about this at today's meeting (logs are here). I'm cautious about merging this without enough consideration because how interrupts are handled is such an important part of our safety story and one of the hardest bits to get right. SafetyThis still seems like a point of concern, especially in relation to critical sections/mutexes. It might be related #196 as well. However I think this argument offers a way out:
I think this means we can keep them safe. Static SCB and state checksIf we use cc @japaric who's probably thought about this stuff the most... |
Thanks a lot for putting that issue as a topic during last meeting 💯
Agree with your points and the conclusion.
That seems like a good option and I agree that the ownership rules are better suited/more efficient to prevent data races than disabling exceptions. |
This removes the duplication of the look-up table and enforces some safety checks with the match statement. Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
9ccb935
to
08f2a69
Compare
Removed the critical sections and the state checks. I am all-in about using references to peripherals in their methods to enforce the ownership rules but one thing which is weird is that in the following code: #[inline]
#[cfg(not(any(armv6m, armv8m_base)))]
pub fn enable(&mut self, exception: Exception) {
if let Some(shift) = SCB::shcsr_enable_shift(exception) {
// The mutable reference to SCB makes sure that only this code is currently modifying
// the register.
unsafe { self.shcsr.modify(|value| value | (1 << shift)) }
}
} changing |
Thanks!
The reason for this is we don't require However in cortex-m we've used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this now but would still like to hear if anyone else @rust-embedded/cortex-m has ideas on how it might be unsafe. If not I'll merge by the end of the week.
Guess we're good to go! bors merge |
👎 Rejected by code reviews |
Hmm, @thejpster please could you approve the changes or dismiss your review? Looks like it still being open is blocking bors. |
Let's see whether that did the trick. bors r=adamgreig |
👎 Rejected by code reviews |
Damn, did not. That's so silly. |
Maybe try the close and re-open dance? |
Nope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be a weird bors thing. Let's wait a bit for @thejpster and then override manually.
bors r+
👎 Rejected by code reviews |
Pushing a new commit should dispose of the old reviews |
Yes, but only the approvals (if configured in the GH branch protection rules), not the change requests. |
205: Stop using randomized symbol names r=therealprof a=jonas-schievink It isn't possible to do this by incrementing a global counter, since the expansion order of macros isn't guaranteed and might change between compiler invocations. Fixes #212 Closes rust-embedded/cortex-m-rt#196 Closes rust-embedded/cortex-m-rt#195 Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Some exceptions might be disabled by default which means that the
HardFault handler will be called instead of the exception handler. This
commit adds methods on the SCB peripheral that use the SHCSR register to
enable/disable exceptions.
Signed-off-by: Hugues de Valon hugues.devalon@arm.com