00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _POSIX_INTERNAL_H
00020 #define _POSIX_INTERNAL_H
00021
00022 #include <nucleus/xenomai.h>
00023 #include <nucleus/core.h>
00024 #include <nucleus/ppd.h>
00025 #include <posix/posix.h>
00026 #include <posix/registry.h>
00027
00028
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 XNCORE_LOW_PRIO
00054 #define PSE51_MAX_PRIORITY XNCORE_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
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
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
00126 return &pse51_global_kqueues;
00127 #endif
00128 }
00129
00130 static inline void ticks2ts(struct timespec *ts, xnticks_t ticks)
00131 {
00132 ts->tv_sec = xnarch_uldivrem(xntbase_ticks2ns(pse51_tbase, ticks),
00133 ONE_BILLION,
00134 &ts->tv_nsec);
00135 }
00136
00137 static inline xnticks_t ts2ticks_floor(const struct timespec *ts)
00138 {
00139 xntime_t nsecs = ts->tv_nsec;
00140 if(ts->tv_sec)
00141 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00142 return xntbase_ns2ticks(pse51_tbase, nsecs);
00143 }
00144
00145 static inline xnticks_t ts2ticks_ceil(const struct timespec *ts)
00146 {
00147 xntime_t nsecs = ts->tv_nsec;
00148 unsigned long rem;
00149 xnticks_t ticks;
00150 if(ts->tv_sec)
00151 nsecs += (xntime_t) ts->tv_sec * ONE_BILLION;
00152 ticks = xnarch_ulldiv(nsecs, xntbase_get_tickval(pse51_tbase), &rem);
00153 return rem ? ticks+1 : ticks;
00154 }
00155
00156 static inline xnticks_t clock_get_ticks(clockid_t clock_id)
00157 {
00158 if(clock_id == CLOCK_REALTIME)
00159 return xntbase_get_time(pse51_tbase);
00160 else
00161 return xntbase_ns2ticks(pse51_tbase, xnpod_get_cpu_time());
00162 }
00163
00164 static inline int clock_flag(int flag, clockid_t clock_id)
00165 {
00166 switch(flag & TIMER_ABSTIME) {
00167 case 0:
00168 return XN_RELATIVE;
00169
00170 case TIMER_ABSTIME:
00171 switch(clock_id) {
00172 case CLOCK_MONOTONIC:
00173 return XN_ABSOLUTE;
00174
00175 case CLOCK_REALTIME:
00176 return XN_REALTIME;
00177 }
00178 }
00179 return -EINVAL;
00180 }
00181
00182 #endif