mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-09-21 02:44:35 +08:00
score: Add and use _TOD_Get_with_nanoseconds()
Delete _TOD_Get_as_timestamp().
This commit is contained in:
@@ -307,7 +307,7 @@ libscore_a_SOURCES += src/ts64addto.c src/ts64dividebyinteger.c \
|
||||
|
||||
## TOD_C_FILES
|
||||
libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
|
||||
src/coretodgetuptime.c src/coretodgetuptimetimespec.c src/coretodtickle.c \
|
||||
src/coretodgetuptimetimespec.c src/coretodtickle.c \
|
||||
src/coretodmsecstoticks.c src/coretodtickspersec.c src/coretodusectoticks.c
|
||||
|
||||
## WATCHDOG_C_FILES
|
||||
|
||||
@@ -197,22 +197,30 @@ static inline void _TOD_Set(
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the time of day in @a tod_as_timestamp.
|
||||
* @brief Returns a snapshot of a clock.
|
||||
*
|
||||
* The @a tod_as_timestamp timestamp represents the time since UNIX epoch.
|
||||
* This function invokes the nanoseconds extension.
|
||||
*
|
||||
* @param[out] snapshot The snapshot.
|
||||
* @param[in] source The clock.
|
||||
*
|
||||
* @return The snapshot.
|
||||
*/
|
||||
void _TOD_Get_as_timestamp(
|
||||
Timestamp_Control *tod_as_timestamp
|
||||
Timestamp_Control *_TOD_Get_with_nanoseconds(
|
||||
Timestamp_Control *snapshot,
|
||||
const Timestamp_Control *clock
|
||||
);
|
||||
|
||||
static inline void _TOD_Get(
|
||||
struct timespec *tod_as_timespec
|
||||
)
|
||||
{
|
||||
Timestamp_Control tod_as_timestamp;
|
||||
Timestamp_Control tod_as_timestamp;
|
||||
Timestamp_Control *tod_as_timestamp_ptr;
|
||||
|
||||
_TOD_Get_as_timestamp( &tod_as_timestamp );
|
||||
_Timestamp_To_timespec( &tod_as_timestamp, tod_as_timespec );
|
||||
tod_as_timestamp_ptr =
|
||||
_TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
|
||||
_Timestamp_To_timespec( tod_as_timestamp_ptr, tod_as_timespec );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,9 +231,12 @@ static inline void _TOD_Get(
|
||||
*
|
||||
* @param[in] time is a pointer to the uptime to be returned
|
||||
*/
|
||||
void _TOD_Get_uptime(
|
||||
static inline void _TOD_Get_uptime(
|
||||
Timestamp_Control *time
|
||||
);
|
||||
)
|
||||
{
|
||||
_TOD_Get_with_nanoseconds( time, &_TOD.uptime );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief _TOD_Get_uptime_as_timespec
|
||||
|
||||
@@ -56,19 +56,12 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
|
||||
struct timeval *time
|
||||
)
|
||||
{
|
||||
ISR_Level level;
|
||||
struct timespec now;
|
||||
suseconds_t useconds;
|
||||
Timestamp_Control snapshot_as_timestamp;
|
||||
Timestamp_Control *snapshot_as_timestamp_ptr;
|
||||
|
||||
_ISR_Disable(level);
|
||||
_TOD_Get( &now );
|
||||
_ISR_Enable(level);
|
||||
|
||||
useconds = (suseconds_t)now.tv_nsec;
|
||||
useconds /= (suseconds_t)TOD_NANOSECONDS_PER_MICROSECOND;
|
||||
|
||||
time->tv_sec = now.tv_sec;
|
||||
time->tv_usec = useconds;
|
||||
snapshot_as_timestamp_ptr =
|
||||
_TOD_Get_with_nanoseconds( &snapshot_as_timestamp, &_TOD.now );
|
||||
_Timestamp_To_timeval( snapshot_as_timestamp_ptr, time );
|
||||
}
|
||||
|
||||
/**@}*/
|
||||
|
||||
@@ -10,35 +10,31 @@
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/timespec.h>
|
||||
#include <rtems/score/timestamp.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
void _TOD_Get_as_timestamp(
|
||||
Timestamp_Control *tod
|
||||
Timestamp_Control *_TOD_Get_with_nanoseconds(
|
||||
Timestamp_Control *snapshot,
|
||||
const Timestamp_Control *clock
|
||||
)
|
||||
{
|
||||
ISR_Level level;
|
||||
Timestamp_Control offset;
|
||||
Timestamp_Control now;
|
||||
long nanoseconds;
|
||||
uint32_t nanoseconds;
|
||||
|
||||
/* assume time checked for NULL by caller */
|
||||
|
||||
/* _TOD.now is the native current time */
|
||||
_ISR_Disable( level );
|
||||
now = _TOD.now;
|
||||
nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
|
||||
now = *clock;
|
||||
_ISR_Enable( level );
|
||||
|
||||
_Timestamp_Set( &offset, 0, nanoseconds );
|
||||
_Timestamp_Add_to( &now, &offset );
|
||||
|
||||
*tod = now;
|
||||
*snapshot = now;
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Time of Day (TOD) Handler - get uptime
|
||||
*/
|
||||
|
||||
/* COPYRIGHT (c) 1989-2008.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.com/license/LICENSE.
|
||||
*/
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rtems/system.h>
|
||||
#include <rtems/score/isr.h>
|
||||
#include <rtems/score/timestamp.h>
|
||||
#include <rtems/score/tod.h>
|
||||
#include <rtems/score/watchdog.h>
|
||||
|
||||
/*
|
||||
* _TOD_Get_uptime
|
||||
*
|
||||
* This routine is used to obtain the system uptime
|
||||
*
|
||||
* Input parameters:
|
||||
* time - pointer to the timestamp structure
|
||||
*
|
||||
* Output parameters: NONE
|
||||
*/
|
||||
|
||||
void _TOD_Get_uptime(
|
||||
Timestamp_Control *uptime
|
||||
)
|
||||
{
|
||||
ISR_Level level;
|
||||
Timestamp_Control offset;
|
||||
Timestamp_Control up;
|
||||
long nanoseconds;
|
||||
|
||||
/* assume time checked for NULL by caller */
|
||||
|
||||
/* _TOD.uptime is in native timestamp format */
|
||||
_ISR_Disable( level );
|
||||
up = _TOD.uptime;
|
||||
nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
|
||||
_ISR_Enable( level );
|
||||
|
||||
_Timestamp_Set( &offset, 0, nanoseconds );
|
||||
_Timestamp_Add_to( &up, &offset );
|
||||
*uptime = up;
|
||||
}
|
||||
Reference in New Issue
Block a user