-
Notifications
You must be signed in to change notification settings - Fork 168
Add an unsafe fn SCB::steal
#169
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
Conversation
r? @adamgreig (rust_highfive has picked a reviewer for you, use r? to override) |
I think this is a good idea and we should consider doing it for the other peripherals, but the unsafety comment should probably be more explicit than currently. Maybe say that users must synchronise SCB access with all other SCB instances to prevent race conditions, what do you think? |
@adamgreig Yeah that's a good point. I've updated the docs. |
|
@m-ou-se Oh, you're right. I thought that still had the I guess having a separate function is still a little bit more convenient, but I can definitely see not providing more |
It still has the Maybe only |
Yeah, I noticed that too. Fortunately most uses will probably not mind that too much since they'll only call |
One issue with this is that RTFM relies on this behavior for soundness. If this was changed, RTFM would call |
That would mean that RTFM's soundness is based on undocumented behaviour. The documentation of Should this be the actual (documented) behaviour of |
Yeah you're right. I think it makes sense to change the documentation for I could also see adding another function that will just set the flag and not do anything else, and then making |
That function already exists: That's just |
Maybe it'd even make sense to have a Cargo feature that RTFM can enable on |
Interesting idea! I think this would be a pretty big change, so it might warrant some more discussion in an RFC issue. |
Blech, adding random features is a huge stumbling block for newcomers. We want to have less of those rather than more. |
A function that effectively always returns None also sounds like a stumbling block. Newcomers wouldn't have to touch the feature. It should be disabled by default, and using RTFM will enable it. It could even replace take() by a function with a #[depracated] marker or something that warns the user: "You're using a framework that handles the core peripherals, so take() will always return None" |
@m-ou-se I doubt it that a random user would stumble across a very special and specific function and be shied away by slightly unexpected semantics while on the other hand a feature gate always affects all users and thus provides a much larger problem surface. Documenting it seems like a good idea though. |
How does an on-by-default feature gate affect users negatively? Edit: The suggestion here is to add a feature that removes the method, so in this case it would be an off-by-default feature gate. I still wonder what's so bad about feature gates though, so my question stands :-) |
@hannobraun On-by-default is even worse because every crate will actively have to opt out. But even for regular features, the additive (global) nature of feature gates is a common source of troubles if some dependency crates decides to enable them (for whatever reason) and they really should be disabled in the application. |
The feature would be opt-in, and only frameworks like RTFM that manage peripherals on their own would enable it, so there shouldn't be problems where the feature gets accidentally enabled in some application. (ie. it wouldn't have the same problems as a default-enabled
This actually sounds pretty neat. However then we'd "pay" with adding a Cargo feature, only to show a warning to the user, not sure if this is a worthwhile tradeoff. Are there any other crates that do something like this? (I realize that we already do way more exotic stuff than this in eg. |
This comment has been minimized.
This comment has been minimized.
Ah, okay. I figured you'd be talking about something more exotic. I probably misread your original comment (you said "always affects all users", which I understood to mean "always affects all users negatively", which I don't think is what you meant). Thanks for explaining! |
Closing this for now. It only provides a tiny utility function, and the future design and naming of take/steal-style APIs is not settled yet. |
This allows safely creating an
SCB
instance from nothing, which is required when combining rtfm 0.4.x with APIs that make use ofSCB
/&mut SCB
(rtfm retains ownership of the SCB).Before, it was already possible to unsafely access the SCB register block via
SCB::ptr()
. However, it was impossible to obtain anSCB
instance itself.