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) (res).high++; \
90 /*****************************************************************/
92 * SeqNumberSub - addition of two sequential numbers
94 * @sn1: source sequential number 1
95 * @sn2: source sequential number 2
99 #define SeqNumberAdd(res,sn1,sn2) { \
100 (res).low = (sn1).low+(sn2).low; \
101 (res).high = (sn1).high+(sn2).high; \
102 if (((res).low < (sn1).low) || \
103 ((res).low < (sn2).low)) { \
108 /*****************************************************************/
110 * SeqNumberDec - decrementation of a sequence number
112 * @sn: sequential number to be decremented
116 #define SeqNumberDec(res,sn) { \
118 if ((res).low--==0) (res).high--; \
121 /*****************************************************************/
123 * SeqNumberSub - substraction of two sequential numbers
125 * @sn1: source sequential number 1
126 * @sn2: source sequential number 2
130 #define SeqNumberSub(res,sn1,sn2) { \
131 (res).low = (sn1).low-(sn2).low; \
132 (res).high = (sn1).high-(sn2).high; \
133 if ((res).low > (sn1).low) { \
138 /*****************************************************************/
140 * NtpTimeCmp - comparation of two NtpTimes
141 * @time1: source time 1
142 * @time2: source time 2
145 * 1 if time 1 > time 2
146 * -1 if time 1 < time 2
147 * 0 if time 1 = time 2
149 #define NtpTimeCmp(time1, time2) \
150 ((((time1).seconds) > ((time2).seconds)) ? 1 : \
151 ((((time1).seconds) < ((time2).seconds)) ? -1 : \
152 ((((time1).fraction) > ((time2).fraction)) ? 1 : \
153 ((((time1).fraction) < ((time2).fraction)) ? -1 : 0))))
156 /*****************************************************************/
158 * NtpTimeAdd - addition of two NtpTimes
160 * @time1: source time 1
161 * @time2: source time 2
163 * res = time1 + time2
165 #define NtpTimeAdd(res, time1, time2) { \
166 (res).seconds = (time1).seconds + (time2).seconds; \
167 (res).fraction = (time1).fraction + (time2).fraction; \
168 if (((res).fraction < (time1).fraction) || \
169 ((res).fraction < (time2).fraction)) { \
174 /*****************************************************************/
176 * NtpTimeSub - substraction of two NtpTimes
178 * @time1: source time 1
179 * @time2: source time 2
181 * res = time1 - time2
183 #define NtpTimeSub(res, time1, time2) { \
184 (res).seconds = (time1).seconds - (time2).seconds; \
185 (res).fraction = (time1).fraction - (time2).fraction; \
186 if ((res).fraction > (time1).fraction) { \
191 /*****************************************************************/
193 * NtpTimeAssembFromMs - converts seconds and miliseconds to NtpTime
194 * @time: time given in NtpTime structure
195 * @s: seconds portion of given time
196 * @msec: miliseconds portion of given time
198 #define NtpTimeAssembFromMs(time, s, msec) { \
199 register uint32_t ms = msec; \
200 (time).seconds = s; \
201 (time).fraction = (ms<<22) + ((ms*393)<<8); \
205 * NtpTimeDisAssembToMs - converts NtpTime to seconds and miliseconds
206 * @s: seconds portion of given time
207 * @msec: miliseconds portion of given time
208 * @time: time given in NtpTime structure
210 #define NtpTimeDisAssembToMs(s, msec, time) { \
211 s = (time).seconds; \
212 msec = ((time).fraction - ((time).fraction>>6) - \
213 ((time).fraction>>7) + (1<<21))>>22; \
214 if ((msec) >= 1000 ) { (msec) -= 1000; (s)++; } \
218 * NtpTimeAssembFromUs - converts seconds and useconds to NtpTime
219 * @time: time given in NtpTime structure
220 * @s: seconds portion of given time
221 * @usec: microseconds portion of given time
223 #define NtpTimeAssembFromUs(time, s, usec) { \
224 register uint32_t us = usec; \
225 (time).seconds = s; \
226 (time).fraction = (us<<12)+ ((us*99)<<1)+ ((us*15 + ((us*61)>>7))>>4); \
230 * NtpTimeDisAssembToUs - converts NtpTime to seconds and useconds
231 * @s: seconds portion of given time
232 * @usec: microseconds portion of given time
233 * @time: time given in NtpTime structure
235 #define NtpTimeDisAssembToUs(s, usec, time) { \
236 register uint32_t NtpTemp = (time).fraction; \
237 s = (time).seconds; \
238 usec = ((time).fraction - (NtpTemp>>5)-(NtpTemp>>7)-(NtpTemp>>8)- \
239 (NtpTemp>>9)-(NtpTemp>>10) - (NtpTemp>>12) - \
240 (NtpTemp>>13)-(NtpTemp>>14) + (1<<11)) >> 12; \
241 if ((usec) >= 1000000) { (usec) -= 1000000; (s)++; } \
245 * Domain2Port - converts Domain value to IP Port value
249 #define Domain2Port(d,p) { \
250 p = RTPS_DEFAULT_PORT + d*10; \
254 * Domain2PortMulticastUserdata - converts Domain value to userdata IP Port value
258 #define Domain2PortMulticastUserdata(d,p) { \
259 p = RTPS_DEFAULT_PORT + d*10+1; \
263 * Domain2PortMulticastMetatraffic - converts Domain value to metatraffic IP Port value
267 #define Domain2PortMulticastMetatraffic(d,p) { \
268 p = RTPS_DEFAULT_PORT + d*10+2; \
272 /* Align an address upward to a boundary, expressed as a number of bytes.
273 E.g. align to an 8-byte boundary with argument of 8. */
276 * (this + boundary - 1)
281 #define ALIGN_ADDRESS(this, boundary) \
282 ((void*)((( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))))
289 #endif /* _DEFINES_API_H */