Xenomai  3.1
rtdm_helpers.h
1 /*
2  * Analogy for Linux, Operation system facilities
3  *
4  * Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org>
5  * Copyright (C) 2008 Alexis Berlemont <alexis.berlemont@free.fr>
6  *
7  * Xenomai is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * Xenomai is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with Xenomai; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 #ifndef _COBALT_RTDM_ANALOGY_RTDM_HELPERS_H
22 #define _COBALT_RTDM_ANALOGY_RTDM_HELPERS_H
23 
24 #include <linux/fs.h>
25 #include <linux/spinlock.h>
26 #include <linux/sched.h>
27 #include <linux/time.h>
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
30 #include <linux/uaccess.h>
31 #include <rtdm/driver.h>
32 
33 /* --- Trace section --- */
34 #define A4L_PROMPT "Analogy: "
35 
36 #define RTDM_SUBCLASS_ANALOGY 0
37 
38 #define __a4l_err(fmt, args...) rtdm_printk(KERN_ERR A4L_PROMPT fmt, ##args)
39 #define __a4l_warn(fmt, args...) rtdm_printk(KERN_WARNING A4L_PROMPT fmt, ##args)
40 
41 #ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_FTRACE
42 #define __a4l_info(fmt, args...) trace_printk(fmt, ##args)
43 #else
44 #define __a4l_info(fmt, args...) \
45  rtdm_printk(KERN_INFO A4L_PROMPT "%s: " fmt, __FUNCTION__, ##args)
46 #endif
47 
48 #ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG
49 #ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_FTRACE
50 #define __a4l_dbg(level, debug, fmt, args...) \
51  do { \
52  if ((debug) >= (level)) \
53  trace_printk(fmt, ##args); \
54  } while (0)
55 #else
56 #define __a4l_dbg(level, debug, fmt, args...) \
57  do { \
58  if ((debug) >= (level)) \
59  rtdm_printk(KERN_DEBUG A4L_PROMPT "%s: " fmt, __FUNCTION__ , ##args); \
60  } while (0)
61 #endif
62 
63 #define core_dbg CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_LEVEL
64 #define drv_dbg CONFIG_XENO_DRIVERS_ANALOGY_DRIVER_DEBUG_LEVEL
65 
66 #else /* !CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */
67 
68 #define __a4l_dbg(level, debug, fmt, args...)
69 
70 #endif /* CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */
71 
72 #define __a4l_dev_name(dev) \
73  (dev->driver == NULL) ? "unattached dev" : dev->driver->board_name
74 
75 #define a4l_err(dev, fmt, args...) \
76  __a4l_err("%s: " fmt, __a4l_dev_name(dev), ##args)
77 
78 #define a4l_warn(dev, fmt, args...) \
79  __a4l_warn("%s: " fmt, __a4l_dev_name(dev), ##args)
80 
81 #define a4l_info(dev, fmt, args...) \
82  __a4l_info("%s: " fmt, __a4l_dev_name(dev), ##args)
83 
84 #define a4l_dbg(level, debug, dev, fmt, args...) \
85  __a4l_dbg(level, debug, "%s: " fmt, __a4l_dev_name(dev), ##args)
86 
87 
88 /* --- Time section --- */
89 static inline void a4l_udelay(unsigned int us)
90 {
91  rtdm_task_busy_sleep(((nanosecs_rel_t) us) * 1000);
92 }
93 
94 /* Function which gives absolute time */
96 
97 /* Function for setting up the absolute time recovery */
98 void a4l_init_time(void);
99 
100 /* --- IRQ section --- */
101 #define A4L_IRQ_DISABLED 0
102 
103 typedef int (*a4l_irq_hdlr_t) (unsigned int irq, void *d);
104 
105 struct a4l_irq_descriptor {
106  /* These fields are useful to launch the IRQ trampoline;
107  that is the reason why a structure has been defined */
108  a4l_irq_hdlr_t handler;
109  unsigned int irq;
110  void *cookie;
111  rtdm_irq_t rtdm_desc;
112 };
113 
114 int __a4l_request_irq(struct a4l_irq_descriptor * dsc,
115  unsigned int irq,
116  a4l_irq_hdlr_t handler,
117  unsigned long flags, void *cookie);
118 int __a4l_free_irq(struct a4l_irq_descriptor * dsc);
119 
120 /* --- Synchronization section --- */
121 #define __NRT_WAITER 1
122 #define __RT_WAITER 2
123 #define __EVT_PDING 3
124 
125 struct a4l_sync {
126  unsigned long status;
127  rtdm_event_t rtdm_evt;
128  rtdm_nrtsig_t nrt_sig;
129  wait_queue_head_t wq;
130 };
131 
132 #define a4l_select_sync(snc, slr, type, fd) \
133  rtdm_event_select(&((snc)->rtdm_evt), slr, type, fd)
134 
135 int a4l_init_sync(struct a4l_sync * snc);
136 void a4l_cleanup_sync(struct a4l_sync * snc);
137 void a4l_flush_sync(struct a4l_sync * snc);
138 int a4l_wait_sync(struct a4l_sync * snc, int rt);
139 int a4l_timedwait_sync(struct a4l_sync * snc,
140  int rt, unsigned long long ns_timeout);
141 void a4l_signal_sync(struct a4l_sync * snc);
142 
143 #endif /* !_COBALT_RTDM_ANALOGY_RTDM_HELPERS_H */
void rtdm_task_busy_sleep(nanosecs_rel_t delay)
Busy-wait a specified amount of time
Definition: drvlib.c:502
int64_t nanosecs_rel_t
RTDM type for representing relative intervals.
Definition: rtdm.h:49
Real-Time Driver Model for Xenomai, driver API header.
unsigned long long a4l_get_time(void)
Get the absolute time in nanoseconds.
Definition: rtdm_helpers.c:40
uint64_t nanosecs_abs_t
RTDM type for representing absolute dates.
Definition: rtdm.h:43