base/include/rtai_signal.h

Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2006 Paolo Mantegazza <mantegazza@aero.polimi.it> 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2 of the License, or (at your option) any later version. 00008 * 00009 * This library 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 GNU 00012 * Lesser General Public License for more details. 00013 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00017 * 00018 */ 00019 00020 #ifndef _RTAI_SIGNAL_H_ 00021 #define _RTAI_SIGNAL_H_ 00022 00023 #define RTAI_SIGNALS_IDX 2 00024 00025 #define SIGNAL_HELPER 0 00026 #define SIGNAL_WAITSIG 1 00027 #define SIGNAL_REQUEST 2 00028 #define SIGNAL_RELEASE 3 00029 #define SIGNAL_ENABLE 4 00030 #define SIGNAL_DISABLE 5 00031 #define SIGNAL_TRIGGER 6 00032 00033 #define SIGNAL_TASK_INIPRIO 0 00034 00035 struct sigsuprt_t { RT_TASK *sigtask; RT_TASK *task; long signal; void (*sighdl)(long, RT_TASK *); unsigned long cpuid; }; 00036 00037 #ifdef __KERNEL__ 00038 00039 #define MAXSIGNALS 16 00040 00041 #define SIGNAL_ENBIT 0 00042 #define SIGNAL_PNDBIT 1 00043 00044 #define SIGNAL_TASK_STACK_SIZE 8192 00045 00046 int rt_request_signal(long signal, void (*sighdl)(long, RT_TASK *)); 00047 00048 int rt_release_signal(long signal, RT_TASK *task); 00049 00050 void rt_enable_signal(long signal, RT_TASK *task); 00051 00052 void rt_disable_signal(long signal, RT_TASK *task); 00053 00054 void rt_trigger_signal(long signal, RT_TASK *task); 00055 00056 #else /* !__KERNEL__ */ 00057 00058 #include <sys/mman.h> 00059 00060 #include <rtai_lxrt.h> 00061 00062 #define SIGNAL_TASK_STACK_SIZE 8192 00063 00064 #ifndef __SIGNAL_SUPPORT_FUN__ 00065 #define __SIGNAL_SUPPORT_FUN__ 00066 00067 static void signal_suprt_fun(struct sigsuprt_t *funarg) 00068 { 00069 struct sigtsk_t { RT_TASK *sigtask; RT_TASK *task; }; 00070 struct sigreq_t { RT_TASK *sigtask; RT_TASK *task; long signal; void (*sighdl)(int, RT_TASK *); }; 00071 struct sigsuprt_t arg = *funarg; 00072 00073 if ((arg.sigtask = rt_thread_init(rt_get_name(0), SIGNAL_TASK_INIPRIO, 0, SCHED_FIFO, 1 << arg.cpuid))) { 00074 if (!rtai_lxrt(RTAI_SIGNALS_IDX, sizeof(struct sigreq_t), SIGNAL_REQUEST, &arg).i[LOW]) { 00075 mlockall(MCL_CURRENT | MCL_FUTURE); 00076 rt_make_hard_real_time(); 00077 while (rtai_lxrt(RTAI_SIGNALS_IDX, sizeof(struct sigtsk_t), SIGNAL_WAITSIG, &arg).i[LOW]) { 00078 arg.sighdl(arg.signal, arg.task); 00079 } 00080 rt_make_soft_real_time(); 00081 } 00082 rt_task_delete(arg.sigtask); 00083 } 00084 } 00085 00086 #endif /* __SIGNAL_SUPPORT_FUN__ */ 00087 00088 static inline int rt_request_signal(long signal, void (*sighdl)(long, RT_TASK *)) 00089 { 00090 if (signal >= 0 && sighdl) { 00091 struct sigsuprt_t arg = { NULL, rt_buddy(), signal, sighdl, rtai_lxrt(RTAI_SIGNALS_IDX, sizeof(void *), SIGNAL_HELPER, &arg.sigtask).i[LOW] }; 00092 if (rt_clone(signal_suprt_fun, &arg, SIGNAL_TASK_STACK_SIZE, 0) > 0) { 00093 return rtai_lxrt(RTAI_SIGNALS_IDX, sizeof(RT_TASK *), SIGNAL_HELPER, &arg.task).i[LOW]; 00094 } 00095 } 00096 return -EINVAL; 00097 } 00098 00099 static inline int rt_release_signal(long signal, RT_TASK *task) 00100 { 00101 struct { long signal; RT_TASK *task; } arg = { signal, task }; 00102 return rtai_lxrt(RTAI_SIGNALS_IDX, SIZARG, SIGNAL_RELEASE, &arg).i[LOW]; 00103 } 00104 00105 static inline void rt_enable_signal(long signal, RT_TASK *task) 00106 { 00107 struct { long signal; RT_TASK *task; } arg = { signal, task }; 00108 rtai_lxrt(RTAI_SIGNALS_IDX, SIZARG, SIGNAL_ENABLE, &arg); 00109 } 00110 00111 static inline void rt_disable_signal(long signal, RT_TASK *task) 00112 { 00113 struct { long signal; RT_TASK *task; } arg = { signal, task }; 00114 rtai_lxrt(RTAI_SIGNALS_IDX, SIZARG, SIGNAL_DISABLE, &arg); 00115 } 00116 00117 static inline void rt_trigger_signal(long signal, RT_TASK *task) 00118 { 00119 struct { long signal; RT_TASK *task; } arg = { signal, task }; 00120 rtai_lxrt(RTAI_SIGNALS_IDX, SIZARG, SIGNAL_TRIGGER, &arg); 00121 } 00122 00123 #endif /* __KERNEL__ */ 00124 00125 #endif /* !_RTAI_SIGNAL_H_ */

Generated on Thu Nov 20 11:49:50 2008 for RTAI API by doxygen 1.3.8