Merge #907
907: Several macro cleanups r=Dirbaio a=Dirbaio Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
16d0ae7678
@ -6,6 +6,12 @@ use cortex_m::peripheral::NVIC;
|
|||||||
use embassy_hal_common::Peripheral;
|
use embassy_hal_common::Peripheral;
|
||||||
pub use embassy_macros::cortex_m_interrupt_take as take;
|
pub use embassy_macros::cortex_m_interrupt_take as take;
|
||||||
|
|
||||||
|
/// Do not use. Used for macros only. Not covered by semver guarantees.
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub mod _export {
|
||||||
|
pub use atomic_polyfill as atomic;
|
||||||
|
}
|
||||||
|
|
||||||
/// Implementation detail, do not use outside embassy crates.
|
/// Implementation detail, do not use outside embassy crates.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct Handler {
|
pub struct Handler {
|
||||||
|
@ -16,15 +16,15 @@ pub fn run(name: syn::Ident) -> Result<TokenStream, TokenStream> {
|
|||||||
static HANDLER: interrupt::Handler;
|
static HANDLER: interrupt::Handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
let func = HANDLER.func.load(::embassy_executor::export::atomic::Ordering::Relaxed);
|
let func = HANDLER.func.load(interrupt::_export::atomic::Ordering::Relaxed);
|
||||||
let ctx = HANDLER.ctx.load(::embassy_executor::export::atomic::Ordering::Relaxed);
|
let ctx = HANDLER.ctx.load(interrupt::_export::atomic::Ordering::Relaxed);
|
||||||
let func: fn(*mut ()) = ::core::mem::transmute(func);
|
let func: fn(*mut ()) = ::core::mem::transmute(func);
|
||||||
func(ctx)
|
func(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
static TAKEN: ::embassy_executor::export::atomic::AtomicBool = ::embassy_executor::export::atomic::AtomicBool::new(false);
|
static TAKEN: interrupt::_export::atomic::AtomicBool = interrupt::_export::atomic::AtomicBool::new(false);
|
||||||
|
|
||||||
if TAKEN.compare_exchange(false, true, ::embassy_executor::export::atomic::Ordering::AcqRel, ::embassy_executor::export::atomic::Ordering::Acquire).is_err() {
|
if TAKEN.compare_exchange(false, true, interrupt::_export::atomic::Ordering::AcqRel, interrupt::_export::atomic::Ordering::Acquire).is_err() {
|
||||||
core::panic!("IRQ Already taken");
|
core::panic!("IRQ Already taken");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,28 +3,16 @@ use proc_macro2::TokenStream;
|
|||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
use crate::util::ctxt::Ctxt;
|
use crate::util::ctxt::Ctxt;
|
||||||
use crate::util::path::ModulePrefix;
|
|
||||||
|
|
||||||
#[cfg(feature = "stm32")]
|
|
||||||
const HAL: Option<&str> = Some("embassy_stm32");
|
|
||||||
#[cfg(feature = "nrf")]
|
|
||||||
const HAL: Option<&str> = Some("embassy_nrf");
|
|
||||||
#[cfg(feature = "rp")]
|
|
||||||
const HAL: Option<&str> = Some("embassy_rp");
|
|
||||||
#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))]
|
|
||||||
const HAL: Option<&str> = None;
|
|
||||||
|
|
||||||
#[derive(Debug, FromMeta)]
|
#[derive(Debug, FromMeta)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[darling(default)]
|
|
||||||
embassy_prefix: ModulePrefix,
|
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[darling(default)]
|
#[darling(default)]
|
||||||
config: Option<syn::LitStr>,
|
config: Option<syn::LitStr>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
||||||
|
#[allow(unused_variables)]
|
||||||
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
||||||
|
|
||||||
let fargs = f.sig.inputs.clone();
|
let fargs = f.sig.inputs.clone();
|
||||||
@ -38,26 +26,32 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||||||
ctxt.error_spanned_by(&f.sig, "task functions must not be generic");
|
ctxt.error_spanned_by(&f.sig, "task functions must not be generic");
|
||||||
}
|
}
|
||||||
|
|
||||||
if HAL.is_some() && fargs.len() != 2 {
|
#[cfg(feature = "stm32")]
|
||||||
|
let hal = Some(quote!(::embassy_stm32));
|
||||||
|
#[cfg(feature = "nrf")]
|
||||||
|
let hal = Some(quote!(::embassy_nrf));
|
||||||
|
#[cfg(feature = "rp")]
|
||||||
|
let hal = Some(quote!(::embassy_rp));
|
||||||
|
#[cfg(not(any(feature = "stm32", feature = "nrf", feature = "rp")))]
|
||||||
|
let hal: Option<TokenStream> = None;
|
||||||
|
|
||||||
|
if hal.is_some() && fargs.len() != 2 {
|
||||||
ctxt.error_spanned_by(&f.sig, "main function must have 2 arguments");
|
ctxt.error_spanned_by(&f.sig, "main function must have 2 arguments");
|
||||||
}
|
}
|
||||||
if HAL.is_none() && fargs.len() != 1 {
|
if hal.is_none() && fargs.len() != 1 {
|
||||||
ctxt.error_spanned_by(&f.sig, "main function must have 1 argument");
|
ctxt.error_spanned_by(&f.sig, "main function must have 1 argument");
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt.check()?;
|
ctxt.check()?;
|
||||||
|
|
||||||
let embassy_prefix = args.embassy_prefix;
|
|
||||||
let embassy_prefix_lit = embassy_prefix.literal();
|
|
||||||
let embassy_path = embassy_prefix.append("embassy_executor").path();
|
|
||||||
let f_body = f.block;
|
let f_body = f.block;
|
||||||
|
|
||||||
#[cfg(feature = "wasm")]
|
#[cfg(feature = "wasm")]
|
||||||
let main = quote! {
|
let main = quote! {
|
||||||
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
#[wasm_bindgen::prelude::wasm_bindgen(start)]
|
||||||
pub fn main() -> Result<(), wasm_bindgen::JsValue> {
|
pub fn main() -> Result<(), wasm_bindgen::JsValue> {
|
||||||
static EXECUTOR: ::embassy_util::Forever<#embassy_path::executor::Executor> = ::embassy_util::Forever::new();
|
static EXECUTOR: ::embassy_util::Forever<::embassy_executor::executor::Executor> = ::embassy_util::Forever::new();
|
||||||
let executor = EXECUTOR.put(#embassy_path::executor::Executor::new());
|
let executor = EXECUTOR.put(::embassy_executor::executor::Executor::new());
|
||||||
|
|
||||||
executor.start(|spawner| {
|
executor.start(|spawner| {
|
||||||
spawner.spawn(__embassy_main(spawner)).unwrap();
|
spawner.spawn(__embassy_main(spawner)).unwrap();
|
||||||
@ -70,7 +64,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||||||
#[cfg(all(feature = "std", not(feature = "wasm")))]
|
#[cfg(all(feature = "std", not(feature = "wasm")))]
|
||||||
let main = quote! {
|
let main = quote! {
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
let mut executor = #embassy_path::executor::Executor::new();
|
let mut executor = ::embassy_executor::executor::Executor::new();
|
||||||
let executor = unsafe { __make_static(&mut executor) };
|
let executor = unsafe { __make_static(&mut executor) };
|
||||||
|
|
||||||
executor.run(|spawner| {
|
executor.run(|spawner| {
|
||||||
@ -87,16 +81,13 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
let (hal_setup, peris_arg) = match HAL {
|
let (hal_setup, peris_arg) = match hal {
|
||||||
Some(hal) => {
|
Some(hal) => (
|
||||||
let embassy_hal_path = embassy_prefix.append(hal).path();
|
|
||||||
(
|
|
||||||
quote!(
|
quote!(
|
||||||
let p = #embassy_hal_path::init(#config);
|
let p = #hal::init(#config);
|
||||||
),
|
),
|
||||||
quote!(p),
|
quote!(p),
|
||||||
)
|
),
|
||||||
}
|
|
||||||
None => (quote!(), quote!()),
|
None => (quote!(), quote!()),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -105,7 +96,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
#hal_setup
|
#hal_setup
|
||||||
|
|
||||||
let mut executor = #embassy_path::executor::Executor::new();
|
let mut executor = ::embassy_executor::executor::Executor::new();
|
||||||
let executor = unsafe { __make_static(&mut executor) };
|
let executor = unsafe { __make_static(&mut executor) };
|
||||||
|
|
||||||
executor.run(|spawner| {
|
executor.run(|spawner| {
|
||||||
@ -116,7 +107,7 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||||||
};
|
};
|
||||||
|
|
||||||
let result = quote! {
|
let result = quote! {
|
||||||
#[#embassy_path::task(embassy_prefix = #embassy_prefix_lit)]
|
#[::embassy_executor::task()]
|
||||||
async fn __embassy_main(#fargs) {
|
async fn __embassy_main(#fargs) {
|
||||||
#f_body
|
#f_body
|
||||||
}
|
}
|
||||||
|
@ -3,22 +3,16 @@ use proc_macro2::TokenStream;
|
|||||||
use quote::{format_ident, quote};
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
use crate::util::ctxt::Ctxt;
|
use crate::util::ctxt::Ctxt;
|
||||||
use crate::util::path::ModulePrefix;
|
|
||||||
|
|
||||||
#[derive(Debug, FromMeta)]
|
#[derive(Debug, FromMeta)]
|
||||||
struct Args {
|
struct Args {
|
||||||
#[darling(default)]
|
#[darling(default)]
|
||||||
pool_size: Option<usize>,
|
pool_size: Option<usize>,
|
||||||
#[darling(default)]
|
|
||||||
embassy_prefix: ModulePrefix,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, TokenStream> {
|
||||||
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
let args = Args::from_list(&args).map_err(|e| e.write_errors())?;
|
||||||
|
|
||||||
let embassy_prefix = args.embassy_prefix.append("embassy_executor");
|
|
||||||
let embassy_path = embassy_prefix.path();
|
|
||||||
|
|
||||||
let pool_size: usize = args.pool_size.unwrap_or(1);
|
let pool_size: usize = args.pool_size.unwrap_or(1);
|
||||||
|
|
||||||
let ctxt = Ctxt::new();
|
let ctxt = Ctxt::new();
|
||||||
@ -70,9 +64,9 @@ pub fn run(args: syn::AttributeArgs, f: syn::ItemFn) -> Result<TokenStream, Toke
|
|||||||
// in the user's code.
|
// in the user's code.
|
||||||
#task_inner
|
#task_inner
|
||||||
|
|
||||||
#visibility fn #task_ident(#fargs) -> #embassy_path::executor::SpawnToken<impl Sized> {
|
#visibility fn #task_ident(#fargs) -> ::embassy_executor::executor::SpawnToken<impl Sized> {
|
||||||
type Fut = impl ::core::future::Future + 'static;
|
type Fut = impl ::core::future::Future + 'static;
|
||||||
static POOL: #embassy_path::executor::raw::TaskPool<Fut, #pool_size> = #embassy_path::executor::raw::TaskPool::new();
|
static POOL: ::embassy_executor::executor::raw::TaskPool<Fut, #pool_size> = ::embassy_executor::executor::raw::TaskPool::new();
|
||||||
unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) }
|
unsafe { POOL._spawn_async_fn(move || #task_inner_ident(#(#arg_names,)*)) }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,2 +1 @@
|
|||||||
pub mod ctxt;
|
pub mod ctxt;
|
||||||
pub mod path;
|
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
use darling::{FromMeta, Result};
|
|
||||||
use proc_macro2::Span;
|
|
||||||
use syn::{LitStr, Path};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct ModulePrefix {
|
|
||||||
literal: LitStr,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ModulePrefix {
|
|
||||||
pub fn new(path: &str) -> Self {
|
|
||||||
let literal = LitStr::new(path, Span::call_site());
|
|
||||||
Self { literal }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn append(&self, component: &str) -> ModulePrefix {
|
|
||||||
let mut lit = self.literal().value();
|
|
||||||
lit.push_str(component);
|
|
||||||
Self::new(lit.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn path(&self) -> Path {
|
|
||||||
self.literal.parse().unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn literal(&self) -> &LitStr {
|
|
||||||
&self.literal
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FromMeta for ModulePrefix {
|
|
||||||
fn from_string(value: &str) -> Result<Self> {
|
|
||||||
Ok(ModulePrefix::new(value))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for ModulePrefix {
|
|
||||||
fn default() -> ModulePrefix {
|
|
||||||
ModulePrefix::new("::")
|
|
||||||
}
|
|
||||||
}
|
|
@ -63,7 +63,7 @@ seq_macro::seq!(N in 2..=128 {
|
|||||||
match self {
|
match self {
|
||||||
PllClkDiv::NotDivided => 1,
|
PllClkDiv::NotDivided => 1,
|
||||||
#(
|
#(
|
||||||
PllClkDiv::Div~N => (N + 1),
|
PllClkDiv::Div~N => N + 1,
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ seq_macro::seq!(N in 4..=512 {
|
|||||||
pub enum PllN {
|
pub enum PllN {
|
||||||
NotMultiplied,
|
NotMultiplied,
|
||||||
#(
|
#(
|
||||||
Mul~N = (N-1),
|
Mul~N = N-1,
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ seq_macro::seq!(N in 4..=512 {
|
|||||||
match self {
|
match self {
|
||||||
PllN::NotMultiplied => 1,
|
PllN::NotMultiplied => 1,
|
||||||
#(
|
#(
|
||||||
PllN::Mul~N => (N + 1),
|
PllN::Mul~N => N + 1,
|
||||||
)*
|
)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -999,10 +999,17 @@ impl SdmmcInner {
|
|||||||
fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> {
|
fn clkcr_set_clkdiv(&self, freq: u32, width: BusWidth, ker_ck: Hertz, clock: &mut Hertz) -> Result<(), Error> {
|
||||||
let regs = self.0;
|
let regs = self.0;
|
||||||
|
|
||||||
|
let width_u32 = match width {
|
||||||
|
BusWidth::One => 1u32,
|
||||||
|
BusWidth::Four => 4u32,
|
||||||
|
BusWidth::Eight => 8u32,
|
||||||
|
_ => panic!("Invalid Bus Width"),
|
||||||
|
};
|
||||||
|
|
||||||
let (clkdiv, new_clock) = clk_div(ker_ck, freq)?;
|
let (clkdiv, new_clock) = clk_div(ker_ck, freq)?;
|
||||||
// Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7
|
// Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7
|
||||||
// Section 55.5.8
|
// Section 55.5.8
|
||||||
let sdmmc_bus_bandwidth = new_clock.0 * (width as u32);
|
let sdmmc_bus_bandwidth = new_clock.0 * width_u32;
|
||||||
assert!(ker_ck.0 > 3 * sdmmc_bus_bandwidth / 32);
|
assert!(ker_ck.0 > 3 * sdmmc_bus_bandwidth / 32);
|
||||||
*clock = new_clock;
|
*clock = new_clock;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Before upgrading check that everything is available on all tier1 targets here:
|
# Before upgrading check that everything is available on all tier1 targets here:
|
||||||
# https://rust-lang.github.io/rustup-components-history
|
# https://rust-lang.github.io/rustup-components-history
|
||||||
[toolchain]
|
[toolchain]
|
||||||
channel = "nightly-2022-07-13"
|
channel = "nightly-2022-08-16"
|
||||||
components = [ "rust-src", "rustfmt" ]
|
components = [ "rust-src", "rustfmt" ]
|
||||||
targets = [
|
targets = [
|
||||||
"thumbv7em-none-eabi",
|
"thumbv7em-none-eabi",
|
||||||
|
Loading…
Reference in New Issue
Block a user