aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src/bin/hsem.rs
blob: fa69f22b2ec45adc3e5d442772caec9d1858e12f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// required-features: hsem
#![no_std]
#![no_main]

#[path = "../common.rs"]
mod common;

use common::*;
use embassy_executor::Spawner;
use embassy_stm32::bind_interrupts;
use embassy_stm32::hsem::{HardwareSemaphore, HardwareSemaphoreInterruptHandler};
use embassy_stm32::peripherals::HSEM;

bind_interrupts!(struct Irqs{
    HSEM => HardwareSemaphoreInterruptHandler<HSEM>;
});

#[embassy_executor::main]
async fn main(_spawner: Spawner) {
    let p: embassy_stm32::Peripherals = init();

    let hsem = HardwareSemaphore::new(p.HSEM, Irqs);

    //    if hsem.channel_for(SemaphoreNumber::Channel5).is_semaphore_locked() {
    //        defmt::panic!("Semaphore 5 already locked!")
    //    }
    //
    //    hsem.channel_for(SemaphoreNumber::Channel5).one_step_lock().unwrap();
    //    hsem.channel_for(SemaphoreNumber::Channel1).two_step_lock(0).unwrap();
    //
    //    hsem.channel_for(SemaphoreNumber::Channel5).unlock(0);

    #[cfg(feature = "stm32wb55rg")]
    let [_channel1, _channel2, mut channel5, _channel6] = hsem.split();
    #[cfg(not(feature = "stm32wb55rg"))]
    let [_channel1, _channel2, _channel3, _channel4, mut channel5, _channel6] = hsem.split();

    info!("Locking channel 5");

    let mutex = channel5.lock(0).await;

    info!("Locked channel 5");

    drop(mutex);

    info!("Unlocked channel 5");

    info!("Test OK");
    cortex_m::asm::bkpt();
}