|
| 1 | +#![no_main] |
| 2 | +#![no_std] |
| 3 | + |
| 4 | +use panic_semihosting as _; |
| 5 | + |
| 6 | +#[rtic::app(device = lm3s6965, dispatchers = [GPIOA, GPIOB])] |
| 7 | +mod app { |
| 8 | + use core::sync::atomic::{AtomicBool, Ordering}; |
| 9 | + |
| 10 | + use cortex_m_semihosting::{debug, hprintln}; |
| 11 | + use rtic_actor_traits::Receive; |
| 12 | + |
| 13 | + struct A; |
| 14 | + struct B; |
| 15 | + |
| 16 | + #[derive(Default)] |
| 17 | + struct M { |
| 18 | + must_not_be_cloned: bool, |
| 19 | + } |
| 20 | + |
| 21 | + impl Clone for M { |
| 22 | + fn clone(&self) -> Self { |
| 23 | + assert!(!self.must_not_be_cloned); |
| 24 | + M { |
| 25 | + must_not_be_cloned: self.must_not_be_cloned, |
| 26 | + } |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + impl Receive<M> for A { |
| 31 | + fn receive(&mut self, _: M) { |
| 32 | + static WAS_CALLED_EXACTLY_ONCE: AtomicBool = AtomicBool::new(false); |
| 33 | + hprintln!("A::receive was called").ok(); |
| 34 | + assert!(!WAS_CALLED_EXACTLY_ONCE.load(Ordering::Relaxed)); |
| 35 | + WAS_CALLED_EXACTLY_ONCE.store(true, Ordering::Relaxed); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + impl Receive<M> for B { |
| 40 | + fn receive(&mut self, _: M) { |
| 41 | + static WAS_CALLED_EXACTLY_ONCE: AtomicBool = AtomicBool::new(false); |
| 42 | + hprintln!("B::receive was called").ok(); |
| 43 | + assert!(!WAS_CALLED_EXACTLY_ONCE.load(Ordering::Relaxed)); |
| 44 | + WAS_CALLED_EXACTLY_ONCE.store(true, Ordering::Relaxed); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + #[actors] |
| 49 | + struct Actors { |
| 50 | + #[subscribe(M, capacity = 2)] |
| 51 | + #[init(A)] |
| 52 | + a: A, |
| 53 | + |
| 54 | + #[subscribe(M, capacity = 1)] |
| 55 | + #[init(B)] |
| 56 | + b: B, |
| 57 | + } |
| 58 | + |
| 59 | + #[init] |
| 60 | + fn init(cx: init::Context) -> (Shared, Local, init::Monotonics, Actors) { |
| 61 | + let mut poster = cx.poster; |
| 62 | + assert!(poster.post(M::default()).is_ok()); |
| 63 | + |
| 64 | + // B's message queue is full so message must NOT be cloned |
| 65 | + // this must also NOT trigger task A even if it has capacity |
| 66 | + assert!(poster |
| 67 | + .post(M { |
| 68 | + must_not_be_cloned: true |
| 69 | + }) |
| 70 | + .is_err()); |
| 71 | + |
| 72 | + (Shared {}, Local {}, init::Monotonics(), Actors {}) |
| 73 | + } |
| 74 | + |
| 75 | + #[idle] |
| 76 | + fn idle(_: idle::Context) -> ! { |
| 77 | + loop { |
| 78 | + debug::exit(debug::EXIT_SUCCESS) |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + #[local] |
| 83 | + struct Local {} |
| 84 | + |
| 85 | + #[shared] |
| 86 | + struct Shared {} |
| 87 | +} |
0 commit comments