-
Notifications
You must be signed in to change notification settings - Fork 11
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 Sharing Data with Interrupts #8
Conversation
r? @korken89 (rust_highfive has picked a reviewer for you, use r? to override) |
README.md
Outdated
* Not all data can be initialized in a `const` context, so it's often necessary to use an `Option<T>` | ||
* Global variables aren't typically idiomatic Rust. | ||
|
||
Tools like [cortex-m-rtfm] achieve this in a zero cost fashion by using a Domain Specific Language to automatically provide safe access to shared resources between tasks and interrupts, however these tools can not be used by applications not using RTFM, or by libraries such as HAL or BSP crates. |
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.
Maybe also mention atomics? Or it could go in the patterns book. Atomics in static
s are fine if you scope them; you can use them in libraries as well. For example
// crate: my-hal-impl
mod timer {
// not global
static DONE: AtomicBool = AtomicBool::new(false);
impl Timer {
fn wait(&mut self, cycles: u32) {
DONE.store(false, Ordering::Relaxed);
// set a timeout
while !DONE.load(Ordering::Relaxed) {
asm::wfi();
}
}
}
#[interrupt]
fn TIM2() {
// clear interrupt flag
DONE.store(true, Ordering::Relaxed);
}
}
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.
(Also I would change "tools like ..." to "frameworks like ..." (in the text))
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.
Maybe also mention atomics?
Or you could reword the request to say "share non-atomic data ..."
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.
(Also I would change "tools like ..." to "frameworks like ..." (in the text))
I actually went back and forth on that exact naming difference! Thanks for the deciding factor.
Maybe also mention atomics? Or it could go in the patterns book. Atomics in
static
s are fine if you scope them; you can use them in libraries as well.
I'll add a bit about this, once there is a section about atomics in the patterns book, I'd be happy to link it here as well.
I think we will need to make a folder of "detailed requests" sooner than later - I'd like to keep the README from becoming 10k-100k lines long, so at some point we should probably move each NYA item to it's own MD file, and just have a title and 1 paragraph summary (and a link to the child MD) on the main readme.
Addressed @japaric's comments, this is ready for re-review! |
Coudn't this kind of issue be solved with a messaging bus system ? |
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.
LGTM
@mathk - yes, but you would still need to get a handle to the message bus system (producer, consumer, etc) to the interrupt! |
bors r=therealprof |
8: Add Sharing Data with Interrupts r=therealprof a=jamesmunns ## Category Is this PR a: - [x] New Not Yet Awesome item? - [ ] A WIP project addressing an open item? - [ ] Removing a Not Yet Awesome item? ## New Not Yet Awesome item checklist - [x] Is the request clearly stated, linking to relevant documentation, such as a whitepaper, protocol definition, datasheet, etc.? - [x] Are the "Success Criteria" defined? - [x] Is this request possible using today's Rust (not blocked by LLVM impl, rustc impl, etc.)? - [x] Is this request broken into reasonable work packages, such as "Create HAL for XYZ chip", not "support all boards from ABC vendor"? Co-authored-by: James Munns <james.munns@ferrous-systems.com>
Build succeeded |
Category
Is this PR a:
New Not Yet Awesome item checklist