00001
00022 #ifndef _RTAI_TASK_H
00023 #define _RTAI_TASK_H
00024
00025 #include <nucleus/fusion.h>
00026 #include <nucleus/thread.h>
00027 #include <nucleus/synch.h>
00028 #include <rtai/timer.h>
00029
00030
00031 #define T_FPU XNFPU
00032 #define T_SUSP XNSUSP
00033
00034 #define T_CPU(cpu) (1 << (24 + (cpu & 7)))
00035 #define T_CPUMASK 0xff000000
00036
00037
00038 #define T_BLOCKED XNPEND
00039 #define T_DELAYED XNDELAY
00040 #define T_READY XNREADY
00041 #define T_DORMANT XNDORMANT
00042 #define T_STARTED XNSTARTED
00043 #define T_BOOST XNBOOST
00044 #define T_LOCK XNLOCK
00045 #define T_RRB XNRRB
00046 #define T_NOSIG XNASDI
00047 #define T_SHIELD XNSHIELD
00048 #define T_WARNSW XNTRAPSW
00049 #define T_PRIMARY XNTHREAD_SPARE0
00050
00051
00052 #define T_HOOK_START XNHOOK_THREAD_START
00053 #define T_HOOK_SWITCH XNHOOK_THREAD_SWITCH
00054 #define T_HOOK_DELETE XNHOOK_THREAD_DELETE
00055 #define T_DESC(cookie) thread2rtask(cookie)
00056
00057
00058 #define T_LOPRIO FUSION_LOW_PRIO
00059 #define T_HIPRIO FUSION_HIGH_PRIO
00060
00061 typedef struct rt_task_placeholder {
00062 rt_handle_t opaque;
00063 unsigned long opaque2;
00064 } RT_TASK_PLACEHOLDER;
00065
00066 #define RT_TASK_STATUS_MASK \
00067 (T_FPU|T_BLOCKED|T_DELAYED|T_READY|T_DORMANT|T_STARTED|T_BOOST|T_LOCK|T_RRB|T_NOSIG|T_SHIELD|T_WARNSW)
00068
00069 struct rt_queue_msg;
00070 struct rt_task;
00071
00072 typedef struct rt_task_info {
00073
00074 int bprio;
00075
00076 int cprio;
00077
00078 unsigned status;
00079
00080 RTIME relpoint;
00081
00082 char name[XNOBJECT_NAME_LEN];
00083
00084 } RT_TASK_INFO;
00085
00086 #define RT_MCB_FSTORE_LIMIT 64
00087
00088 typedef struct rt_task_mcb {
00089
00090 int flowid;
00091
00092 int opcode;
00093
00094 caddr_t data;
00095
00096 size_t size;
00097
00098 } RT_TASK_MCB;
00099
00100 #if defined(__KERNEL__) || defined(__RTAI_SIM__)
00101
00102 #define RTAI_TASK_MAGIC 0x55550101
00103
00104 typedef struct rt_task {
00105
00106 unsigned magic;
00107
00108 xnholder_t link;
00109
00110 #define link2rtask(laddr) \
00111 ((RT_TASK *)(((char *)laddr) - (int)(&((RT_TASK *)0)->link)))
00112
00113 xntimer_t timer;
00114
00115 xnthread_t thread_base;
00116
00117 rt_handle_t handle;
00118
00119 int suspend_depth;
00120
00121 int overrun;
00122
00123 xnarch_cpumask_t affinity;
00124
00125 union {
00126
00127 struct {
00128 int mode;
00129 unsigned long mask;
00130 } event;
00131
00132 struct rt_queue_msg *qmsg;
00133
00134 struct {
00135 size_t size;
00136 void *block;
00137 } heap;
00138
00139 struct {
00140 const char *key;
00141 } registry;
00142
00143 #ifdef CONFIG_RTAI_OPT_NATIVE_MPS
00144 struct {
00145 RT_TASK_MCB mcb_s;
00146 RT_TASK_MCB mcb_r;
00147 } mps;
00148 #endif
00149
00150 } wait_args;
00151
00152 #ifdef CONFIG_RTAI_OPT_NATIVE_MPS
00153 xnsynch_t mrecv,
00154 msendq;
00155
00156 int flowgen;
00157 #endif
00158
00159 } RT_TASK;
00160
00161 static inline RT_TASK *thread2rtask (xnthread_t *t)
00162 {
00163 return t ? ((RT_TASK *)(((char *)(t)) - (int)(&((RT_TASK *)0)->thread_base))) : NULL;
00164 }
00165
00166 #define rtai_current_task() thread2rtask(xnpod_current_thread())
00167
00168 #ifdef __cplusplus
00169 extern "C" {
00170 #endif
00171
00172 int __task_pkg_init(void);
00173
00174 void __task_pkg_cleanup(void);
00175
00176
00177
00178 int rt_task_add_hook(int type,
00179 void (*routine)(void *cookie));
00180
00181 int rt_task_remove_hook(int type,
00182 void (*routine)(void *cookie));
00183
00184 #ifdef __cplusplus
00185 }
00186 #endif
00187
00188 #else
00189
00190 typedef RT_TASK_PLACEHOLDER RT_TASK;
00191
00192 #ifdef __cplusplus
00193 extern "C" {
00194 #endif
00195
00196 int rt_task_shadow(RT_TASK *task,
00197 const char *name,
00198 int prio,
00199 int mode);
00200
00201 int rt_task_bind(RT_TASK *task,
00202 const char *name,
00203 RTIME timeout);
00204
00205 static inline int rt_task_unbind (RT_TASK *task)
00206
00207 {
00208 task->opaque = RT_HANDLE_INVALID;
00209 return 0;
00210 }
00211
00212 #ifdef __cplusplus
00213 }
00214 #endif
00215
00216 #endif
00217
00218 #ifdef __cplusplus
00219 extern "C" {
00220 #endif
00221
00222
00223
00224 int rt_task_create(RT_TASK *task,
00225 const char *name,
00226 int stksize,
00227 int prio,
00228 int mode);
00229
00230 int rt_task_start(RT_TASK *task,
00231 void (*fun)(void *cookie),
00232 void *cookie);
00233
00234 int rt_task_suspend(RT_TASK *task);
00235
00236 int rt_task_resume(RT_TASK *task);
00237
00238 int rt_task_delete(RT_TASK *task);
00239
00240 int rt_task_yield(void);
00241
00242 int rt_task_set_periodic(RT_TASK *task,
00243 RTIME idate,
00244 RTIME period);
00245
00246 int rt_task_wait_period(void);
00247
00248 int rt_task_set_priority(RT_TASK *task,
00249 int prio);
00250
00251 int rt_task_sleep(RTIME delay);
00252
00253 int rt_task_sleep_until(RTIME date);
00254
00255 int rt_task_unblock(RT_TASK *task);
00256
00257 int rt_task_inquire(RT_TASK *task,
00258 RT_TASK_INFO *info);
00259
00260 int rt_task_catch(void (*handler)(rt_sigset_t));
00261
00262 int rt_task_notify(RT_TASK *task,
00263 rt_sigset_t signals);
00264
00265 int rt_task_set_mode(int clrmask,
00266 int setmask,
00267 int *mode_r);
00268
00269 RT_TASK *rt_task_self(void);
00270
00271 int rt_task_slice(RT_TASK *task,
00272 RTIME quantum);
00273
00274 #ifdef CONFIG_RTAI_OPT_NATIVE_MPS
00275
00276 ssize_t rt_task_send(RT_TASK *task,
00277 RT_TASK_MCB *mcb_s,
00278 RT_TASK_MCB *mcb_r,
00279 RTIME timeout);
00280
00281 int rt_task_receive(RT_TASK_MCB *mcb_r,
00282 RTIME timeout);
00283
00284 int rt_task_reply(int flowid,
00285 RT_TASK_MCB *mcb_s);
00286
00287 #endif
00288
00289 static inline int rt_task_spawn(RT_TASK *task,
00290 const char *name,
00291 int stksize,
00292 int prio,
00293 int mode,
00294 void (*entry)(void *cookie),
00295 void *cookie)
00296 {
00297 int err = rt_task_create(task,name,stksize,prio,mode);
00298
00299 if (!err)
00300 err = rt_task_start(task,entry,cookie);
00301
00302 return err;
00303 }
00304
00305 #ifdef __cplusplus
00306 }
00307 #endif
00308
00309 #endif