Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
stm32f4-hal
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
stm32f4-hal
Commits
c2409c0a
Commit
c2409c0a
authored
7 years ago
by
Jorge Aparicio
Browse files
Options
Downloads
Patches
Plain Diff
add `time::Instant` API
parent
d9d0252a
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/time.rs
+49
-0
49 additions, 0 deletions
src/time.rs
with
49 additions
and
0 deletions
src/time.rs
+
49
−
0
View file @
c2409c0a
//! Time units
//! Time units
use
cortex_m
::
peripheral
::
DWT
;
use
rcc
::
Clocks
;
/// Bits per second
/// Bits per second
#[derive(Clone,
Copy)]
#[derive(Clone,
Copy)]
pub
struct
Bps
(
pub
u32
);
pub
struct
Bps
(
pub
u32
);
...
@@ -66,3 +70,48 @@ impl Into<KiloHertz> for MegaHertz {
...
@@ -66,3 +70,48 @@ impl Into<KiloHertz> for MegaHertz {
KiloHertz
(
self
.0
*
1_000
)
KiloHertz
(
self
.0
*
1_000
)
}
}
}
}
/// A monotonic nondecreasing timer
#[derive(Clone,
Copy)]
pub
struct
MonoTimer
{
frequency
:
Hertz
,
}
impl
MonoTimer
{
/// Creates a new `Monotonic` timer
pub
fn
new
(
mut
dwt
:
DWT
,
clocks
:
Clocks
)
->
Self
{
dwt
.enable_cycle_counter
();
// now the CYCCNT counter can't be stopped or resetted
drop
(
dwt
);
MonoTimer
{
frequency
:
clocks
.sysclk
(),
}
}
/// Returns the frequency at which the monotonic timer is operating at
pub
fn
frequency
(
&
self
)
->
Hertz
{
self
.frequency
}
/// Returns an `Instant` corresponding to "now"
pub
fn
now
(
&
self
)
->
Instant
{
Instant
{
now
:
DWT
::
get_cycle_count
(),
}
}
}
/// A measurement of a monotonically nondecreasing clock
#[derive(Clone,
Copy)]
pub
struct
Instant
{
now
:
u32
,
}
impl
Instant
{
/// Ticks elapsed since the `Instant` was created
pub
fn
elapsed
(
&
self
)
->
u32
{
DWT
::
get_cycle_count
()
.wrapping_sub
(
self
.now
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment