task.h

Go to the documentation of this file.
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 /* Creation flags. */
00031 #define T_FPU     XNFPU
00032 #define T_SUSP    XNSUSP
00033 /* <!> High bits must not conflict with XNFPU|XNSHADOW|XNSHIELD|XNSUSP. */
00034 #define T_CPU(cpu) (1 << (24 + (cpu & 7))) /* Up to 8 cpus [0-7] */
00035 #define T_CPUMASK  0xff000000
00036 
00037 /* Status/mode flags. */
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 /* Task hook types. */
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 /* Priority range (POSIXish, same bounds as fusion). */
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;                  /* !< Base priority. */
00075 
00076     int cprio;                  /* !< Current priority. */
00077 
00078     unsigned status;            /* !< Status. */
00079 
00080     RTIME relpoint;             /* !< Periodic release point. */
00081 
00082     char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
00083 
00084 } RT_TASK_INFO;
00085 
00086 #define RT_MCB_FSTORE_LIMIT  64
00087 
00088 typedef struct rt_task_mcb {
00089 
00090     int flowid;                 /* !< Flow identifier. */
00091 
00092     int opcode;                 /* !< Operation code. */
00093 
00094     caddr_t data;               /* !< Address of message. */
00095 
00096     size_t size;                /* !< Size of message. */
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;   /* !< Magic code - must be first */
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; /* !< Handle in registry -- zero if unregistered. */
00118 
00119     int suspend_depth;
00120 
00121     int overrun;
00122 
00123     xnarch_cpumask_t affinity;
00124 
00125     union { /* Saved args for current synch. wait operation. */
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; /* Send area. */
00146             RT_TASK_MCB mcb_r; /* Reply area. */
00147         } mps;
00148 #endif /* CONFIG_RTAI_OPT_NATIVE_MPS */
00149 
00150     } wait_args;
00151 
00152 #ifdef CONFIG_RTAI_OPT_NATIVE_MPS
00153     xnsynch_t mrecv,
00154               msendq;
00155 
00156     int flowgen;                /* !< FLow id. generator. */
00157 #endif /* CONFIG_RTAI_OPT_NATIVE_MPS */
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 /* Public kernel interface */
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 /* !(__KERNEL__ || __RTAI_SIM__) */
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 
00204 static inline int rt_task_unbind (RT_TASK *task)
00205 
00206 {
00207     task->opaque = RT_HANDLE_INVALID;
00208     return 0;
00209 }
00210 
00211 #ifdef __cplusplus
00212 }
00213 #endif
00214 
00215 #endif /* __KERNEL__ || __RTAI_SIM__ */
00216 
00217 #ifdef __cplusplus
00218 extern "C" {
00219 #endif
00220 
00221 /* Public interface */
00222 
00223 int rt_task_create(RT_TASK *task,
00224                    const char *name,
00225                    int stksize,
00226                    int prio,
00227                    int mode);
00228 
00229 int rt_task_start(RT_TASK *task,
00230                   void (*fun)(void *cookie),
00231                   void *cookie);
00232 
00233 int rt_task_suspend(RT_TASK *task);
00234 
00235 int rt_task_resume(RT_TASK *task);
00236 
00237 int rt_task_delete(RT_TASK *task);
00238 
00239 int rt_task_yield(void);
00240 
00241 int rt_task_set_periodic(RT_TASK *task,
00242                          RTIME idate,
00243                          RTIME period);
00244 
00245 int rt_task_wait_period(void);
00246 
00247 int rt_task_set_priority(RT_TASK *task,
00248                          int prio);
00249 
00250 int rt_task_sleep(RTIME delay);
00251 
00252 int rt_task_sleep_until(RTIME date);
00253 
00254 int rt_task_unblock(RT_TASK *task);
00255 
00256 int rt_task_inquire(RT_TASK *task,
00257                      RT_TASK_INFO *info);
00258 
00259 int rt_task_catch(void (*handler)(rt_sigset_t));
00260 
00261 int rt_task_notify(RT_TASK *task,
00262                    rt_sigset_t signals);
00263 
00264 int rt_task_set_mode(int clrmask,
00265                      int setmask,
00266                      int *mode_r);
00267 
00268 RT_TASK *rt_task_self(void);
00269 
00270 int rt_task_slice(RT_TASK *task,
00271                   RTIME quantum);
00272 
00273 #ifdef CONFIG_RTAI_OPT_NATIVE_MPS
00274 
00275 ssize_t rt_task_send(RT_TASK *task,
00276                      RT_TASK_MCB *mcb_s,
00277                      RT_TASK_MCB *mcb_r,
00278                      RTIME timeout);
00279 
00280 int rt_task_receive(RT_TASK_MCB *mcb_r,
00281                     RTIME timeout);
00282 
00283 int rt_task_reply(int flowid,
00284                   RT_TASK_MCB *mcb_s);
00285 
00286 #endif /* CONFIG_RTAI_OPT_NATIVE_MPS */
00287 
00288 static inline int rt_task_spawn(RT_TASK *task,
00289                                 const char *name,
00290                                 int stksize,
00291                                 int prio,
00292                                 int mode,
00293                                 void (*entry)(void *cookie),
00294                                 void *cookie)
00295 {
00296     int err = rt_task_create(task,name,stksize,prio,mode);
00297 
00298     if (!err)
00299         err = rt_task_start(task,entry,cookie);
00300 
00301     return err;
00302 }
00303 
00304 #ifdef __cplusplus
00305 }
00306 #endif
00307 
00308 #endif /* !_RTAI_TASK_H */

Generated on Wed Jun 22 22:54:02 2005 for RTAI Fusion API by  doxygen 1.4.1