Xenomai API  2.5.6.1
ksrc/skins/posix/internal.h
00001 /*
00002  * Written by Gilles Chanteperdrix <[email protected]>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #ifndef _POSIX_INTERNAL_H
00020 #define _POSIX_INTERNAL_H
00021 
00022 #include <nucleus/xenomai.h>
00023 #include <nucleus/ppd.h>
00024 #include <nucleus/select.h>
00025 #include <posix/posix.h>
00026 #include <posix/registry.h>
00027 
00028 /* debug support */
00029 #include <nucleus/assert.h>
00030 
00031 #ifndef CONFIG_XENO_OPT_DEBUG_POSIX
00032 #define CONFIG_XENO_OPT_DEBUG_POSIX 0
00033 #endif
00034 
00035 #define PSE51_MAGIC(n) (0x8686##n##n)
00036 #define PSE51_ANY_MAGIC         PSE51_MAGIC(00)
00037 #define PSE51_THREAD_MAGIC      PSE51_MAGIC(01)
00038 #define PSE51_THREAD_ATTR_MAGIC PSE51_MAGIC(02)
00039 #define PSE51_MUTEX_MAGIC       PSE51_MAGIC(03)
00040 #define PSE51_MUTEX_ATTR_MAGIC  (PSE51_MAGIC(04) & ((1 << 24) - 1))
00041 #define PSE51_COND_MAGIC        PSE51_MAGIC(05)
00042 #define PSE51_COND_ATTR_MAGIC   (PSE51_MAGIC(05) & ((1 << 24) - 1))
00043 #define PSE51_SEM_MAGIC         PSE51_MAGIC(06)
00044 #define PSE51_KEY_MAGIC         PSE51_MAGIC(07)
00045 #define PSE51_ONCE_MAGIC        PSE51_MAGIC(08)
00046 #define PSE51_MQ_MAGIC          PSE51_MAGIC(09)
00047 #define PSE51_MQD_MAGIC         PSE51_MAGIC(0A)
00048 #define PSE51_INTR_MAGIC        PSE51_MAGIC(0B)
00049 #define PSE51_NAMED_SEM_MAGIC   PSE51_MAGIC(0C)
00050 #define PSE51_TIMER_MAGIC       PSE51_MAGIC(0D)
00051 #define PSE51_SHM_MAGIC         PSE51_MAGIC(0E)
00052 
00053 #define PSE51_MIN_PRIORITY      XNSCHED_LOW_PRIO
00054 #define PSE51_MAX_PRIORITY      XNSCHED_HIGH_PRIO
00055 
00056 #define ONE_BILLION             1000000000
00057 
00058 #define pse51_obj_active(h,m,t)                 \
00059         ((h) && ((t *)(h))->magic == (m))
00060 
00061 #define pse51_obj_deleted(h,m,t)                \
00062         ((h) && ((t *)(h))->magic == ~(m))
00063 
00064 #define pse51_mark_deleted(t) ((t)->magic = ~(t)->magic)
00065 
00066 typedef struct {
00067         xnqueue_t condq;
00068         xnqueue_t intrq;
00069         xnqueue_t mutexq;
00070         xnqueue_t semq;
00071         xnqueue_t threadq;
00072         xnqueue_t timerq;
00073 } pse51_kqueues_t;
00074 
00075 #ifdef CONFIG_XENO_OPT_PERVASIVE
00076 typedef struct {
00077         pse51_kqueues_t kqueues;
00078         pse51_assocq_t uqds;
00079         pse51_assocq_t usems;
00080         pse51_assocq_t umaps;
00081         pse51_assocq_t ufds;
00082 
00083         xnshadow_ppd_t ppd;
00084 
00085 #define ppd2queues(addr)                                                \
00086         ((pse51_queues_t *) ((char *) (addr) - offsetof(pse51_queues_t, ppd)))
00087 
00088 } pse51_queues_t;
00089 
00090 extern int pse51_muxid;
00091 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00092 
00093 extern xntbase_t *pse51_tbase;
00094 
00095 extern pse51_kqueues_t pse51_global_kqueues;
00096 
00097 #ifdef CONFIG_XENO_OPT_PERVASIVE
00098 static inline pse51_queues_t *pse51_queues(void)
00099 {
00100         xnshadow_ppd_t *ppd;
00101         spl_t s;
00102 
00103         xnlock_get_irqsave(&nklock, s);
00104 
00105         ppd = xnshadow_ppd_get(pse51_muxid);
00106 
00107         xnlock_put_irqrestore(&nklock, s);
00108 
00109         if (!ppd)
00110                 return NULL;
00111 
00112         return ppd2queues(ppd);
00113 }
00114 #endif /* CONFIG_XENO_OPT_PERVASIVE */
00115 
00116 static inline pse51_kqueues_t *pse51_kqueues(int pshared)
00117 {
00118 #ifdef CONFIG_XENO_OPT_PERVASIVE
00119         xnshadow_ppd_t *ppd;
00120 
00121         if (pshared || !(ppd = xnshadow_ppd_get(pse51_muxid)))
00122                 return &pse51_global_kqueues;
00123 
00124         return &ppd2queues(ppd)->kqueues;
00125 #else /* !CONFIG_XENO_OPT_PERVASIVE */
00126         return &pse51_global_kqueues;
00127 #endif /* !CONFIG_XENO_OPT_PERVASIVE */
00128 }
00129 
00130 static inline void ticks2ts(struct timespec *ts, xnticks_t ticks)
00131 {
00132         ts->tv_sec = xnarch_divrem_billion(xntbase_ticks2ns(pse51_tbase, ticks),
00133                                            &ts->tv_nsec);
00134 }
00135 
00136 static inline xnticks_t ts2ticks_floor(const struct timespec *ts)
00137 {
00138         xntime_t nsecs = ts->tv_nsec;
00139         if(ts->tv_sec)
00140                 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00141         return xntbase_ns2ticks(pse51_tbase, nsecs);
00142 }
00143 
00144 static inline xnticks_t ts2ticks_ceil(const struct timespec *ts)
00145 {
00146         xntime_t nsecs = ts->tv_nsec;
00147         unsigned long rem;
00148         xnticks_t ticks;
00149         if(ts->tv_sec)
00150                 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00151         ticks = xnarch_ulldiv(nsecs, xntbase_get_tickval(pse51_tbase), &rem);
00152         return rem ? ticks+1 : ticks;
00153 }
00154 
00155 static inline xnticks_t tv2ticks_ceil(const struct timeval *tv)
00156 {
00157         xntime_t nsecs = tv->tv_usec * 1000;
00158         unsigned long rem;
00159         xnticks_t ticks;
00160         if(tv->tv_sec)
00161                 nsecs += (xntime_t) tv->tv_sec * ONE_BILLION;
00162         ticks = xnarch_ulldiv(nsecs, xntbase_get_tickval(pse51_tbase), &rem);
00163         return rem ? ticks+1 : ticks;
00164 }
00165 
00166 static inline void ticks2tv(struct timeval *tv, xnticks_t ticks)
00167 {
00168         unsigned long nsecs;
00169         tv->tv_sec = xnarch_divrem_billion(xntbase_ticks2ns(pse51_tbase, ticks),
00170                                            &nsecs);
00171         tv->tv_usec = nsecs / 1000;
00172 }
00173 
00174 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
00175 {
00176         if(clock_id == CLOCK_REALTIME)
00177                 return xntbase_get_time(pse51_tbase);
00178         else
00179                 return xntbase_get_jiffies(pse51_tbase);
00180 }
00181 
00182 static inline int clock_flag(int flag, clockid_t clock_id)
00183 {
00184         switch(flag & TIMER_ABSTIME) {
00185         case 0:
00186                 return XN_RELATIVE;
00187 
00188         case TIMER_ABSTIME:
00189                 switch(clock_id) {
00190                 case CLOCK_MONOTONIC:
00191                         return XN_ABSOLUTE;
00192 
00193                 case CLOCK_REALTIME:
00194                         return XN_REALTIME;
00195                 }
00196         }
00197         return -EINVAL;
00198 }
00199 
00200 int pse51_mq_select_bind(mqd_t fd, struct xnselector *selector,
00201                          unsigned type, unsigned index);
00202 
00203 #endif /* !_POSIX_INTERNAL_H */
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines