mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-24 04:32:52 +01:00
remove special case around peripherals from codegen
This commit is contained in:
parent
e97afa71ce
commit
1830bdbe5c
1 changed files with 114 additions and 209 deletions
|
@ -27,12 +27,7 @@ pub fn app(app: &App, ownerships: &Ownerships) -> Tokens {
|
||||||
quote!(#(#root)*)
|
quote!(#(#root)*)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn idle(
|
fn idle(app: &App, ownerships: &Ownerships, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
app: &App,
|
|
||||||
ownerships: &Ownerships,
|
|
||||||
main: &mut Vec<Tokens>,
|
|
||||||
root: &mut Vec<Tokens>,
|
|
||||||
) {
|
|
||||||
let krate = krate();
|
let krate = krate();
|
||||||
|
|
||||||
let mut mod_items = vec![];
|
let mut mod_items = vec![];
|
||||||
|
@ -45,8 +40,6 @@ fn idle(
|
||||||
}
|
}
|
||||||
|
|
||||||
if !app.idle.resources.is_empty() {
|
if !app.idle.resources.is_empty() {
|
||||||
let device = &app.device;
|
|
||||||
|
|
||||||
let mut needs_reexport = false;
|
let mut needs_reexport = false;
|
||||||
for name in &app.idle.resources {
|
for name in &app.idle.resources {
|
||||||
if ownerships[name].is_owned() {
|
if ownerships[name].is_owned() {
|
||||||
|
@ -66,32 +59,26 @@ fn idle(
|
||||||
let mut rfields = vec![];
|
let mut rfields = vec![];
|
||||||
for name in &app.idle.resources {
|
for name in &app.idle.resources {
|
||||||
if ownerships[name].is_owned() {
|
if ownerships[name].is_owned() {
|
||||||
if let Some(resource) = app.resources.get(name) {
|
let resource = app.resources.get(name).expect(&format!(
|
||||||
let ty = &resource.ty;
|
"BUG: resource {} assigned to `idle` has no definition",
|
||||||
|
name
|
||||||
|
));
|
||||||
|
let ty = &resource.ty;
|
||||||
|
|
||||||
rfields.push(quote! {
|
rfields.push(quote! {
|
||||||
pub #name: &'static mut #ty,
|
pub #name: &'static mut #ty,
|
||||||
});
|
});
|
||||||
|
|
||||||
let _name = Ident::new(format!("_{}", name.as_ref()));
|
let _name = Ident::new(format!("_{}", name.as_ref()));
|
||||||
rexprs.push(if resource.expr.is_some() {
|
rexprs.push(if resource.expr.is_some() {
|
||||||
quote! {
|
quote! {
|
||||||
#name: &mut #super_::#_name,
|
#name: &mut #super_::#_name,
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
quote! {
|
|
||||||
#name: #super_::#_name.as_mut(),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
rfields.push(quote! {
|
quote! {
|
||||||
pub #name: &'static mut ::#device::#name,
|
#name: #super_::#_name.as_mut(),
|
||||||
});
|
}
|
||||||
|
});
|
||||||
rexprs.push(quote! {
|
|
||||||
#name: &mut *::#device::#name.get(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
rfields.push(quote! {
|
rfields.push(quote! {
|
||||||
pub #name: #super_::_resource::#name,
|
pub #name: #super_::_resource::#name,
|
||||||
|
@ -162,16 +149,19 @@ fn init(app: &App, main: &mut Vec<Tokens>, root: &mut Vec<Tokens>) {
|
||||||
let krate = krate();
|
let krate = krate();
|
||||||
|
|
||||||
let mut tys = vec![quote!(init::Peripherals)];
|
let mut tys = vec![quote!(init::Peripherals)];
|
||||||
let mut exprs = vec![quote!{
|
let mut exprs = vec![
|
||||||
init::Peripherals {
|
quote!{
|
||||||
core: ::#device::CorePeripherals::steal(),
|
init::Peripherals {
|
||||||
device: ::#device::Peripherals::steal(),
|
core: ::#device::CorePeripherals::steal(),
|
||||||
}
|
device: ::#device::Peripherals::steal(),
|
||||||
}];
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
let mut ret = None;
|
let mut ret = None;
|
||||||
let mut mod_items = vec![];
|
let mut mod_items = vec![];
|
||||||
|
|
||||||
let (init_resources, late_resources): (Vec<_>, Vec<_>) = app.resources.iter()
|
let (init_resources, late_resources): (Vec<_>, Vec<_>) = app.resources
|
||||||
|
.iter()
|
||||||
.partition(|&(_, res)| res.expr.is_some());
|
.partition(|&(_, res)| res.expr.is_some());
|
||||||
|
|
||||||
if !init_resources.is_empty() {
|
if !init_resources.is_empty() {
|
||||||
|
@ -363,154 +353,81 @@ fn resources(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
// For owned resources we don't need claim() or borrow()
|
// For owned resources we don't need claim() or borrow()
|
||||||
}
|
}
|
||||||
Ownership::Shared { ceiling } => {
|
Ownership::Shared { ceiling } => {
|
||||||
if let Some(resource) = app.resources.get(name) {
|
let resource = app.resources
|
||||||
let ty = &resource.ty;
|
.get(name)
|
||||||
let res_rvalue = if resource.expr.is_some() {
|
.expect(&format!("BUG: resource {} has no definition", name));
|
||||||
quote!(#_name)
|
let ty = &resource.ty;
|
||||||
} else {
|
let res_rvalue = if resource.expr.is_some() {
|
||||||
quote!(#_name.some)
|
quote!(#_name)
|
||||||
};
|
|
||||||
|
|
||||||
impl_items.push(quote! {
|
|
||||||
type Data = #ty;
|
|
||||||
|
|
||||||
fn borrow<'cs>(
|
|
||||||
&'cs self,
|
|
||||||
t: &'cs #krate::Threshold,
|
|
||||||
) -> &'cs #krate::Static<#ty> {
|
|
||||||
assert!(t.value() >= #ceiling);
|
|
||||||
|
|
||||||
unsafe { #krate::Static::ref_(&#res_rvalue) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fn borrow_mut<'cs>(
|
|
||||||
&'cs mut self,
|
|
||||||
t: &'cs #krate::Threshold,
|
|
||||||
) -> &'cs mut #krate::Static<#ty> {
|
|
||||||
assert!(t.value() >= #ceiling);
|
|
||||||
|
|
||||||
unsafe {
|
|
||||||
#krate::Static::ref_mut(&mut #res_rvalue)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn claim<R, F>(
|
|
||||||
&self,
|
|
||||||
t: &mut #krate::Threshold,
|
|
||||||
f: F,
|
|
||||||
) -> R
|
|
||||||
where
|
|
||||||
F: FnOnce(
|
|
||||||
&#krate::Static<#ty>,
|
|
||||||
&mut #krate::Threshold) -> R
|
|
||||||
{
|
|
||||||
unsafe {
|
|
||||||
#krate::claim(
|
|
||||||
#krate::Static::ref_(&#res_rvalue),
|
|
||||||
#ceiling,
|
|
||||||
#device::NVIC_PRIO_BITS,
|
|
||||||
t,
|
|
||||||
f,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn claim_mut<R, F>(
|
|
||||||
&mut self,
|
|
||||||
t: &mut #krate::Threshold,
|
|
||||||
f: F,
|
|
||||||
) -> R
|
|
||||||
where
|
|
||||||
F: FnOnce(
|
|
||||||
&mut #krate::Static<#ty>,
|
|
||||||
&mut #krate::Threshold) -> R
|
|
||||||
{
|
|
||||||
unsafe {
|
|
||||||
#krate::claim(
|
|
||||||
#krate::Static::ref_mut(&mut #res_rvalue),
|
|
||||||
#ceiling,
|
|
||||||
#device::NVIC_PRIO_BITS,
|
|
||||||
t,
|
|
||||||
f,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
impl_items.push(quote! {
|
quote!(#_name.some)
|
||||||
type Data = #device::#name;
|
};
|
||||||
|
|
||||||
fn borrow<'cs>(
|
impl_items.push(quote! {
|
||||||
&'cs self,
|
type Data = #ty;
|
||||||
t: &'cs #krate::Threshold,
|
|
||||||
) -> &'cs #krate::Static<#device::#name> {
|
|
||||||
assert!(t.value() >= #ceiling);
|
|
||||||
|
|
||||||
unsafe {
|
fn borrow<'cs>(
|
||||||
#krate::Static::ref_(&*#device::#name.get())
|
&'cs self,
|
||||||
}
|
t: &'cs #krate::Threshold,
|
||||||
|
) -> &'cs #krate::Static<#ty> {
|
||||||
|
assert!(t.value() >= #ceiling);
|
||||||
|
|
||||||
|
unsafe { #krate::Static::ref_(&#res_rvalue) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn borrow_mut<'cs>(
|
||||||
|
&'cs mut self,
|
||||||
|
t: &'cs #krate::Threshold,
|
||||||
|
) -> &'cs mut #krate::Static<#ty> {
|
||||||
|
assert!(t.value() >= #ceiling);
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
#krate::Static::ref_mut(&mut #res_rvalue)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn borrow_mut<'cs>(
|
fn claim<R, F>(
|
||||||
&'cs mut self,
|
&self,
|
||||||
t: &'cs #krate::Threshold,
|
t: &mut #krate::Threshold,
|
||||||
) -> &'cs mut #krate::Static<#device::#name> {
|
f: F,
|
||||||
assert!(t.value() >= #ceiling);
|
) -> R
|
||||||
|
where
|
||||||
unsafe {
|
F: FnOnce(
|
||||||
#krate::Static::ref_mut(
|
&#krate::Static<#ty>,
|
||||||
&mut *#device::#name.get(),
|
&mut #krate::Threshold) -> R
|
||||||
)
|
{
|
||||||
}
|
unsafe {
|
||||||
|
#krate::claim(
|
||||||
|
#krate::Static::ref_(&#res_rvalue),
|
||||||
|
#ceiling,
|
||||||
|
#device::NVIC_PRIO_BITS,
|
||||||
|
t,
|
||||||
|
f,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn claim<R, F>(
|
fn claim_mut<R, F>(
|
||||||
&self,
|
&mut self,
|
||||||
t: &mut #krate::Threshold,
|
t: &mut #krate::Threshold,
|
||||||
f: F,
|
f: F,
|
||||||
) -> R
|
) -> R
|
||||||
where
|
where
|
||||||
F: FnOnce(
|
F: FnOnce(
|
||||||
&#krate::Static<#device::#name>,
|
&mut #krate::Static<#ty>,
|
||||||
&mut #krate::Threshold) -> R
|
&mut #krate::Threshold) -> R
|
||||||
{
|
{
|
||||||
unsafe {
|
unsafe {
|
||||||
#krate::claim(
|
#krate::claim(
|
||||||
#krate::Static::ref_(
|
#krate::Static::ref_mut(&mut #res_rvalue),
|
||||||
&*#device::#name.get(),
|
#ceiling,
|
||||||
),
|
#device::NVIC_PRIO_BITS,
|
||||||
#ceiling,
|
t,
|
||||||
#device::NVIC_PRIO_BITS,
|
f,
|
||||||
t,
|
)
|
||||||
f,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fn claim_mut<R, F>(
|
});
|
||||||
&mut self,
|
|
||||||
t: &mut #krate::Threshold,
|
|
||||||
f: F,
|
|
||||||
) -> R
|
|
||||||
where
|
|
||||||
F: FnOnce(
|
|
||||||
&mut #krate::Static<#device::#name>,
|
|
||||||
&mut #krate::Threshold) -> R
|
|
||||||
{
|
|
||||||
unsafe {
|
|
||||||
#krate::claim(
|
|
||||||
#krate::Static::ref_mut(
|
|
||||||
&mut *#device::#name.get(),
|
|
||||||
),
|
|
||||||
#ceiling,
|
|
||||||
#device::NVIC_PRIO_BITS,
|
|
||||||
t,
|
|
||||||
f,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
impls.push(quote! {
|
impls.push(quote! {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -568,9 +485,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
let _name = Ident::new(format!("_{}", name.as_ref()));
|
let _name = Ident::new(format!("_{}", name.as_ref()));
|
||||||
|
|
||||||
match ownerships[name] {
|
match ownerships[name] {
|
||||||
Ownership::Shared { ceiling }
|
Ownership::Shared { ceiling } if ceiling > task.priority => {
|
||||||
if ceiling > task.priority =>
|
|
||||||
{
|
|
||||||
needs_threshold = true;
|
needs_threshold = true;
|
||||||
|
|
||||||
fields.push(quote! {
|
fields.push(quote! {
|
||||||
|
@ -585,35 +500,26 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
lifetime = Some(quote!('a));
|
lifetime = Some(quote!('a));
|
||||||
if let Some(resource) = app.resources.get(name) {
|
let resource = app.resources
|
||||||
needs_reexport = true;
|
.get(name)
|
||||||
let ty = &resource.ty;
|
.expect(&format!("BUG: resource {} has no definition", name));
|
||||||
|
|
||||||
fields.push(quote! {
|
needs_reexport = true;
|
||||||
pub #name: &'a mut ::#krate::Static<#ty>,
|
let ty = &resource.ty;
|
||||||
});
|
|
||||||
|
|
||||||
exprs.push(if resource.expr.is_some() {
|
fields.push(quote! {
|
||||||
quote! {
|
pub #name: &'a mut ::#krate::Static<#ty>,
|
||||||
#name: ::#krate::Static::ref_mut(&mut ::#_name),
|
});
|
||||||
}
|
|
||||||
} else {
|
exprs.push(if resource.expr.is_some() {
|
||||||
quote! {
|
quote! {
|
||||||
#name: ::#krate::Static::ref_mut(::#_name.as_mut()),
|
#name: ::#krate::Static::ref_mut(&mut ::#_name),
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
fields.push(quote! {
|
quote! {
|
||||||
pub #name:
|
#name: ::#krate::Static::ref_mut(::#_name.as_mut()),
|
||||||
&'a mut ::#krate::Static<::#device::#name>,
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
exprs.push(quote! {
|
|
||||||
#name: ::#krate::Static::ref_mut(
|
|
||||||
&mut *::#device::#name.get(),
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -674,8 +580,7 @@ fn tasks(app: &App, ownerships: &Ownerships, root: &mut Vec<Tokens>) {
|
||||||
|
|
||||||
let path = &task.path;
|
let path = &task.path;
|
||||||
let _name = Ident::new(format!("_{}", name));
|
let _name = Ident::new(format!("_{}", name));
|
||||||
let export_name =
|
let export_name = Lit::Str(name.as_ref().to_owned(), StrStyle::Cooked);
|
||||||
Lit::Str(name.as_ref().to_owned(), StrStyle::Cooked);
|
|
||||||
root.push(quote! {
|
root.push(quote! {
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
|
Loading…
Reference in a new issue