Checked for Y2K complience. It turns out it was even ok when NTP time overflows

in 2036. However it was modified so that no overflows should occur while convert
ing between NTP, UNIX, and EPICS epochs.
In addition the conversion of fractions of a second to nanaoseconds was changed
Formatting was changed so that interesting code does not run off right side of page.
Hopefully EPICS base is now fine for Y2K.
In fact it should be fine (as far as time is converned) until the Unix epoch
overflows a 32 unsigned integer in the year 2106.
This commit is contained in:
Marty Kraimer
1998-03-19 20:41:16 +00:00
parent 54cd86e819
commit 4486982ee6
5 changed files with 2445 additions and 2738 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,9 @@
/*
* $Log$
* Revision 1.1 1996/01/25 21:11:56 mrk
* moved includes; .ascii=> .db; path changes
*
* Revision 1.12 1995/08/30 15:39:07 jbk
* Added global variables for force accurate time stamps and direct time.
*
@@ -39,53 +42,17 @@
* .01 01-06-94 jbk initial version
*
***********************************************************************/
/*
*****************************************************************
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
THE FOLLOWING IS A NOTICE OF COPYRIGHT, AVAILABILITY OF THE CODE,
AND DISCLAIMER WHICH MUST BE INCLUDED IN THE PROLOGUE OF THE CODE
AND IN ALL SOURCE LISTINGS OF THE CODE.
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
Argonne National Laboratory (ANL), with facilities in the States of
Illinois and Idaho, is owned by the United States Government, and
operated by the University of Chicago under provision of a contract
with the Department of Energy.
Portions of this material resulted from work developed under a U.S.
Government contract and are subject to the following license: For
a period of five years from March 30, 1993, the Government is
granted for itself and others acting on its behalf a paid-up,
nonexclusive, irrevocable worldwide license in this computer
software to reproduce, prepare derivative works, and perform
publicly and display publicly. With the approval of DOE, this
period may be renewed for two additional five year periods.
Following the expiration of this period or periods, the Government
is granted for itself and others acting on its behalf, a paid-up,
nonexclusive, irrevocable worldwide license in this computer
software to reproduce, prepare derivative works, distribute copies
to the public, perform publicly and display publicly, and to permit
others to do so.
*****************************************************************
DISCLAIMER
*****************************************************************
NEITHER THE UNITED STATES GOVERNMENT NOR ANY AGENCY THEREOF, NOR
THE UNIVERSITY OF CHICAGO, NOR ANY OF THEIR EMPLOYEES OR OFFICERS,
MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR
USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR PROCESS
DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
OWNED RIGHTS.
*****************************************************************
LICENSING INQUIRIES MAY BE DIRECTED TO THE INDUSTRIAL TECHNOLOGY
DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
*/
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
#include <vxWorks.h>
#include <timers.h>
@@ -118,12 +85,15 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#define TS_SYNC_RATE_SEC 10
#define TS_CLOCK_RATE_HZ 1000
#define TS_TOTAL_EVENTS 128
#define TS_SEC_IN_DAY (24*60*60)
#define TS_SEC_IN_YEAR (TS_SEC_IN_DAY*365)
#define TS_LEAPS_SINCE_1900 23
#define TS_1900_TO_EPICS_EPOCH ((TS_SEC_IN_YEAR*90)+(22*TS_SEC_IN_DAY))
#define TS_1900_TO_VXWORKS_EPOCH ((TS_SEC_IN_YEAR*70)+(17*TS_SEC_IN_DAY))
#define TS_VXWORKS_TO_EPICS_EPOCH ((TS_SEC_IN_YEAR*20)+(5*TS_SEC_IN_DAY))
/*Following is (SEC_IN_YEAR*90)+(22*SEC_IN_DAY) */
/*22 is leap years from 1900 to 1990*/
#define TS_1900_TO_EPICS_EPOCH 2840140800UL
/*Following is (SEC_IN_YEAR*70)+(17*SEC_IN_DAY) */
/*17 is leap years from 1900 to 1970*/
#define TS_1900_TO_VXWORKS_EPOCH 2208988800UL
/*Following is (SEC_IN_YEAR*20)+(5*SEC_IN_DAY) */
/*5 is leap years from 1970 to 1990*/
#define TS_VXWORKS_TO_EPICS_EPOCH 631152000UL
#define TS_STAMP_SERVER_PRI 70
#define TS_SYNC_SERVER_PRI 70
@@ -133,14 +103,14 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
typedef enum { TS_time_request, TS_sync_request, TS_sync_msg } TStype;
typedef enum { TS_master_alive, TS_master_dead } TSstate;
typedef enum { TS_async_none, TS_async_private,
TS_async_ntp, TS_async_time } TStime_protocol;
TS_async_ntp, TS_async_time } TStime_protocol;
typedef enum { TS_sync_master, TS_async_master,
TS_sync_slave, TS_async_slave,
TS_direct_master, TS_direct_slave } TStime_type;
TS_sync_slave, TS_async_slave,
TS_direct_master, TS_direct_slave} TStime_type;
struct TSstampTransStruct {
unsigned long magic; /* identifier */
TStype type; /* transaction type */
TStype type; /* transaction type */
struct timespec master_time; /* master time stamp - last sync time */
struct timespec current_time; /* master current time stamp 1990 epoch */
struct timespec unix_time; /* time using 1900 epoch */
@@ -159,13 +129,13 @@ struct TSinfoStruct {
unsigned long sync_rate; /* master send sync at this rate */
unsigned long clock_hz; /* master clock is this frequency */
unsigned long clock_conv; /* conversion factor for tick_rate->ns */
unsigned long clock_conv;/* conversion factor for tick_rate->ns */
unsigned long time_out; /* udp packet time-out in milliseconds */
int master_timing_IOC; /* 1=master, 0=slave */
int master_port; /* port that master listens on */
int slave_port; /* port that slave listens on */
int total_events; /* this is the total event in the event system */
int sync_event; /* this is the sync event number */
int master_port; /* port that master listens on */
int slave_port; /* port that slave listens on */
int total_events; /* this is the total event in the event system*/
int sync_event; /* this is the sync event number */
int has_event_system; /* 1=has event system, 0=no event system */
int has_direct_time; /* 1=has direct time, 0=no direct time */
int UserRequestedType; /* let user force the setting of type */
@@ -182,17 +152,22 @@ typedef struct TSinfoStruct TSinfo;
extern "C" {
#endif
TS_EXTERN long TSinit(void);
TS_EXTERN long TSgetTimeStamp(int event_number,struct timespec* sp);
TS_EXTERN long TScurrentTimeStamp(struct timespec* sp);
TS_EXTERN long TSaccurateTimeStamp(struct timespec* sp);
TS_EXTERN long TSgetFirstOfYearVx(struct timespec* sp);
TS_EXTERN long TSgetTimeStamp(int event_number,struct timespec* ts);
TS_EXTERN unsigned long TSepochNtpToUnix(struct timespec* ts);
TS_EXTERN unsigned long TSfractionToNano(unsigned long fraction);
TS_EXTERN unsigned long TSepochNtpToEpics(struct timespec* ts);
TS_EXTERN unsigned long TSepochUnixToEpics(struct timespec* ts);
TS_EXTERN unsigned long TSepochEpicsToUnix(struct timespec* ts);
TS_EXTERN long TScurrentTimeStamp(struct timespec* ts);
TS_EXTERN long TSaccurateTimeStamp(struct timespec* ts);
TS_EXTERN long TSgetFirstOfYearVx(struct timespec* ts);
TS_EXTERN void TSconfigure(int master, int sync_rate_sec, int clock_rate_hz,
int master_port, int slave_port,
unsigned long millisecond_request_time_out, int type);
int master_port, int slave_port,
unsigned long millisecond_request_time_out, int type);
#ifndef TS_DRIVER
TS_EXTERN TSinfo TSdata;
TS_EXTERN TSdirectTimeVar; /* set to !=0 to indicate direct time available */
TS_EXTERN TSdirectTimeVar; /* set to !=0 to indicate direct time available*/
TS_EXTERN TSgoodTimeStamps; /* force best time stamps by setting != 0 */
#endif
@@ -204,27 +179,27 @@ TS_EXTERN TSgoodTimeStamps; /* force best time stamps by setting != 0 */
#define VN_SHIFT 2 /* Version - 3 bits */
#define VN_version 3<<VN_SHIFT
#define LI_SHIFT 0 /* Leap Indicator LI - 2 bits */
#define LI_SHIFT 0 /* Leap Indicator LI - 2 bits */
#define LI_no_warning (0x00<<LI_SHIFT)
#define LI_61_sec_minute (0x01<<LI_SHIFT)
#define LI_59_sec_minute (0x02<<LI_SHIFT)
#define LI_alarm_condition (0x03<<LI_SHIFT)
#define MODE_SHIFT 5 /* Mode MODE - 3 bits */
#define MODE_SHIFT 5 /* Mode MODE - 3 bits */
#define MODE_reserved (0x00<<MODE_SHIFT)
#define MODE_sym_active (0x01<<MODE_SHIFT)
#define MODE_sym_passive (0x02<<MODE_SHIFT)
#define MODE_client (0x03<<MODE_SHIFT)
#define MODE_server (0x04<<MODE_SHIFT)
#define MODE_client (0x03<<MODE_SHIFT)
#define MODE_server (0x04<<MODE_SHIFT)
#define MODE_broadcast (0x05<<MODE_SHIFT)
#define MODE_reserved_NTP (0x06<<MODE_SHIFT)
#define MODE_reserved_pvt (0x07<<MODE_SHIFT)
#define STRAT_SHIFT 8 /* Stratum STRAT - 8 bits */
#define STRAT_SHIFT 8 /* Stratum STRAT - 8 bits */
#define STRAT_unspecified (0x00<<STRAT_SHIFT)
#define STRAT_ascii (0x00<<STRAT_SHIFT)
#define STRAT_GPS (0x01<<STRAT_SHIFT)
#define STRAT_ATOM (0x01<<STRAT_SHIFT)
#define STRAT_ascii (0x00<<STRAT_SHIFT)
#define STRAT_GPS (0x01<<STRAT_SHIFT)
#define STRAT_ATOM (0x01<<STRAT_SHIFT)
#define STRAT_address (0x02<<STRAT_SHIFT)
#define POLL_SHIFT 16 /* eight bits */

View File

@@ -3,6 +3,9 @@
/*
* $Log$
* Revision 1.1 1996/01/25 21:11:56 mrk
* moved includes; .ascii=> .db; path changes
*
* Revision 1.12 1995/08/30 15:39:07 jbk
* Added global variables for force accurate time stamps and direct time.
*
@@ -39,53 +42,17 @@
* .01 01-06-94 jbk initial version
*
***********************************************************************/
/*
*****************************************************************
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
THE FOLLOWING IS A NOTICE OF COPYRIGHT, AVAILABILITY OF THE CODE,
AND DISCLAIMER WHICH MUST BE INCLUDED IN THE PROLOGUE OF THE CODE
AND IN ALL SOURCE LISTINGS OF THE CODE.
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
Argonne National Laboratory (ANL), with facilities in the States of
Illinois and Idaho, is owned by the United States Government, and
operated by the University of Chicago under provision of a contract
with the Department of Energy.
Portions of this material resulted from work developed under a U.S.
Government contract and are subject to the following license: For
a period of five years from March 30, 1993, the Government is
granted for itself and others acting on its behalf a paid-up,
nonexclusive, irrevocable worldwide license in this computer
software to reproduce, prepare derivative works, and perform
publicly and display publicly. With the approval of DOE, this
period may be renewed for two additional five year periods.
Following the expiration of this period or periods, the Government
is granted for itself and others acting on its behalf, a paid-up,
nonexclusive, irrevocable worldwide license in this computer
software to reproduce, prepare derivative works, distribute copies
to the public, perform publicly and display publicly, and to permit
others to do so.
*****************************************************************
DISCLAIMER
*****************************************************************
NEITHER THE UNITED STATES GOVERNMENT NOR ANY AGENCY THEREOF, NOR
THE UNIVERSITY OF CHICAGO, NOR ANY OF THEIR EMPLOYEES OR OFFICERS,
MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR
USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR PROCESS
DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
OWNED RIGHTS.
*****************************************************************
LICENSING INQUIRIES MAY BE DIRECTED TO THE INDUSTRIAL TECHNOLOGY
DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
*/
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
#include <vxWorks.h>
#include <timers.h>
@@ -118,12 +85,15 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#define TS_SYNC_RATE_SEC 10
#define TS_CLOCK_RATE_HZ 1000
#define TS_TOTAL_EVENTS 128
#define TS_SEC_IN_DAY (24*60*60)
#define TS_SEC_IN_YEAR (TS_SEC_IN_DAY*365)
#define TS_LEAPS_SINCE_1900 23
#define TS_1900_TO_EPICS_EPOCH ((TS_SEC_IN_YEAR*90)+(22*TS_SEC_IN_DAY))
#define TS_1900_TO_VXWORKS_EPOCH ((TS_SEC_IN_YEAR*70)+(17*TS_SEC_IN_DAY))
#define TS_VXWORKS_TO_EPICS_EPOCH ((TS_SEC_IN_YEAR*20)+(5*TS_SEC_IN_DAY))
/*Following is (SEC_IN_YEAR*90)+(22*SEC_IN_DAY) */
/*22 is leap years from 1900 to 1990*/
#define TS_1900_TO_EPICS_EPOCH 2840140800UL
/*Following is (SEC_IN_YEAR*70)+(17*SEC_IN_DAY) */
/*17 is leap years from 1900 to 1970*/
#define TS_1900_TO_VXWORKS_EPOCH 2208988800UL
/*Following is (SEC_IN_YEAR*20)+(5*SEC_IN_DAY) */
/*5 is leap years from 1970 to 1990*/
#define TS_VXWORKS_TO_EPICS_EPOCH 631152000UL
#define TS_STAMP_SERVER_PRI 70
#define TS_SYNC_SERVER_PRI 70
@@ -133,14 +103,14 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
typedef enum { TS_time_request, TS_sync_request, TS_sync_msg } TStype;
typedef enum { TS_master_alive, TS_master_dead } TSstate;
typedef enum { TS_async_none, TS_async_private,
TS_async_ntp, TS_async_time } TStime_protocol;
TS_async_ntp, TS_async_time } TStime_protocol;
typedef enum { TS_sync_master, TS_async_master,
TS_sync_slave, TS_async_slave,
TS_direct_master, TS_direct_slave } TStime_type;
TS_sync_slave, TS_async_slave,
TS_direct_master, TS_direct_slave} TStime_type;
struct TSstampTransStruct {
unsigned long magic; /* identifier */
TStype type; /* transaction type */
TStype type; /* transaction type */
struct timespec master_time; /* master time stamp - last sync time */
struct timespec current_time; /* master current time stamp 1990 epoch */
struct timespec unix_time; /* time using 1900 epoch */
@@ -159,13 +129,13 @@ struct TSinfoStruct {
unsigned long sync_rate; /* master send sync at this rate */
unsigned long clock_hz; /* master clock is this frequency */
unsigned long clock_conv; /* conversion factor for tick_rate->ns */
unsigned long clock_conv;/* conversion factor for tick_rate->ns */
unsigned long time_out; /* udp packet time-out in milliseconds */
int master_timing_IOC; /* 1=master, 0=slave */
int master_port; /* port that master listens on */
int slave_port; /* port that slave listens on */
int total_events; /* this is the total event in the event system */
int sync_event; /* this is the sync event number */
int master_port; /* port that master listens on */
int slave_port; /* port that slave listens on */
int total_events; /* this is the total event in the event system*/
int sync_event; /* this is the sync event number */
int has_event_system; /* 1=has event system, 0=no event system */
int has_direct_time; /* 1=has direct time, 0=no direct time */
int UserRequestedType; /* let user force the setting of type */
@@ -182,17 +152,22 @@ typedef struct TSinfoStruct TSinfo;
extern "C" {
#endif
TS_EXTERN long TSinit(void);
TS_EXTERN long TSgetTimeStamp(int event_number,struct timespec* sp);
TS_EXTERN long TScurrentTimeStamp(struct timespec* sp);
TS_EXTERN long TSaccurateTimeStamp(struct timespec* sp);
TS_EXTERN long TSgetFirstOfYearVx(struct timespec* sp);
TS_EXTERN long TSgetTimeStamp(int event_number,struct timespec* ts);
TS_EXTERN unsigned long TSepochNtpToUnix(struct timespec* ts);
TS_EXTERN unsigned long TSfractionToNano(unsigned long fraction);
TS_EXTERN unsigned long TSepochNtpToEpics(struct timespec* ts);
TS_EXTERN unsigned long TSepochUnixToEpics(struct timespec* ts);
TS_EXTERN unsigned long TSepochEpicsToUnix(struct timespec* ts);
TS_EXTERN long TScurrentTimeStamp(struct timespec* ts);
TS_EXTERN long TSaccurateTimeStamp(struct timespec* ts);
TS_EXTERN long TSgetFirstOfYearVx(struct timespec* ts);
TS_EXTERN void TSconfigure(int master, int sync_rate_sec, int clock_rate_hz,
int master_port, int slave_port,
unsigned long millisecond_request_time_out, int type);
int master_port, int slave_port,
unsigned long millisecond_request_time_out, int type);
#ifndef TS_DRIVER
TS_EXTERN TSinfo TSdata;
TS_EXTERN TSdirectTimeVar; /* set to !=0 to indicate direct time available */
TS_EXTERN TSdirectTimeVar; /* set to !=0 to indicate direct time available*/
TS_EXTERN TSgoodTimeStamps; /* force best time stamps by setting != 0 */
#endif
@@ -204,27 +179,27 @@ TS_EXTERN TSgoodTimeStamps; /* force best time stamps by setting != 0 */
#define VN_SHIFT 2 /* Version - 3 bits */
#define VN_version 3<<VN_SHIFT
#define LI_SHIFT 0 /* Leap Indicator LI - 2 bits */
#define LI_SHIFT 0 /* Leap Indicator LI - 2 bits */
#define LI_no_warning (0x00<<LI_SHIFT)
#define LI_61_sec_minute (0x01<<LI_SHIFT)
#define LI_59_sec_minute (0x02<<LI_SHIFT)
#define LI_alarm_condition (0x03<<LI_SHIFT)
#define MODE_SHIFT 5 /* Mode MODE - 3 bits */
#define MODE_SHIFT 5 /* Mode MODE - 3 bits */
#define MODE_reserved (0x00<<MODE_SHIFT)
#define MODE_sym_active (0x01<<MODE_SHIFT)
#define MODE_sym_passive (0x02<<MODE_SHIFT)
#define MODE_client (0x03<<MODE_SHIFT)
#define MODE_server (0x04<<MODE_SHIFT)
#define MODE_client (0x03<<MODE_SHIFT)
#define MODE_server (0x04<<MODE_SHIFT)
#define MODE_broadcast (0x05<<MODE_SHIFT)
#define MODE_reserved_NTP (0x06<<MODE_SHIFT)
#define MODE_reserved_pvt (0x07<<MODE_SHIFT)
#define STRAT_SHIFT 8 /* Stratum STRAT - 8 bits */
#define STRAT_SHIFT 8 /* Stratum STRAT - 8 bits */
#define STRAT_unspecified (0x00<<STRAT_SHIFT)
#define STRAT_ascii (0x00<<STRAT_SHIFT)
#define STRAT_GPS (0x01<<STRAT_SHIFT)
#define STRAT_ATOM (0x01<<STRAT_SHIFT)
#define STRAT_ascii (0x00<<STRAT_SHIFT)
#define STRAT_GPS (0x01<<STRAT_SHIFT)
#define STRAT_ATOM (0x01<<STRAT_SHIFT)
#define STRAT_address (0x02<<STRAT_SHIFT)
#define POLL_SHIFT 16 /* eight bits */

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,9 @@
/*
* $Log$
* Revision 1.1 1996/01/25 21:11:56 mrk
* moved includes; .ascii=> .db; path changes
*
* Revision 1.12 1995/08/30 15:39:07 jbk
* Added global variables for force accurate time stamps and direct time.
*
@@ -39,53 +42,17 @@
* .01 01-06-94 jbk initial version
*
***********************************************************************/
/*
*****************************************************************
/*****************************************************************
COPYRIGHT NOTIFICATION
*****************************************************************
THE FOLLOWING IS A NOTICE OF COPYRIGHT, AVAILABILITY OF THE CODE,
AND DISCLAIMER WHICH MUST BE INCLUDED IN THE PROLOGUE OF THE CODE
AND IN ALL SOURCE LISTINGS OF THE CODE.
(C) COPYRIGHT 1993 UNIVERSITY OF CHICAGO
Argonne National Laboratory (ANL), with facilities in the States of
Illinois and Idaho, is owned by the United States Government, and
operated by the University of Chicago under provision of a contract
with the Department of Energy.
Portions of this material resulted from work developed under a U.S.
Government contract and are subject to the following license: For
a period of five years from March 30, 1993, the Government is
granted for itself and others acting on its behalf a paid-up,
nonexclusive, irrevocable worldwide license in this computer
software to reproduce, prepare derivative works, and perform
publicly and display publicly. With the approval of DOE, this
period may be renewed for two additional five year periods.
Following the expiration of this period or periods, the Government
is granted for itself and others acting on its behalf, a paid-up,
nonexclusive, irrevocable worldwide license in this computer
software to reproduce, prepare derivative works, distribute copies
to the public, perform publicly and display publicly, and to permit
others to do so.
*****************************************************************
DISCLAIMER
*****************************************************************
NEITHER THE UNITED STATES GOVERNMENT NOR ANY AGENCY THEREOF, NOR
THE UNIVERSITY OF CHICAGO, NOR ANY OF THEIR EMPLOYEES OR OFFICERS,
MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
LIABILITY OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR
USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR PROCESS
DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
OWNED RIGHTS.
*****************************************************************
LICENSING INQUIRIES MAY BE DIRECTED TO THE INDUSTRIAL TECHNOLOGY
DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
*/
This software was developed under a United States Government license
described on the COPYRIGHT_UniversityOfChicago file included as part
of this distribution.
**********************************************************************/
#include <vxWorks.h>
#include <timers.h>
@@ -118,12 +85,15 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
#define TS_SYNC_RATE_SEC 10
#define TS_CLOCK_RATE_HZ 1000
#define TS_TOTAL_EVENTS 128
#define TS_SEC_IN_DAY (24*60*60)
#define TS_SEC_IN_YEAR (TS_SEC_IN_DAY*365)
#define TS_LEAPS_SINCE_1900 23
#define TS_1900_TO_EPICS_EPOCH ((TS_SEC_IN_YEAR*90)+(22*TS_SEC_IN_DAY))
#define TS_1900_TO_VXWORKS_EPOCH ((TS_SEC_IN_YEAR*70)+(17*TS_SEC_IN_DAY))
#define TS_VXWORKS_TO_EPICS_EPOCH ((TS_SEC_IN_YEAR*20)+(5*TS_SEC_IN_DAY))
/*Following is (SEC_IN_YEAR*90)+(22*SEC_IN_DAY) */
/*22 is leap years from 1900 to 1990*/
#define TS_1900_TO_EPICS_EPOCH 2840140800UL
/*Following is (SEC_IN_YEAR*70)+(17*SEC_IN_DAY) */
/*17 is leap years from 1900 to 1970*/
#define TS_1900_TO_VXWORKS_EPOCH 2208988800UL
/*Following is (SEC_IN_YEAR*20)+(5*SEC_IN_DAY) */
/*5 is leap years from 1970 to 1990*/
#define TS_VXWORKS_TO_EPICS_EPOCH 631152000UL
#define TS_STAMP_SERVER_PRI 70
#define TS_SYNC_SERVER_PRI 70
@@ -133,14 +103,14 @@ DEVELOPMENT CENTER AT ARGONNE NATIONAL LABORATORY (708-252-2000).
typedef enum { TS_time_request, TS_sync_request, TS_sync_msg } TStype;
typedef enum { TS_master_alive, TS_master_dead } TSstate;
typedef enum { TS_async_none, TS_async_private,
TS_async_ntp, TS_async_time } TStime_protocol;
TS_async_ntp, TS_async_time } TStime_protocol;
typedef enum { TS_sync_master, TS_async_master,
TS_sync_slave, TS_async_slave,
TS_direct_master, TS_direct_slave } TStime_type;
TS_sync_slave, TS_async_slave,
TS_direct_master, TS_direct_slave} TStime_type;
struct TSstampTransStruct {
unsigned long magic; /* identifier */
TStype type; /* transaction type */
TStype type; /* transaction type */
struct timespec master_time; /* master time stamp - last sync time */
struct timespec current_time; /* master current time stamp 1990 epoch */
struct timespec unix_time; /* time using 1900 epoch */
@@ -159,13 +129,13 @@ struct TSinfoStruct {
unsigned long sync_rate; /* master send sync at this rate */
unsigned long clock_hz; /* master clock is this frequency */
unsigned long clock_conv; /* conversion factor for tick_rate->ns */
unsigned long clock_conv;/* conversion factor for tick_rate->ns */
unsigned long time_out; /* udp packet time-out in milliseconds */
int master_timing_IOC; /* 1=master, 0=slave */
int master_port; /* port that master listens on */
int slave_port; /* port that slave listens on */
int total_events; /* this is the total event in the event system */
int sync_event; /* this is the sync event number */
int master_port; /* port that master listens on */
int slave_port; /* port that slave listens on */
int total_events; /* this is the total event in the event system*/
int sync_event; /* this is the sync event number */
int has_event_system; /* 1=has event system, 0=no event system */
int has_direct_time; /* 1=has direct time, 0=no direct time */
int UserRequestedType; /* let user force the setting of type */
@@ -182,17 +152,22 @@ typedef struct TSinfoStruct TSinfo;
extern "C" {
#endif
TS_EXTERN long TSinit(void);
TS_EXTERN long TSgetTimeStamp(int event_number,struct timespec* sp);
TS_EXTERN long TScurrentTimeStamp(struct timespec* sp);
TS_EXTERN long TSaccurateTimeStamp(struct timespec* sp);
TS_EXTERN long TSgetFirstOfYearVx(struct timespec* sp);
TS_EXTERN long TSgetTimeStamp(int event_number,struct timespec* ts);
TS_EXTERN unsigned long TSepochNtpToUnix(struct timespec* ts);
TS_EXTERN unsigned long TSfractionToNano(unsigned long fraction);
TS_EXTERN unsigned long TSepochNtpToEpics(struct timespec* ts);
TS_EXTERN unsigned long TSepochUnixToEpics(struct timespec* ts);
TS_EXTERN unsigned long TSepochEpicsToUnix(struct timespec* ts);
TS_EXTERN long TScurrentTimeStamp(struct timespec* ts);
TS_EXTERN long TSaccurateTimeStamp(struct timespec* ts);
TS_EXTERN long TSgetFirstOfYearVx(struct timespec* ts);
TS_EXTERN void TSconfigure(int master, int sync_rate_sec, int clock_rate_hz,
int master_port, int slave_port,
unsigned long millisecond_request_time_out, int type);
int master_port, int slave_port,
unsigned long millisecond_request_time_out, int type);
#ifndef TS_DRIVER
TS_EXTERN TSinfo TSdata;
TS_EXTERN TSdirectTimeVar; /* set to !=0 to indicate direct time available */
TS_EXTERN TSdirectTimeVar; /* set to !=0 to indicate direct time available*/
TS_EXTERN TSgoodTimeStamps; /* force best time stamps by setting != 0 */
#endif
@@ -204,27 +179,27 @@ TS_EXTERN TSgoodTimeStamps; /* force best time stamps by setting != 0 */
#define VN_SHIFT 2 /* Version - 3 bits */
#define VN_version 3<<VN_SHIFT
#define LI_SHIFT 0 /* Leap Indicator LI - 2 bits */
#define LI_SHIFT 0 /* Leap Indicator LI - 2 bits */
#define LI_no_warning (0x00<<LI_SHIFT)
#define LI_61_sec_minute (0x01<<LI_SHIFT)
#define LI_59_sec_minute (0x02<<LI_SHIFT)
#define LI_alarm_condition (0x03<<LI_SHIFT)
#define MODE_SHIFT 5 /* Mode MODE - 3 bits */
#define MODE_SHIFT 5 /* Mode MODE - 3 bits */
#define MODE_reserved (0x00<<MODE_SHIFT)
#define MODE_sym_active (0x01<<MODE_SHIFT)
#define MODE_sym_passive (0x02<<MODE_SHIFT)
#define MODE_client (0x03<<MODE_SHIFT)
#define MODE_server (0x04<<MODE_SHIFT)
#define MODE_client (0x03<<MODE_SHIFT)
#define MODE_server (0x04<<MODE_SHIFT)
#define MODE_broadcast (0x05<<MODE_SHIFT)
#define MODE_reserved_NTP (0x06<<MODE_SHIFT)
#define MODE_reserved_pvt (0x07<<MODE_SHIFT)
#define STRAT_SHIFT 8 /* Stratum STRAT - 8 bits */
#define STRAT_SHIFT 8 /* Stratum STRAT - 8 bits */
#define STRAT_unspecified (0x00<<STRAT_SHIFT)
#define STRAT_ascii (0x00<<STRAT_SHIFT)
#define STRAT_GPS (0x01<<STRAT_SHIFT)
#define STRAT_ATOM (0x01<<STRAT_SHIFT)
#define STRAT_ascii (0x00<<STRAT_SHIFT)
#define STRAT_GPS (0x01<<STRAT_SHIFT)
#define STRAT_ATOM (0x01<<STRAT_SHIFT)
#define STRAT_address (0x02<<STRAT_SHIFT)
#define POLL_SHIFT 16 /* eight bits */