Xenomai API  2.6.5
os_facilities.h
Go to the documentation of this file.
1 
23 #ifndef __ANALOGY_OS_FACILITIES__
24 #define __ANALOGY_OS_FACILITIES__
25 
26 #if defined(__KERNEL__) && !defined(DOXYGEN_CPP)
27 
28 #include <linux/fs.h>
29 #include <linux/spinlock.h>
30 #include <linux/sched.h>
31 #include <linux/time.h>
32 #include <linux/delay.h>
33 #include <linux/interrupt.h>
34 #include <asm/uaccess.h>
35 
36 #if !(defined(CONFIG_XENO_SKIN_RTDM) || \
37  defined(CONFIG_XENO_SKIN_RTDM_MODULE))
38 #error Analogy needs RTDM enabled \
39  (statically or as amodule) to compile properly
40 #endif /* !(CONFIG_XENO_SKIN_RTDM ||
41  CONFIG_XENO_SKIN_RTDM_MODULE */
42 
43 #include <rtdm/rtdm_driver.h>
44 
45 /* --- Kernel traces functions --- */
46 
47 #define A4L_PROMPT "Analogy: "
48 
49 #define RTDM_SUBCLASS_ANALOGY 0
50 
51 #define __a4l_err(fmt, args...) \
52  rtdm_printk(KERN_ERR A4L_PROMPT fmt, ##args)
53 
54 #define __a4l_warn(fmt, args...) \
55  rtdm_printk(KERN_WARNING A4L_PROMPT fmt, ##args)
56 
57 #define __a4l_info(fmt, args...) \
58  rtdm_printk(KERN_INFO A4L_PROMPT fmt, ##args)
59 
60 #ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG
61 
62 #define __a4l_dbg(level, debug, fmt, args...) \
63  do { \
64  if ((debug) >= (level)) \
65  rtdm_printk(KERN_DEBUG A4L_PROMPT fmt, ##args); \
66  } while (0)
67 
68 #define core_dbg CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_LEVEL
69 #define drv_dbg CONFIG_XENO_DRIVERS_ANALOGY_DRIVER_DEBUG_LEVEL
70 
71 #else /* !CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */
72 
73 #define __a4l_dbg(level, debug, fmt, args...)
74 
75 #endif /* CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */
76 
77 #define __a4l_dev_name(dev) \
78  (dev->driver == NULL) ? "unattached dev" : dev->driver->board_name
79 
80 #define a4l_err(dev, fmt, args...) \
81  __a4l_err("%s: " fmt, __a4l_dev_name(dev), ##args)
82 
83 #define a4l_warn(dev, fmt, args...) \
84  __a4l_warn("%s: " fmt, __a4l_dev_name(dev), ##args)
85 
86 #define a4l_info(dev, fmt, args...) \
87  __a4l_info("%s: " fmt, __a4l_dev_name(dev), ##args)
88 
89 #define a4l_dbg(level, debug, dev, fmt, args...) \
90  __a4l_dbg(level, debug, "%s: " fmt, __a4l_dev_name(dev), ##args)
91 
92 /* --- Spinlock section --- */
93 
94 typedef rtdm_lock_t a4l_lock_t;
95 
96 #define A4L_LOCK_UNLOCKED RTDM_LOCK_UNLOCKED
97 
98 #define a4l_lock_init(lock) rtdm_lock_init(lock)
99 #define a4l_lock(lock) rtdm_lock_get(lock)
100 #define a4l_unlock(lock) rtdm_lock_put(lock)
101 #define a4l_lock_irqsave(lock, context) \
102  rtdm_lock_get_irqsave(lock, context)
103 #define a4l_unlock_irqrestore(lock, context) \
104  rtdm_lock_put_irqrestore(lock, context)
105 
106 /* --- Task section --- */
107 
108 #define A4L_TASK_LOWEST_PRIORITY RTDM_TASK_LOWEST_PRIORITY
109 #define A4L_TASK_HIGHEST_PRIORITY RTDM_TASK_HIGHEST_PRIORITY
110 
111 typedef rtdm_task_t a4l_task_t;
112 typedef rtdm_task_proc_t a4l_task_proc_t;
113 
114 #define a4l_task_init(tsk, name, proc, arg, priority) \
115  rtdm_task_init(tsk, name, proc, arg, priority, 0)
116 
117 #define a4l_task_destroy(tsk) rtdm_task_destroy(tsk)
118 
119 #define a4l_task_sleep(delay) rtdm_task_sleep(delay)
120 
121 /* --- Time section --- */
122 
123 static inline void a4l_udelay(unsigned int us)
124 {
125  rtdm_task_busy_sleep(((nanosecs_rel_t) us) * 1000);
126 }
127 
128 static inline nanosecs_abs_t a4l_get_rawtime(void)
129 {
130  return rtdm_clock_read();
131 }
132 
133 /* Function which gives absolute time */
135 
136 /* Function for setting up the absolute time recovery */
137 void a4l_init_time(void);
138 
139 /* --- IRQ section --- */
140 
141 #define A4L_IRQ_SHARED RTDM_IRQTYPE_SHARED
142 #define A4L_IRQ_EDGE RTDM_IRQTYPE_EDGE
143 #define A4L_IRQ_DISABLED 0
144 
145 typedef int (*a4l_irq_hdlr_t) (unsigned int irq, void *d);
146 
147 struct a4l_irq_descriptor {
148  /* These fields are useful to launch the IRQ trampoline;
149  that is the reason why a structure has been defined */
150  a4l_irq_hdlr_t handler;
151  unsigned int irq;
152  void *cookie;
153  rtdm_irq_t rtdm_desc;
154 };
155 typedef struct a4l_irq_descriptor a4l_irq_desc_t;
156 
157 int __a4l_request_irq(a4l_irq_desc_t * dsc,
158  unsigned int irq,
159  a4l_irq_hdlr_t handler,
160  unsigned long flags, void *cookie);
161 int __a4l_free_irq(a4l_irq_desc_t * dsc);
162 
163 /* --- Synchronization section --- */
164 
165 #define __NRT_WAITER 1
166 #define __RT_WAITER 2
167 #define __EVT_PDING 3
168 
169 struct a4l_sync {
170  unsigned long status;
171  rtdm_event_t rtdm_evt;
172  rtdm_nrtsig_t nrt_sig;
173  wait_queue_head_t wq;
174 };
175 typedef struct a4l_sync a4l_sync_t;
176 
177 #define a4l_select_sync(snc, slr, type, fd) \
178  rtdm_event_select_bind(&((snc)->rtdm_evt), slr, type, fd)
179 
180 int a4l_init_sync(a4l_sync_t * snc);
181 void a4l_cleanup_sync(a4l_sync_t * snc);
182 void a4l_flush_sync(a4l_sync_t * snc);
183 int a4l_wait_sync(a4l_sync_t * snc, int rt);
184 int a4l_timedwait_sync(a4l_sync_t * snc,
185  int rt, unsigned long long ns_timeout);
186 void a4l_signal_sync(a4l_sync_t * snc);
187 
188 /* --- Misc section --- */
189 
190 #define a4l_test_rt() rtdm_in_rt_context()
191 
192 #endif /* __KERNEL__ && !DOXYGEN_CPP */
193 
194 #endif /* __ANALOGY_OS_FACILITIES__ */
int64_t nanosecs_rel_t
RTDM type for representing relative intervals.
Definition: rtdm.h:95
rthal_spinlock_t rtdm_lock_t
Lock variable.
Definition: rtdm_driver.h:690
uint64_t nanosecs_abs_t
RTDM type for representing absolute dates.
Definition: rtdm.h:89
void rtdm_task_busy_sleep(nanosecs_rel_t delay)
Busy-wait a specified amount of time.
Definition: drvlib.c:471
nanosecs_abs_t rtdm_clock_read(void)
Get system time.
void(* rtdm_task_proc_t)(void *arg)
Real-time task procedure.
Definition: rtdm_driver.h:1061
Real-Time Driver Model for Xenomai, driver API header.
unsigned long long a4l_get_time(void)
Get the absolute time in nanoseconds.