rtic/examples/lockall_cost.rs

68 lines
2 KiB
Rust
Raw Normal View History

2021-10-25 10:02:59 +02:00
//! examples/lockall_cost.rs
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965)]
mod app {
#[shared]
struct Shared {
shared: u32,
}
#[local]
struct Local {}
#[init]
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
2021-10-26 20:04:07 +02:00
use cortex_m_semihosting::debug;
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
2021-10-25 10:02:59 +02:00
(Shared { shared: 0 }, Local {}, init::Monotonics())
}
2021-10-25 10:58:58 +02:00
#[task(binds = GPIOA, shared = [shared])]
fn low(mut cx: low::Context) {
2021-10-25 10:02:59 +02:00
cx.shared.lock(|x| *x.shared += 1);
}
2021-11-03 16:10:10 +01:00
// #[task(binds = GPIOB, priority = 2, shared = [shared])]
// fn high(mut cx: high::Context) {
// cx.shared.lock(|x| *x.shared += 1);
// }
2021-10-25 10:02:59 +02:00
}
// cargo objdump --example lockall_cost --target thumbv7m-none-eabi --release --features inline-asm -- --disassemble > lockall_cost.ojbdump
//
2021-10-25 10:58:58 +02:00
// Zero-Cost implementations:
// 0000016c <GPIOA>:
2021-10-25 10:02:59 +02:00
// 16c: 80 b5 push {r7, lr}
// 16e: 6f 46 mov r7, sp
2021-10-25 10:58:58 +02:00
// 170: c0 20 movs r0, #192
// 172: 80 f3 11 88 msr basepri, r0
// 176: 40 f2 00 00 movw r0, #0
// 17a: c2 f2 00 00 movt r0, #8192
// 17e: 01 68 ldr r1, [r0]
// 180: 01 31 adds r1, #1
// 182: 01 60 str r1, [r0]
// 184: e0 20 movs r0, #224
// 186: 80 f3 11 88 msr basepri, r0
// 18a: 00 20 movs r0, #0
// 18c: 80 f3 11 88 msr basepri, r0
// 190: 80 bd pop {r7, pc}
2021-10-25 10:02:59 +02:00
2021-10-25 10:58:58 +02:00
// 00000192 <GPIOB>:
// 192: 80 b5 push {r7, lr}
// 194: 6f 46 mov r7, sp
// 196: 40 f2 00 01 movw r1, #0
// 19a: ef f3 11 80 mrs r0, basepri
// 19e: c2 f2 00 01 movt r1, #8192
// 1a2: 0a 68 ldr r2, [r1]
// 1a4: 01 32 adds r2, #1
// 1a6: 0a 60 str r2, [r1]
// 1a8: 80 f3 11 88 msr basepri, r0
// 1ac: 80 bd pop {r7, pc}