interrupt on DMA1_CHANNEL4
This commit is contained in:
parent
415e6583a2
commit
20cdf7b6a6
1 changed files with 32 additions and 18 deletions
|
@ -31,14 +31,14 @@ mod app {
|
||||||
struct Shared {
|
struct Shared {
|
||||||
buffer: &'static mut [u8],
|
buffer: &'static mut [u8],
|
||||||
delay_us: timer::DelayUs<pac::TIM2>,
|
delay_us: timer::DelayUs<pac::TIM2>,
|
||||||
|
dmx: DMX<DMX_LEN>,
|
||||||
|
int_led: gpio::gpiob::PB0<gpio::Output<gpio::OpenDrain>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[local]
|
#[local]
|
||||||
struct Local {
|
struct Local {
|
||||||
dmx: DMX<DMX_LEN>,
|
|
||||||
led: gpio::gpioc::PC13<gpio::Output<gpio::PushPull>>,
|
led: gpio::gpioc::PC13<gpio::Output<gpio::PushPull>>,
|
||||||
int_pin: gpio::gpiob::PB10<gpio::Input<gpio::PullUp>>,
|
int_pin: gpio::gpiob::PB10<gpio::Input<gpio::PullUp>>,
|
||||||
int_led: gpio::gpiob::PB0<gpio::Output<gpio::OpenDrain>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
|
@ -67,7 +67,7 @@ mod app {
|
||||||
let mut gpioc = cx.device.GPIOC.split();
|
let mut gpioc = cx.device.GPIOC.split();
|
||||||
|
|
||||||
let mut afio = cx.device.AFIO.constrain();
|
let mut afio = cx.device.AFIO.constrain();
|
||||||
let dma1 = cx.device.DMA1.split();
|
let mut dma1 = cx.device.DMA1.split();
|
||||||
|
|
||||||
// setup EXTI10 for Pin B10
|
// setup EXTI10 for Pin B10
|
||||||
let mut int_pin = gpiob.pb10.into_pull_up_input(&mut gpiob.crh);
|
let mut int_pin = gpiob.pb10.into_pull_up_input(&mut gpiob.crh);
|
||||||
|
@ -76,6 +76,10 @@ mod app {
|
||||||
int_pin.trigger_on_edge(&mut cx.device.EXTI, gpio::Edge::Falling);
|
int_pin.trigger_on_edge(&mut cx.device.EXTI, gpio::Edge::Falling);
|
||||||
unsafe { cx.core.NVIC.set_priority(pac::Interrupt::EXTI15_10, 1) }; // EXTI10 priority
|
unsafe { cx.core.NVIC.set_priority(pac::Interrupt::EXTI15_10, 1) }; // EXTI10 priority
|
||||||
|
|
||||||
|
// setup DMA1_CHANNEL4 interrupt on TransferComplete
|
||||||
|
dma1.4.listen(stm32f1xx_hal::dma::Event::TransferComplete);
|
||||||
|
unsafe { cx.core.NVIC.set_priority(pac::Interrupt::DMA1_CHANNEL4, 1) };
|
||||||
|
|
||||||
// Serial config
|
// Serial config
|
||||||
let serial = serial::Serial::new(
|
let serial = serial::Serial::new(
|
||||||
cx.device.USART1,
|
cx.device.USART1,
|
||||||
|
@ -88,7 +92,7 @@ mod app {
|
||||||
&clocks,
|
&clocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
foo::spawn().unwrap();
|
sender::spawn().unwrap();
|
||||||
|
|
||||||
(
|
(
|
||||||
Shared {
|
Shared {
|
||||||
|
@ -96,10 +100,14 @@ mod app {
|
||||||
|
|
||||||
// Configure timer
|
// Configure timer
|
||||||
delay_us: cx.device.TIM2.delay_us(&clocks),
|
delay_us: cx.device.TIM2.delay_us(&clocks),
|
||||||
},
|
|
||||||
Local {
|
|
||||||
dmx: DMX::new(serial, dma1.4, &clocks),
|
dmx: DMX::new(serial, dma1.4, &clocks),
|
||||||
|
|
||||||
|
int_led: gpiob
|
||||||
|
.pb0
|
||||||
|
.into_open_drain_output_with_state(&mut gpiob.crl, gpio::PinState::Low),
|
||||||
|
},
|
||||||
|
Local {
|
||||||
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
|
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
|
||||||
// in order to configure the port. For pins 0-7, crl should be passed instead.
|
// in order to configure the port. For pins 0-7, crl should be passed instead.
|
||||||
led: gpioc
|
led: gpioc
|
||||||
|
@ -107,9 +115,6 @@ mod app {
|
||||||
.into_push_pull_output_with_state(&mut gpioc.crh, gpio::PinState::High),
|
.into_push_pull_output_with_state(&mut gpioc.crh, gpio::PinState::High),
|
||||||
|
|
||||||
int_pin: int_pin,
|
int_pin: int_pin,
|
||||||
int_led: gpiob
|
|
||||||
.pb0
|
|
||||||
.into_open_drain_output_with_state(&mut gpiob.crl, gpio::PinState::Low),
|
|
||||||
},
|
},
|
||||||
init::Monotonics(mono),
|
init::Monotonics(mono),
|
||||||
)
|
)
|
||||||
|
@ -122,21 +127,30 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [dmx, led], shared = [&buffer, delay_us])]
|
#[task(local = [led], shared = [&buffer, delay_us, dmx])]
|
||||||
fn foo(mut cx: foo::Context) {
|
fn sender(mut cx: sender::Context) {
|
||||||
cx.local.dmx.send(cx.shared.buffer);
|
cx.shared.dmx.lock(|dmx| dmx.send(cx.shared.buffer));
|
||||||
|
|
||||||
cx.local.led.toggle();
|
cx.local.led.toggle();
|
||||||
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
|
cx.shared.delay_us.lock(|d| d.delay(1.secs()));
|
||||||
|
|
||||||
// cx.local.dmx.wait();
|
sender::spawn().unwrap();
|
||||||
foo::spawn().unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = EXTI15_10, local = [int_pin, int_led], shared = [delay_us])]
|
#[task(binds = DMA1_CHANNEL4, shared = [dmx, int_led])]
|
||||||
fn bar(mut cx: bar::Context) {
|
fn waiter(cx: waiter::Context) {
|
||||||
cx.local.int_led.toggle();
|
(cx.shared.dmx, cx.shared.int_led).lock(|dmx, int_led| {
|
||||||
cx.shared.delay_us.lock(|d| d.delay(100.millis()));
|
dmx.wait();
|
||||||
|
int_led.toggle();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[task(binds = EXTI15_10, local = [int_pin], shared = [delay_us, int_led])]
|
||||||
|
fn toggler(cx: toggler::Context) {
|
||||||
|
(cx.shared.delay_us, cx.shared.int_led).lock(|delay_us, int_led| {
|
||||||
|
int_led.toggle();
|
||||||
|
delay_us.delay(100.millis());
|
||||||
|
});
|
||||||
|
|
||||||
// clear EXTI10 pending status
|
// clear EXTI10 pending status
|
||||||
cx.local.int_pin.clear_interrupt_pending_bit()
|
cx.local.int_pin.clear_interrupt_pending_bit()
|
||||||
|
|
Loading…
Reference in a new issue