TimerCounter

Struct TimerCounter 

Source
pub struct TimerCounter<TC> { /* private fields */ }
Expand description

Hardware timers for atsam4 can be 16 or 32-bit depending on the hardware.. It is also possible to chain TC (timer channels) within a Timer Module to create larger timer registers (not currently implemented in this hal). TimerCounter implements both the Periodic and the CountDown embedded_hal timer traits. Before a hardware timer can be used, it must first have a clock configured.

Implementations§

Source§

impl TimerCounter<TC0>

Source

pub fn new(tc: TC0) -> Self

Configure this timer counter block. Each TC block has 3 channels The clock is obtained from the ClockController instance and its frequency impacts the resolution and maximum range of the timeout values that can be passed to the start method.

Example

let clocks = ClockController::new(
    cx.device.PMC,
    &cx.device.SUPC,
    &cx.device.EFC0,
    MainClock::Crystal12Mhz,
    SlowClock::RcOscillator32Khz,
);

let mut tc0 = TimerCounter::new(TC0);
let tc0_chs = tc0.split(
    clocks.peripheral_clocks.tc_0.into_enabled_clock(),
    clocks.peripheral_clocks.tc_1.into_enabled_clock(),
    clocks.peripheral_clocks.tc_2.into_enabled_clock(),
);

let mut tcc0 = tc0_chs.ch0;
tcc0.clock_input(ClockSource::Slck32768Hz);
tcc0.start(500_u32.millis());
while !tcc0.wait().is_ok() {}

let mut tcc1 = tc0_chs.ch1;
tcc1.clock_input(ClockSource::MckDiv2);
tcc1.start(17_u32.nanos()); // Assuming MCK is 120 MHz or faster
while !tcc1.wait().is_ok() {}
Source

pub fn split<const FREQ1: u32, const FREQ2: u32, const FREQ3: u32>( self, clock1: Tc0Clock<Enabled>, _clock2: Tc1Clock<Enabled>, _clock3: Tc2Clock<Enabled>, ) -> TimerCounterChannels<TC0, Tc0Clock<Enabled>, Tc1Clock<Enabled>, Tc2Clock<Enabled>, FREQ1, FREQ2, FREQ3>

Splits the TimerCounter module into 3 channels Defaults to MckDiv2 clock source

Source§

impl TimerCounter<TC1>

Source

pub fn new(tc: TC1) -> Self

Configure this timer counter block. Each TC block has 3 channels The clock is obtained from the ClockController instance and its frequency impacts the resolution and maximum range of the timeout values that can be passed to the start method.

Example

let clocks = ClockController::new(
    cx.device.PMC,
    &cx.device.SUPC,
    &cx.device.EFC0,
    MainClock::Crystal12Mhz,
    SlowClock::RcOscillator32Khz,
);

let mut tc0 = TimerCounter::new(TC0);
let tc0_chs = tc0.split(
    clocks.peripheral_clocks.tc_0.into_enabled_clock(),
    clocks.peripheral_clocks.tc_1.into_enabled_clock(),
    clocks.peripheral_clocks.tc_2.into_enabled_clock(),
);

let mut tcc0 = tc0_chs.ch0;
tcc0.clock_input(ClockSource::Slck32768Hz);
tcc0.start(500_u32.millis());
while !tcc0.wait().is_ok() {}

let mut tcc1 = tc0_chs.ch1;
tcc1.clock_input(ClockSource::MckDiv2);
tcc1.start(17_u32.nanos()); // Assuming MCK is 120 MHz or faster
while !tcc1.wait().is_ok() {}
Source

pub fn split<const FREQ1: u32, const FREQ2: u32, const FREQ3: u32>( self, clock1: Tc3Clock<Enabled>, _clock2: Tc4Clock<Enabled>, _clock3: Tc5Clock<Enabled>, ) -> TimerCounterChannels<TC1, Tc3Clock<Enabled>, Tc4Clock<Enabled>, Tc5Clock<Enabled>, FREQ1, FREQ2, FREQ3>

Splits the TimerCounter module into 3 channels Defaults to MckDiv2 clock source

Source§

impl TimerCounter<TC2>

Source

pub fn new(tc: TC2) -> Self

Configure this timer counter block. Each TC block has 3 channels The clock is obtained from the ClockController instance and its frequency impacts the resolution and maximum range of the timeout values that can be passed to the start method.

Example

let clocks = ClockController::new(
    cx.device.PMC,
    &cx.device.SUPC,
    &cx.device.EFC0,
    MainClock::Crystal12Mhz,
    SlowClock::RcOscillator32Khz,
);

let mut tc0 = TimerCounter::new(TC0);
let tc0_chs = tc0.split(
    clocks.peripheral_clocks.tc_0.into_enabled_clock(),
    clocks.peripheral_clocks.tc_1.into_enabled_clock(),
    clocks.peripheral_clocks.tc_2.into_enabled_clock(),
);

let mut tcc0 = tc0_chs.ch0;
tcc0.clock_input(ClockSource::Slck32768Hz);
tcc0.start(500_u32.millis());
while !tcc0.wait().is_ok() {}

let mut tcc1 = tc0_chs.ch1;
tcc1.clock_input(ClockSource::MckDiv2);
tcc1.start(17_u32.nanos()); // Assuming MCK is 120 MHz or faster
while !tcc1.wait().is_ok() {}
Source

pub fn split<const FREQ1: u32, const FREQ2: u32, const FREQ3: u32>( self, clock1: Tc6Clock<Enabled>, _clock2: Tc7Clock<Enabled>, _clock3: Tc8Clock<Enabled>, ) -> TimerCounterChannels<TC2, Tc6Clock<Enabled>, Tc7Clock<Enabled>, Tc8Clock<Enabled>, FREQ1, FREQ2, FREQ3>

Splits the TimerCounter module into 3 channels Defaults to MckDiv2 clock source

Auto Trait Implementations§

§

impl<TC> Freeze for TimerCounter<TC>
where TC: Freeze,

§

impl<TC> RefUnwindSafe for TimerCounter<TC>
where TC: RefUnwindSafe,

§

impl<TC> Send for TimerCounter<TC>
where TC: Send,

§

impl<TC> Sync for TimerCounter<TC>
where TC: Sync,

§

impl<TC> Unpin for TimerCounter<TC>
where TC: Unpin,

§

impl<TC> UnwindSafe for TimerCounter<TC>
where TC: UnwindSafe,

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.