summaryrefslogtreecommitdiff
path: root/third_party/ptpd-1.1.0/src/dep/ptpd_dep.h
blob: 63cf6748ee96e70580ac514c0707ec227853ca10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
 * @file   ptpd_dep.h
 * @date   Tue Jul 20 16:18:39 2010
 * 
 * @brief  External definitions for inclusion elsewhere.
 * 
 * 
 */

#ifndef PTPD_DEP_H
#define PTPD_DEP_H

#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<errno.h>
#include<signal.h>
#include<fcntl.h>
#include<sys/stat.h>
#include<time.h>
#include<sys/time.h>
#include<sys/timex.h>
#include<sys/socket.h>
#include<sys/select.h>
#include<sys/ioctl.h>
#include<arpa/inet.h>
#include<stdarg.h>
#include<syslog.h>
#include<limits.h>

/* system messages */
#define ERROR(x, ...)  message(LOG_ERR, x, ##__VA_ARGS__)
#define PERROR(x, ...) message(LOG_ERR, x ": %m\n", ##__VA_ARGS__)
#define NOTIFY(x, ...) message(LOG_NOTICE, x, ##__VA_ARGS__)
#define INFO(x, ...)   message(LOG_INFO, x, ##__VA_ARGS__)

/* debug messages */
#ifdef PTPD_DBGV
#define PTPD_DBG
#define DBGV(x, ...) message(LOG_DEBUG, x, ##__VA_ARGS__)
#else
#define DBGV(x, ...)
#endif

#ifdef PTPD_DBG
#define DBG(x, ...) message(LOG_DEBUG, x, ##__VA_ARGS__) 
#else
#define DBG(x, ...)
#endif

/* endian corrections */
#if defined(PTPD_MSBF)
#define shift8(x,y)   ( (x) << ((3-y)<<3) )
#define shift16(x,y)  ( (x) << ((1-y)<<4) )
#elif defined(PTPD_LSBF)
#define shift8(x,y)   ( (x) << ((y)<<3) )
#define shift16(x,y)  ( (x) << ((y)<<4) )
#endif

#define flip16(x) htons(x)
#define flip32(x) htonl(x)

/* i don't know any target platforms that do not have htons and htonl,
   but here are generic funtions just in case */
/*
#if defined(PTPD_MSBF)
#define flip16(x) (x)
#define flip32(x) (x)
#elif defined(PTPD_LSBF)
static inline Integer16 flip16(Integer16 x)
{
   return (((x) >> 8) & 0x00ff) | (((x) << 8) & 0xff00);
}

static inline Integer32 flip32(x)
{
  return (((x) >> 24) & 0x000000ff) | (((x) >> 8 ) & 0x0000ff00) |
         (((x) << 8 ) & 0x00ff0000) | (((x) << 24) & 0xff000000);
}
#endif
*/

/* bit array manipulation */
#define getFlag(x,y)  !!( *(UInteger8*)((x)+((y)<8?1:0)) &   (1<<((y)<8?(y):(y)-8)) )
#define setFlag(x,y)    ( *(UInteger8*)((x)+((y)<8?1:0)) |=   1<<((y)<8?(y):(y)-8)  )
#define clearFlag(x,y)  ( *(UInteger8*)((x)+((y)<8?1:0)) &= ~(1<<((y)<8?(y):(y)-8)) )


/* msg.c */
Boolean	msgPeek(void *, ssize_t);
void	msgUnpackHeader(void *, MsgHeader *);
void	msgUnpackSync(void *, MsgSync *);
void	msgUnpackDelayReq(void *, MsgDelayReq *);
void	msgUnpackFollowUp(void *, MsgFollowUp *);
void	msgUnpackDelayResp(void *, MsgDelayResp *);
void	msgUnpackManagement(void *, MsgManagement *);
UInteger8 msgUnloadManagement(void *, MsgManagement *, PtpClock *, RunTimeOpts *);
void	msgUnpackManagementPayload(void *buf, MsgManagement * manage);
void	msgPackHeader(void *, PtpClock *);
void	msgPackSync(void *, Boolean, TimeRepresentation *, PtpClock *);
void	msgPackDelayReq(void *, Boolean, TimeRepresentation *, PtpClock *);
void	msgPackFollowUp(void *, UInteger16, TimeRepresentation *, PtpClock *);
void	msgPackDelayResp(void *, MsgHeader *, TimeRepresentation *, PtpClock *);
UInteger16 msgPackManagement(void *, MsgManagement *, PtpClock *);
UInteger16 msgPackManagementResponse(void *, MsgHeader *, MsgManagement *, PtpClock *);

/* net.c */
/* linux API dependent */
Boolean	netInit(NetPath *, RunTimeOpts *, PtpClock *);
Boolean	netShutdown(NetPath *);
int	netSelect(TimeInternal *, NetPath *);
ssize_t	netRecvEvent(Octet *, TimeInternal *, NetPath *);
ssize_t	netRecvGeneral(Octet *, NetPath *);
ssize_t	netSendEvent(Octet *, UInteger16, NetPath *);
ssize_t	netSendGeneral(Octet *, UInteger16, NetPath *);

/* servo.c */
void	initClock(RunTimeOpts *, PtpClock *);
void 
updateDelay(TimeInternal *, TimeInternal *,
    one_way_delay_filter *, RunTimeOpts *, PtpClock *);
void 
updateOffset(TimeInternal *, TimeInternal *,
    offset_from_master_filter *, RunTimeOpts *, PtpClock *);
void	updateClock(RunTimeOpts *, PtpClock *);

/* startup.c */
/* unix API dependent */
int logToFile();
int recordToFile();
PtpClock *ptpdStartup(int, char **, Integer16 *, RunTimeOpts *);
void	ptpdShutdown(void);

/* sys.c */
char *translatePortState(PtpClock *ptpClock);
/* unix API dependent */
void	message(int priority, const char *format, ...);
void	displayStats(RunTimeOpts *, PtpClock *);
Boolean	nanoSleep(TimeInternal *);
void	getTime(TimeInternal *);
void	setTime(TimeInternal *);
UInteger16 getRand(UInteger32 *);
Boolean	adjFreq(Integer32);

/* timer.c */
void	initTimer(void);
void	timerUpdate(IntervalTimer *);
void	timerStop(UInteger16, IntervalTimer *);
void	timerStart(UInteger16, UInteger16, IntervalTimer *);
Boolean	timerExpired(UInteger16, IntervalTimer *);


#endif