2 * $Id: defines_api.h,v 0.0.0.1 2003/08/21
4 * AUTHOR: Petr Smolik petr.smolik@wo.cz
6 * ORTE - OCERA Real-Time Ethernet http://www.ocera.org/
7 * --------------------------------------------------------------------
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
21 #ifndef _DEFINES_API_H
22 #define _DEFINES_API_H
28 #define MAX_INTERFACES 5
29 #define ORTE_DEFAULT_DOMAIN 0
30 #define MAX_STRING_IPADDRESS_LENGTH 4*3+3+1
31 #define MAX_STRING_NTPTIME_LENGTH 30 //need fix
33 ////////////////////////////////////////////////////////////////////////////////
36 #define ORTE_BAD_HANDLE -1
37 #define ORTE_TIMEOUT -2
38 #define ORTE_QUEUE_FULL -3
40 /*****************************************************************/
41 // Cmp two sequence numbers
42 // Return: 1 if sn1>sn2
45 #define SeqNumberCmp(sn1, sn2) ( \
46 (sn1).high>(sn2).high ? 1 : \
47 ((sn1).high<(sn2).high ? -1 : \
48 ((sn1).low>(sn2).low ? 1 : \
49 ((sn1).low<(sn2).low ? -1 : 0))) \
52 /*****************************************************************/
53 #define SeqNumberInc(res,sn) { \
55 if (++(res).low==0) (res).high++; \
59 /*****************************************************************/
60 #define SeqNumberAdd(res,sn1,sn2) { \
61 (res).low = (sn1).low+(sn2).low; \
62 (res).high = (sn1).high+(sn2).high; \
63 if (((res).low < (sn1).low) || \
64 ((res).low < (sn2).low)) { \
69 /*****************************************************************/
70 #define SeqNumberDec(res,sn) { \
72 if ((res).low--==0) (res).high--; \
75 /*****************************************************************/
76 #define SeqNumberSub(res,sn1,sn2) { \
77 (res).low = (sn1).low-(sn2).low; \
78 (res).high = (sn1).high-(sn2).high; \
79 if ((res).low > (sn1).low) { \
84 /*****************************************************************/
85 #define NtpTimeCmp(time1, time2) \
86 ((((time1).seconds) > ((time2).seconds)) ? 1 : \
87 ((((time1).seconds) < ((time2).seconds)) ? -1 : \
88 ((((time1).fraction) > ((time2).fraction)) ? 1 : \
89 ((((time1).fraction) < ((time2).fraction)) ? -1 : 0))))
92 /*****************************************************************/
93 #define NtpTimeAdd(res, time1, time2) { \
94 (res).seconds = (time1).seconds + (time2).seconds; \
95 (res).fraction = (time1).fraction + (time2).fraction; \
96 if (((res).fraction < (time1).fraction) || \
97 ((res).fraction < (time2).fraction)) { \
102 /*****************************************************************/
103 #define NtpTimeSub(res, time1, time2) { \
104 (res).seconds = (time1).seconds - (time2).seconds; \
105 (res).fraction = (time1).fraction - (time2).fraction; \
106 if ((res).fraction > (time1).fraction) { \
111 /*****************************************************************/
113 * NtpTimeAssembFromMs - converts seconds and miliseconds to NtpTime
114 * @time: time given in NtpTime structure
115 * @s: seconds portion of given time
116 * @msec: miliseconds portion of given time
118 #define NtpTimeAssembFromMs(time, s, msec) { \
119 register u_int32_t ms = msec; \
120 (time).seconds = s; \
121 (time).fraction = (ms<<22) + ((ms*393)<<8); \
125 * NtpTimeDisAssembToMs - converts NtpTime to seconds and miliseconds
126 * @s: seconds portion of given time
127 * @msec: miliseconds portion of given time
128 * @time: time given in NtpTime structure
130 #define NtpTimeDisAssembToMs(s, msec, time) { \
131 s = (time).seconds; \
132 msec = ((time).fraction - ((time).fraction>>6) - \
133 ((time).fraction>>7) + (1<<21))>>22; \
134 if ((msec) >= 1000 ) { (msec) -= 1000; (s)++; } \
138 * NtpTimeAssembFromUs - converts seconds and useconds to NtpTime
139 * @time: time given in NtpTime structure
140 * @s: seconds portion of given time
141 * @usec: microseconds portion of given time
143 #define NtpTimeAssembFromUs(time, s, usec) { \
144 register u_int32_t us = usec; \
145 (time).seconds = s; \
146 (time).fraction = (us<<12)+ ((us*99)<<1)+ ((us*15 + ((us*61)>>7))>>4); \
150 * NtpTimeDisAssembToUs - converts NtpTime to seconds and useconds
151 * @s: seconds portion of given time
152 * @usec: microseconds portion of given time
153 * @time: time given in NtpTime structure
155 #define NtpTimeDisAssembToUs(s, usec, time) { \
156 register u_int32_t NtpTemp = (time).fraction; \
157 s = (time).seconds; \
158 usec = ((time).fraction - (NtpTemp>>5)-(NtpTemp>>7)-(NtpTemp>>8)- \
159 (NtpTemp>>9)-(NtpTemp>>10) - (NtpTemp>>12) - \
160 (NtpTemp>>13)-(NtpTemp>>14) + (1<<11)) >> 12; \
161 if ((usec) >= 1000000) { (usec) -= 1000000; (s)++; } \
165 * Domain2Port - converts Domain value to IP Port value
169 #define Domain2Port(d,p) { \
170 p = RTPS_DEFAULT_PORT + d*10; \
174 * Domain2PortMulticastUserdata - converts Domain value to userdata IP Port value
178 #define Domain2PortMulticastUserdata(d,p) { \
179 p = RTPS_DEFAULT_PORT + d*10+1; \
183 * Domain2PortMulticastMetatraffic - converts Domain value to metatraffic IP Port value
187 #define Domain2PortMulticastMetatraffic(d,p) { \
188 p = RTPS_DEFAULT_PORT + d*10+2; \
195 #endif /* _DEFINES_API_H */