aboutsummaryrefslogtreecommitdiff
path: root/book/en/src/internals
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2020-10-05 08:40:19 +0000
committerGravatar GitHub <noreply@github.com> 2020-10-05 08:40:19 +0000
commitdbf9a7f2983fb00aee130305fec0019c12eaef76 (patch)
tree0422a3712af398436cebfa9f8e6ac422de65dde1 /book/en/src/internals
parent04d415c3c6cce7f763decdf02104d827f2e4de7c (diff)
parent95503b6bdff3f392450d1972b0c499b79a9c2092 (diff)
downloadrtic-dbf9a7f2983fb00aee130305fec0019c12eaef76.tar.gz
rtic-dbf9a7f2983fb00aee130305fec0019c12eaef76.tar.zst
rtic-dbf9a7f2983fb00aee130305fec0019c12eaef76.zip
Merge #368
368: Mod over const r=korken89 a=AfoHT Related [RFC](https://github.com/rtic-rs/rfcs/pull/34) Dependent on [rtic-syntax-PR30](https://github.com/rtic-rs/rtic-syntax/pull/30) ~~Currently using my own dev-branch~~ Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
Diffstat (limited to 'book/en/src/internals')
-rw-r--r--book/en/src/internals/access.md12
-rw-r--r--book/en/src/internals/ceilings.md4
-rw-r--r--book/en/src/internals/critical-sections.md24
-rw-r--r--book/en/src/internals/interrupt-configuration.md4
-rw-r--r--book/en/src/internals/late-resources.md8
-rw-r--r--book/en/src/internals/non-reentrancy.md8
-rw-r--r--book/en/src/internals/tasks.md24
-rw-r--r--book/en/src/internals/timer-queue.md28
8 files changed, 56 insertions, 56 deletions
diff --git a/book/en/src/internals/access.md b/book/en/src/internals/access.md
index 6433707e..3894470c 100644
--- a/book/en/src/internals/access.md
+++ b/book/en/src/internals/access.md
@@ -15,7 +15,7 @@ To achieve the fine-grained access control where tasks can only access the
static variables (resources) that they have specified in their RTIC attribute
the RTIC framework performs a source code level transformation. This
transformation consists of placing the resources (static variables) specified by
-the user *inside* a `const` item and the user code *outside* the `const` item.
+the user *inside* a module and the user code *outside* the module.
This makes it impossible for the user code to refer to these static variables.
Access to the resources is then given to each task using a `Resources` struct
@@ -29,7 +29,7 @@ happens behind the scenes:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
static mut X: u64: 0;
static mut Y: bool: 0;
@@ -49,7 +49,7 @@ const APP: () = {
}
// ..
-};
+}
```
The framework produces codes like this:
@@ -103,8 +103,8 @@ pub mod bar {
}
/// Implementation details
-const APP: () = {
- // everything inside this `const` item is hidden from user code
+mod app {
+ // everything inside this module is hidden from user code
static mut X: u64 = 0;
static mut Y: bool = 0;
@@ -154,5 +154,5 @@ const APP: () = {
// ..
});
}
-};
+}
```
diff --git a/book/en/src/internals/ceilings.md b/book/en/src/internals/ceilings.md
index 49d248ad..07bd0add 100644
--- a/book/en/src/internals/ceilings.md
+++ b/book/en/src/internals/ceilings.md
@@ -28,7 +28,7 @@ An example to illustrate the ceiling analysis:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
struct Resources {
// accessed by `foo` (prio = 1) and `bar` (prio = 2)
// -> CEILING = 2
@@ -80,5 +80,5 @@ const APP: () = {
}
// ..
-};
+}
```
diff --git a/book/en/src/internals/critical-sections.md b/book/en/src/internals/critical-sections.md
index f95a5a7a..a064ad09 100644
--- a/book/en/src/internals/critical-sections.md
+++ b/book/en/src/internals/critical-sections.md
@@ -32,7 +32,7 @@ The example below shows the different types handed out to each task:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mut app {
struct Resources {
#[init(0)]
x: u64,
@@ -57,7 +57,7 @@ const APP: () = {
}
// ..
-};
+}
```
Now let's see how these types are created by the framework.
@@ -99,7 +99,7 @@ pub mod bar {
}
}
-const APP: () = {
+mod app {
static mut x: u64 = 0;
impl rtic::Mutex for resources::x {
@@ -129,7 +129,7 @@ const APP: () = {
// ..
})
}
-};
+}
```
## `lock`
@@ -225,7 +225,7 @@ Consider this program:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
struct Resources {
#[init(0)]
x: u64,
@@ -277,7 +277,7 @@ const APP: () = {
}
// ..
-};
+}
```
The code generated by the framework looks like this:
@@ -315,7 +315,7 @@ pub mod foo {
}
}
-const APP: () = {
+mod app {
use cortex_m::register::basepri;
#[no_mangle]
@@ -368,7 +368,7 @@ const APP: () = {
}
// repeat for resource `y`
-};
+}
```
At the end the compiler will optimize the function `foo` into something like
@@ -430,7 +430,7 @@ handler through preemption. This is best observed in the following example:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
struct Resources {
#[init(0)]
x: u64,
@@ -484,7 +484,7 @@ const APP: () = {
// ..
}
-};
+}
```
IMPORTANT: let's say we *forget* to roll back `BASEPRI` in `UART1` -- this would
@@ -493,7 +493,7 @@ be a bug in the RTIC code generator.
``` rust
// code generated by RTIC
-const APP: () = {
+mod app {
// ..
#[no_mangle]
@@ -513,7 +513,7 @@ const APP: () = {
// BUG: FORGOT to roll back the BASEPRI to the snapshot value we took before
basepri::write(initial);
}
-};
+}
```
The consequence is that `idle` will run at a dynamic priority of `2` and in fact
diff --git a/book/en/src/internals/interrupt-configuration.md b/book/en/src/internals/interrupt-configuration.md
index 278707c0..7aec9c9f 100644
--- a/book/en/src/internals/interrupt-configuration.md
+++ b/book/en/src/internals/interrupt-configuration.md
@@ -13,7 +13,7 @@ This example gives you an idea of the code that the RTIC framework runs:
``` rust
#[rtic::app(device = lm3s6965)]
-const APP: () = {
+mod app {
#[init]
fn init(c: init::Context) {
// .. user code ..
@@ -28,7 +28,7 @@ const APP: () = {
fn foo(c: foo::Context) {
// .. user code ..
}
-};
+}
```
The framework generates an entry point that looks like this:
diff --git a/book/en/src/internals/late-resources.md b/book/en/src/internals/late-resources.md
index ad2a5e51..f3a0b0ae 100644
--- a/book/en/src/internals/late-resources.md
+++ b/book/en/src/internals/late-resources.md
@@ -10,7 +10,7 @@ initialize late resources.
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
struct Resources {
x: Thing,
}
@@ -34,7 +34,7 @@ const APP: () = {
}
// ..
-};
+}
```
The code generated by the framework looks like this:
@@ -69,7 +69,7 @@ pub mod foo {
}
/// Implementation details
-const APP: () = {
+mod app {
// uninitialized static
static mut x: MaybeUninit<Thing> = MaybeUninit::uninit();
@@ -101,7 +101,7 @@ const APP: () = {
// ..
})
}
-};
+}
```
An important detail here is that `interrupt::enable` behaves like a *compiler
diff --git a/book/en/src/internals/non-reentrancy.md b/book/en/src/internals/non-reentrancy.md
index 0b0e4a73..17b34d0c 100644
--- a/book/en/src/internals/non-reentrancy.md
+++ b/book/en/src/internals/non-reentrancy.md
@@ -12,7 +12,7 @@ are discouraged from directly invoking an interrupt handler.
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
#[init]
fn init(c: init::Context) { .. }
@@ -39,7 +39,7 @@ const APP: () = {
// in aliasing of the static variable `X`
unsafe { UART0() }
}
-};
+}
```
The RTIC framework must generate the interrupt handler code that calls the user
@@ -57,7 +57,7 @@ fn bar(c: bar::Context) {
// .. user code ..
}
-const APP: () = {
+mod app {
// everything in this block is not visible to user code
#[no_mangle]
@@ -69,7 +69,7 @@ const APP: () = {
unsafe fn USART1() {
bar(..);
}
-};
+}
```
## By hardware
diff --git a/book/en/src/internals/tasks.md b/book/en/src/internals/tasks.md
index 995a8857..a533dc0c 100644
--- a/book/en/src/internals/tasks.md
+++ b/book/en/src/internals/tasks.md
@@ -28,7 +28,7 @@ Consider this example:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
// ..
#[interrupt(binds = UART0, priority = 2, spawn = [bar, baz])]
@@ -51,7 +51,7 @@ const APP: () = {
extern "C" {
fn UART1();
}
-};
+}
```
The framework produces the following task dispatcher which consists of an
@@ -62,7 +62,7 @@ fn bar(c: bar::Context) {
// .. user code ..
}
-const APP: () = {
+mod app {
use heapless::spsc::Queue;
use cortex_m::register::basepri;
@@ -110,7 +110,7 @@ const APP: () = {
// BASEPRI invariant
basepri::write(snapshot);
}
-};
+}
```
## Spawning a task
@@ -144,7 +144,7 @@ mod foo {
}
}
-const APP: () = {
+mod app {
// ..
// Priority ceiling for the producer endpoint of the `RQ1`
@@ -194,7 +194,7 @@ const APP: () = {
}
}
}
-};
+}
```
Using `bar_FQ` to limit the number of `bar` tasks that can be spawned may seem
@@ -211,7 +211,7 @@ fn baz(c: baz::Context, input: u64) {
// .. user code ..
}
-const APP: () = {
+mod app {
// ..
// Now we show the full contents of the `Ready` struct
@@ -263,13 +263,13 @@ const APP: () = {
}
}
}
-};
+}
```
And now let's look at the real implementation of the task dispatcher:
``` rust
-const APP: () = {
+mod app {
// ..
#[no_mangle]
@@ -304,7 +304,7 @@ const APP: () = {
// BASEPRI invariant
basepri::write(snapshot);
}
-};
+}
```
`INPUTS` plus `FQ`, the free queue, is effectively a memory pool. However,
@@ -357,7 +357,7 @@ Consider the following example:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
#[idle(spawn = [foo, bar])]
fn idle(c: idle::Context) -> ! {
// ..
@@ -382,7 +382,7 @@ const APP: () = {
fn quux(c: quux::Context) {
// ..
}
-};
+}
```
This is how the ceiling analysis would go:
diff --git a/book/en/src/internals/timer-queue.md b/book/en/src/internals/timer-queue.md
index 0eba1069..fcd345c5 100644
--- a/book/en/src/internals/timer-queue.md
+++ b/book/en/src/internals/timer-queue.md
@@ -12,7 +12,7 @@ Let's see how this in implemented in code. Consider the following program:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
// ..
#[task(capacity = 2, schedule = [foo])]
@@ -24,7 +24,7 @@ const APP: () = {
extern "C" {
fn UART0();
}
-};
+}
```
## `schedule`
@@ -46,7 +46,7 @@ mod foo {
}
}
-const APP: () = {
+mod app {
type Instant = <path::to::user::monotonic::timer as rtic::Monotonic>::Instant;
// all tasks that can be `schedule`-d
@@ -100,7 +100,7 @@ const APP: () = {
}
}
}
-};
+}
```
This looks very similar to the `Spawn` implementation. In fact, the same
@@ -123,7 +123,7 @@ is up.
Let's see the associated code.
``` rust
-const APP: () = {
+mod app {
#[no_mangle]
fn SysTick() {
const PRIORITY: u8 = 1;
@@ -146,7 +146,7 @@ const APP: () = {
}
}
}
-};
+}
```
This looks similar to a task dispatcher except that instead of running the
@@ -197,7 +197,7 @@ able to insert the task in the timer queue; this lets us omit runtime checks.
## System timer priority
-The priority of the system timer can't set by the user; it is chosen by the
+The priority of the system timer can't be set by the user; it is chosen by the
framework. To ensure that lower priority tasks don't prevent higher priority
tasks from running we choose the priority of the system timer to be the maximum
of all the `schedule`-able tasks.
@@ -222,7 +222,7 @@ To illustrate, consider the following example:
``` rust
#[rtic::app(device = ..)]
-const APP: () = {
+mod app {
#[task(priority = 3, spawn = [baz])]
fn foo(c: foo::Context) {
// ..
@@ -237,7 +237,7 @@ const APP: () = {
fn baz(c: baz::Context) {
// ..
}
-};
+}
```
The ceiling analysis would go like this:
@@ -246,7 +246,7 @@ The ceiling analysis would go like this:
`SysTick` must run at the highest priority between these two, that is `3`.
- `foo::Spawn` (prio = 3) and `bar::Schedule` (prio = 2) contend over the
- consumer endpoind of `baz_FQ`; this leads to a priority ceiling of `3`.
+ consumer endpoint of `baz_FQ`; this leads to a priority ceiling of `3`.
- `bar::Schedule` (prio = 2) has exclusive access over the consumer endpoint of
`foo_FQ`; thus the priority ceiling of `foo_FQ` is effectively `2`.
@@ -270,7 +270,7 @@ run; this `Instant` is read in the task dispatcher and passed to the user code
as part of the task context.
``` rust
-const APP: () = {
+mod app {
// ..
#[no_mangle]
@@ -303,7 +303,7 @@ const APP: () = {
// BASEPRI invariant
basepri::write(snapshot);
}
-};
+}
```
Conversely, the `spawn` implementation needs to write a value to the `INSTANTS`
@@ -333,7 +333,7 @@ mod foo {
}
}
-const APP: () = {
+mod app {
impl<'a> foo::Spawn<'a> {
/// Spawns the `baz` task
pub fn baz(&self, message: u64) -> Result<(), u64> {
@@ -364,5 +364,5 @@ const APP: () = {
}
}
}
-};
+}
```