Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
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
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Niklas Roy
firmware
Commits
869ac617
Commit
869ac617
authored
5 years ago
by
Ferdinand Bachmann
Browse files
Options
Downloads
Patches
Plain Diff
epicardium/rtc: add explanation comment for numerically stable subsecond decode
parent
18936b7e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
epicardium/modules/rtc.c
+16
-0
16 additions, 0 deletions
epicardium/modules/rtc.c
with
16 additions
and
0 deletions
epicardium/modules/rtc.c
+
16
−
0
View file @
869ac617
...
...
@@ -44,6 +44,22 @@ uint64_t epic_rtc_get_milliseconds(void)
while
(
RTC_GetTime
(
&
sec
,
&
subsec
)
==
E_BUSY
)
{
vTaskDelay
(
pdMS_TO_TICKS
(
4
));
}
// Without the bias of 999 (0.24 milliseconds), this decoding function is
// numerically unstable:
//
// Encoding 5 milliseconds into 20 subsecs (using the encoding function in
// epic_rtc_set_milliseconds) and decoding it without the bias of 999 yields
// 4 milliseconds.
//
// The following invariants should hold when encoding / decoding from and to
// milliseconds / subseconds:
//
// - 0 <= encode(ms) < 4096 for 0 <= ms < 1000
// - decode(encode(ms)) == ms for 0 <= ms < 1000
// - 0 <= decode(subsec) < 1000 for 0 <= subsec < 4096
//
// These invariants were proven experimentally.
return
(
subsec
*
1000ULL
+
999ULL
)
/
4096
+
sec
*
1000ULL
;
}
...
...
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