Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NuttX RTOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
f4grx
NuttX RTOS
Commits
27c48a38
Commit
27c48a38
authored
10 years ago
by
Gregory Nutt
Browse files
Options
Downloads
Patches
Plain Diff
Don't do 64-bit calculations if accuracy not achievable; Fix compile error in high res RTC mode
parent
88bf9f3f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sched/clock/clock_systimespec.c
+35
-34
35 additions, 34 deletions
sched/clock/clock_systimespec.c
with
35 additions
and
34 deletions
sched/clock/clock_systimespec.c
+
35
−
34
View file @
27c48a38
...
...
@@ -78,63 +78,64 @@
int
clock_systimespec
(
FAR
struct
timespec
*
ts
)
{
#ifdef CONFIG_RTC_HIRES
#ifdef CONFIG_RTC_HIRES
/* Do we have a high-resolution RTC that can provide us with the time? */
if
(
g_rtc_enabled
)
{
/* Get the hi-resolution time from the RTC */
ret
=
up_rtc_gettime
(
tp
);
ret
urn
up_rtc_gettime
(
tp
);
}
else
#endif
{
#if defined(CONFIG_SCHED_TICKLESS)
{
/* Let the platform time do the work */
/* In tickless mode, all timing is controlled by platform-specific
* code. Let the platform timer do the work.
*/
return
up_timer_gettime
(
ts
);
return
up_timer_gettime
(
ts
);
}
#elif defined(CONFIG_HAVE_LONG_LONG) && (CONFIG_USEC_PER_TICK % 1000) != 0
/* 64-bit microsecond calculations should improve our accuracy. */
#elif defined(CONFIG_HAVE_LONG_LONG)
{
uint64_t
usecs
;
uint64_t
secs
;
uint64_t
nsecs
;
uint64_t
usecs
;
uint64_t
secs
;
uint64_t
nsecs
;
/* Get the time since power-on in seconds and milliseconds */
/* Get the time since power-on in seconds and milliseconds */
usecs
=
TICK2MSEC
(
clock_systimer
());
secs
=
usecs
/
USEC_PER_SEC
;
usecs
=
TICK2MSEC
(
clock_systimer
());
secs
=
usecs
/
USEC_PER_SEC
;
/* Return the elapsed time in seconds and nanoseconds */
/* Return the elapsed time in seconds and nanoseconds */
nsecs
=
(
usecs
-
(
secs
*
USEC_PER_SEC
))
*
NSEC_PER_USEC
;
nsecs
=
(
usecs
-
(
secs
*
USEC_PER_SEC
))
*
NSEC_PER_USEC
;
ts
->
tv_sec
=
(
time_t
)
secs
;
ts
->
tv_nsec
=
(
long
)
nsecs
;
return
OK
;
}
ts
->
tv_sec
=
(
time_t
)
secs
;
ts
->
tv_nsec
=
(
long
)
nsecs
;
return
OK
;
#else
{
uint32_t
msecs
;
uint32_t
secs
;
uint32_t
nsecs
;
/* 32-bit millisecond calculations should be just fine. */
/* Get the time since power-on in seconds and milliseconds */
uint32_t
msecs
;
uint32_t
secs
;
uint32_t
nsecs
;
msecs
=
TICK2MSEC
(
clock_systimer
());
secs
=
msecs
/
MSEC_PER_SEC
;
/* Get the time since power-on in seconds and milliseconds */
/* Return the elapsed time in seconds and nanoseconds */
msecs
=
TICK2MSEC
(
clock_systimer
());
secs
=
msecs
/
MSEC_PER_SEC
;
nsecs
=
(
msecs
-
(
secs
*
MSEC_PER_SEC
))
*
NSEC_PER_MSEC
;
/* Return the elapsed time in seconds and nanoseconds */
ts
->
tv_sec
=
(
time_t
)
secs
;
ts
->
tv_nsec
=
(
long
)
nsecs
;
return
OK
;
}
nsecs
=
(
msecs
-
(
secs
*
MSEC_PER_SEC
))
*
NSEC_PER_MSEC
;
ts
->
tv_sec
=
(
time_t
)
secs
;
ts
->
tv_nsec
=
(
long
)
nsecs
;
return
OK
;
#endif
}
}
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