Skip to content

Commit 028231a

Browse files
committed
doc: mention binding in README.md
Getting a mutable static storage is one of the largest pet peeves in Rust, especially Embedded Rust. This shows how it's resolved in R3.
1 parent 411b0c0 commit 028231a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ R3 is a proof-of-concept of a static RTOS that utilizes Rust's compile-time func
2727

2828
- The kernel timing mechanism drives **software timers** and a **system-global clock** with microsecond precision. The system clock can be rewound or fast-forwarded for drift compensation. The timing algorithm has a logarithmic time complexity and is therefore scalable. The implementation is robust against a large interrupt processing delay.
2929

30+
- **Bindings** are a statically-defined storage with runtime initialization and configuration-time borrow checking. They can be bound to tasks and other objects to provide safe mutable access.
31+
3032
- The utility library includes safe container types such as **`Mutex`** and **`RecursiveMutex`**, which are built upon low-level synchronization primitives.
3133

3234
[the priority ceiling protocol]: https://en.wikipedia.org/wiki/Priority_ceiling_protocol
@@ -74,7 +76,7 @@ impl port::SysTickOptions for SystemTraits {
7476

7577
// ----------------------------------------------------------------
7678

77-
use r3::kernel::StaticTask;
79+
use r3::{bind::bind, kernel::StaticTask, prelude::*};
7880

7981
struct Objects {
8082
task: StaticTask<System>,
@@ -86,16 +88,20 @@ const COTTAGE: Objects = r3_kernel::build!(SystemTraits, configure_app => Object
8688
const fn configure_app(b: &mut r3_kernel::Cfg<SystemTraits>) -> Objects {
8789
System::configure_systick(b);
8890

91+
// Runtime-initialized static storage
92+
let count = bind((), || 1u32).finish(b);
93+
8994
Objects {
95+
// Create a task, giving the ownership of `count`
9096
task: StaticTask::define()
91-
.start(task_body)
97+
.start_with_bind((count.borrow_mut(),), task_body)
9298
.priority(2)
9399
.active(true)
94100
.finish(b),
95101
}
96102
}
97103

98-
fn task_body() {
104+
fn task_body(count: &mut u32) {
99105
// ...
100106
}
101107
```

0 commit comments

Comments
 (0)