summaryrefslogtreecommitdiff
path: root/third_party/ptpd-1.1.0/src/dep-tiva/ptpd_dep.h
blob: 10b297ea987b631f06d0b2b439035f4b02c7c7f4 (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
/* ptpd_dep.h */

#ifndef PTPD_DEP_H
#define PTPD_DEP_H

#include <string.h>

/*
 * Remove the following #if 0 and its matching #endif to enable PTPd debug
 * output on UART0. This is disabled by default even in debug builds due to
 * the volume of information transmitted.
 */
#if 0
#ifdef DEBUG
#include "utils/uartstdio.h"
#define PTPD_DBG
/*
 * Define the following to enable verbose debug.
 */
#undef PTPD_DBGV
#endif
#endif

#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef size_t
#define size_t long
#endif
#ifndef ssize_t
#define ssize_t long
#endif

/* system messages */
#ifndef PTPD_DBG
#define ERROR(...)
#define PERROR(...)
#define NOTIFY(...)
#else
#define ERROR(x, ...)  UARTprintf("(ptpd error) " x, ##__VA_ARGS__)
#define PERROR(x, ...) UARTprintf("(ptpd error) " x ": %m\n", ##__VA_ARGS__)
#define NOTIFY(x, ...) UARTprintf("(ptpd notice) " x, ##__VA_ARGS__)
#endif

/* debug messages */
#ifdef PTPD_DBGV
#define PTPD_DBG
#define DBGV(x, ...) UARTprintf("(ptpd debug) " x, ##__VA_ARGS__)
#else
#define DBGV(...)
#endif

#ifdef PTPD_DBG
#define DBG(x, ...)  UARTprintf("(ptpd debug) " x, ##__VA_ARGS__)
#else
#define DBG(...)
#endif

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

#elif defined(PTPD_LSBF)
#define shift8(x,y)   ( (x) << ((y)<<3) )
#define shift16(x,y)  ( (x) << ((y)<<4) )
#define flip16(x)     ((((x) >> 8) & 0x00ff) | (((x) << 8) & 0xff00))
#define flip32(x)     ((((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)) )


#define labs(x)         (((x) >= 0) ? (x) : -(x))

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

/* net.c */
Boolean netInit(NetPath*,RunTimeOpts*,PtpClock*);
Boolean netShutdown(NetPath*);
int netSelect(TimeInternal*,NetPath*);
size_t netRecvEvent(Octet*,TimeInternal*,NetPath*);
size_t netRecvGeneral(Octet*,NetPath*);
size_t netSendEvent(Octet*,UInteger16,NetPath*);
size_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*);

/* sys.c */
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 timerTick(int);
void timerUpdate(IntervalTimer*);
void timerStop(UInteger16,IntervalTimer*);
void timerStart(UInteger16,UInteger16,IntervalTimer*);
Boolean timerExpired(UInteger16,IntervalTimer*);


#endif