]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/orte/defines_api.h
Reformat the sources with orte/uncrustify script
[orte.git] / orte / include / orte / defines_api.h
1 /*
2  *  $Id: defines_api.h,v 0.0.0.1        2003/08/21
3  *
4  *  -------------------------------------------------------------------
5  *                                ORTE
6  *                      Open Real-Time Ethernet
7  *
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
12  *
13  *  Author:              Petr Smolik    petr@smoliku.cz
14  *  Advisor:             Pavel Pisa
15  *  Project Responsible: Zdenek Hanzalek
16  *  --------------------------------------------------------------------
17  *
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.
22  *
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.
27  *
28  */
29
30 #ifndef _DEFINES_API_H
31 #define _DEFINES_API_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
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
41
42 ////////////////////////////////////////////////////////////////////////////////
43 //Return values
44 #define ORTE_OK                   0
45 #define ORTE_BAD_HANDLE           -1
46 #define ORTE_TIMEOUT              -2
47 #define ORTE_QUEUE_FULL           -3
48
49 ////////////////////////////////////////////////////////////////////////////////
50 //Logging - flags
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
58
59 /*****************************************************************/
60 /**
61  * SeqNumberCmp - comparison of two sequence numbers
62  * @sn1: source sequential number 1
63  * @sn2: source sequential number 2
64  *
65  * Return:  1 if sn1 > sn2
66  *         -1 if sn1 < sn2
67  *          0 if sn1 = sn2
68  */
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)))     \
74     )
75
76 /*****************************************************************/
77 /**
78  * SeqNumberInc - incrementation of a sequence number
79  * @res: result
80  * @sn: sequential number to be incremented
81  *
82  * res = sn + 1
83  */
84 #define SeqNumberInc(res, sn) {                   \
85     (res) = (sn);                              \
86     if (++(res).low == 0) \
87       (res).high++;      \
88 }
89
90
91 /*****************************************************************/
92 /**
93  * SeqNumberSub - addition of two sequential numbers
94  * @res: result
95  * @sn1: source sequential number 1
96  * @sn2: source sequential number 2
97  *
98  * res = sn1 + sn2
99  */
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)) {               \
105       (res).high++;                              \
106     }                                            \
107 }
108
109 /*****************************************************************/
110 /**
111  * SeqNumberDec - decrementation of a sequence number
112  * @res: result
113  * @sn: sequential number to be decremented
114  *
115  * res = sn - 1
116  */
117 #define SeqNumberDec(res, sn) {                   \
118     (res) = (sn);                              \
119     if ((res).low-- == 0) \
120       (res).high--;      \
121 }
122
123 /*****************************************************************/
124 /**
125  * SeqNumberSub - substraction of two sequential numbers
126  * @res: result
127  * @sn1: source sequential number 1
128  * @sn2: source sequential number 2
129  *
130  * res = sn1 - sn2
131  */
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) {                     \
136       (res).high--;                                  \
137     }                                                \
138 }
139
140 /*****************************************************************/
141 /**
142  * NtpTimeCmp - comparation of two NtpTimes
143  * @time1: source time 1
144  * @time2: source time 2
145  *
146  * Return value:
147  * 1 if time 1 > time 2
148  * -1 if time 1 < time 2
149  * 0 if time 1 = time 2
150  */
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))))
156
157
158 /*****************************************************************/
159 /**
160  * NtpTimeAdd - addition of two NtpTimes
161  * @res: result
162  * @time1: source time 1
163  * @time2: source time 2
164  *
165  * res = time1 + time2
166  */
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)) {       \
172       (res).seconds++;                               \
173     }                                                \
174 }
175
176 /*****************************************************************/
177 /**
178  * NtpTimeSub - substraction of two NtpTimes
179  * @res: result
180  * @time1: source time 1
181  * @time2: source time 2
182  *
183  * res = time1 - time2
184  */
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) {          \
189       (res).seconds--;                                \
190     }                                                 \
191 }
192
193 /*****************************************************************/
194 /**
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
199  */
200 #define NtpTimeAssembFromMs(time, s, msec) {         \
201     register uint32_t ms = msec;                     \
202     (time).seconds  = s;                             \
203     (time).fraction = (ms<<22) + ((ms*393)<<8);      \
204 }
205
206 /**
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
211  */
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)++; }  \
217 }
218
219 /**
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
224  */
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); \
229 }
230
231 /**
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
236  */
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)++; } \
244 }
245
246 /**
247  * Domain2Port - converts Domain value to IP Port value
248  * @d: domain
249  * @p: port
250  */
251 #define Domain2Port(d, p) {                   \
252     p = RTPS_DEFAULT_PORT + d*10;              \
253 }
254
255 /**
256  * Domain2PortMulticastUserdata - converts Domain value to userdata IP Port value
257  * @d: domain
258  * @p: port
259  */
260 #define Domain2PortMulticastUserdata(d, p) {  \
261     p = RTPS_DEFAULT_PORT + d*10+1;          \
262 }
263
264 /**
265  * Domain2PortMulticastMetatraffic - converts Domain value to metatraffic IP Port value
266  * @d: domain
267  * @p: port
268  */
269 #define Domain2PortMulticastMetatraffic(d, p) {        \
270     p = RTPS_DEFAULT_PORT + d*10+2;          \
271 }
272
273
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.  */
276
277 /*
278  *   (this + boundary - 1)
279  *          &
280  *    ~(boundary - 1)
281  */
282
283 #define ALIGN_ADDRESS(this, boundary) \
284   ((void *)((( ((unsigned long)(this)) + (((unsigned long)(boundary)) -1)) & (~(((unsigned long)(boundary))-1)))))
285
286
287 #ifdef __cplusplus
288 } /* extern "C"*/
289 #endif
290
291 #endif /* _DEFINES_API_H */