00001
00006 #ifndef L4_SYS_TIMEOUT_H__
00007 #define L4_SYS_TIMEOUT_H__
00008
00009 #include <l4/sys/l4int.h>
00010
00020 typedef struct l4_timeout_s {
00021 l4_uint16_t t;
00022 } __attribute__((packed)) l4_timeout_s;
00023
00024
00030 typedef union l4_timeout_t {
00031 l4_uint32_t raw;
00032 struct
00033 {
00034 l4_timeout_s rcv;
00035 l4_timeout_s snd;
00036 } p;
00037 } l4_timeout_t;
00038
00039
00040 #define L4_IPC_TIMEOUT_0 ((l4_timeout_s){0x0400})
00041 #define L4_IPC_TIMEOUT_NEVER ((l4_timeout_s){0})
00042 #define L4_IPC_NEVER_INITIALIZER {0}
00043 #define L4_IPC_NEVER ((l4_timeout_t){0})
00044 #define L4_IPC_RECV_TIMEOUT_0 ((l4_timeout_t){0x00000400})
00045 #define L4_IPC_SEND_TIMEOUT_0 ((l4_timeout_t){0x04000000})
00046 #define L4_IPC_BOTH_TIMEOUT_0 ((l4_timeout_t){0x04000400})
00047
00048
00054 enum l4_timeout_abs_validity {
00055 L4_TIMEOUT_ABS_V1_ms = 0,
00056 L4_TIMEOUT_ABS_V2_ms,
00057 L4_TIMEOUT_ABS_V4_ms,
00058 L4_TIMEOUT_ABS_V8_ms,
00059 L4_TIMEOUT_ABS_V16_ms,
00060 L4_TIMEOUT_ABS_V32_ms,
00061 L4_TIMEOUT_ABS_V64_ms,
00062 L4_TIMEOUT_ABS_V128_ms,
00063 L4_TIMEOUT_ABS_V256_ms,
00064 L4_TIMEOUT_ABS_V512_ms,
00065 L4_TIMEOUT_ABS_V1_s,
00066 L4_TIMEOUT_ABS_V2_s,
00067 L4_TIMEOUT_ABS_V4_s,
00068 L4_TIMEOUT_ABS_V8_s,
00069 L4_TIMEOUT_ABS_V16_s,
00070 L4_TIMEOUT_ABS_V32_s,
00071 };
00072
00083 L4_INLINE
00084 l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp);
00085
00096 L4_INLINE
00097 l4_timeout_s l4_timeout_abs(l4_kernel_clock_t pint,
00098 enum l4_timeout_abs_validity v);
00099
00100
00111 L4_INLINE
00112 l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
00113 unsigned rcv_man, unsigned rcv_exp);
00114
00125 L4_INLINE
00126 l4_timeout_t l4_timeout(l4_timeout_s snd, l4_timeout_s rcv);
00127
00136 L4_INLINE
00137 void l4_snd_timeout(l4_timeout_s snd, l4_timeout_t *to);
00138
00147 L4_INLINE
00148 void l4_rcv_timeout(l4_timeout_s rcv, l4_timeout_t *to);
00149
00159 L4_INLINE
00160 l4_kernel_clock_t l4_timeout_rel_get(l4_timeout_s to);
00161
00172 L4_INLINE
00173 l4_kernel_clock_t l4_timeout_abs_get(l4_kernel_clock_t cur, l4_timeout_s to);
00174
00184 L4_INLINE
00185 unsigned l4_timeout_is_absolute(l4_timeout_s to);
00186
00197 L4_INLINE
00198 l4_kernel_clock_t l4_timeout_get(l4_kernel_clock_t cur, l4_timeout_s to);
00199
00200
00201
00202
00203
00204
00205 L4_INLINE
00206 l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
00207 unsigned rcv_man, unsigned rcv_exp)
00208 {
00209 l4_timeout_t t;
00210 t.p.snd.t = (snd_man & 0x3ff) | ((snd_exp << 10) & 0x7c00);
00211 t.p.rcv.t = (rcv_man & 0x3ff) | ((rcv_exp << 10) & 0x7c00);
00212 return t;
00213 }
00214
00215
00216 L4_INLINE
00217 l4_timeout_t l4_timeout(l4_timeout_s snd, l4_timeout_s rcv)
00218 {
00219 l4_timeout_t t;
00220 t.p.snd = snd;
00221 t.p.rcv = rcv;
00222 return t;
00223 }
00224
00225
00226 L4_INLINE
00227 void l4_snd_timeout(l4_timeout_s snd, l4_timeout_t *to)
00228 {
00229 to->p.snd = snd;
00230 }
00231
00232
00233 L4_INLINE
00234 void l4_rcv_timeout(l4_timeout_s rcv, l4_timeout_t *to)
00235 {
00236 to->p.rcv = rcv;
00237 }
00238
00239
00240 L4_INLINE
00241 l4_timeout_s l4_timeout_abs(l4_kernel_clock_t pint,
00242 enum l4_timeout_abs_validity v)
00243 {
00244 int e, m, c;
00245 l4_timeout_s to;
00246
00247 e = v;
00248 m = pint >> e;
00249 c = (pint >> (e + 10)) & 1;
00250 m &= 0x3ff;
00251
00252 to.t = 0x8000 | m | (e << 11) | (c << 10);
00253 return to;
00254 }
00255
00256
00257 L4_INLINE
00258 l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp)
00259 {
00260 return (l4_timeout_s){(man & 0x3ff) | ((exp << 10) & 0x7c00)};
00261 }
00262
00263
00264 L4_INLINE
00265 l4_kernel_clock_t l4_timeout_rel_get(l4_timeout_s to)
00266 {
00267 if (to.t == 0)
00268 return ~0ULL;
00269 return (l4_kernel_clock_t)(to.t & 0x3ff) << ((to.t >> 10) & 0x1f);
00270 }
00271
00272
00273 L4_INLINE
00274 l4_kernel_clock_t l4_timeout_abs_get(l4_kernel_clock_t cur, l4_timeout_s to)
00275 {
00276 unsigned long e = (to.t >> 11) & 0xf;
00277 l4_kernel_clock_t timeout = (cur & ~((1 << (e + 10)) - 1)) | ((to.t & 0x3ff) << e);
00278 if (((cur >> (e + 10)) & 1) != ((to.t >> 10) & 1U))
00279 timeout += 1 << (e + 10);
00280
00281 if (timeout < cur)
00282 return 0;
00283
00284 return timeout;
00285 }
00286
00287
00288 L4_INLINE
00289 unsigned l4_timeout_is_absolute(l4_timeout_s to)
00290 {
00291 return to.t & 0x8000;
00292 }
00293
00294
00295 L4_INLINE
00296 l4_kernel_clock_t l4_timeout_get(l4_kernel_clock_t cur, l4_timeout_s to)
00297 {
00298 if (l4_timeout_is_absolute(to))
00299 return l4_timeout_abs_get(cur, to);
00300 else
00301 return cur + l4_timeout_rel_get(to);
00302 }
00303
00304
00305 #endif