Struct Scheduler

Source
pub struct Scheduler<'a, C, T, E = Error> {
    pub tasks: &'a mut [Task<T, E>],
    pub clock: C,
    pub tick: u16,
    pub max_task_slowdown: u8,
    pub loop_rate_hz: i16,
    pub task_not_achieved: u32,
    pub task_all_achieved: u32,
    pub loop_timer_start_us: u32,
    pub last_loop_time_s: f32,
    pub extra_loop_us: u32,
    /* private fields */
}
Expand description

Task scheduler for flight controllers

Fields§

§tasks: &'a mut [Task<T, E>]

The tasks to run in order of highest to lowest priority.

§clock: C

The clock used for timing.

§tick: u16

The current tick, incremented each run.

§max_task_slowdown: u8

The maximum amount of ticks a task can miss before slowing down the scheduler.

§loop_rate_hz: i16

The desired loop rate to run (in hz).

§task_not_achieved: u32

The amount of ticks with tasks that exceed the max_task_slowdown.

§task_all_achieved: u32

The amount of ticks with tasks that remain in the max_task_slowdown.

§loop_timer_start_us: u32

The start time of the run loop (in microseconds).

§last_loop_time_s: f32

The start time of the run loop (in seconds).

§extra_loop_us: u32

Extra time to spend in the loop to catch up on tasks not achieved (in microseconds).

Implementations§

Source§

impl<'a, C, T, E> Scheduler<'a, C, T, E>
where C: Clock, C::T: ToPrimitive, E: From<Error>,

Source

pub fn new(tasks: &'a mut [Task<T, E>], clock: C, loop_rate_hz: i16) -> Self

Create a new scheduler from a slice of tasks, a clock, and the loop rate (in hz)

Source

pub fn run(&mut self, state: &mut T) -> Result<(), E>

Calculate the time available and run as many tasks as possible.

Source

pub fn run_with_time_available( &mut self, system: &mut T, time_available: u32, ) -> Result<(), E>

Run as many tasks as possible in the given time_available.

Auto Trait Implementations§

§

impl<'a, C, T, E> Freeze for Scheduler<'a, C, T, E>
where C: Freeze,

§

impl<'a, C, T, E> RefUnwindSafe for Scheduler<'a, C, T, E>
where C: RefUnwindSafe,

§

impl<'a, C, T, E> Send for Scheduler<'a, C, T, E>
where C: Send,

§

impl<'a, C, T, E> Sync for Scheduler<'a, C, T, E>
where C: Sync,

§

impl<'a, C, T, E> Unpin for Scheduler<'a, C, T, E>
where C: Unpin,

§

impl<'a, C, T, E = Error> !UnwindSafe for Scheduler<'a, C, T, E>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.