You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 1, 2025. It is now read-only.
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>
*[Sharing Data With Interrupts](#sharing-data-with-interrupts)
32
32
33
33
# The List
34
34
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
0 commit comments