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 /*****************************************************************/
42 * SeqNumberCmp - comparison of two sequence numbers
43 * @sn1: source sequential number 1
44 * @sn2: source sequential number 2
46 * Return: 1 if sn1 > sn2
50 #define SeqNumberCmp(sn1, sn2) ( \
51 (sn1).high>(sn2).high ? 1 : \
52 ((sn1).high<(sn2).high ? -1 : \
53 ((sn1).low>(sn2).low ? 1 : \
54 ((sn1).low<(sn2).low ? -1 : 0))) \
57 /*****************************************************************/
59 * SeqNumberInc - incrementation of a sequence number
61 * @sn: sequential number to be incremented
65 #define SeqNumberInc(res,sn) { \
67 if (++(res).low==0) (res).high++; \
71 /*****************************************************************/
73 * SeqNumberSub - addition of two sequential numbers
75 * @sn1: source sequential number 1
76 * @sn2: source sequential number 2
80 #define SeqNumberAdd(res,sn1,sn2) { \
81 (res).low = (sn1).low+(sn2).low; \
82 (res).high = (sn1).high+(sn2).high; \
83 if (((res).low < (sn1).low) || \
84 ((res).low < (sn2).low)) { \
89 /*****************************************************************/
91 * SeqNumberDec - decrementation of a sequence number
93 * @sn: sequential number to be decremented
97 #define SeqNumberDec(res,sn) { \
99 if ((res).low--==0) (res).high--; \
102 /*****************************************************************/
104 * SeqNumberSub - substraction of two sequential numbers
106 * @sn1: source sequential number 1
107 * @sn2: source sequential number 2
111 #define SeqNumberSub(res,sn1,sn2) { \
112 (res).low = (sn1).low-(sn2).low; \
113 (res).high = (sn1).high-(sn2).high; \
114 if ((res).low > (sn1).low) { \
119 /*****************************************************************/
121 * NtpTimeCmp - comparation of two NtpTimes
122 * @time1: source time 1
123 * @time2: source time 2
126 * 1 if time 1 > time 2
127 * -1 if time 1 < time 2
128 * 0 if time 1 = time 2
130 #define NtpTimeCmp(time1, time2) \
131 ((((time1).seconds) > ((time2).seconds)) ? 1 : \
132 ((((time1).seconds) < ((time2).seconds)) ? -1 : \
133 ((((time1).fraction) > ((time2).fraction)) ? 1 : \
134 ((((time1).fraction) < ((time2).fraction)) ? -1 : 0))))
137 /*****************************************************************/
139 * NtpTimeAdd - addition of two NtpTimes
141 * @time1: source time 1
142 * @time2: source time 2
144 * res = time1 + time2
146 #define NtpTimeAdd(res, time1, time2) { \
147 (res).seconds = (time1).seconds + (time2).seconds; \
148 (res).fraction = (time1).fraction + (time2).fraction; \
149 if (((res).fraction < (time1).fraction) || \
150 ((res).fraction < (time2).fraction)) { \
155 /*****************************************************************/
157 * NtpTimeSub - substraction of two NtpTimes
159 * @time1: source time 1
160 * @time2: source time 2
162 * res = time1 - time2
164 #define NtpTimeSub(res, time1, time2) { \
165 (res).seconds = (time1).seconds - (time2).seconds; \
166 (res).fraction = (time1).fraction - (time2).fraction; \
167 if ((res).fraction > (time1).fraction) { \
172 /*****************************************************************/
174 * NtpTimeAssembFromMs - converts seconds and miliseconds to NtpTime
175 * @time: time given in NtpTime structure
176 * @s: seconds portion of given time
177 * @msec: miliseconds portion of given time
179 #define NtpTimeAssembFromMs(time, s, msec) { \
180 register u_int32_t ms = msec; \
181 (time).seconds = s; \
182 (time).fraction = (ms<<22) + ((ms*393)<<8); \
186 * NtpTimeDisAssembToMs - converts NtpTime to seconds and miliseconds
187 * @s: seconds portion of given time
188 * @msec: miliseconds portion of given time
189 * @time: time given in NtpTime structure
191 #define NtpTimeDisAssembToMs(s, msec, time) { \
192 s = (time).seconds; \
193 msec = ((time).fraction - ((time).fraction>>6) - \
194 ((time).fraction>>7) + (1<<21))>>22; \
195 if ((msec) >= 1000 ) { (msec) -= 1000; (s)++; } \
199 * NtpTimeAssembFromUs - converts seconds and useconds to NtpTime
200 * @time: time given in NtpTime structure
201 * @s: seconds portion of given time
202 * @usec: microseconds portion of given time
204 #define NtpTimeAssembFromUs(time, s, usec) { \
205 register u_int32_t us = usec; \
206 (time).seconds = s; \
207 (time).fraction = (us<<12)+ ((us*99)<<1)+ ((us*15 + ((us*61)>>7))>>4); \
211 * NtpTimeDisAssembToUs - converts NtpTime to seconds and useconds
212 * @s: seconds portion of given time
213 * @usec: microseconds portion of given time
214 * @time: time given in NtpTime structure
216 #define NtpTimeDisAssembToUs(s, usec, time) { \
217 register u_int32_t NtpTemp = (time).fraction; \
218 s = (time).seconds; \
219 usec = ((time).fraction - (NtpTemp>>5)-(NtpTemp>>7)-(NtpTemp>>8)- \
220 (NtpTemp>>9)-(NtpTemp>>10) - (NtpTemp>>12) - \
221 (NtpTemp>>13)-(NtpTemp>>14) + (1<<11)) >> 12; \
222 if ((usec) >= 1000000) { (usec) -= 1000000; (s)++; } \
226 * Domain2Port - converts Domain value to IP Port value
230 #define Domain2Port(d,p) { \
231 p = RTPS_DEFAULT_PORT + d*10; \
235 * Domain2PortMulticastUserdata - converts Domain value to userdata IP Port value
239 #define Domain2PortMulticastUserdata(d,p) { \
240 p = RTPS_DEFAULT_PORT + d*10+1; \
244 * Domain2PortMulticastMetatraffic - converts Domain value to metatraffic IP Port value
248 #define Domain2PortMulticastMetatraffic(d,p) { \
249 p = RTPS_DEFAULT_PORT + d*10+2; \
256 #endif /* _DEFINES_API_H */