From 9a4f97ca5ebf19e6612115db5c763d0d61dd28a1 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Sat, 7 Jan 2023 17:59:39 +0100 Subject: more examples --- examples/big-struct-opt.rs | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'examples/big-struct-opt.rs') diff --git a/examples/big-struct-opt.rs b/examples/big-struct-opt.rs index bbc2535..4bf93b2 100644 --- a/examples/big-struct-opt.rs +++ b/examples/big-struct-opt.rs @@ -5,6 +5,7 @@ #![no_main] #![no_std] +#![feature(type_alias_impl_trait)] use panic_semihosting as _; @@ -20,11 +21,12 @@ impl BigStruct { } } -#[rtic::app(device = lm3s6965)] +#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] mod app { use super::BigStruct; use core::mem::MaybeUninit; - use cortex_m_semihosting::debug; + use cortex_m_semihosting::{debug, hprintln}; + use lm3s6965::Interrupt; #[shared] struct Shared { @@ -35,25 +37,43 @@ mod app { struct Local {} #[init(local = [bs: MaybeUninit = MaybeUninit::uninit()])] - fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) { + fn init(cx: init::Context) -> (Shared, Local) { let big_struct = unsafe { // write directly into the static storage cx.local.bs.as_mut_ptr().write(BigStruct::new()); &mut *cx.local.bs.as_mut_ptr() }; - debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator - + rtic::pend(Interrupt::UART0); + async_task::spawn().unwrap(); ( Shared { // assign the reference so we can use the resource big_struct, }, Local {}, - init::Monotonics(), ) } + #[idle] + fn idle(_: idle::Context) -> ! { + loop { + hprintln!("idle"); + debug::exit(debug::EXIT_SUCCESS); + } + } + #[task(binds = UART0, shared = [big_struct])] - fn task(_: task::Context) {} + fn uart0(mut cx: uart0::Context) { + cx.shared + .big_struct + .lock(|b| hprintln!("uart0 data:{:?}", &b.data[0..5]).unwrap()); + } + + #[task(shared = [big_struct], priority = 2)] + async fn async_task(mut cx: async_task::Context) { + cx.shared + .big_struct + .lock(|b| hprintln!("async_task data:{:?}", &b.data[0..5]).unwrap()); + } } -- cgit v1.2.3 From ceaf3613d3256f60b139a4f93220e3c298603b83 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 8 Jan 2023 19:40:31 +0100 Subject: Update semihosting --- examples/big-struct-opt.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'examples/big-struct-opt.rs') diff --git a/examples/big-struct-opt.rs b/examples/big-struct-opt.rs index 4bf93b2..3100a0e 100644 --- a/examples/big-struct-opt.rs +++ b/examples/big-struct-opt.rs @@ -67,13 +67,13 @@ mod app { fn uart0(mut cx: uart0::Context) { cx.shared .big_struct - .lock(|b| hprintln!("uart0 data:{:?}", &b.data[0..5]).unwrap()); + .lock(|b| hprintln!("uart0 data:{:?}", &b.data[0..5])); } #[task(shared = [big_struct], priority = 2)] async fn async_task(mut cx: async_task::Context) { cx.shared .big_struct - .lock(|b| hprintln!("async_task data:{:?}", &b.data[0..5]).unwrap()); + .lock(|b| hprintln!("async_task data:{:?}", &b.data[0..5])); } } -- cgit v1.2.3 From b8b881f446a226d6f3c4a7db7c9174590b47dbf6 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 19 Jan 2023 13:56:59 +0100 Subject: Fix so deny(missing_docs) work --- examples/big-struct-opt.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'examples/big-struct-opt.rs') diff --git a/examples/big-struct-opt.rs b/examples/big-struct-opt.rs index 3100a0e..408a2de 100644 --- a/examples/big-struct-opt.rs +++ b/examples/big-struct-opt.rs @@ -6,6 +6,7 @@ #![no_main] #![no_std] #![feature(type_alias_impl_trait)] +#![deny(missing_docs)] use panic_semihosting as _; -- cgit v1.2.3 From 306aa47170fd59369b7a184924e287dc3706d64d Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 23 Jan 2023 20:05:47 +0100 Subject: Add rtic-timer (timerqueue + monotonic) and rtic-monotonics (systick-monotonic) --- examples/big-struct-opt.rs | 80 ---------------------------------------------- 1 file changed, 80 deletions(-) delete mode 100644 examples/big-struct-opt.rs (limited to 'examples/big-struct-opt.rs') diff --git a/examples/big-struct-opt.rs b/examples/big-struct-opt.rs deleted file mode 100644 index 408a2de..0000000 --- a/examples/big-struct-opt.rs +++ /dev/null @@ -1,80 +0,0 @@ -//! examples/big-struct-opt.rs -//! -//! Example on how to initialize a large struct without needing to copy it via `LateResources`, -//! effectively saving stack space needed for the copies. - -#![no_main] -#![no_std] -#![feature(type_alias_impl_trait)] -#![deny(missing_docs)] - -use panic_semihosting as _; - -/// Some big struct -pub struct BigStruct { - /// Big content - pub data: [u8; 2048], -} - -impl BigStruct { - fn new() -> Self { - BigStruct { data: [22; 2048] } - } -} - -#[rtic::app(device = lm3s6965, dispatchers = [SSI0])] -mod app { - use super::BigStruct; - use core::mem::MaybeUninit; - use cortex_m_semihosting::{debug, hprintln}; - use lm3s6965::Interrupt; - - #[shared] - struct Shared { - big_struct: &'static mut BigStruct, - } - - #[local] - struct Local {} - - #[init(local = [bs: MaybeUninit = MaybeUninit::uninit()])] - fn init(cx: init::Context) -> (Shared, Local) { - let big_struct = unsafe { - // write directly into the static storage - cx.local.bs.as_mut_ptr().write(BigStruct::new()); - &mut *cx.local.bs.as_mut_ptr() - }; - - rtic::pend(Interrupt::UART0); - async_task::spawn().unwrap(); - ( - Shared { - // assign the reference so we can use the resource - big_struct, - }, - Local {}, - ) - } - - #[idle] - fn idle(_: idle::Context) -> ! { - loop { - hprintln!("idle"); - debug::exit(debug::EXIT_SUCCESS); - } - } - - #[task(binds = UART0, shared = [big_struct])] - fn uart0(mut cx: uart0::Context) { - cx.shared - .big_struct - .lock(|b| hprintln!("uart0 data:{:?}", &b.data[0..5])); - } - - #[task(shared = [big_struct], priority = 2)] - async fn async_task(mut cx: async_task::Context) { - cx.shared - .big_struct - .lock(|b| hprintln!("async_task data:{:?}", &b.data[0..5])); - } -} -- cgit v1.2.3