2 * $Id: defines_api.h,v 0.0.0.1 2003/08/21
4 * -------------------------------------------------------------------
6 * Open Real-Time Ethernet
8 * Copyright (C) 2001-2006
9 * Department of Control Engineering FEE CTU Prague, Czech Republic
10 * http://dce.felk.cvut.cz
11 * http://www.ocera.org
13 * Author: Petr Smolik petr@smoliku.cz
15 * Project Responsible: Zdenek Hanzalek
16 * --------------------------------------------------------------------
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
30 #ifndef _DEFINES_API_H
31 #define _DEFINES_API_H
37 #define MAX_INTERFACES 5
38 #define ORTE_DEFAULT_DOMAIN 0
39 #define MAX_STRING_IPADDRESS_LENGTH 4*3+3+1
40 #define MAX_STRING_NTPTIME_LENGTH 30 //need fix
42 ////////////////////////////////////////////////////////////////////////////////
45 #define ORTE_BAD_HANDLE -1
46 #define ORTE_TIMEOUT -2
47 #define ORTE_QUEUE_FULL -3
49 ////////////////////////////////////////////////////////////////////////////////
51 #define LOG_FNONE 0x00
52 #define LOG_FEXCEPTION 0x01
53 #define LOG_FWARN 0x02
54 #define LOG_FLOCAL_OBJECT 0x04
55 #define LOG_FREMOTE_OBJECT 0x08
56 #define LOG_FPERIODIC 0x10
57 #define LOG_FCONTENT 0x20
59 /*****************************************************************/
61 * SeqNumberCmp - comparison of two sequence numbers
62 * @sn1: source sequential number 1
63 * @sn2: source sequential number 2
65 * Return: 1 if sn1 > sn2
69 #define SeqNumberCmp(sn1, sn2) ( \
70 (sn1).high > (sn2).high ? 1 : \
71 ((sn1).high < (sn2).high ? -1 : \
72 ((sn1).low > (sn2).low ? 1 : \
73 ((sn1).low < (sn2).low ? -1 : 0))) \
76 /*****************************************************************/
78 * SeqNumberInc - incrementation of a sequence number
80 * @sn: sequential number to be incremented
84 #define SeqNumberInc(res, sn) { \
86 if (++(res).low == 0) \
91 /*****************************************************************/
93 * SeqNumberSub - addition of two sequential numbers
95 * @sn1: source sequential number 1
96 * @sn2: source sequential number 2
100 #define SeqNumberAdd(res, sn1, sn2) { \
101 (res).low = (sn1).low+(sn2).low; \
102 (res).high = (sn1).high+(sn2).high; \
103 if (((res).low < (sn1).low) || \
104 ((res).low < (sn2).low)) { \
109 /*****************************************************************/
111 * SeqNumberDec - decrementation of a sequence number
113 * @sn: sequential number to be decremented
117 #define SeqNumberDec(res, sn) { \
119 if ((res).low-- == 0) \
123 /*****************************************************************/
125 * SeqNumberSub - substraction of two sequential numbers
127 * @sn1: source sequential number 1
128 * @sn2: source sequential number 2
132 #define SeqNumberSub(res, sn1, sn2) { \
133 (res).low = (sn1).low-(sn2).low; \
134 (res).high = (sn1).high-(sn2).high; \
135 if ((res).low > (sn1).low) { \
140 /*****************************************************************/
142 * NtpTimeCmp - comparation of two NtpTimes
143 * @time1: source time 1
144 * @time2: source time 2
147 * 1 if time 1 > time 2
148 * -1 if time 1 < time 2
149 * 0 if time 1 = time 2
151 #define NtpTimeCmp(time1, time2) \
152 ((((time1).seconds) > ((time2).seconds)) ? 1 : \
153 ((((time1).seconds) < ((time2).seconds)) ? -1 : \
154 ((((time1).fraction) > ((time2).fraction)) ? 1 : \
155 ((((time1).fraction) < ((time2).fraction)) ? -1 : 0))))
158 /*****************************************************************/
160 * NtpTimeAdd - addition of two NtpTimes
162 * @time1: source time 1
163 * @time2: source time 2
165 * res = time1 + time2
167 #define NtpTimeAdd(res, time1, time2) { \
168 (res).seconds = (time1).seconds + (time2).seconds; \
169 (res).fraction = (time1).fraction + (time2).fraction; \
170 if (((res).fraction < (time1).fraction) || \
171 ((res).fraction < (time2).fraction)) { \
176 /*****************************************************************/
178 * NtpTimeSub - substraction of two NtpTimes
180 * @time1: source time 1
181 * @time2: source time 2
183 * res = time1 - time2
185 #define NtpTimeSub(res, time1, time2) { \
186 (res).seconds = (time1).seconds - (time2).seconds; \
187 (res).fraction = (time1).fraction - (time2).fraction; \
188 if ((res).fraction > (time1).fraction) { \
193 /*****************************************************************/
195 * NtpTimeAssembFromMs - converts seconds and miliseconds to NtpTime
196 * @time: time given in NtpTime structure
197 * @s: seconds portion of given time
198 * @msec: miliseconds portion of given time
200 #define NtpTimeAssembFromMs(time, s, msec) { \
201 register uint32_t ms = msec; \
202 (time).seconds = s; \
203 (time).fraction = (ms<<22) + ((ms*393)<<8); \
207 * NtpTimeDisAssembToMs - converts NtpTime to seconds and miliseconds
208 * @s: seconds portion of given time
209 * @msec: miliseconds portion of given time
210 * @time: time given in NtpTime structure
212 #define NtpTimeDisAssembToMs(s, msec, time) { \
213 s = (time).seconds; \
214 msec = ((time).fraction - ((time).fraction>>6) - \
215 ((time).fraction>>7) + (1<<21))>>22; \
216 if ((msec) >= 1000) { (msec) -= 1000; (s)++; } \
220 * NtpTimeAssembFromUs - converts seconds and useconds to NtpTime
221 * @time: time given in NtpTime structure
222 * @s: seconds portion of given time
223 * @usec: microseconds portion of given time
225 #define NtpTimeAssembFromUs(time, s, usec) { \
226 register uint32_t us = usec; \
227 (time).seconds = s; \
228 (time).fraction = (us<<12)+ ((us*99)<<1)+ ((us*15 + ((us*61)>>7))>>4); \
232 * NtpTimeDisAssembToUs - converts NtpTime to seconds and useconds
233 * @s: seconds portion of given time
234 * @usec: microseconds portion of given time
235 * @time: time given in NtpTime structure
237 #define NtpTimeDisAssembToUs(s, usec, time) { \
238 register uint32_t NtpTemp = (time).fraction; \
239 s = (time).seconds; \
240 usec = ((time).fraction - (NtpTemp>>5)-(NtpTemp>>7)-(NtpTemp>>8)- \
241 (NtpTemp>>9)-(NtpTemp>>10) - (NtpTemp>>12) - \
242 (NtpTemp>>13)-(NtpTemp>>14) + (1<<11)) >> 12; \
243 if ((usec) >= 1000000) { (usec) -= 1000000; (s)++; } \
247 * Domain2Port - converts Domain value to IP Port value
251 #define Domain2Port(d, p) { \
252 p = RTPS_DEFAULT_PORT + d*10; \
256 * Domain2PortMulticastUserdata - converts Domain value to userdata IP Port value
260 #define Domain2PortMulticastUserdata(d, p) { \
261 p = RTPS_DEFAULT_PORT + d*10+1; \
265 * Domain2PortMulticastMetatraffic - converts Domain value to metatraffic IP Port value
269 #define Domain2PortMulticastMetatraffic(d, p) { \
270 p = RTPS_DEFAULT_PORT + d*10+2; \
274 /* Align an address upward to a boundary, expressed as a number of bytes.
275 E.g. align to an 8-byte boundary with argument of 8. */
278 * (this + boundary - 1)
283 #define ALIGN_ADDRESS(this, boundary) \
284 ((void *)((( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))))
291 #endif /* _DEFINES_API_H */