Xenomai API
2.5.6.1
|
00001 00022 #ifndef _XENO_TASK_H 00023 #define _XENO_TASK_H 00024 00025 #include <nucleus/sched.h> 00026 #include <native/types.h> 00027 00028 /* Creation flags. */ 00029 #define T_FPU XNFPU 00030 #define T_SUSP XNSUSP 00031 /* <!> High bits must not conflict with XNFPU|XNSHADOW|XNSUSP. */ 00032 #define T_CPU(cpu) (1 << (24 + (cpu & 7))) /* Up to 8 cpus [0-7] */ 00033 #define T_CPUMASK 0xff000000 00034 00042 #define T_BLOCKED XNPEND 00043 #define T_DELAYED XNDELAY 00044 #define T_READY XNREADY 00045 #define T_DORMANT XNDORMANT 00046 #define T_STARTED XNSTARTED 00047 #define T_BOOST XNBOOST 00048 #define T_LOCK XNLOCK 00049 #define T_NOSIG XNASDI 00050 #define T_WARNSW XNTRAPSW 00051 #define T_RPIOFF XNRPIOFF 00052 #define T_PRIMARY 0x00000200 /* Recycle internal bits status which */ 00053 #define T_JOINABLE 0x00000400 /* won't be passed to the nucleus. */ 00054 /* Ends doxygen-group native_task_status */ 00055 00056 /* Task hook types. */ 00057 #define T_HOOK_START XNHOOK_THREAD_START 00058 #define T_HOOK_SWITCH XNHOOK_THREAD_SWITCH 00059 #define T_HOOK_DELETE XNHOOK_THREAD_DELETE 00060 #define T_DESC(cookie) thread2rtask(cookie) 00061 00062 /* Priority range (POSIXish, same bounds as Xenomai's). */ 00063 #define T_LOPRIO XNSCHED_LOW_PRIO 00064 #define T_HIPRIO XNSCHED_HIGH_PRIO 00065 00066 typedef struct rt_task_placeholder { 00067 xnhandle_t opaque; 00068 unsigned long opaque2; 00069 } RT_TASK_PLACEHOLDER; 00070 00071 struct rt_queue_msg; 00072 struct rt_task; 00073 00078 typedef struct rt_task_info { 00079 00080 int bprio; 00082 int cprio; 00084 unsigned status; 00086 RTIME relpoint; 00088 char name[XNOBJECT_NAME_LEN]; 00090 RTIME exectime; 00092 int modeswitches; 00094 int ctxswitches; 00096 int pagefaults; 00098 } RT_TASK_INFO; 00099 00100 #define RT_MCB_FSTORE_LIMIT 64 00101 00105 typedef struct rt_task_mcb { 00106 00107 int flowid; 00109 int opcode; 00111 caddr_t data; 00113 size_t size; 00115 } RT_TASK_MCB; 00116 00117 #if (defined(__KERNEL__) || defined(__XENO_SIM__)) && !defined(DOXYGEN_CPP) 00118 00119 #include <nucleus/synch.h> 00120 00121 #define XENO_TASK_MAGIC 0x55550101 00122 00123 typedef struct rt_task { 00124 00125 unsigned magic; /* !< Magic code - must be first */ 00126 00127 xnholder_t link; 00128 00129 #define link2rtask(ln) container_of(ln, RT_TASK, link) 00130 00131 xnthread_t thread_base; 00132 00133 char rname[XNOBJECT_NAME_LEN]; /* !< Name in registry. Not the same as 00134 thread name for anonymous threads. */ 00135 int suspend_depth; 00136 00137 int overrun; 00138 00139 xnsynch_t safesynch; /* !< Safe synchronization object. */ 00140 00141 u_long safelock; /* !< Safe lock count. */ 00142 00143 u_long cstamp; /* !< Creation stamp. */ 00144 00145 xnarch_cpumask_t affinity; 00146 00147 union { /* Saved args for current synch. wait operation. */ 00148 00149 struct { 00150 int mode; 00151 unsigned long mask; 00152 } event; 00153 00154 #ifdef CONFIG_XENO_OPT_NATIVE_MPS 00155 struct { 00156 RT_TASK_MCB mcb_s; /* Send area. */ 00157 RT_TASK_MCB mcb_r; /* Reply area. */ 00158 } mps; 00159 #endif /* CONFIG_XENO_OPT_NATIVE_MPS */ 00160 00161 } wait_args; 00162 00163 #ifdef CONFIG_XENO_OPT_NATIVE_MPS 00164 xnsynch_t mrecv, 00165 msendq; 00166 00167 int flowgen; /* !< Flow id. generator. */ 00168 #endif /* CONFIG_XENO_OPT_NATIVE_MPS */ 00169 00170 } RT_TASK; 00171 00172 static inline RT_TASK *thread2rtask (xnthread_t *t) 00173 { 00174 return t ? container_of(t, RT_TASK, thread_base) : NULL; 00175 } 00176 00177 #define xeno_current_task() thread2rtask(xnpod_current_thread()) 00178 00179 #ifdef __cplusplus 00180 extern "C" { 00181 #endif 00182 00183 void __native_task_safe(RT_TASK *task); 00184 00185 void __native_task_unsafe(RT_TASK *task); 00186 00187 int __native_task_safewait(RT_TASK *task); 00188 00189 int __native_task_pkg_init(void); 00190 00191 void __native_task_pkg_cleanup(void); 00192 00193 /* Public kernel interface */ 00194 00195 int rt_task_add_hook(int type, 00196 void (*routine)(void *cookie)); 00197 00198 int rt_task_remove_hook(int type, 00199 void (*routine)(void *cookie)); 00200 00201 int rt_task_catch(void (*handler)(rt_sigset_t)); 00202 00203 static inline int rt_task_same(RT_TASK *task1, RT_TASK *task2) 00204 { 00205 return task1 == task2; 00206 } 00207 00208 #ifdef __cplusplus 00209 } 00210 #endif 00211 00212 #else /* !(__KERNEL__ || __XENO_SIM__) */ 00213 00214 typedef RT_TASK_PLACEHOLDER RT_TASK; 00215 00216 #ifdef __cplusplus 00217 extern "C" { 00218 #endif 00219 00220 int rt_task_shadow(RT_TASK *task, 00221 const char *name, 00222 int prio, 00223 int mode); 00224 00225 int rt_task_bind(RT_TASK *task, 00226 const char *name, 00227 RTIME timeout); 00228 00229 static inline int rt_task_unbind (RT_TASK *task) 00230 00231 { 00232 task->opaque = XN_NO_HANDLE; 00233 return 0; 00234 } 00235 00236 int rt_task_join(RT_TASK *task); 00237 00238 #ifdef __cplusplus 00239 } 00240 #endif 00241 00242 #endif /* __KERNEL__ || __XENO_SIM__ */ 00243 00244 #ifdef __cplusplus 00245 extern "C" { 00246 #endif 00247 00248 /* Public interface */ 00249 00250 int rt_task_create(RT_TASK *task, 00251 const char *name, 00252 int stksize, 00253 int prio, 00254 int mode) __deprecated_in_kernel__; 00255 00256 int rt_task_start(RT_TASK *task, 00257 void (*fun)(void *cookie), 00258 void *cookie); 00259 00260 int rt_task_suspend(RT_TASK *task); 00261 00262 int rt_task_resume(RT_TASK *task); 00263 00264 int rt_task_delete(RT_TASK *task); 00265 00266 int rt_task_yield(void); 00267 00268 int rt_task_set_periodic(RT_TASK *task, 00269 RTIME idate, 00270 RTIME period); 00271 00272 int rt_task_wait_period(unsigned long *overruns_r); 00273 00274 int rt_task_set_priority(RT_TASK *task, 00275 int prio); 00276 00277 int rt_task_sleep(RTIME delay); 00278 00279 int rt_task_sleep_until(RTIME date); 00280 00281 int rt_task_unblock(RT_TASK *task); 00282 00283 int rt_task_inquire(RT_TASK *task, 00284 RT_TASK_INFO *info); 00285 00286 int rt_task_notify(RT_TASK *task, 00287 rt_sigset_t signals); 00288 00289 int rt_task_set_mode(int clrmask, 00290 int setmask, 00291 int *mode_r); 00292 00293 RT_TASK *rt_task_self(void); 00294 00295 int rt_task_slice(RT_TASK *task, 00296 RTIME quantum); 00297 00298 ssize_t rt_task_send(RT_TASK *task, 00299 RT_TASK_MCB *mcb_s, 00300 RT_TASK_MCB *mcb_r, 00301 RTIME timeout); 00302 00303 int rt_task_receive(RT_TASK_MCB *mcb_r, 00304 RTIME timeout); 00305 00306 int rt_task_reply(int flowid, 00307 RT_TASK_MCB *mcb_s); 00308 00309 static inline int rt_task_spawn(RT_TASK *task, 00310 const char *name, 00311 int stksize, 00312 int prio, 00313 int mode, 00314 void (*entry)(void *cookie), 00315 void *cookie) 00316 { 00317 int err = rt_task_create(task,name,stksize,prio,mode); 00318 00319 if (!err) 00320 err = rt_task_start(task,entry,cookie); 00321 00322 return err; 00323 } 00324 00325 int rt_task_same(RT_TASK *task1, RT_TASK *task2); 00326 00327 #ifdef __cplusplus 00328 } 00329 #endif 00330 00331 #endif /* !_XENO_TASK_H */