mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +01:00
Implement all clippy suggestions
This commit is contained in:
parent
355cb82d06
commit
21253297e4
11 changed files with 61 additions and 29 deletions
1
build.rs
1
build.rs
|
@ -1,5 +1,4 @@
|
||||||
use std::env;
|
use std::env;
|
||||||
use version_check;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let target = env::var("TARGET").unwrap();
|
let target = env::var("TARGET").unwrap();
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> {
|
||||||
let priorities = app
|
let priorities = app
|
||||||
.software_tasks
|
.software_tasks
|
||||||
.values()
|
.values()
|
||||||
.filter_map(|task| Some(task.args.priority))
|
.map(|task| task.args.priority)
|
||||||
.collect::<BTreeSet<_>>();
|
.collect::<BTreeSet<_>>();
|
||||||
|
|
||||||
if !priorities.is_empty() {
|
if !priorities.is_empty() {
|
||||||
|
|
|
@ -44,9 +44,9 @@ pub fn app<'a>(app: &'a App, _analysis: &Analysis) -> parse::Result<Extra<'a>> {
|
||||||
let priorities = app
|
let priorities = app
|
||||||
.software_tasks
|
.software_tasks
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|(name, task)| {
|
.map(|(name, task)| {
|
||||||
first = Some(name);
|
first = Some(name);
|
||||||
Some(task.args.priority)
|
task.args.priority
|
||||||
})
|
})
|
||||||
.collect::<HashSet<_>>();
|
.collect::<HashSet<_>>();
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ pub fn app<'a>(app: &'a App, _analysis: &Analysis) -> parse::Result<Extra<'a>> {
|
||||||
},
|
},
|
||||||
|
|
||||||
"peripherals" => match v {
|
"peripherals" => match v {
|
||||||
CustomArg::Bool(x) => peripherals = if *x { true } else { false },
|
CustomArg::Bool(x) => peripherals = *x,
|
||||||
_ => {
|
_ => {
|
||||||
return Err(parse::Error::new(
|
return Err(parse::Error::new(
|
||||||
k.span(),
|
k.span(),
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn codegen(
|
||||||
// call_idle
|
// call_idle
|
||||||
TokenStream2,
|
TokenStream2,
|
||||||
) {
|
) {
|
||||||
if app.idles.len() > 0 {
|
if !app.idles.is_empty() {
|
||||||
let idle = &app.idles.first().unwrap();
|
let idle = &app.idles.first().unwrap();
|
||||||
let mut needs_lt = false;
|
let mut needs_lt = false;
|
||||||
let mut mod_app = None;
|
let mut mod_app = None;
|
||||||
|
|
|
@ -8,12 +8,7 @@ use crate::{
|
||||||
codegen::{locals, module, resources_struct, util},
|
codegen::{locals, module, resources_struct, util},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Generates support code for `#[init]` functions
|
type CodegenResult = (
|
||||||
pub fn codegen(
|
|
||||||
app: &App,
|
|
||||||
analysis: &Analysis,
|
|
||||||
extra: &Extra,
|
|
||||||
) -> (
|
|
||||||
// mod_app_idle -- the `${init}Resources` constructor
|
// mod_app_idle -- the `${init}Resources` constructor
|
||||||
Option<TokenStream2>,
|
Option<TokenStream2>,
|
||||||
// root_init -- items that must be placed in the root of the crate:
|
// root_init -- items that must be placed in the root of the crate:
|
||||||
|
@ -28,8 +23,11 @@ pub fn codegen(
|
||||||
Vec<TokenStream2>,
|
Vec<TokenStream2>,
|
||||||
// call_init -- the call to the user `#[init]` if there's one
|
// call_init -- the call to the user `#[init]` if there's one
|
||||||
Option<TokenStream2>,
|
Option<TokenStream2>,
|
||||||
) {
|
);
|
||||||
if app.inits.len() > 0 {
|
|
||||||
|
/// Generates support code for `#[init]` functions
|
||||||
|
pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
|
||||||
|
if !app.inits.is_empty() {
|
||||||
let init = &app.inits.first().unwrap();
|
let init = &app.inits.first().unwrap();
|
||||||
let mut needs_lt = false;
|
let mut needs_lt = false;
|
||||||
let name = &init.name;
|
let name = &init.name;
|
||||||
|
|
|
@ -9,7 +9,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
||||||
let mut stmts = vec![];
|
let mut stmts = vec![];
|
||||||
|
|
||||||
// Initialize late resources
|
// Initialize late resources
|
||||||
if analysis.late_resources.len() > 0 {
|
if !analysis.late_resources.is_empty() {
|
||||||
// BTreeSet wrapped in a vector
|
// BTreeSet wrapped in a vector
|
||||||
for name in analysis.late_resources.first().unwrap() {
|
for name in analysis.late_resources.first().unwrap() {
|
||||||
// If it's live
|
// If it's live
|
||||||
|
|
|
@ -56,7 +56,7 @@ pub fn codegen(
|
||||||
pub static mut #fq: #fq_ty = #fq_expr;
|
pub static mut #fq: #fq_ty = #fq_expr;
|
||||||
));
|
));
|
||||||
|
|
||||||
let ref elems = (0..cap)
|
let elems = &(0..cap)
|
||||||
.map(|_| quote!(core::mem::MaybeUninit::uninit()))
|
.map(|_| quote!(core::mem::MaybeUninit::uninit()))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let doc = format!("Tasks that can be scheduled");
|
let doc = "Tasks that can be scheduled".to_string();
|
||||||
items.push(quote!(
|
items.push(quote!(
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
@ -41,7 +41,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
|
|
||||||
// Static variable and resource proxy
|
// Static variable and resource proxy
|
||||||
{
|
{
|
||||||
let doc = format!("Timer queue");
|
let doc = "Timer queue".to_string();
|
||||||
let cap = app
|
let cap = app
|
||||||
.software_tasks
|
.software_tasks
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -90,12 +90,17 @@ pub fn interrupt_ident() -> Ident {
|
||||||
pub fn is_exception(name: &Ident) -> bool {
|
pub fn is_exception(name: &Ident) -> bool {
|
||||||
let s = name.to_string();
|
let s = name.to_string();
|
||||||
|
|
||||||
match &*s {
|
matches!(
|
||||||
"MemoryManagement" | "BusFault" | "UsageFault" | "SecureFault" | "SVCall"
|
&*s,
|
||||||
| "DebugMonitor" | "PendSV" | "SysTick" => true,
|
"MemoryManagement"
|
||||||
|
| "BusFault"
|
||||||
_ => false,
|
| "UsageFault"
|
||||||
}
|
| "SecureFault"
|
||||||
|
| "SVCall"
|
||||||
|
| "DebugMonitor"
|
||||||
|
| "PendSV"
|
||||||
|
| "SysTick"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a pre-reexport identifier for the "late resources" struct
|
/// Generates a pre-reexport identifier for the "late resources" struct
|
||||||
|
@ -209,7 +214,7 @@ pub fn rq_ident(priority: u8) -> Ident {
|
||||||
|
|
||||||
/// Generates an identifier for the `enum` of `schedule`-able tasks
|
/// Generates an identifier for the `enum` of `schedule`-able tasks
|
||||||
pub fn schedule_t_ident() -> Ident {
|
pub fn schedule_t_ident() -> Ident {
|
||||||
Ident::new(&format!("SCHED_T"), Span::call_site())
|
Ident::new(&"SCHED_T".to_string(), Span::call_site())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates an identifier for the `enum` of `spawn`-able tasks
|
/// Generates an identifier for the `enum` of `spawn`-able tasks
|
||||||
|
@ -229,5 +234,5 @@ pub fn suffixed(name: &str) -> Ident {
|
||||||
///
|
///
|
||||||
/// At most there is one timer queue
|
/// At most there is one timer queue
|
||||||
pub fn tq_ident() -> Ident {
|
pub fn tq_ident() -> Ident {
|
||||||
Ident::new(&format!("TQ"), Span::call_site())
|
Ident::new(&"TQ".to_string(), Span::call_site())
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,11 @@ pub struct Priority {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Priority {
|
impl Priority {
|
||||||
|
/// Create a new Priority
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Will overwrite the current Priority
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn new(value: u8) -> Self {
|
pub unsafe fn new(value: u8) -> Self {
|
||||||
Priority {
|
Priority {
|
||||||
|
@ -79,12 +84,14 @@ impl Priority {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Change the current priority to `value`
|
||||||
// These two methods are used by `lock` (see below) but can't be used from the RTIC application
|
// These two methods are used by `lock` (see below) but can't be used from the RTIC application
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn set(&self, value: u8) {
|
fn set(&self, value: u8) {
|
||||||
self.inner.set(value)
|
self.inner.set(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the current priority
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn get(&self) -> u8 {
|
fn get(&self) -> u8 {
|
||||||
self.inner.get()
|
self.inner.get()
|
||||||
|
@ -105,6 +112,13 @@ where
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lock the resource proxy by setting the BASEPRI
|
||||||
|
/// and running the closure with interrupt::free
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Writing to the BASEPRI
|
||||||
|
/// Dereferencing a raw pointer
|
||||||
#[cfg(armv7m)]
|
#[cfg(armv7m)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn lock<T, R>(
|
pub unsafe fn lock<T, R>(
|
||||||
|
@ -135,6 +149,13 @@ pub unsafe fn lock<T, R>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lock the resource proxy by setting the PRIMASK
|
||||||
|
/// and running the closure with interrupt::free
|
||||||
|
///
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Writing to the PRIMASK
|
||||||
|
/// Dereferencing a raw pointer
|
||||||
#[cfg(not(armv7m))]
|
#[cfg(not(armv7m))]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn lock<T, R>(
|
pub unsafe fn lock<T, R>(
|
||||||
|
|
15
src/tq.rs
15
src/tq.rs
|
@ -24,18 +24,26 @@ where
|
||||||
N: ArrayLength<NotReady<M, T>>,
|
N: ArrayLength<NotReady<M, T>>,
|
||||||
T: Copy,
|
T: Copy,
|
||||||
{
|
{
|
||||||
|
/// # Safety
|
||||||
|
///
|
||||||
|
/// Writing to memory with a transmute in order to enable
|
||||||
|
/// interrupts of the SysTick timer
|
||||||
|
///
|
||||||
|
/// Enqueue a task without checking if it is full
|
||||||
#[inline]
|
#[inline]
|
||||||
pub unsafe fn enqueue_unchecked(&mut self, nr: NotReady<M, T>) {
|
pub unsafe fn enqueue_unchecked(&mut self, nr: NotReady<M, T>) {
|
||||||
let mut is_empty = true;
|
let mut is_empty = true;
|
||||||
if self
|
// Check if the top contains a non-empty element and if that element is
|
||||||
|
// greater than nr
|
||||||
|
let if_heap_max_greater_than_nr = self
|
||||||
.0
|
.0
|
||||||
.peek()
|
.peek()
|
||||||
.map(|head| {
|
.map(|head| {
|
||||||
is_empty = false;
|
is_empty = false;
|
||||||
nr.instant < head.instant
|
nr.instant < head.instant
|
||||||
})
|
})
|
||||||
.unwrap_or(true)
|
.unwrap_or(true);
|
||||||
{
|
if if_heap_max_greater_than_nr {
|
||||||
if is_empty {
|
if is_empty {
|
||||||
mem::transmute::<_, SYST>(()).enable_interrupt();
|
mem::transmute::<_, SYST>(()).enable_interrupt();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +55,7 @@ where
|
||||||
self.0.push_unchecked(nr);
|
self.0.push_unchecked(nr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dequeue a task from the TimerQueue
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn dequeue(&mut self) -> Option<(T, u8)> {
|
pub fn dequeue(&mut self) -> Option<(T, u8)> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue