Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

Commit 30eda89

Browse files
bors[bot]James Munns
andcommitted
Merge #8
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>
2 parents d417421 + dac52ce commit 30eda89

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,50 @@ And don't forget to check our [Awesome Embedded Rust][aer] list! The thing you a
2626

2727
* Useful Links
2828
* [Contributing Guide]
29-
* [Item Template](https://github.com/rust-embedded/not-yet-awesome-embedded-rust#not-yet-awesome-item-template)
29+
* [Item Template](#not-yet-awesome-item-template)
3030
* Not Yet Awesome List
31-
* [nothing yet...](#)
31+
* [Sharing Data With Interrupts](#sharing-data-with-interrupts)
3232

3333
# The List
3434

35-
Nothing here yet...
35+
## Sharing Data With Interrupts
36+
37+
### Background
38+
39+
Currently, it is not convenient to share non-atomic or non-`Sync` data with an interrupt using safe Rust. Because interrupt handlers are functions that take no arguments, all data consumed by interrupts must either be global or module scoped Atomics (e.g. `AtomicBool`), local `static` variables, or global or module scoped `static` variables.
40+
41+
Global variables are not great in Rust, because:
42+
43+
* All mutable access (of non-`Sync`/`Atomic` data) must be `unsafe`
44+
* Not all data can be initialized in a `const` context, so it's often necessary to use an `Option<T>` to delay the initialization to runtime
45+
* Global variables aren't typically idiomatic Rust.
46+
47+
Frameworks 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.
48+
49+
**Useful Links**
50+
51+
* [wg#294] - An Embedded-WG issue discussing this topic
52+
* [bare-metal#15] - One proposed solution hiding the un-idiomatic syntax
53+
54+
[wg#294]: https://github.com/rust-embedded/wg/issues/294
55+
[bare-metal#15]: https://github.com/japaric/bare-metal/pull/15
56+
[cortex-m-rtfm]: https://github.com/japaric/cortex-m-rtfm
57+
58+
### Success Criteria
59+
60+
Ideally, we would be able to support all of the following use cases:
61+
62+
1. Sharing a variable between the main thread and only one interrupt handler
63+
2. Sharing a variable between the main thread and one or more interrupt handlers
64+
3. Moving a variable from the main thread to one interrupt handler
65+
66+
We should be able to serve the three use cases listed above, while:
67+
68+
* Using only safe Rust (at least as a user of the library)
69+
* Add only minimal overhead, if not "zero cost"
70+
71+
<!-- TODO: Uncomment when there is work in progress -->
72+
<!-- ### Work in progress -->
3673

3774
# Not Yet Awesome Item Template
3875

0 commit comments

Comments
 (0)