]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/defines_api.h
OCERA SF CVS tree of ORTE framework updated to
[orte.git] / orte / include / defines_api.h
1 /*
2  *  $Id: defines_api.h,v 0.0.0.1        2003/08/21 
3  *
4  *  AUTHOR: Petr Smolik                 petr.smolik@wo.cz
5  *
6  *  ORTE - OCERA Real-Time Ethernet     http://www.ocera.org/
7  *  --------------------------------------------------------------------
8  *
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.
13  *  
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.
18  *  
19  */
20
21 #ifndef _DEFINES_API_H
22 #define _DEFINES_API_H
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
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
32
33 ////////////////////////////////////////////////////////////////////////////////
34 //Return values
35 #define ORTE_OK                   0
36 #define ORTE_BAD_HANDLE           -1
37 #define ORTE_TIMEOUT              -2
38 #define ORTE_QUEUE_FULL           -3
39
40 /*****************************************************************/
41 // Cmp two sequence numbers
42 // Return:  1 if sn1>sn2
43 //         -1 if sn1<sn2
44 //          0 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)))     \
50     )
51
52 /*****************************************************************/
53 #define SeqNumberInc(res,sn) {                   \
54       (res) = (sn);                              \
55           if (++(res).low==0) (res).high++;      \
56         }
57
58
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)) {               \
65       (res).high++;                              \
66     }                                            \
67 }
68
69 /*****************************************************************/
70 #define SeqNumberDec(res,sn) {                   \
71       (res) = (sn);                              \
72           if ((res).low--==0) (res).high--;      \
73         }
74
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) {                     \
80       (res).high--;                                  \
81     }                                                \
82 }
83
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))))
90
91
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)) {       \
98       (res).seconds++;                               \
99     }                                                \
100 }
101
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) {          \
107      (res).seconds--;                                \
108    }                                                 \
109 }
110
111 /*****************************************************************/
112 /**
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
117  */
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);      \
122 }
123
124 /**
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
129  */
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)++; }  \
135 }
136
137 /**
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
142  */
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); \
147 }
148
149 /**
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
154  */
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)++; } \
162 }
163
164 /**
165  * Domain2Port - converts Domain value to IP Port value
166  * @domain: 
167  * @port:
168  */
169 #define Domain2Port(d,p) {                   \
170   p = RTPS_DEFAULT_PORT + d*10;              \
171 }
172
173 /**
174  * Domain2PortMulticastUserdata - converts Domain value to userdata IP Port value
175  * @domain: 
176  * @port:
177  */
178 #define Domain2PortMulticastUserdata(d,p) {  \
179     p = RTPS_DEFAULT_PORT + d*10+1;          \
180 }
181
182 /**
183  * Domain2PortMulticastMetatraffic - converts Domain value to metatraffic IP Port value
184  * @domain: 
185  * @port:
186  */
187 #define Domain2PortMulticastMetatraffic(d,p) {        \
188     p = RTPS_DEFAULT_PORT + d*10+2;          \
189 }
190
191 #ifdef __cplusplus
192 } /* extern "C"*/
193 #endif
194
195 #endif /* _DEFINES_API_H */