Xenomai API
2.5.6.1
|
00001 00023 #ifndef __ANALOGY_OS_FACILITIES__ 00024 #define __ANALOGY_OS_FACILITIES__ 00025 00026 #if defined(__KERNEL__) && !defined(DOXYGEN_CPP) 00027 00028 #include <linux/fs.h> 00029 #include <linux/spinlock.h> 00030 #include <linux/sched.h> 00031 #include <linux/time.h> 00032 #include <linux/delay.h> 00033 #include <linux/interrupt.h> 00034 #include <asm/uaccess.h> 00035 00036 #if !(defined(CONFIG_XENO_SKIN_RTDM) || \ 00037 defined(CONFIG_XENO_SKIN_RTDM_MODULE)) 00038 #error Analogy needs RTDM enabled \ 00039 (statically or as amodule) to compile properly 00040 #endif /* !(CONFIG_XENO_SKIN_RTDM || 00041 CONFIG_XENO_SKIN_RTDM_MODULE */ 00042 00043 #include <rtdm/rtdm_driver.h> 00044 00045 /* --- Kernel traces functions --- */ 00046 00047 #define A4L_PROMPT "Analogy: " 00048 00049 #define RTDM_SUBCLASS_ANALOGY 0 00050 00051 #define __a4l_err(fmt, args...) \ 00052 rtdm_printk(KERN_ERR A4L_PROMPT fmt, ##args) 00053 00054 #define __a4l_warn(fmt, args...) \ 00055 rtdm_printk(KERN_WARNING A4L_PROMPT fmt, ##args) 00056 00057 #define __a4l_info(fmt, args...) \ 00058 rtdm_printk(KERN_INFO A4L_PROMPT fmt, ##args) 00059 00060 #ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG 00061 00062 #define __a4l_dbg(level, debug, fmt, args...) \ 00063 do { \ 00064 if ((debug) >= (level)) \ 00065 rtdm_printk(KERN_DEBUG A4L_PROMPT fmt, ##args); \ 00066 } while (0) 00067 00068 #define core_dbg CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_LEVEL 00069 #define drv_dbg CONFIG_XENO_DRIVERS_ANALOGY_DRIVER_DEBUG_LEVEL 00070 00071 #else /* !CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */ 00072 00073 #define __a4l_dbg(level, debug, fmt, args...) 00074 00075 #endif /* CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */ 00076 00077 #define __a4l_dev_name(dev) \ 00078 (dev->driver == NULL) ? "unattached dev" : dev->driver->board_name 00079 00080 #define a4l_err(dev, fmt, args...) \ 00081 __a4l_err("%s: " fmt, __a4l_dev_name(dev), ##args) 00082 00083 #define a4l_warn(dev, fmt, args...) \ 00084 __a4l_warn("%s: " fmt, __a4l_dev_name(dev), ##args) 00085 00086 #define a4l_info(dev, fmt, args...) \ 00087 __a4l_info("%s: " fmt, __a4l_dev_name(dev), ##args) 00088 00089 #define a4l_dbg(level, debug, dev, fmt, args...) \ 00090 __a4l_dbg(level, debug, "%s: " fmt, __a4l_dev_name(dev), ##args) 00091 00092 /* --- Spinlock section --- */ 00093 00094 typedef rtdm_lock_t a4l_lock_t; 00095 00096 #define A4L_LOCK_UNLOCKED RTDM_LOCK_UNLOCKED 00097 00098 #define a4l_lock_init(lock) rtdm_lock_init(lock) 00099 #define a4l_lock(lock) rtdm_lock_get(lock) 00100 #define a4l_unlock(lock) rtdm_lock_put(lock) 00101 #define a4l_lock_irqsave(lock, context) \ 00102 rtdm_lock_get_irqsave(lock, context) 00103 #define a4l_unlock_irqrestore(lock, context) \ 00104 rtdm_lock_put_irqrestore(lock, context) 00105 00106 /* --- Task section --- */ 00107 00108 #define A4L_TASK_LOWEST_PRIORITY RTDM_TASK_LOWEST_PRIORITY 00109 #define A4L_TASK_HIGHEST_PRIORITY RTDM_TASK_HIGHEST_PRIORITY 00110 00111 typedef rtdm_task_t a4l_task_t; 00112 typedef rtdm_task_proc_t a4l_task_proc_t; 00113 00114 #define a4l_task_init(tsk, name, proc, arg, priority) \ 00115 rtdm_task_init(tsk, name, proc, arg, priority, 0) 00116 00117 #define a4l_task_destroy(tsk) rtdm_task_destroy(tsk) 00118 00119 #define a4l_task_sleep(delay) rtdm_task_sleep(delay) 00120 00121 /* --- Time section --- */ 00122 00123 static inline void a4l_udelay(unsigned int us) 00124 { 00125 rtdm_task_busy_sleep(((nanosecs_rel_t) us) * 1000); 00126 } 00127 00128 static inline nanosecs_abs_t a4l_get_rawtime(void) 00129 { 00130 return rtdm_clock_read(); 00131 } 00132 00133 /* Function which gives absolute time */ 00134 nanosecs_abs_t a4l_get_time(void); 00135 00136 /* Function for setting up the absolute time recovery */ 00137 void a4l_init_time(void); 00138 00139 /* --- IRQ section --- */ 00140 00141 #define A4L_IRQ_SHARED RTDM_IRQTYPE_SHARED 00142 #define A4L_IRQ_EDGE RTDM_IRQTYPE_EDGE 00143 #define A4L_IRQ_DISABLED 0 00144 00145 typedef int (*a4l_irq_hdlr_t) (unsigned int irq, void *d); 00146 00147 struct a4l_irq_descriptor { 00148 /* These fields are useful to launch the IRQ trampoline; 00149 that is the reason why a structure has been defined */ 00150 a4l_irq_hdlr_t handler; 00151 unsigned int irq; 00152 void *cookie; 00153 rtdm_irq_t rtdm_desc; 00154 }; 00155 typedef struct a4l_irq_descriptor a4l_irq_desc_t; 00156 00157 int __a4l_request_irq(a4l_irq_desc_t * dsc, 00158 unsigned int irq, 00159 a4l_irq_hdlr_t handler, 00160 unsigned long flags, void *cookie); 00161 int __a4l_free_irq(a4l_irq_desc_t * dsc); 00162 00163 /* --- Synchronization section --- */ 00164 00165 #define __NRT_WAITER 1 00166 #define __RT_WAITER 2 00167 #define __EVT_PDING 3 00168 00169 struct a4l_sync { 00170 unsigned long status; 00171 rtdm_event_t rtdm_evt; 00172 rtdm_nrtsig_t nrt_sig; 00173 wait_queue_head_t wq; 00174 }; 00175 typedef struct a4l_sync a4l_sync_t; 00176 00177 #define a4l_select_sync(snc, slr, type, fd) \ 00178 rtdm_event_select_bind(&((snc)->rtdm_evt), slr, type, fd) 00179 00180 int a4l_init_sync(a4l_sync_t * snc); 00181 void a4l_cleanup_sync(a4l_sync_t * snc); 00182 void a4l_flush_sync(a4l_sync_t * snc); 00183 int a4l_wait_sync(a4l_sync_t * snc, int rt); 00184 int a4l_timedwait_sync(a4l_sync_t * snc, 00185 int rt, unsigned long long ns_timeout); 00186 void a4l_signal_sync(a4l_sync_t * snc); 00187 00188 /* --- Misc section --- */ 00189 00190 #define a4l_test_rt() rtdm_in_rt_context() 00191 00192 #endif /* __KERNEL__ && !DOXYGEN_CPP */ 00193 00194 #endif /* __ANALOGY_OS_FACILITIES__ */