replace cortex_m::interrupt::Mutex with critical_section::Mutex in examples (#422)

This commit is contained in:
Wilfried Chauveau 2022-08-21 19:00:57 +01:00 committed by GitHub
parent 735597b145
commit 51db37a4cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 18 deletions

View file

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- `rp2040-e5` feature enabling the workaround for errata 5 on the USB device peripheral.
- Support for critical-section 1.0.0 in the examples.
### Changed

View file

@ -37,6 +37,7 @@ embedded-graphics = "0.7.1"
hd44780-driver = "0.4.0"
pio = "0.2.0"
pio-proc = "0.2.1"
critical-section = "1.0.0"
defmt = "0.3.0"
defmt-rtt = "0.3.0"

View file

@ -49,7 +49,7 @@ use pac::interrupt;
// Some short-cuts to useful types
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;
use critical_section::Mutex;
use heapless::spsc::Queue;
/// Import the GPIO pins we use
@ -148,7 +148,7 @@ fn main() -> ! {
// Now we give away the entire UART peripheral, via the variable
// `GLOBAL_UART`. We can no longer access the UART from this main thread.
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
GLOBAL_UART.borrow(cs).replace(Some(uart));
});
@ -180,7 +180,7 @@ fn main() -> ! {
impl UartQueue {
/// Try and get some data out of the UART Queue. Returns None if queue empty.
fn read_byte(&self) -> Option<u8> {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
let cell_queue = self.mutex_cell_queue.borrow(cs);
let mut queue = cell_queue.borrow_mut();
queue.dequeue()
@ -189,7 +189,7 @@ impl UartQueue {
/// Peek at the next byte in the queue without removing it.
fn peek_byte(&self) -> Option<u8> {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
let cell_queue = self.mutex_cell_queue.borrow(cs);
let queue = cell_queue.borrow_mut();
queue.peek().cloned()
@ -208,7 +208,7 @@ impl UartQueue {
// Grab the mutex, by turning interrupts off. NOTE: This
// doesn't work if you are using Core 1 as we only turn
// interrupts off on one core.
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
// Grab the mutex contents.
let cell_queue = self.mutex_cell_queue.borrow(cs);
// Grab mutable access to the queue. This can't fail
@ -262,7 +262,7 @@ fn UART0_IRQ() {
// This is one-time lazy initialisation. We steal the variable given to us
// via `GLOBAL_UART`.
if UART.is_none() {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
*UART = GLOBAL_UART.borrow(cs).take();
});
}

View file

@ -47,7 +47,7 @@ use hal::pac::interrupt;
// Some short-cuts to useful types
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;
use critical_section::Mutex;
/// Import the GPIO pins we use
use hal::gpio::pin::bank0::{Gpio0, Gpio1};
@ -142,7 +142,7 @@ fn main() -> ! {
// Now we give away the entire UART peripheral, via the variable
// `GLOBAL_UART`. We can no longer access the UART from this main thread.
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
GLOBAL_UART.borrow(cs).replace(Some(uart));
});
@ -177,7 +177,7 @@ fn UART0_IRQ() {
// This is one-time lazy initialisation. We steal the variable given to us
// via `GLOBAL_UART`.
if UART.is_none() {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
*UART = GLOBAL_UART.borrow(cs).take();
});
}

View file

@ -168,7 +168,7 @@ fn main() -> ! {
///
/// We do this with interrupts disabled, to avoid a race hazard with the USB IRQ.
fn push_mouse_movement(report: MouseReport) -> Result<usize, usb_device::UsbError> {
cortex_m::interrupt::free(|_| unsafe {
critical_section::with(|_| unsafe {
// Now interrupts are disabled, grab the global variable and, if
// available, send it a HID report
USB_HID.as_mut().map(|hid| hid.push_input(&report))

View file

@ -44,7 +44,7 @@ use hal::pac::interrupt;
// Some short-cuts to useful types
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;
use critical_section::Mutex;
use rp2040_hal::gpio;
// The GPIO interrupt type we're going to generate
@ -133,7 +133,7 @@ fn main() -> ! {
// Give away our pins by moving them into the `GLOBAL_PINS` variable.
// We won't need to access them in the main thread again
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
GLOBAL_PINS.borrow(cs).replace(Some((led, in_pin)));
});
@ -159,7 +159,7 @@ fn IO_IRQ_BANK0() {
// This is one-time lazy initialisation. We steal the variables given to us
// via `GLOBAL_PINS`.
if LED_AND_BUTTON.is_none() {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
*LED_AND_BUTTON = GLOBAL_PINS.borrow(cs).take();
});
}

View file

@ -23,7 +23,7 @@ use hal::pac;
// Some traits we need
use core::cell::RefCell;
use cortex_m::interrupt::Mutex;
use critical_section::Mutex;
use embedded_hal::digital::v2::ToggleableOutputPin;
use embedded_time::duration::Microseconds;
use embedded_time::fixed_point::FixedPoint;
@ -113,7 +113,7 @@ fn main() -> ! {
let led_pin = pins.gpio25.into_push_pull_output();
let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS);
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
let mut alarm = timer.alarm_0().unwrap();
// Schedule an alarm in 1 second
let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US));
@ -132,7 +132,7 @@ fn main() -> ! {
// After 5 seconds, switch to our modified vector rable
delay.delay_ms(5000);
unsafe {
cortex_m::interrupt::free(|_| {
critical_section::with(|_| {
RAM_VTABLE.activate(ppb);
});
}
@ -147,7 +147,7 @@ fn main() -> ! {
// that this interrupt entry ends up in the vector table.
#[interrupt]
fn TIMER_IRQ_0() {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
// Temporarily take our LED_AND_ALARM
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
if let Some((mut led, mut alarm)) = ledalarm {
@ -169,7 +169,7 @@ fn TIMER_IRQ_0() {
// This is the function we will use to replace TIMER_IRQ_0 in our RAM Vector Table
extern "C" fn timer_irq0_replacement() {
cortex_m::interrupt::free(|cs| {
critical_section::with(|cs| {
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
if let Some((mut led, mut alarm)) = ledalarm {
// Clear the alarm interrupt or this interrupt service routine will keep firing