Skip to content
This repository has been archived by the owner on May 15, 2021. It is now read-only.

Drivers for the TIMER and RTC peripherals #19

Merged
merged 12 commits into from
Apr 6, 2019

Conversation

mattheww
Copy link
Contributor

@mattheww mattheww commented Apr 6, 2019

Includes standalone modules for the TIMER and RTC peripherals exposing most but not all of their functionality (the main missing feature is the TIMERs' counter mode).

Provides new implementations of the embedded-hal CountDown and Delay traits based on these modules.

These support using all three TIMERs, or either RTC, at any frequency supported by the hardware.

Includes backwards-compatible timer::Timer and delay::Delay types.

The approach is loosely based on PR #12 but the implementation is new, with the 'driver' code separated from the countdown/delay support, and no macros.

The hardware restriction to no more than 16-bit mode for TIMER1 and TIMER2 is enforced statically.

There are usage examples in the rustdoc and in test_timer.rs and test_countdown.rs on the mattheww/microbit timer-test-examples branch (which is based on the droogmic/microbit timer-rtc branch).

mattheww added 12 commits April 4, 2019 22:24
… the event register

If we don't do this, a second call to start() shortly before the countdown was
due to expire could find the event flag was set again between it being cleared
and the timer being reset to zero, causing a following wait() to exit
immediately.
Provides type-safe access to the TIMER peripherals.

Makes the timer's current bit-width part of the type, so we can statically
prevent misuse including
 - setting a bit-width not supported by a particular TIMER
 - passing a compare register value out of range for the current bit-width

Includes HiResTimer, TimerFrequency, and TimerCc types.
Now uses 32-bit mode rather than 24-bit mode.

Now uses a shortcut to stop the timer.

Now checks for overlong delay times.
Adds a free() method.

No longer enables the TIMER's interrupt.
The frequency is still always 1MHz, so the maximum delay when not using TIMER0
is ~65ms.

Adds new struct DelayTimer<T: Nrf51Timer>.

Delay is now an alias for DelayTimer<TIMER0>.
The frequency is still always 1MHz, so the maximum period when not using TIMER0
is ~65ms.

Adds new struct CountDownTimer<T: Nrf51Timer>.

Timer is now an alias for CountDownTimer<TIMER0>.
DelayTimer::new() now requires a TimerFrequency parameter.

Adds new module time.rs, defining an Hfticks type.
Adds new method TimerFrequency::scale().

Delay is now a wrapper rather than an alias, so that its new() can keep the
same signature.
CountDownTimer::new() now requires a TimerFrequency parameter.

Implements From<Duration> for Hfticks.

Timer is now a wrapper rather than an alias, so that its new() can keep the
same signature.

The From<Duration> implementation is based on code from
https://github.com/droogmic/nrf51-hal/tree/timers
Provides access to the RTC peripherals.

Includes LoResTimer, RtcFrequency, and RtcCc types.
Adds new struct DelayRtc<T: Nrf51Rtc>.

Adds new Lfticks type to time.rs.
Unlike the TIMER-backed implementation, this one isn't Periodic (because
there's no shortcut to use).

Adds new struct CountDownRtc<T: Nrf51Rtc>.

Implements From<Duration> for Lfticks.

The From<Duration> implementation is based on code from
https://github.com/droogmic/nrf51-hal/tree/timers
///
/// # Panics
///
/// `delay_ms()` and `delay_us()` panic if the requested time requires more
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to allow the timers to wrap as often as required for longer delays instead of panicking but this is fine for now.

Copy link
Collaborator

@therealprof therealprof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outstanding work! Thank you so much.

@therealprof therealprof merged commit 20faa82 into nrf-rs:master Apr 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants