]> rtime.felk.cvut.cz Git - orte.git/blob - orte/include/rtai/compat.h
0e69bffb5997e17d8dcd8a4401dd730675848580
[orte.git] / orte / include / rtai / compat.h
1 /*
2  *  $Id: compat.h,v 0.0.0.1             2004/11/14
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  *  Author - this code:  Jan Kiszka        jan.kiszka@web.de
15  *  Advisor:             Pavel Pisa                                   
16  *  Project Responsible: Zdenek Hanzalek                              
17  *  --------------------------------------------------------------------
18  *
19  *  This program is free software; you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License as published by
21  *  the Free Software Foundation; either version 2 of the License, or
22  *  (at your option) any later version.
23  *
24  *  This program is distributed in the hope that it will be useful,
25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *  GNU General Public License for more details.
28  *
29  */
30
31 #ifndef _COMPAT_H
32 #define _COMPAT_H
33
34 #include <linux/if.h>
35 #include <linux/in.h>
36 #include <rtnet.h>
37 #include "rtai_posix.h.patched"
38 #include <defines.h>  //macro MALLOC
39
40 /* This should become a bit more generic for all platforms... */
41 #define rtl_printf  rt_printk
42 #define printf      rt_printk /* catch some probably forgotten printf's */
43 #define malloc      rt_malloc
44 #define free        rt_free
45
46 typedef __u32 in_addr_t;
47
48 static inline in_addr_t inet_addr(const char *cp)
49 {
50     return rt_inet_aton(cp);
51 }
52
53
54 static char inet_ntoa_buf[16];
55
56 static inline char *inet_ntoa(struct in_addr in)
57 {
58     unsigned char *octet;
59
60     octet = (unsigned char *)&(in.s_addr);
61     sprintf(inet_ntoa_buf, "%u.%u.%u.%u", octet[0], octet[1], octet[2], octet[3]);
62
63     return inet_ntoa_buf;
64 }
65
66
67 #define CLOCK_REALTIME  0
68
69 static inline void clock_gettime(int dummy, struct timespec *time)
70 {
71     count2timespec(rt_get_time(), time);
72 }
73
74
75 static inline int atoi(const char* nptr)
76 {
77     return simple_strtol(nptr, (char **)NULL, 10);
78 }
79
80
81 #define sem_init                    sem_init_rt
82 #define sem_destroy                 sem_destroy_rt
83 #define sem_timedwait               sem_timedwait_rt
84 #define sem_post                    sem_post_rt
85 #define sem_getvalue                sem_getvalue_rt
86
87 #define pthread_rwlock_init         pthread_rwlock_init_rt
88 #define pthread_rwlock_rdlock       pthread_rwlock_rdlock_rt
89 #define pthread_rwlock_wrlock       pthread_rwlock_wrlock_rt
90 #define pthread_rwlock_unlock       pthread_rwlock_unlock_rt
91 #define pthread_rwlock_destroy      pthread_rwlock_destroy_rt
92
93 #define pthread_mutex_init          pthread_mutex_init_rt
94 #define pthread_mutex_lock          pthread_mutex_lock_rt
95 #define pthread_mutex_timedlock     pthread_mutex_timedlock_rt
96 #define pthread_mutex_unlock        pthread_mutex_unlock_rt
97 #define pthread_mutex_destroy       pthread_mutex_destroy_rt
98
99 #define pthread_create              pthread_create_rt
100 #define pthread_join                pthread_join_rt
101 #define pthread_exit                pthread_exit_rt
102
103 #define pthread_cond_init           pthread_cond_init_rt
104 #define pthread_cond_timedwait      pthread_cond_timedwait_rt
105 #define pthread_cond_signal         pthread_cond_signal_rt
106 #define pthread_cond_destroy        pthread_cond_destroy_rt
107
108 #define socket                      socket_rt
109 #define setsockopt                  setsockopt_rt
110 #define getsockopt                  getsockopt_rt
111 #define ioctl                       ioctl_rt
112 #define bind                        bind_rt
113 #define getsockname                 getsockname_rt
114 #define recvfrom                    recvfrom_rt
115 #define sendto                      sendto_rt
116
117 static inline int close(int s)
118 {
119     int result;
120
121     while ((result = close_rt(s)) == -EAGAIN)
122         rt_sleep(nano2count(100000000));
123     return result;
124 }
125
126 #endif /* _COMPAT_H */