mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-23 12:41:31 +11:00
replace cortex_m::interrupt::Mutex with critical_section::Mutex in examples (#422)
This commit is contained in:
parent
735597b145
commit
51db37a4cb
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
- `rp2040-e5` feature enabling the workaround for errata 5 on the USB device peripheral.
|
- `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
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ embedded-graphics = "0.7.1"
|
||||||
hd44780-driver = "0.4.0"
|
hd44780-driver = "0.4.0"
|
||||||
pio = "0.2.0"
|
pio = "0.2.0"
|
||||||
pio-proc = "0.2.1"
|
pio-proc = "0.2.1"
|
||||||
|
critical-section = "1.0.0"
|
||||||
|
|
||||||
defmt = "0.3.0"
|
defmt = "0.3.0"
|
||||||
defmt-rtt = "0.3.0"
|
defmt-rtt = "0.3.0"
|
||||||
|
|
|
@ -49,7 +49,7 @@ use pac::interrupt;
|
||||||
|
|
||||||
// Some short-cuts to useful types
|
// Some short-cuts to useful types
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use cortex_m::interrupt::Mutex;
|
use critical_section::Mutex;
|
||||||
use heapless::spsc::Queue;
|
use heapless::spsc::Queue;
|
||||||
|
|
||||||
/// Import the GPIO pins we use
|
/// Import the GPIO pins we use
|
||||||
|
@ -148,7 +148,7 @@ fn main() -> ! {
|
||||||
|
|
||||||
// Now we give away the entire UART peripheral, via the variable
|
// Now we give away the entire UART peripheral, via the variable
|
||||||
// `GLOBAL_UART`. We can no longer access the UART from this main thread.
|
// `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));
|
GLOBAL_UART.borrow(cs).replace(Some(uart));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -180,7 +180,7 @@ fn main() -> ! {
|
||||||
impl UartQueue {
|
impl UartQueue {
|
||||||
/// Try and get some data out of the UART Queue. Returns None if queue empty.
|
/// Try and get some data out of the UART Queue. Returns None if queue empty.
|
||||||
fn read_byte(&self) -> Option<u8> {
|
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 cell_queue = self.mutex_cell_queue.borrow(cs);
|
||||||
let mut queue = cell_queue.borrow_mut();
|
let mut queue = cell_queue.borrow_mut();
|
||||||
queue.dequeue()
|
queue.dequeue()
|
||||||
|
@ -189,7 +189,7 @@ impl UartQueue {
|
||||||
|
|
||||||
/// Peek at the next byte in the queue without removing it.
|
/// Peek at the next byte in the queue without removing it.
|
||||||
fn peek_byte(&self) -> Option<u8> {
|
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 cell_queue = self.mutex_cell_queue.borrow(cs);
|
||||||
let queue = cell_queue.borrow_mut();
|
let queue = cell_queue.borrow_mut();
|
||||||
queue.peek().cloned()
|
queue.peek().cloned()
|
||||||
|
@ -208,7 +208,7 @@ impl UartQueue {
|
||||||
// Grab the mutex, by turning interrupts off. NOTE: This
|
// Grab the mutex, by turning interrupts off. NOTE: This
|
||||||
// doesn't work if you are using Core 1 as we only turn
|
// doesn't work if you are using Core 1 as we only turn
|
||||||
// interrupts off on one core.
|
// interrupts off on one core.
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
// Grab the mutex contents.
|
// Grab the mutex contents.
|
||||||
let cell_queue = self.mutex_cell_queue.borrow(cs);
|
let cell_queue = self.mutex_cell_queue.borrow(cs);
|
||||||
// Grab mutable access to the queue. This can't fail
|
// 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
|
// This is one-time lazy initialisation. We steal the variable given to us
|
||||||
// via `GLOBAL_UART`.
|
// via `GLOBAL_UART`.
|
||||||
if UART.is_none() {
|
if UART.is_none() {
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
*UART = GLOBAL_UART.borrow(cs).take();
|
*UART = GLOBAL_UART.borrow(cs).take();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ use hal::pac::interrupt;
|
||||||
|
|
||||||
// Some short-cuts to useful types
|
// Some short-cuts to useful types
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use cortex_m::interrupt::Mutex;
|
use critical_section::Mutex;
|
||||||
|
|
||||||
/// Import the GPIO pins we use
|
/// Import the GPIO pins we use
|
||||||
use hal::gpio::pin::bank0::{Gpio0, Gpio1};
|
use hal::gpio::pin::bank0::{Gpio0, Gpio1};
|
||||||
|
@ -142,7 +142,7 @@ fn main() -> ! {
|
||||||
|
|
||||||
// Now we give away the entire UART peripheral, via the variable
|
// Now we give away the entire UART peripheral, via the variable
|
||||||
// `GLOBAL_UART`. We can no longer access the UART from this main thread.
|
// `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));
|
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
|
// This is one-time lazy initialisation. We steal the variable given to us
|
||||||
// via `GLOBAL_UART`.
|
// via `GLOBAL_UART`.
|
||||||
if UART.is_none() {
|
if UART.is_none() {
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
*UART = GLOBAL_UART.borrow(cs).take();
|
*UART = GLOBAL_UART.borrow(cs).take();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,7 +168,7 @@ fn main() -> ! {
|
||||||
///
|
///
|
||||||
/// We do this with interrupts disabled, to avoid a race hazard with the USB IRQ.
|
/// 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> {
|
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
|
// Now interrupts are disabled, grab the global variable and, if
|
||||||
// available, send it a HID report
|
// available, send it a HID report
|
||||||
USB_HID.as_mut().map(|hid| hid.push_input(&report))
|
USB_HID.as_mut().map(|hid| hid.push_input(&report))
|
||||||
|
|
|
@ -44,7 +44,7 @@ use hal::pac::interrupt;
|
||||||
|
|
||||||
// Some short-cuts to useful types
|
// Some short-cuts to useful types
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use cortex_m::interrupt::Mutex;
|
use critical_section::Mutex;
|
||||||
use rp2040_hal::gpio;
|
use rp2040_hal::gpio;
|
||||||
|
|
||||||
// The GPIO interrupt type we're going to generate
|
// 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.
|
// Give away our pins by moving them into the `GLOBAL_PINS` variable.
|
||||||
// We won't need to access them in the main thread again
|
// 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)));
|
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
|
// This is one-time lazy initialisation. We steal the variables given to us
|
||||||
// via `GLOBAL_PINS`.
|
// via `GLOBAL_PINS`.
|
||||||
if LED_AND_BUTTON.is_none() {
|
if LED_AND_BUTTON.is_none() {
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
*LED_AND_BUTTON = GLOBAL_PINS.borrow(cs).take();
|
*LED_AND_BUTTON = GLOBAL_PINS.borrow(cs).take();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ use hal::pac;
|
||||||
|
|
||||||
// Some traits we need
|
// Some traits we need
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
use cortex_m::interrupt::Mutex;
|
use critical_section::Mutex;
|
||||||
use embedded_hal::digital::v2::ToggleableOutputPin;
|
use embedded_hal::digital::v2::ToggleableOutputPin;
|
||||||
use embedded_time::duration::Microseconds;
|
use embedded_time::duration::Microseconds;
|
||||||
use embedded_time::fixed_point::FixedPoint;
|
use embedded_time::fixed_point::FixedPoint;
|
||||||
|
@ -113,7 +113,7 @@ fn main() -> ! {
|
||||||
let led_pin = pins.gpio25.into_push_pull_output();
|
let led_pin = pins.gpio25.into_push_pull_output();
|
||||||
|
|
||||||
let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS);
|
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();
|
let mut alarm = timer.alarm_0().unwrap();
|
||||||
// Schedule an alarm in 1 second
|
// Schedule an alarm in 1 second
|
||||||
let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US));
|
let _ = alarm.schedule(Microseconds(SLOW_BLINK_INTERVAL_US));
|
||||||
|
@ -132,7 +132,7 @@ fn main() -> ! {
|
||||||
// After 5 seconds, switch to our modified vector rable
|
// After 5 seconds, switch to our modified vector rable
|
||||||
delay.delay_ms(5000);
|
delay.delay_ms(5000);
|
||||||
unsafe {
|
unsafe {
|
||||||
cortex_m::interrupt::free(|_| {
|
critical_section::with(|_| {
|
||||||
RAM_VTABLE.activate(ppb);
|
RAM_VTABLE.activate(ppb);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ fn main() -> ! {
|
||||||
// that this interrupt entry ends up in the vector table.
|
// that this interrupt entry ends up in the vector table.
|
||||||
#[interrupt]
|
#[interrupt]
|
||||||
fn TIMER_IRQ_0() {
|
fn TIMER_IRQ_0() {
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
// Temporarily take our LED_AND_ALARM
|
// Temporarily take our LED_AND_ALARM
|
||||||
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
|
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
|
||||||
if let Some((mut led, mut alarm)) = ledalarm {
|
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
|
// This is the function we will use to replace TIMER_IRQ_0 in our RAM Vector Table
|
||||||
extern "C" fn timer_irq0_replacement() {
|
extern "C" fn timer_irq0_replacement() {
|
||||||
cortex_m::interrupt::free(|cs| {
|
critical_section::with(|cs| {
|
||||||
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
|
let ledalarm = unsafe { LED_AND_ALARM.borrow(cs).take() };
|
||||||
if let Some((mut led, mut alarm)) = ledalarm {
|
if let Some((mut led, mut alarm)) = ledalarm {
|
||||||
// Clear the alarm interrupt or this interrupt service routine will keep firing
|
// Clear the alarm interrupt or this interrupt service routine will keep firing
|
||||||
|
|
Loading…
Reference in a new issue