aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml1
-rw-r--r--book/en/src/by-example/app.md5
-rw-r--r--book/en/src/migration/migration_v5.md49
-rw-r--r--examples/t-schedule.rs6
-rw-r--r--macros/src/codegen.rs25
5 files changed, 75 insertions, 11 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e5f99434..93e32545 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -740,6 +740,7 @@ jobs:
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./bookstodeploy
+ force_orphan: true
# Refs: https://github.com/rust-lang/crater/blob/9ab6f9697c901c4a44025cf0a39b73ad5b37d198/.github/workflows/bors.yml#L125-L149
#
diff --git a/book/en/src/by-example/app.md b/book/en/src/by-example/app.md
index 6a011936..50f2842c 100644
--- a/book/en/src/by-example/app.md
+++ b/book/en/src/by-example/app.md
@@ -23,9 +23,8 @@ to use the [`cortex_m_rt::entry`] attribute.
## `init`
Within the `app` module the attribute expects to find an initialization
-function marked with the `init` attribute. This function must have signature
-`fn(init::Context) [-> init::LateResources]` (the return type is not always
-required).
+function marked with the `init` attribute. This function must have
+signature `fn(init::Context) -> (init::LateResources, init::Monotonics)`.
This initialization function will be the first part of the application to run.
The `init` function will run *with interrupts disabled* and has exclusive access
diff --git a/book/en/src/migration/migration_v5.md b/book/en/src/migration/migration_v5.md
index 8edefd2d..505a8b6c 100644
--- a/book/en/src/migration/migration_v5.md
+++ b/book/en/src/migration/migration_v5.md
@@ -30,7 +30,46 @@ mod app {
Now that a regular Rust module is used it means it is possible to have custom
user code within that module.
-Additionally, it means that `use`-statements for resources etc may be required.
+Additionally, it means that `use`-statements for resources used in user
+code must be moved inside `mod app`, or be referred to with `super`. For
+example, change:
+
+```rust
+use some_crate::some_func;
+
+#[rtic::app(/* .. */)]
+const APP: () = {
+ fn func() {
+ some_crate::some_func();
+ }
+};
+```
+
+into
+
+```rust
+#[rtic::app(/* .. */)]
+mod app {
+ use some_crate::some_func;
+
+ fn func() {
+ some_crate::some_func();
+ }
+}
+```
+
+or
+
+```rust
+use some_crate::some_func;
+
+#[rtic::app(/* .. */)]
+mod app {
+ fn func() {
+ super::some_crate::some_func();
+ }
+};
+```
## Move Dispatchers from `extern "C"` to app arguments.
@@ -71,14 +110,14 @@ From this:
``` rust
#[rtic::app(device = lm3s6965)]
-mod app {
+const APP: () = {
#[init]
fn init(_: init::Context) {
rtic::pend(Interrupt::UART0);
}
// [more code]
-}
+};
```
to this:
@@ -87,10 +126,10 @@ to this:
#[rtic::app(device = lm3s6965)]
mod app {
#[init]
- fn init(_: init::Context) -> init::LateResources {
+ fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
rtic::pend(Interrupt::UART0);
- init::LateResources {}
+ (init::LateResources {}, init::Monotonics())
}
// [more code]
diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs
index 5e38dbaf..4ce62b47 100644
--- a/examples/t-schedule.rs
+++ b/examples/t-schedule.rs
@@ -7,11 +7,15 @@
use panic_semihosting as _;
+pub struct SomeStruct;
+
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
use dwt_systick_monotonic::DwtSystick;
use rtic::time::duration::Seconds;
+ use super::SomeStruct;
+
#[monotonic(binds = SysTick, default = true)]
type MyMono = DwtSystick<8_000_000>; // 8 MHz
@@ -40,7 +44,7 @@ mod app {
let _: Result<(), ()> = handle.unwrap().cancel();
// Using default
- let _: Result<foo::SpawnHandle, ()> = foo::spawn_at(monotonics::MyMono::now());
+ let _: Result<foo::SpawnHandle, ()> = foo::spawn_at(monotonics::now());
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(Seconds(1_u32));
let _: Result<foo::SpawnHandle, ()> = handle.unwrap().reschedule_after(Seconds(1_u32));
diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs
index 167ba500..de11cce4 100644
--- a/macros/src/codegen.rs
+++ b/macros/src/codegen.rs
@@ -66,9 +66,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
#(#pre_init_stmts)*
- #call_init
+ #[inline(never)]
+ fn __rtic_init_resources<F>(f: F) where F: FnOnce() {
+ f();
+ }
+
+ // Wrap late_init_stmts in a function to ensure that stack space is reclaimed.
+ __rtic_init_resources(||{
+ #call_init
- #(#post_init_stmts)*
+ #(#post_init_stmts)*
+ });
#call_idle
}
@@ -111,7 +119,15 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
);
let user_imports = &app.user_imports;
+ let default_monotonic = if monotonic.args.default {
+ quote!(pub use #name::now;)
+ } else {
+ quote!()
+ };
+
quote! {
+ #default_monotonic
+
#[doc = #doc]
#[allow(non_snake_case)]
pub mod #name {
@@ -147,6 +163,11 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
/// Holds static methods for each monotonic.
pub mod monotonics {
+ #(
+ #[allow(unused_imports)]
+ #user_imports
+ )*
+
#(#monotonic_parts)*
}
)