diff options
Diffstat (limited to 'tests/stm32/src/bin/hsem.rs')
| -rw-r--r-- | tests/stm32/src/bin/hsem.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/hsem.rs b/tests/stm32/src/bin/hsem.rs new file mode 100644 index 000000000..fa69f22b2 --- /dev/null +++ b/tests/stm32/src/bin/hsem.rs | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | // required-features: hsem | ||
| 2 | #![no_std] | ||
| 3 | #![no_main] | ||
| 4 | |||
| 5 | #[path = "../common.rs"] | ||
| 6 | mod common; | ||
| 7 | |||
| 8 | use common::*; | ||
| 9 | use embassy_executor::Spawner; | ||
| 10 | use embassy_stm32::bind_interrupts; | ||
| 11 | use embassy_stm32::hsem::{HardwareSemaphore, HardwareSemaphoreInterruptHandler}; | ||
| 12 | use embassy_stm32::peripherals::HSEM; | ||
| 13 | |||
| 14 | bind_interrupts!(struct Irqs{ | ||
| 15 | HSEM => HardwareSemaphoreInterruptHandler<HSEM>; | ||
| 16 | }); | ||
| 17 | |||
| 18 | #[embassy_executor::main] | ||
| 19 | async fn main(_spawner: Spawner) { | ||
| 20 | let p: embassy_stm32::Peripherals = init(); | ||
| 21 | |||
| 22 | let hsem = HardwareSemaphore::new(p.HSEM, Irqs); | ||
| 23 | |||
| 24 | // if hsem.channel_for(SemaphoreNumber::Channel5).is_semaphore_locked() { | ||
| 25 | // defmt::panic!("Semaphore 5 already locked!") | ||
| 26 | // } | ||
| 27 | // | ||
| 28 | // hsem.channel_for(SemaphoreNumber::Channel5).one_step_lock().unwrap(); | ||
| 29 | // hsem.channel_for(SemaphoreNumber::Channel1).two_step_lock(0).unwrap(); | ||
| 30 | // | ||
| 31 | // hsem.channel_for(SemaphoreNumber::Channel5).unlock(0); | ||
| 32 | |||
| 33 | #[cfg(feature = "stm32wb55rg")] | ||
| 34 | let [_channel1, _channel2, mut channel5, _channel6] = hsem.split(); | ||
| 35 | #[cfg(not(feature = "stm32wb55rg"))] | ||
| 36 | let [_channel1, _channel2, _channel3, _channel4, mut channel5, _channel6] = hsem.split(); | ||
| 37 | |||
| 38 | info!("Locking channel 5"); | ||
| 39 | |||
| 40 | let mutex = channel5.lock(0).await; | ||
| 41 | |||
| 42 | info!("Locked channel 5"); | ||
| 43 | |||
| 44 | drop(mutex); | ||
| 45 | |||
| 46 | info!("Unlocked channel 5"); | ||
| 47 | |||
| 48 | info!("Test OK"); | ||
| 49 | cortex_m::asm::bkpt(); | ||
| 50 | } | ||
