sched/clock/clock_timespec.c: Fix an error in the time conversion
This commit is contained in:
parent
de995653fe
commit
e001f37593
@ -11332,4 +11332,10 @@
|
||||
read-only passwd file (2016-01-20).
|
||||
* sim/nsh: Uses the custom start up script, includes hoks for
|
||||
an MOTD message. (2016-01-20).
|
||||
* include/clock.h and lots of other files: If the 64-bit timer is
|
||||
selected, then use it whenever clock_systimer() is called rather
|
||||
then chopping the 64-bit timer down to 32-bits. Add a new type,
|
||||
systime_t to represent the 32- or 64-bit system timer (2016-01-21).
|
||||
* sched/clock/clock_systimespec.c: Fix an error in a time
|
||||
conversion (2016-01-21).
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************************
|
||||
* sched/clock/clock_abstime2ticks.c
|
||||
*
|
||||
* Copyright (C) 2007, 2008, 2013-2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2008, 2013-2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -44,22 +44,6 @@
|
||||
#include <debug.h>
|
||||
#include "clock/clock.h"
|
||||
|
||||
/********************************************************************************
|
||||
* Pre-processor Definitions
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Type Declarations
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Public Data
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Variables
|
||||
********************************************************************************/
|
||||
|
||||
/********************************************************************************
|
||||
* Private Functions
|
||||
********************************************************************************/
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* sched/clock/clock_gettime.c
|
||||
*
|
||||
* Copyright (C) 2007, 2009, 2011, 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2009, 2011, 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -50,34 +50,6 @@
|
||||
|
||||
#include "clock/clock.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Type Declarations
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Variables
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* sched/clock/clock_systimespec.c
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -48,14 +48,6 @@
|
||||
|
||||
#include "clock/clock.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@ -138,15 +130,17 @@ int clock_systimespec(FAR struct timespec *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. */
|
||||
/* 64-bit microsecond calculations should improve our accuracy
|
||||
* when the clock period is in units of microseconds.
|
||||
*/
|
||||
|
||||
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 microsecon */
|
||||
|
||||
usecs = TICK2MSEC(clock_systimer());
|
||||
usecs = (uint64_t)TICK2USEC(clock_systimer());
|
||||
secs = usecs / USEC_PER_SEC;
|
||||
|
||||
/* Return the elapsed time in seconds and nanoseconds */
|
||||
@ -158,11 +152,28 @@ int clock_systimespec(FAR struct timespec *ts)
|
||||
return OK;
|
||||
|
||||
#else
|
||||
/* 32-bit millisecond calculations should be just fine. */
|
||||
/* We know that the clock rate is in units of milliseconds
|
||||
* show we should be able to do the calculations with less
|
||||
* chance of overflow.
|
||||
*
|
||||
* 32-bit millisecond calculations should be just fine in
|
||||
* most cases. For a 32-bit system timer and a clock period
|
||||
* of 10 milliseconds, the msecs value will overflow at about
|
||||
* 49.7 days.
|
||||
*
|
||||
* So, we will still use 64-bit calculations if we have them
|
||||
* in order to avoid that limitation.
|
||||
*/
|
||||
|
||||
uint32_t msecs;
|
||||
uint32_t secs;
|
||||
uint32_t nsecs;
|
||||
#ifdef CONFIG_HAVE_LONG_LONG
|
||||
uint64_t msecs;
|
||||
uint64_t secs;
|
||||
uint64_t nsecs;
|
||||
#else
|
||||
systime_t msecs;
|
||||
systime_t secs;
|
||||
systime_t nsecs;
|
||||
#endif
|
||||
|
||||
/* Get the time since power-on in seconds and milliseconds */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user