Skip to content

Commit c0920e5

Browse files
committed
fix: migrate to 2024 edition and fmt
1 parent 1e809d9 commit c0920e5

File tree

7 files changed

+70
-75
lines changed

7 files changed

+70
-75
lines changed

rtic/src/export/cortex_basepri.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use super::cortex_logical2hw;
22
use cortex_m::register::{basepri, basepri_max};
33
pub use cortex_m::{
4+
Peripherals,
45
asm::wfi,
56
interrupt,
6-
peripheral::{scb::SystemHandler, DWT, SCB, SYST},
7-
Peripherals,
7+
peripheral::{DWT, SCB, SYST, scb::SystemHandler},
88
};
99

1010
#[cfg(not(any(feature = "thumbv7-backend", feature = "thumbv8main-backend")))]
@@ -69,13 +69,15 @@ pub unsafe fn lock<T, R>(
6969
nvic_prio_bits: u8,
7070
f: impl FnOnce(&mut T) -> R,
7171
) -> R {
72-
if ceiling == (1 << nvic_prio_bits) {
73-
critical_section::with(|_| f(&mut *ptr))
74-
} else {
75-
let current = basepri::read();
76-
basepri_max::write(cortex_logical2hw(ceiling, nvic_prio_bits));
77-
let r = f(&mut *ptr);
78-
basepri::write(current);
79-
r
72+
unsafe {
73+
if ceiling == (1 << nvic_prio_bits) {
74+
critical_section::with(|_| f(&mut *ptr))
75+
} else {
76+
let current = basepri::read();
77+
basepri_max::write(cortex_logical2hw(ceiling, nvic_prio_bits));
78+
let r = f(&mut *ptr);
79+
basepri::write(current);
80+
r
81+
}
8082
}
8183
}

rtic/src/export/cortex_source_mask.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
pub use cortex_m::{
2+
Peripherals,
23
asm::wfi,
34
interrupt,
4-
peripheral::{scb::SystemHandler, DWT, NVIC, SCB, SYST},
5-
Peripherals,
5+
peripheral::{DWT, NVIC, SCB, SYST, scb::SystemHandler},
66
};
77

88
#[cfg(not(any(feature = "thumbv6-backend", feature = "thumbv8base-backend")))]
@@ -57,7 +57,9 @@ impl<const M: usize> Mask<M> {
5757
let block = bit / 32;
5858

5959
if block as usize >= M {
60-
panic!("Generating masks for thumbv6/thumbv8m.base failed! Are you compiling for thumbv6 on an thumbv7 MCU or using an unsupported thumbv8m.base MCU?");
60+
panic!(
61+
"Generating masks for thumbv6/thumbv8m.base failed! Are you compiling for thumbv6 on an thumbv7 MCU or using an unsupported thumbv8m.base MCU?"
62+
);
6163
}
6264

6365
let offset = bit - (block * 32);

rtic/src/export/executor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ unsafe fn waker_clone(p: *const ()) -> RawWaker {
1717
unsafe fn waker_wake(p: *const ()) {
1818
// The only thing we need from a waker is the function to call to pend the async
1919
// dispatcher.
20-
let f: fn() = mem::transmute(p);
20+
let f: fn() = unsafe { mem::transmute(p) };
2121
f();
2222
}
2323

@@ -81,7 +81,7 @@ macro_rules! from_ptr_n_args {
8181
($name:ident, $($t:ident),*) => {
8282
#[inline(always)]
8383
pub unsafe fn $name<$($t,)* Fun: Fn($($t,)*) -> F>(_f: Fun, ptr: &AsyncTaskExecutorPtr) -> &Self {
84-
&*(ptr.get() as *const _)
84+
unsafe { &*(ptr.get() as *const _) }
8585
}
8686
};
8787
}

rtic/src/export/riscv_esp32c3.rs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,24 @@ pub fn run<F>(priority: u8, f: F)
1010
where
1111
F: FnOnce(),
1212
{
13-
if priority == 1 {
14-
//if priority is 1, priority thresh should be 1
15-
f();
16-
unsafe {
13+
unsafe {
14+
if priority == 1 {
15+
//if priority is 1, priority thresh should be 1
16+
f();
17+
1718
(*INTERRUPT_CORE0::ptr())
1819
.cpu_int_thresh()
1920
.write(|w| w.cpu_int_thresh().bits(1));
20-
}
21-
} else {
22-
//read current thresh
23-
let initial = unsafe {
24-
(*INTERRUPT_CORE0::ptr())
21+
} else {
22+
//read current thresh
23+
let initial = (*INTERRUPT_CORE0::ptr())
2524
.cpu_int_thresh()
2625
.read()
2726
.cpu_int_thresh()
28-
.bits()
29-
};
30-
f();
31-
//write back old thresh
32-
unsafe {
27+
.bits();
28+
f();
29+
//write back old thresh
30+
3331
(*INTERRUPT_CORE0::ptr())
3432
.cpu_int_thresh()
3533
.write(|w| w.cpu_int_thresh().bits(initial));
@@ -55,30 +53,29 @@ where
5553
/// priority is current priority >= ceiling.
5654
#[inline(always)]
5755
pub unsafe fn lock<T, R>(ptr: *mut T, ceiling: u8, f: impl FnOnce(&mut T) -> R) -> R {
58-
if ceiling == (15) {
59-
//turn off interrupts completely, were at max prio
60-
critical_section::with(|_| f(&mut *ptr))
61-
} else {
62-
let current = unsafe {
63-
(*INTERRUPT_CORE0::ptr())
56+
unsafe {
57+
if ceiling == (15) {
58+
//turn off interrupts completely, were at max prio
59+
critical_section::with(|_| f(&mut *ptr))
60+
} else {
61+
let current = (*INTERRUPT_CORE0::ptr())
6462
.cpu_int_thresh()
6563
.read()
6664
.cpu_int_thresh()
67-
.bits()
68-
};
65+
.bits();
6966

70-
unsafe {
7167
(*INTERRUPT_CORE0::ptr())
7268
.cpu_int_thresh()
7369
.write(|w| w.cpu_int_thresh().bits(ceiling + 1));
74-
} //esp32c3 lets interrupts with prio equal to threshold through so we up it by one
75-
let r = f(&mut *ptr);
76-
unsafe {
70+
//esp32c3 lets interrupts with prio equal to threshold through so we up it by one
71+
let r = f(&mut *ptr);
72+
7773
(*INTERRUPT_CORE0::ptr())
7874
.cpu_int_thresh()
7975
.write(|w| w.cpu_int_thresh().bits(current));
76+
77+
r
8078
}
81-
r
8279
}
8380
}
8481

rtic/src/export/riscv_esp32c6.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
pub use esp32c6::{Interrupt, Peripherals};
21
use esp32c6::{INTERRUPT_CORE0, PLIC_MX};
2+
pub use esp32c6::{Interrupt, Peripherals};
33
pub use riscv::interrupt;
44
pub use riscv::register::mcause;
55

@@ -11,26 +11,24 @@ pub fn run<F>(priority: u8, f: F)
1111
where
1212
F: FnOnce(),
1313
{
14-
if priority == 1 {
15-
//if priority is 1, priority thresh should be 1
16-
f();
17-
unsafe {
14+
unsafe {
15+
if priority == 1 {
16+
//if priority is 1, priority thresh should be 1
17+
f();
18+
1819
(*PLIC_MX::ptr())
1920
.mxint_thresh()
2021
.write(|w| w.cpu_mxint_thresh().bits(1));
21-
}
22-
} else {
23-
//read current thresh
24-
let initial = unsafe {
25-
(*PLIC_MX::ptr())
22+
} else {
23+
//read current thresh
24+
let initial = (*PLIC_MX::ptr())
2625
.mxint_thresh()
2726
.read()
2827
.cpu_mxint_thresh()
29-
.bits()
30-
};
31-
f();
32-
//write back old thresh
33-
unsafe {
28+
.bits();
29+
f();
30+
//write back old thresh
31+
3432
(*PLIC_MX::ptr())
3533
.mxint_thresh()
3634
.write(|w| w.cpu_mxint_thresh().bits(initial));
@@ -56,34 +54,30 @@ where
5654
/// priority is current priority >= ceiling.
5755
#[inline(always)]
5856
pub unsafe fn lock<T, R>(ptr: *mut T, ceiling: u8, f: impl FnOnce(&mut T) -> R) -> R {
59-
if ceiling == (15) {
60-
// Turn off interrupts completely, we're at max prio
61-
critical_section::with(|_| f(&mut *ptr))
62-
} else {
63-
let current = unsafe {
64-
(*PLIC_MX::ptr())
57+
unsafe {
58+
if ceiling == (15) {
59+
// Turn off interrupts completely, we're at max prio
60+
critical_section::with(|_| f(&mut *ptr))
61+
} else {
62+
let current = (*PLIC_MX::ptr())
6563
.mxint_thresh()
6664
.read()
6765
.cpu_mxint_thresh()
68-
.bits()
69-
};
66+
.bits();
7067

71-
// esp32c6 lets interrupts with prio equal to threshold through so we up it by one
72-
unsafe {
68+
// esp32c6 lets interrupts with prio equal to threshold through so we up it by one
7369
(*PLIC_MX::ptr())
7470
.mxint_thresh()
7571
.write(|w| w.cpu_mxint_thresh().bits(ceiling + 1));
76-
}
7772

78-
let r = f(&mut *ptr);
73+
let r = f(&mut *ptr);
7974

80-
unsafe {
8175
(*PLIC_MX::ptr())
8276
.mxint_thresh()
8377
.write(|w| w.cpu_mxint_thresh().bits(current));
84-
}
8578

86-
r
79+
r
80+
}
8781
}
8882
}
8983

rtic/src/export/slic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub use riscv_slic::{lock, pend, run, InterruptNumber};
1+
pub use riscv_slic::{InterruptNumber, lock, pend, run};
22

33
#[cfg(all(
44
feature = "riscv-slic",

rtic/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
#![allow(clippy::inline_always)]
3434
#![allow(unexpected_cfgs)]
3535

36-
pub use rtic_core::{prelude as mutex_prelude, Exclusive, Mutex};
36+
pub use rtic_core::{Exclusive, Mutex, prelude as mutex_prelude};
3737
pub use rtic_macros::app;
3838

3939
/// module `mutex::prelude` provides `Mutex` and multi-lock variants. Recommended over `mutex_prelude`
4040
pub mod mutex {
41-
pub use rtic_core::prelude;
4241
pub use rtic_core::Mutex;
42+
pub use rtic_core::prelude;
4343
}
4444

4545
#[doc(hidden)]

0 commit comments

Comments
 (0)