fmt: make all macros macro_rules
so scoping is consistent.
This commit is contained in:
@ -9,7 +9,6 @@ mod timer_queue;
|
||||
mod util;
|
||||
mod waker;
|
||||
|
||||
use crate::fmt::panic;
|
||||
use crate::interrupt::{Interrupt, InterruptExt};
|
||||
use crate::time::Alarm;
|
||||
|
||||
|
@ -24,7 +24,9 @@ pub(crate) unsafe fn from_task(p: NonNull<TaskHeader>) -> Waker {
|
||||
|
||||
pub unsafe fn task_from_waker(waker: &Waker) -> NonNull<TaskHeader> {
|
||||
let hack: &WakerHack = mem::transmute(waker);
|
||||
assert_eq!(hack.vtable, &VTABLE);
|
||||
if hack.vtable != &VTABLE {
|
||||
panic!("Found waker not created by the embassy executor. Consider enabling the `executor-agnostic` feature on the `embassy` crate.")
|
||||
}
|
||||
NonNull::new_unchecked(hack.data as *mut TaskHeader)
|
||||
}
|
||||
|
||||
|
@ -1,69 +1,170 @@
|
||||
#![macro_use]
|
||||
#![allow(clippy::module_inception)]
|
||||
#![allow(unused)]
|
||||
#![allow(unused_macros)]
|
||||
|
||||
#[cfg(all(feature = "defmt", feature = "log"))]
|
||||
compile_error!("You may not enable both `defmt` and `log` features.");
|
||||
|
||||
pub use fmt::*;
|
||||
macro_rules! assert {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::assert!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::assert!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_eq {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::assert_eq!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::assert_eq!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! assert_ne {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::assert_ne!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::assert_ne!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug_assert {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::debug_assert!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::debug_assert!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug_assert_eq {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::debug_assert_eq!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::debug_assert_eq!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug_assert_ne {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::debug_assert_ne!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::debug_assert_ne!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! todo {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::todo!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::todo!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! unreachable {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::unreachable!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::unreachable!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! panic {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
core::panic!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::panic!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! trace {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(feature = "log")]
|
||||
log::trace!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::trace!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(fevature = "log")]
|
||||
log::debug!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::debug!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! info {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(feature = "log")]
|
||||
log::info!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::info!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! warn {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(feature = "log")]
|
||||
log::warn!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::warn!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
($($x:tt)*) => {
|
||||
{
|
||||
#[cfg(feature = "log")]
|
||||
log::error!($($x)*);
|
||||
#[cfg(feature = "defmt")]
|
||||
defmt::error!($($x)*);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "defmt")]
|
||||
mod fmt {
|
||||
pub use defmt::{
|
||||
assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error,
|
||||
info, panic, todo, trace, unreachable, unwrap, warn,
|
||||
macro_rules! unwrap {
|
||||
($($x:tt)*) => {
|
||||
defmt::unwrap!($($x)*)
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "log")]
|
||||
mod fmt {
|
||||
pub use core::{
|
||||
assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
|
||||
unreachable,
|
||||
};
|
||||
pub use log::{debug, error, info, trace, warn};
|
||||
}
|
||||
|
||||
#[cfg(not(any(feature = "defmt", feature = "log")))]
|
||||
mod fmt {
|
||||
#![macro_use]
|
||||
|
||||
pub use core::{
|
||||
assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo,
|
||||
unreachable,
|
||||
};
|
||||
|
||||
macro_rules! trace {
|
||||
($($msg:expr),+ $(,)?) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! debug {
|
||||
($($msg:expr),+ $(,)?) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! info {
|
||||
($($msg:expr),+ $(,)?) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! warn {
|
||||
($($msg:expr),+ $(,)?) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! error {
|
||||
($($msg:expr),+ $(,)?) => {
|
||||
()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "defmt"))]
|
||||
macro_rules! unwrap {
|
||||
($arg:expr) => {
|
||||
|
@ -10,8 +10,6 @@ pub use duration::Duration;
|
||||
pub use instant::Instant;
|
||||
pub use traits::*;
|
||||
|
||||
use crate::fmt::*;
|
||||
|
||||
// TODO allow customizing, probably via Cargo features `tick-hz-32768` or something.
|
||||
pub const TICKS_PER_SECOND: u64 = 32768;
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::fmt::panic;
|
||||
use core::mem;
|
||||
|
||||
/// An explosive ordinance that panics if it is improperly disposed of.
|
||||
|
@ -1,8 +1,6 @@
|
||||
use core::cell::UnsafeCell;
|
||||
use critical_section::CriticalSection;
|
||||
|
||||
use crate::fmt::assert;
|
||||
|
||||
/// A "mutex" based on critical sections
|
||||
///
|
||||
/// # Safety
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::fmt::panic;
|
||||
use core::cell::UnsafeCell;
|
||||
use core::mem;
|
||||
use core::mem::MaybeUninit;
|
||||
|
@ -9,7 +9,6 @@ use executor::raw::TaskHeader;
|
||||
use ptr::NonNull;
|
||||
|
||||
use crate::executor;
|
||||
use crate::fmt::panic;
|
||||
use crate::interrupt::{Interrupt, InterruptExt};
|
||||
|
||||
/// Synchronization primitive. Allows creating awaitable signals that may be passed between tasks.
|
||||
|
Reference in New Issue
Block a user