Module: xenomai-forge
Branch: next
Commit: a9a5cf6c1bbfa4f16d636c89f9827842db427e4e
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a9a5cf6c1bbfa4f16d636c89f9827842db427e4e

Author: Jorge Ramirez-Ortiz <j...@xenomai.org>
Date:   Tue Jun 24 16:42:59 2014 -0400

drivers/analogy: add ftrace support to a4l_dbg and a4l_info

Enable ftrace support in the analogy debug config

---

 include/cobalt/kernel/rtdm/analogy/buffer.h        |   14 ++--
 include/cobalt/kernel/rtdm/analogy/rtdm_helpers.h  |   40 +++++++-----
 kernel/drivers/analogy/Kconfig                     |   10 ++-
 kernel/drivers/analogy/buffer.c                    |   40 ++++++++----
 kernel/drivers/analogy/command.c                   |    8 +--
 kernel/drivers/analogy/device.c                    |    5 +-
 kernel/drivers/analogy/driver.c                    |    6 +-
 kernel/drivers/analogy/intel/parport.c             |    6 +-
 .../analogy/national_instruments/mio_common.c      |   48 +++++---------
 kernel/drivers/analogy/national_instruments/mite.c |   29 +++-----
 .../drivers/analogy/national_instruments/ni_660x.c |   21 +++---
 .../drivers/analogy/national_instruments/ni_670x.c |   18 ++---
 .../drivers/analogy/national_instruments/pcimio.c  |    4 +-
 kernel/drivers/analogy/rtdm_interface.c            |    8 ++-
 kernel/drivers/analogy/sensoray/s526.c             |    2 +-
 kernel/drivers/analogy/testing/fake.c              |   21 +++---
 kernel/drivers/analogy/transfer.c                  |    7 +-
 utils/analogy/cmd_read.c                           |   69 +++++++++-----------
 utils/analogy/cmd_write.c                          |    9 +--
 19 files changed, 175 insertions(+), 190 deletions(-)

diff --git a/include/cobalt/kernel/rtdm/analogy/buffer.h 
b/include/cobalt/kernel/rtdm/analogy/buffer.h
index 3003a4f..d4baefe 100644
--- a/include/cobalt/kernel/rtdm/analogy/buffer.h
+++ b/include/cobalt/kernel/rtdm/analogy/buffer.h
@@ -50,6 +50,7 @@
 #define A4L_BUF_MAP_NR 9
 #define A4L_BUF_MAP (1 << A4L_BUF_MAP_NR)
 
+
 /* Buffer descriptor structure */
 struct a4l_buffer {
 
@@ -87,6 +88,13 @@ struct a4l_buffer {
        unsigned long wake_count;
 };
 
+static inline void __dump_buffer_counters(struct a4l_buffer *buf)
+{
+       __a4l_dbg(1, core_dbg, "a4l_buffer=0x%p, p=0x%p \n", buf, buf->buf);
+       __a4l_dbg(1, core_dbg, "end=%06ld, prd=%06ld, cns=%06ld, tmp=%06ld \n",
+               buf->end_count, buf->prd_count, buf->cns_count, buf->tmp_count);
+}
+
 /* --- Static inline functions related with
    user<->kernel data transfers --- */
 
@@ -191,13 +199,11 @@ static inline int __handle_event(struct a4l_buffer * buf)
 
        /* The event "End of acquisition" must not be cleaned
           before the complete flush of the buffer */
-       if (test_bit(A4L_BUF_EOA_NR, &buf->flags)) {
+       if (test_bit(A4L_BUF_EOA_NR, &buf->flags))
                ret = -ENOENT;
-       }
 
-       if (test_bit(A4L_BUF_ERROR_NR, &buf->flags)) {
+       if (test_bit(A4L_BUF_ERROR_NR, &buf->flags))
                ret = -EPIPE;
-       }
 
        return ret;
 }
diff --git a/include/cobalt/kernel/rtdm/analogy/rtdm_helpers.h 
b/include/cobalt/kernel/rtdm/analogy/rtdm_helpers.h
index 2dffc89..8a0798c 100644
--- a/include/cobalt/kernel/rtdm/analogy/rtdm_helpers.h
+++ b/include/cobalt/kernel/rtdm/analogy/rtdm_helpers.h
@@ -36,22 +36,30 @@
 
 #define RTDM_SUBCLASS_ANALOGY 0
 
-#define __a4l_err(fmt, args...) \
-       rtdm_printk(KERN_ERR A4L_PROMPT fmt, ##args)
+#define __a4l_err(fmt, args...)  rtdm_printk(KERN_ERR A4L_PROMPT fmt, ##args)
+#define __a4l_warn(fmt, args...) rtdm_printk(KERN_WARNING A4L_PROMPT fmt, 
##args)
 
-#define __a4l_warn(fmt, args...) \
-       rtdm_printk(KERN_WARNING A4L_PROMPT fmt, ##args)
-
-#define __a4l_info(fmt, args...) \
-       rtdm_printk(KERN_INFO A4L_PROMPT fmt, ##args)
+#ifdef  CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_FTRACE
+#define __a4l_info(fmt, args...) trace_printk(fmt, ##args)
+#else
+#define __a4l_info(fmt, args...)                                               
\
+        rtdm_printk(KERN_INFO A4L_PROMPT "%s: " fmt, __FUNCTION__, ##args)
+#endif
 
 #ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG
-
-#define __a4l_dbg(level, debug, fmt, args...)                  \
-       do {                                                    \
-       if ((debug) >= (level))                                 \
-               rtdm_printk(KERN_DEBUG A4L_PROMPT fmt, ##args); \
+#ifdef CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_FTRACE
+#define __a4l_dbg(level, debug, fmt, args...)                          \
+       do {                                                            \
+       if ((debug) >= (level))                                         \
+               trace_printk(fmt, ##args);                              \
+       } while (0)
+#else
+#define __a4l_dbg(level, debug, fmt, args...)                                  
        \
+       do {                                                                    
        \
+       if ((debug) >= (level))                                                 
        \
+               rtdm_printk(KERN_DEBUG A4L_PROMPT "%s: " fmt, __FUNCTION__ , 
##args);   \
        } while (0)
+#endif
 
 #define core_dbg CONFIG_XENO_DRIVERS_ANALOGY_DEBUG_LEVEL
 #define drv_dbg CONFIG_XENO_DRIVERS_ANALOGY_DRIVER_DEBUG_LEVEL
@@ -62,16 +70,16 @@
 
 #endif /* CONFIG_XENO_DRIVERS_ANALOGY_DEBUG */
 
-#define __a4l_dev_name(dev) \
+#define __a4l_dev_name(dev)                                            \
        (dev->driver == NULL) ? "unattached dev" : dev->driver->board_name
 
-#define a4l_err(dev, fmt, args...) \
+#define a4l_err(dev, fmt, args...)                                     \
        __a4l_err("%s: " fmt, __a4l_dev_name(dev), ##args)
 
-#define a4l_warn(dev, fmt, args...) \
+#define a4l_warn(dev, fmt, args...)                                    \
        __a4l_warn("%s: " fmt, __a4l_dev_name(dev), ##args)
 
-#define a4l_info(dev, fmt, args...) \
+#define a4l_info(dev, fmt, args...)                                    \
        __a4l_info("%s: " fmt, __a4l_dev_name(dev), ##args)
 
 #define a4l_dbg(level, debug, dev, fmt, args...)                       \
diff --git a/kernel/drivers/analogy/Kconfig b/kernel/drivers/analogy/Kconfig
index 8e58371..e8fa953 100644
--- a/kernel/drivers/analogy/Kconfig
+++ b/kernel/drivers/analogy/Kconfig
@@ -10,12 +10,20 @@ config XENO_DRIVERS_ANALOGY
 config XENO_DRIVERS_ANALOGY_DEBUG
        depends on XENO_DRIVERS_ANALOGY
        bool "Analogy debug trace"
-       default y
+       default n
        help
 
        Enable debugging traces in Analogy so as to monitor Analogy's
        core and drivers behaviours.
 
+config XENO_DRIVERS_ANALOGY_DEBUG_FTRACE
+       depends on XENO_DRIVERS_ANALOGY_DEBUG
+       bool "Analogy debug ftrace"
+       default n
+       help
+
+       Route the Analogy a4l_dbg and a4l_info statements to /sys/kernel/debug/
+
 config XENO_DRIVERS_ANALOGY_DEBUG_LEVEL
        depends on XENO_DRIVERS_ANALOGY_DEBUG
        int "Analogy core debug level threshold"
diff --git a/kernel/drivers/analogy/buffer.c b/kernel/drivers/analogy/buffer.c
index a338f26..6589565 100644
--- a/kernel/drivers/analogy/buffer.c
+++ b/kernel/drivers/analogy/buffer.c
@@ -34,6 +34,8 @@
 
 void a4l_free_buffer(struct a4l_buffer * buf_desc)
 {
+       __a4l_dbg(1, core_dbg, "buf=%p buf->buf=%p\n", buf_desc, buf_desc->buf);
+
        if (buf_desc->pg_list != NULL) {
                rtdm_free(buf_desc->pg_list);
                buf_desc->pg_list = NULL;
@@ -81,6 +83,8 @@ int a4l_alloc_buffer(struct a4l_buffer *buf_desc, int 
buf_size)
                buf_desc->pg_list[(vaddr - vabase) >> PAGE_SHIFT] =
                        (unsigned long) page_to_phys(vmalloc_to_page(vaddr));
 
+       __a4l_dbg(1, core_dbg, "buf=%p buf->buf=%p\n", buf_desc, buf_desc->buf);
+
 out_virt_contig_alloc:
        if (ret != 0)
                a4l_free_buffer(buf_desc);
@@ -160,8 +164,7 @@ int a4l_setup_buffer(struct a4l_device_context *cxt, struct 
a4l_cmd_desc *cmd)
                buf_desc->end_count *= cmd->stop_arg;
        }
 
-       __a4l_dbg(1, core_dbg,
-                 "a4l_setup_buffer: end_count=%lu\n", buf_desc->end_count);
+       __a4l_dbg(1, core_dbg, "end_count=%lu\n", buf_desc->end_count);
 
        return 0;
 }
@@ -709,8 +712,7 @@ int a4l_ioctl_bufinfo(struct a4l_device_context * cxt, void 
*arg)
                /* Retrieves the data amount to read */
                tmp_cnt = info.rw_count = __count_to_get(buf);
 
-               __a4l_dbg(1, core_dbg,
-                         "a4l_ioctl_bufinfo: count to read=%lu\n", tmp_cnt);
+               __a4l_dbg(1, core_dbg, "count to read=%lu\n", tmp_cnt);
 
                if ((ret < 0 && ret != -ENOENT) ||
                    (ret == -ENOENT && tmp_cnt == 0)) {
@@ -740,9 +742,7 @@ int a4l_ioctl_bufinfo(struct a4l_device_context * cxt, void 
*arg)
                /* Retrieves the data amount which is writable */
                info.rw_count = __count_to_put(buf);
 
-               __a4l_dbg(1, core_dbg,
-                         "a4l_ioctl_bufinfo: count to write=%lu\n",
-                         info.rw_count);
+               __a4l_dbg(1, core_dbg, " count to write=%lu\n", info.rw_count);
 
        } else {
                __a4l_err("a4l_ioctl_bufinfo: inappropriate subdevice\n");
@@ -828,11 +828,15 @@ ssize_t a4l_read_buffer(struct a4l_device_context * cxt, 
void *bufdata, size_t n
 
        while (count < nbytes) {
 
+               unsigned long tmp_cnt;
+
                /* Check the events */
                int ret = __handle_event(buf);
 
+               __dump_buffer_counters(buf);
+
                /* Compute the data amount to copy */
-               unsigned long tmp_cnt = __count_to_get(buf);
+               tmp_cnt = __count_to_get(buf);
 
                /* Check tmp_cnt count is not higher than
                   the global count to read */
@@ -841,6 +845,7 @@ ssize_t a4l_read_buffer(struct a4l_device_context * cxt, 
void *bufdata, size_t n
 
                /* We check whether there is an error */
                if (ret < 0 && ret != -ENOENT) {
+                       __a4l_err("a4l_read: failed to handle event %d \n", 
ret);
                        a4l_cancel_buffer(cxt);
                        count = ret;
                        goto out_a4l_read;
@@ -848,6 +853,8 @@ ssize_t a4l_read_buffer(struct a4l_device_context * cxt, 
void *bufdata, size_t n
 
                /* We check whether the acquisition is over */
                if (ret == -ENOENT && tmp_cnt == 0) {
+                       __a4l_info("a4l_read: acquisition done - all data "
+                                  "requested by the client was delivered \n");
                        a4l_cancel_buffer(cxt);
                        count = 0;
                        goto out_a4l_read;
@@ -873,6 +880,7 @@ ssize_t a4l_read_buffer(struct a4l_device_context * cxt, 
void *bufdata, size_t n
 
                        /* Updates consume count */
                        buf->cns_count += tmp_cnt;
+                       a4l_dbg(1, core_dbg, dev, "buf->cns_cnt=%ld \n", 
buf->cns_count);
 
                        /* Updates the return value */
                        count += tmp_cnt;
@@ -882,9 +890,9 @@ ssize_t a4l_read_buffer(struct a4l_device_context * cxt, 
void *bufdata, size_t n
                        if (!test_bit(A4L_BUF_BULK, &buf->flags))
                                goto out_a4l_read;
                }
-               /* If the acquisition is not over, we must not
-                  leave the function without having read a least byte */
                else {
+                       /* If the acquisition is not over, we must not
+                          leave the function without having read a least byte 
*/
                        ret = a4l_wait_sync(&(buf->sync), rtdm_in_rt_context());
                        if (ret < 0) {
                                if (ret == -ERESTARTSYS)
@@ -929,11 +937,15 @@ ssize_t a4l_write_buffer(struct a4l_device_context *cxt, 
const void *bufdata, si
 
        while (count < nbytes) {
 
+               unsigned long tmp_cnt;
+
                /* Check the events */
                int ret = __handle_event(buf);
 
+               __dump_buffer_counters(buf);
+
                /* Compute the data amount to copy */
-               unsigned long tmp_cnt = __count_to_put(buf);
+               tmp_cnt = __count_to_put(buf);
 
                /* Check tmp_cnt count is not higher than
                   the global count to write */
@@ -941,13 +953,15 @@ ssize_t a4l_write_buffer(struct a4l_device_context *cxt, 
const void *bufdata, si
                        tmp_cnt = nbytes - count;
 
                if (ret < 0) {
-                       a4l_cancel_buffer(cxt);
                        count = (ret == -ENOENT) ? -EINVAL : ret;
+                       __a4l_err("a4l_write: failed to handle event %d \n", 
ret);
+                       a4l_cancel_buffer(cxt);
                        goto out_a4l_write;
                }
 
                if (tmp_cnt > 0) {
 
+
                        /* Performs the copy */
                        ret = __produce(cxt,
                                        buf, (void *)bufdata + count, tmp_cnt);
@@ -966,6 +980,7 @@ ssize_t a4l_write_buffer(struct a4l_device_context *cxt, 
const void *bufdata, si
 
                        /* Updates produce count */
                        buf->prd_count += tmp_cnt;
+                       a4l_dbg(1, core_dbg, dev , "buf->prd_cnt=%ld \n", 
buf->prd_count);
 
                        /* Updates the return value */
                        count += tmp_cnt;
@@ -978,6 +993,7 @@ ssize_t a4l_write_buffer(struct a4l_device_context *cxt, 
const void *bufdata, si
                        /* The buffer is full, we have to wait for a slot to 
free */
                        ret = a4l_wait_sync(&(buf->sync), rtdm_in_rt_context());
                        if (ret < 0) {
+                               __a4l_err("a4l_write: failed to wait for free 
slot (%d)\n", ret);
                                if (ret == -ERESTARTSYS)
                                        ret = -EINTR;
                                count = ret;
diff --git a/kernel/drivers/analogy/command.c b/kernel/drivers/analogy/command.c
index b1f6cf9..1c544bf 100644
--- a/kernel/drivers/analogy/command.c
+++ b/kernel/drivers/analogy/command.c
@@ -57,7 +57,7 @@ int a4l_fill_cmddesc(struct a4l_device_context * cxt, struct 
a4l_cmd_desc * desc
 
        desc->chan_descs = tmpchans;
 
-       __a4l_dbg(1, core_dbg, "a4l_fill_cmddesc: desc dump\n");
+       __a4l_dbg(1, core_dbg, "desc dump\n");
        __a4l_dbg(1, core_dbg, "\t->idx_subd=%u\n", desc->idx_subd);
        __a4l_dbg(1, core_dbg, "\t->flags=%lu\n", desc->flags);
        __a4l_dbg(1, core_dbg, "\t->nb_chan=%u\n", desc->nb_chan);
@@ -327,8 +327,7 @@ int a4l_ioctl_cmd(struct a4l_device_context * cxt, void 
*arg)
        if (ret != 0)
                goto out_ioctl_cmd;
 
-       __a4l_dbg(1, core_dbg,
-                 "a4l_ioctl_cmd: 1st cmd checks passed\n");
+       __a4l_dbg(1, core_dbg,"1st cmd checks passed\n");
 
        subd = dev->transfer.subds[cmd_desc->idx_subd];
 
@@ -340,8 +339,7 @@ int a4l_ioctl_cmd(struct a4l_device_context * cxt, void 
*arg)
                goto out_ioctl_cmd;
        }
 
-       __a4l_dbg(1, core_dbg,
-                 "a4l_ioctl_cmd: driver's cmd checks passed\n");
+       __a4l_dbg(1, core_dbg, "driver's cmd checks passed\n");
 
        if (cmd_desc->flags & A4L_CMD_SIMUL) {
                simul_flag = 1;
diff --git a/kernel/drivers/analogy/device.c b/kernel/drivers/analogy/device.c
index f1e129c..4bccc83 100644
--- a/kernel/drivers/analogy/device.c
+++ b/kernel/drivers/analogy/device.c
@@ -269,9 +269,8 @@ int a4l_assign_driver(struct a4l_device_context * cxt,
        INIT_LIST_HEAD(&dev->subdvsq);
 
        if (drv->privdata_size == 0)
-               __a4l_dbg(1, core_dbg,
-                         "a4l_assign_driver: warning! "
-                         "the field priv will not be usable\n");
+               __a4l_dbg(1, core_dbg, " warning! "
+                                      "the field priv will not be usable\n");
        else {
                dev->priv = rtdm_malloc(drv->privdata_size);
                if (dev->priv == NULL) {
diff --git a/kernel/drivers/analogy/driver.c b/kernel/drivers/analogy/driver.c
index 473abe9..760869c 100644
--- a/kernel/drivers/analogy/driver.c
+++ b/kernel/drivers/analogy/driver.c
@@ -33,7 +33,7 @@ int a4l_lct_drv(char *pin, struct a4l_driver ** pio)
        struct list_head *this;
        int ret = -EINVAL;
 
-       __a4l_dbg(1, core_dbg, "a4l_lct_drv: name=%s\n", pin);
+       __a4l_dbg(1, core_dbg, "name=%s\n", pin);
 
        /* Goes through the linked list so as to find
           a driver instance with the same name */
@@ -58,7 +58,7 @@ int a4l_register_drv(struct a4l_driver * drv)
        if (!realtime_core_enabled())
                return 0;
 
-       __a4l_dbg(1, core_dbg, "a4l_add_drv: name=%s\n", drv->board_name);
+       __a4l_dbg(1, core_dbg, "name=%s\n", drv->board_name);
 
        if (a4l_lct_drv(drv->board_name, NULL) != 0) {
                list_add(&drv->list, &a4l_drvs);
@@ -72,7 +72,7 @@ int a4l_unregister_drv(struct a4l_driver * drv)
        if (!realtime_core_enabled())
                return 0;
 
-       __a4l_dbg(1, core_dbg, "a4l_rm_drv: name=%s\n", drv->board_name);
+       __a4l_dbg(1, core_dbg, "name=%s\n", drv->board_name);
 
        if (a4l_lct_drv(drv->board_name, NULL) == 0) {
                /* Here, we consider the argument is pointing
diff --git a/kernel/drivers/analogy/intel/parport.c 
b/kernel/drivers/analogy/intel/parport.c
index 539c011..9b97f93 100644
--- a/kernel/drivers/analogy/intel/parport.c
+++ b/kernel/drivers/analogy/intel/parport.c
@@ -238,7 +238,7 @@ static void parport_intr_cancel(struct a4l_subdevice *subd)
 {
        struct a4l_device *dev = subd->dev;
 
-       a4l_info(dev, "parport_intr_cancel: cancel in progress\n");
+       a4l_info(dev, "cancel in progress\n");
 
        devpriv->c_data &= ~0x10;
        outb(devpriv->c_data, devpriv->io_base + PARPORT_C);
@@ -369,7 +369,7 @@ static int dev_parport_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
                return -EIO;
        }
 
-       a4l_info(dev, "dev_parport_attach: address = 0x%lx\n", io_base);
+       a4l_info(dev, "address = 0x%lx\n", io_base);
 
        for (i = 0; i < 3; i++) {
 
@@ -387,7 +387,7 @@ static int dev_parport_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
 
                struct a4l_subdevice *subd;
 
-               a4l_info(dev, "dev_parport_attach: irq = %d\n", irq);
+               a4l_info(dev, "irq = %d\n", irq);
 
                err = a4l_request_irq(dev, irq, parport_interrupt, 0, dev);
                if (err < 0) {
diff --git a/kernel/drivers/analogy/national_instruments/mio_common.c 
b/kernel/drivers/analogy/national_instruments/mio_common.c
index e933ba2..f0f2abf 100644
--- a/kernel/drivers/analogy/national_instruments/mio_common.c
+++ b/kernel/drivers/analogy/national_instruments/mio_common.c
@@ -1263,12 +1263,9 @@ static int ni_ai_drain_dma(struct a4l_subdevice *subd)
                        a4l_udelay(5);
                }
                if (i == timeout) {
-                       a4l_info(dev,
-                                "ni_mio_common: "
-                                "wait for dma drain timed out\n");
+                       a4l_info(dev, "wait for dma drain timed out\n");
 
-                       a4l_info(dev,
-                                "a4l_mite_bytes_in_transit=%i, "
+                       a4l_info(dev, "a4l_mite_bytes_in_transit=%i, "
                                 "AI_Status1_Register=0x%x\n",
                                 
a4l_mite_bytes_in_transit(devpriv->ai_mite_chan),
                                 devpriv->stc_readw(dev, AI_Status_1_Register));
@@ -2197,7 +2194,7 @@ static int ni_ai_cmd(struct a4l_subdevice *subd, struct 
a4l_cmd_desc *cmd)
        unsigned int stop_count;
        int interrupt_a_enable = 0;
 
-       a4l_info(dev, "ni_ai_cmd: start\n");
+       a4l_info(dev, "start\n");
 
        if (a4l_get_irq(dev) == A4L_IRQ_UNUSED) {
                a4l_err(dev, "ni_ai_cmd: cannot run command without an irq");
@@ -2445,8 +2442,7 @@ static int ni_ai_cmd(struct a4l_subdevice *subd, struct 
a4l_cmd_desc *cmd)
                ni_set_bits(dev, Interrupt_A_Enable_Register,
                            interrupt_a_enable, 1);
 
-               a4l_info(dev,
-                        "ni_ai_cmd: Interrupt_A_Enable_Register = 0x%04x\n",
+               a4l_info(dev, "Interrupt_A_Enable_Register = 0x%04x\n",
                         devpriv->int_a_enable_reg);
        } else {
                /* interrupt on nothing */
@@ -2497,7 +2493,7 @@ static int ni_ai_cmd(struct a4l_subdevice *subd, struct 
a4l_cmd_desc *cmd)
                break;
        }
 
-       a4l_info(dev, "ni_ai_cmd: exit\n");
+       a4l_info(dev, "exit\n");
 
        return 0;
 }
@@ -3233,9 +3229,7 @@ int ni_dio_insn_config(struct a4l_subdevice *subd, struct 
a4l_kernel_instruction
        unsigned int *data = (unsigned int *)insn->data;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_dio_insn_config() chan=%d io=%d\n",
-                CR_CHAN(insn->chan_desc), data[0]);
+       a4l_info(dev, "chan=%d io=%d\n", CR_CHAN(insn->chan_desc), data[0]);
 #endif /* CONFIG_DEBUG_DIO */
 
        switch (data[0]) {
@@ -3268,9 +3262,7 @@ int ni_dio_insn_bits(struct a4l_subdevice *subd, struct 
a4l_kernel_instruction *
        uint8_t *data = (uint8_t *)insn->data;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_dio_insn_bits_8() mask=0x%x bits=0x%x\n",
-                data[0], data[1]);
+       a4l_info(dev, "mask=0x%x bits=0x%x\n", data[0], data[1]);
 #endif
 
        if (insn->data_size != 2 * sizeof(uint8_t))
@@ -3304,9 +3296,7 @@ int ni_m_series_dio_insn_config(struct a4l_subdevice 
*subd, struct a4l_kernel_in
        unsigned int *data = (unsigned int *)insn->data;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_m_series_dio_insn_config() chan=%d io=%d\n",
-                CR_CHAN(insn->chan_desc), data[0]);
+       a4l_info(dev, "chan=%d io=%d\n", CR_CHAN(insn->chan_desc), data[0]);
 #endif
        switch (data[0]) {
        case A4L_INSN_CONFIG_DIO_OUTPUT:
@@ -3336,9 +3326,7 @@ int ni_m_series_dio_insn_bits_8(struct a4l_subdevice 
*subd, struct a4l_kernel_in
        uint8_t *data = (uint8_t *)insn->data;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_m_series_dio_insn_bits() mask=0x%x bits=0x%x\n",
-                data[0], data[1]);
+       a4l_info(dev, "mask=0x%x bits=0x%x\n", data[0], data[1]);
 #endif
 
        if (insn->data_size != 2 * sizeof(uint8_t))
@@ -3361,9 +3349,7 @@ int ni_m_series_dio_insn_bits_32(struct a4l_subdevice 
*subd, struct a4l_kernel_i
        uint32_t *data = (uint32_t *)insn->data;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_m_series_dio_insn_bits() mask=0x%x bits=0x%x\n",
-                data[0], data[1]);
+       a4l_info(dev, "mask=0x%x bits=0x%x\n", data[0], data[1]);
 #endif
 
        if (insn->data_size != 2 * sizeof(uint32_t))
@@ -3563,8 +3549,7 @@ static int ni_serial_hw_readwrite8(struct a4l_device * 
dev,
        int err = 0, count = 20;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_serial_hw_readwrite8: outputting 0x%x\n", data_out);
+       a4l_info(dev, "outputting 0x%x\n", data_out);
 #endif
 
        devpriv->dio_output &= ~DIO_Serial_Data_Mask;
@@ -3604,9 +3589,7 @@ static int ni_serial_hw_readwrite8(struct a4l_device * 
dev,
        if (data_in != NULL) {
                *data_in = devpriv->stc_readw(dev, DIO_Serial_Input_Register);
 #ifdef CONFIG_DEBUG_DIO
-               a4l_info(dev,
-                        "ni_serial_hw_readwrite8: inputted 0x%x\n",
-                        *data_in);
+               a4l_info(dev, "inputted 0x%x\n", *data_in);
 #endif
        }
 
@@ -3622,8 +3605,7 @@ static int ni_serial_sw_readwrite8(struct a4l_device * 
dev,
        unsigned char mask, input = 0;
 
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev,
-                "ni_serial_sw_readwrite8: outputting 0x%x\n", data_out);
+       a4l_info(dev, "outputting 0x%x\n", data_out);
 #endif
 
        /* Wait for one bit before transfer */
@@ -3661,7 +3643,7 @@ static int ni_serial_sw_readwrite8(struct a4l_device * 
dev,
                }
        }
 #ifdef CONFIG_DEBUG_DIO
-       a4l_info(dev, "ni_serial_sw_readwrite8: inputted 0x%x\n", input);
+       a4l_info(dev, "inputted 0x%x\n", input);
 #endif
        if (data_in)
                *data_in = input;
@@ -3683,7 +3665,7 @@ int ni_serial_insn_config(struct a4l_subdevice *subd, 
struct a4l_kernel_instruct
        case A4L_INSN_CONFIG_SERIAL_CLOCK:
 
 #ifdef CONFIG_DEBUG_DIO
-               a4l_info(dev, "SPI serial clock Config cd\n", data[1]);
+               a4l_info(dev, "SPI serial clock Config %d\n", data[1]);
 #endif
 
                devpriv->serial_hw_mode = 1;
diff --git a/kernel/drivers/analogy/national_instruments/mite.c 
b/kernel/drivers/analogy/national_instruments/mite.c
index b4562a1..84dbdda 100644
--- a/kernel/drivers/analogy/national_instruments/mite.c
+++ b/kernel/drivers/analogy/national_instruments/mite.c
@@ -123,7 +123,7 @@ int a4l_mite_setup(struct mite_struct *mite, int 
use_iodwbsr_1)
        u32 csigr_bits;
        unsigned unknown_dma_burst_bits;
 
-       __a4l_dbg(1, drv_dbg, "mite: starting setup...\n");
+       __a4l_dbg(1, drv_dbg, "starting setup...\n");
 
        pci_set_master(mite->pcidev);
 
@@ -142,8 +142,7 @@ int a4l_mite_setup(struct mite_struct *mite, int 
use_iodwbsr_1)
                return -ENOMEM;
        }
 
-       __a4l_dbg(1, drv_dbg,
-                 "mite: bar0(mite) 0x%08llx mapped to %p\n",
+       __a4l_dbg(1, drv_dbg, "bar0(mite) 0x%08llx mapped to %p\n",
                  (unsigned long long)mite->mite_phys_addr,
                  mite->mite_io_addr);
 
@@ -158,16 +157,12 @@ int a4l_mite_setup(struct mite_struct *mite, int 
use_iodwbsr_1)
                return -ENOMEM;
        }
 
-       __a4l_dbg(1, drv_dbg,
-                 "mite: bar0(daq) 0x%08llx mapped to %p\n",
+       __a4l_dbg(1, drv_dbg, "bar0(daq) 0x%08llx mapped to %p\n",
                  (unsigned long long)mite->daq_phys_addr,
                  mite->daq_io_addr);
 
        if (use_iodwbsr_1) {
-
-               __a4l_dbg(1, drv_dbg,
-                         "mite: using I/O Window Base Size register 1\n");
-
+               __a4l_dbg(1, drv_dbg, "using I/O Window Base Size register 
1\n");
                writel(0, mite->mite_io_addr + MITE_IODWBSR);
                writel(mite->
                       daq_phys_addr | WENAB |
@@ -200,15 +195,13 @@ int a4l_mite_setup(struct mite_struct *mite, int 
use_iodwbsr_1)
                mite->num_channels = MAX_MITE_DMA_CHANNELS;
        }
 
-       __a4l_dbg(1, drv_dbg,
-                 "mite: version = %i, type = %i, mite mode = %i, "
+       __a4l_dbg(1, drv_dbg, " version = %i, type = %i, mite mode = %i, "
                  "interface mode = %i\n",
                  mite_csigr_version(csigr_bits),
                  mite_csigr_type(csigr_bits),
                  mite_csigr_mmode(csigr_bits),
                  mite_csigr_imode(csigr_bits));
-       __a4l_dbg(1, drv_dbg,
-                 "mite: num channels = %i, write post fifo depth = %i, "
+       __a4l_dbg(1, drv_dbg, " num channels = %i, write post fifo depth = %i, "
                  "wins = %i, iowins = %i\n",
                  mite_csigr_dmac(csigr_bits),
                  mite_csigr_wpdep(csigr_bits),
@@ -226,7 +219,7 @@ int a4l_mite_setup(struct mite_struct *mite, int 
use_iodwbsr_1)
                       CHCR_CLR_LC_IE | CHCR_CLR_CONT_RB_IE,
                       mite->mite_io_addr + MITE_CHCR(i));
 
-               __a4l_dbg(1, drv_dbg, "mite: channel[%d] initialized\n", i);
+               __a4l_dbg(1, drv_dbg, "channel[%d] initialized\n", i);
        }
 
        mite->used = 1;
@@ -305,9 +298,7 @@ a4l_mite_request_channel_in_range(struct mite_struct *mite,
        unsigned long flags;
        struct mite_channel *channel = NULL;
 
-       __a4l_dbg(1, drv_dbg,
-                 "mite: a4l_mite_request_channel_in_range: "
-                 "min_channel = %u, max_channel = %u\n",
+       __a4l_dbg(1, drv_dbg, " min_channel = %u, max_channel = %u\n",
                  min_channel, max_channel);
 
        /* spin lock so a4l_mite_release_channel can be called safely
@@ -315,9 +306,7 @@ a4l_mite_request_channel_in_range(struct mite_struct *mite,
        rtdm_lock_get_irqsave(&mite->lock, flags);
        for (i = min_channel; i <= max_channel; ++i) {
 
-       __a4l_dbg(1, drv_dbg,
-                 "mite: a4l_mite_request_channel_in_range: "
-                 "channel[%d] allocated = %d\n",
+       __a4l_dbg(1, drv_dbg, " channel[%d] allocated = %d\n",
                  i, mite->channel_allocated[i]);
 
                if (mite->channel_allocated[i] == 0) {
diff --git a/kernel/drivers/analogy/national_instruments/ni_660x.c 
b/kernel/drivers/analogy/national_instruments/ni_660x.c
index 03e694b..14b0b00 100644
--- a/kernel/drivers/analogy/national_instruments/ni_660x.c
+++ b/kernel/drivers/analogy/national_instruments/ni_660x.c
@@ -1084,13 +1084,12 @@ static int ni_660x_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
 
 
        if(mitedev == NULL) {
-               a4l_info(dev, "%s: mite device not found\n", __FUNCTION__);
+               a4l_info(dev, "mite device not found\n");
                return -ENOENT;
        }
 
-       a4l_info(dev,
-                "%s: Board found (name=%s), continue initialization ...",
-                __FUNCTION__, boardptr->name);
+       a4l_info(dev, "Board found (name=%s), continue initialization ...",
+                boardptr->name);
 
        private(dev)->mite      = mitedev;
        private(dev)->board_ptr = boardptr;
@@ -1123,9 +1122,7 @@ static int ni_660x_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
 
        err = a4l_add_subd(dev, s);
        if (err != nsubdev) {
-               a4l_info(dev,
-                        "%s: cannot add first subdevice, "
-                        "returns %d, expect %d\n", __FUNCTION__, err, i);
+               a4l_info(dev, "cannot add first subdevice, returns %d, expect 
%d\n", err, i);
                return err;
        }
 
@@ -1134,9 +1131,7 @@ static int ni_660x_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
        /* Setup second subdevice */
        s = a4l_alloc_subd(sizeof(struct ni_660x_subd_priv), NULL);
        if (s == NULL) {
-               a4l_info(dev,
-                        "%s: cannot allocate second subdevice\n",
-                        __FUNCTION__);
+               a4l_info(dev, "cannot allocate second subdevice\n");
                return -ENOMEM;
        }
 
@@ -1251,7 +1246,7 @@ static int ni_660x_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
        ni_660x_write_register(dev, 0, global_interrupt_config_bits,
                               GlobalInterruptConfigRegister);
 
-       a4l_info(dev, "%s: attach succeed, ready to be used\n", __FUNCTION__);
+       a4l_info(dev, "attach succeed, ready to be used\n");
 
        return 0;
 }
@@ -1260,7 +1255,7 @@ static int ni_660x_detach(struct a4l_device *dev)
 {
        int i;
 
-       a4l_info(dev, "%s: begin to detach the driver ...", __FUNCTION__);
+       a4l_info(dev, "begin to detach the driver ...");
 
        /* Free irq */
        if(a4l_get_irq(dev)!=A4L_IRQ_UNUSED)
@@ -1283,7 +1278,7 @@ static int ni_660x_detach(struct a4l_device *dev)
                }
        }
 
-       a4l_info(dev, "%s: driver detached !\n", __FUNCTION__);
+       a4l_info(dev, "driver detached !\n");
 
        return 0;
 }
diff --git a/kernel/drivers/analogy/national_instruments/ni_670x.c 
b/kernel/drivers/analogy/national_instruments/ni_670x.c
index 652b536..103a635 100644
--- a/kernel/drivers/analogy/national_instruments/ni_670x.c
+++ b/kernel/drivers/analogy/national_instruments/ni_670x.c
@@ -270,9 +270,8 @@ static int ni_670x_attach (struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
                        ((unsigned long *)arg->opts)[1] : 0;
        }
 
-       a4l_info(dev,
-                "%s: ni670x attach procedure started(bus=%d/slot=%d)...\n",
-                __FUNCTION__, bus, slot);
+       a4l_info(dev, "ni670x attach procedure started(bus=%d/slot=%d)...\n",
+                bus, slot);
 
        mite = NULL;
 
@@ -287,9 +286,7 @@ static int ni_670x_attach (struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
                return -ENOENT;
        }
 
-       a4l_info(dev,
-                "%s: Found device %d %s\n",
-                __FUNCTION__, i , ni_670x_boards[i].name);
+       a4l_info(dev, "Found device %d %s\n", i, ni_670x_boards[i].name);
 
        devpriv->irq_polarity = PCIMIO_IRQ_POLARITY;
        devpriv->irq_pin = 0;
@@ -306,7 +303,7 @@ static int ni_670x_attach (struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
        irq = mite_irq(devpriv->mite);
        devpriv->irq = irq;
 
-       a4l_info(dev, "ni670x attach: found %s board\n", board->name);
+       a4l_info(dev, "found %s board\n", board->name);
 
        for (i = 0; i < 2; i++) {
                struct a4l_subdevice *subd =
@@ -335,20 +332,19 @@ static int ni_670x_attach (struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
        /* Config of ao registers */
        writel(0x00, devpriv->mite->daq_io_addr + AO_CONTROL_OFFSET);
 
-       a4l_info(dev, "%s: ni670x attached\n", __FUNCTION__);
+       a4l_info(dev, "ni670x attached\n");
 
        return 0;
 }
 
 static int ni_670x_detach(struct a4l_device *dev)
 {
-       a4l_info(dev, "%s: ni670x detach procedure started...\n", __FUNCTION__);
+       a4l_info(dev, "ni670x detach procedure started...\n");
 
        if(dev->priv != NULL && devpriv->mite != NULL)
                a4l_mite_unsetup(devpriv->mite);
 
-       a4l_info(dev,
-                "%s: ni670x detach procedure succeeded...\n", __FUNCTION__);
+       a4l_info(dev, "ni670x detach procedure succeeded...\n");
 
        return 0;
 }
diff --git a/kernel/drivers/analogy/national_instruments/pcimio.c 
b/kernel/drivers/analogy/national_instruments/pcimio.c
index 5c764d7..7209d19 100644
--- a/kernel/drivers/analogy/national_instruments/pcimio.c
+++ b/kernel/drivers/analogy/national_instruments/pcimio.c
@@ -1507,7 +1507,7 @@ static int pcimio_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
           devpriv->gpct_mite_ring[1] == NULL)
                return -ENOMEM;
 
-       a4l_info(dev, "pcimio_attach: found %s board\n", boardtype.name);
+       a4l_info(dev, "found %s board\n", boardtype.name);
 
        if(boardtype.reg_type & ni_reg_m_series_mask)
        {
@@ -1540,7 +1540,7 @@ static int pcimio_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
        if(irq == 0){
                a4l_warn(dev, "pcimio_attach: unknown irq (bad)\n\n");
        }else{
-               a4l_info(dev, "pcimio_attach: found irq %u\n", irq);
+               a4l_info(dev, "found irq %u\n", irq);
                ret = a4l_request_irq(dev,
                                      irq,
                                      a4l_ni_E_interrupt, RTDM_IRQTYPE_SHARED, 
dev);
diff --git a/kernel/drivers/analogy/rtdm_interface.c 
b/kernel/drivers/analogy/rtdm_interface.c
index e4d4768..c35959c 100644
--- a/kernel/drivers/analogy/rtdm_interface.c
+++ b/kernel/drivers/analogy/rtdm_interface.c
@@ -132,14 +132,13 @@ int a4l_open(struct rtdm_fd *fd, int flags)
 {
        struct a4l_device_context *cxt = (struct a4l_device_context 
*)rtdm_fd_to_private(fd);
 
-       /* Get a pointer on the selected device
-          (thanks to minor index) */
+       /* Get a pointer on the selected device (thanks to minor index) */
        a4l_set_dev(cxt);
 
        /* Initialize the buffer structure */
        cxt->buffer = rtdm_malloc(sizeof(struct a4l_buffer));
-       a4l_init_buffer(cxt->buffer);
 
+       a4l_init_buffer(cxt->buffer);
        /* Allocate the asynchronous buffer
           NOTE: it should be interesting to allocate the buffer only
           on demand especially if the system is short of memory */
@@ -147,6 +146,9 @@ int a4l_open(struct rtdm_fd *fd, int flags)
                a4l_alloc_buffer(cxt->buffer,
                                 cxt->dev->transfer.default_bufsize);
 
+       __a4l_dbg(1, core_dbg, "cxt=%p cxt->buf=%p, cxt->buf->buf=%p\n",
+               cxt, cxt->buffer, cxt->buffer->buf);
+
        return 0;
 }
 
diff --git a/kernel/drivers/analogy/sensoray/s526.c 
b/kernel/drivers/analogy/sensoray/s526.c
index ee969ad..f95a7de 100644
--- a/kernel/drivers/analogy/sensoray/s526.c
+++ b/kernel/drivers/analogy/sensoray/s526.c
@@ -715,7 +715,7 @@ static int dev_s526_attach(struct a4l_device *dev, 
a4l_lnkdesc_t *arg)
 
        devpriv->io_base = io_base;
 
-       a4l_info(dev, "dev_s526_attach: attached (address = 0x%x)\n", io_base);
+       a4l_info(dev, " attached (address = 0x%x)\n", io_base);
 
        return 0;
 }
diff --git a/kernel/drivers/analogy/testing/fake.c 
b/kernel/drivers/analogy/testing/fake.c
index a674e74..c91f3dc 100644
--- a/kernel/drivers/analogy/testing/fake.c
+++ b/kernel/drivers/analogy/testing/fake.c
@@ -195,7 +195,7 @@ int ao_pull_values(struct a4l_subdevice *subd)
 
        }
 
-       a4l_info(subd->dev, "ao_pull_values: count %d \n", priv->count);
+       a4l_info(subd->dev, A4L_FUNCTION " count %d \n", priv->count);
        a4l_buf_evt(subd, 0);
 
        return 0;
@@ -238,8 +238,8 @@ static int ai_cmd(struct a4l_subdevice *subd, struct 
a4l_cmd_desc *cmd)
        ai_priv->convert_period_ns = (cmd->convert_src==TRIG_TIMER)?
                cmd->convert_arg:0;
 
-       a4l_dbg(1, drv_dbg, subd->dev,
-               "ai_cmd: scan_period=%luns convert_period=%luns\n",
+       a4l_dbg(1, drv_dbg, subd->dev, A4L_FUNCTION
+               " scan_period=%luns convert_period=%luns\n",
                ai_priv->scan_period_ns, ai_priv->convert_period_ns);
 
        ai_priv->last_ns = a4l_get_time();
@@ -287,7 +287,7 @@ static void ai_munge(struct a4l_subdevice *subd, void *buf, 
unsigned long size)
 
 int ao_cmd(struct a4l_subdevice *subd, struct a4l_cmd_desc *cmd)
 {
-       a4l_info(subd->dev, "ao_cmd: (subd=%d)\n", subd->idx);
+       a4l_info(subd->dev, A4L_FUNCTION " (subd=%d)\n", subd->idx);
        return 0;
 }
 
@@ -295,7 +295,7 @@ int ao_trigger(struct a4l_subdevice *subd, lsampl_t trignum)
 {
        struct fake_priv *priv = (struct fake_priv *)subd->dev->priv;
 
-       a4l_info(subd->dev, "ao_trigger: (subd=%d)\n", subd->idx);
+       a4l_info(subd->dev, A4L_FUNCTION " (subd=%d)\n", subd->idx);
        priv->ao_running = 1;
        return 0;
 }
@@ -306,7 +306,7 @@ void ao_cancel(struct a4l_subdevice *subd)
        struct ao_ai2_priv *ao_priv = (struct ao_ai2_priv *)subd->priv;
        int running;
 
-       a4l_info(subd->dev, "ao_cancel: (subd=%d)\n", subd->idx);
+       a4l_info(subd->dev, A4L_FUNCTION " (subd=%d)\n", subd->idx);
        priv->ao_running = 0;
 
        running = priv->ai2_running;
@@ -328,7 +328,7 @@ int ai2_cmd(struct a4l_subdevice *subd, struct a4l_cmd_desc 
*cmd)
 {
        struct fake_priv *priv = (struct fake_priv *)subd->dev->priv;
 
-       a4l_info(subd->dev, "ai2_cmd: (subd=%d)\n", subd->idx);
+       a4l_info(subd->dev, A4L_FUNCTION " (subd=%d)\n", subd->idx);
        priv->ai2_running = 1;
        return 0;
 }
@@ -340,7 +340,7 @@ void ai2_cancel(struct a4l_subdevice *subd)
 
        int running;
 
-       a4l_info(subd->dev, "ai2_cancel: (subd=%d)\n", subd->idx);
+       a4l_info(subd->dev, A4L_FUNCTION " (subd=%d)\n", subd->idx);
        priv->ai2_running = 0;
 
        running = priv->ao_running;
@@ -627,9 +627,8 @@ int test_attach(struct a4l_device *dev, a4l_lnkdesc_t *arg)
        if (ret)
                a4l_dbg(1, drv_dbg, dev, "Error creating A4L task \n");
 
-       a4l_dbg(1, drv_dbg, dev, "attach procedure completed \n"
-                                " - amplitude divisor = %lu \n"
-                                " - quanta count = %lu\n "
+       a4l_dbg(1, drv_dbg, dev, "attach procedure completed: "
+                                "adiv = %lu, qcount = %lu \n"
                                  , priv->amplitude_div, priv->quanta_cnt);
 
        return ret;
diff --git a/kernel/drivers/analogy/transfer.c 
b/kernel/drivers/analogy/transfer.c
index c1d4727..88c4c84 100644
--- a/kernel/drivers/analogy/transfer.c
+++ b/kernel/drivers/analogy/transfer.c
@@ -45,9 +45,7 @@ int a4l_precleanup_transfer(struct a4l_device_context * cxt)
        for (i = 0; i < tsf->nb_subd; i++) {
                unsigned long *status = &tsf->subds[i]->status;
 
-               __a4l_dbg(1, core_dbg,
-                         "a4l_precleanup_transfer: "
-                         "subd[%d]->status=0x%08lx\n", i, *status);
+               __a4l_dbg(1, core_dbg, "subd[%d]->status=0x%08lx\n", i, 
*status);
 
                if (test_and_set_bit(A4L_SUBD_BUSY, status)) {
                        __a4l_err("a4l_precleanup_transfer: "
@@ -125,8 +123,7 @@ int a4l_setup_transfer(struct a4l_device_context * cxt)
                tsf->nb_subd++;
        }
 
-       __a4l_dbg(1, core_dbg,
-                 "a4l_setup_transfer: nb_subd=%d\n", tsf->nb_subd);
+       __a4l_dbg(1, core_dbg, "nb_subd=%d\n", tsf->nb_subd);
 
        /* Allocates a suitable tab for the subdevices */
        tsf->subds = rtdm_malloc(tsf->nb_subd * sizeof(struct a4l_subdevice *));
diff --git a/utils/analogy/cmd_read.c b/utils/analogy/cmd_read.c
index ddab9af..816bb30 100644
--- a/utils/analogy/cmd_read.c
+++ b/utils/analogy/cmd_read.c
@@ -56,6 +56,12 @@ static unsigned long wake_count = 0;
 
 static RT_TASK rt_task_desc;
 
+#define DBG(fmt, args...)                                              \
+        do {                                                           \
+               if (verbose)                                            \
+                          printf(fmt, ##args);                         \
+       } while (0);
+
 /* The command to send by default */
 a4l_cmd_t cmd = {
        .idx_subd = ID_SUBD,
@@ -257,8 +263,7 @@ int main(int argc, char *argv[])
 
        if (real_time != 0) {
 
-               if (verbose != 0)
-                       printf("cmd_read: switching to real-time mode\n");
+               DBG("cmd_read: switching to real-time mode\n");
 
                /* Prevent any memory-swapping for this program */
                ret = mlockall(MCL_CURRENT | MCL_FUTURE);
@@ -287,14 +292,11 @@ int main(int argc, char *argv[])
                return ret;
        }
 
-       if (verbose != 0) {
-               printf("cmd_read: device %s opened (fd=%d)\n",
-                      filename, dsc.fd);
-               printf("cmd_read: basic descriptor retrieved\n");
-               printf("\t subdevices count = %d\n", dsc.nb_subd);
-               printf("\t read subdevice index = %d\n", dsc.idx_read_subd);
-               printf("\t write subdevice index = %d\n", dsc.idx_write_subd);
-       }
+       DBG("cmd_read: device %s opened (fd=%d)\n", filename, dsc.fd);
+       DBG("cmd_read: basic descriptor retrieved\n");
+       DBG("\t subdevices count = %d\n", dsc.nb_subd);
+       DBG("\t read subdevice index = %d\n", dsc.idx_read_subd);
+       DBG("\t write subdevice index = %d\n", dsc.idx_write_subd);
 
        /* Allocate a buffer so as to get more info (subd, chan, rng) */
        dsc.sbdata = malloc(dsc.sbsize);
@@ -311,8 +313,8 @@ int main(int argc, char *argv[])
                goto out_main;
        }
 
-       if (verbose != 0)
-               printf("cmd_read: complex descriptor retrieved\n");
+
+       DBG("cmd_read: complex descriptor retrieved\n");
 
        /* Get the size of a single acquisition */
        for (i = 0; i < cmd.nb_chan; i++) {
@@ -327,21 +329,15 @@ int main(int argc, char *argv[])
                        goto out_main;
                }
 
-               if (verbose != 0) {
-                       printf("cmd_read: channel %x\n", cmd.chan_descs[i]);
-                       printf("\t ranges count = %d\n", info->nb_rng);
-                       printf("\t bit width = %d (bits)\n", info->nb_bits);
-               }
+               DBG("cmd_read: channel %x\n", cmd.chan_descs[i]);
+               DBG("\t ranges count = %d\n", info->nb_rng);
+               DBG("\t bit width = %d (bits)\n", info->nb_bits);
 
                scan_size += a4l_sizeof_chan(info);
        }
 
-       if (verbose != 0) {
-               printf("cmd_read: scan size = %u\n", scan_size);
-               if (cmd.stop_arg != 0)
-                       printf("cmd_read: size to read = %u\n",
-                              scan_size * cmd.stop_arg);
-       }
+       DBG("cmd_read: scan size = %u\n", scan_size);
+       DBG("cmd_read: size to read = %u\n", scan_size * cmd.stop_arg);
 
        /* Cancel any former command which might be in progress */
        a4l_snd_cancel(&dsc, cmd.idx_subd);
@@ -357,8 +353,7 @@ int main(int argc, char *argv[])
                        goto out_main;
                }
 
-               if (verbose != 0)
-                       printf("cmd_read: buffer size = %lu bytes\n", buf_size);
+               DBG("cmd_read: buffer size = %lu bytes\n", buf_size);
 
                /* Map the analog input subdevice buffer */
                ret = a4l_mmap(&dsc, cmd.idx_subd, buf_size, &map);
@@ -369,10 +364,7 @@ int main(int argc, char *argv[])
                        goto out_main;
                }
 
-               if (verbose != 0)
-                       printf
-                               ("cmd_read: mmap performed successfully 
(map=0x%p)\n",
-                                map);
+               DBG("cmd_read: mmap performed successfully (map=0x%p)\n",map);
        }
 
        ret = a4l_set_wakesize(&dsc, wake_count);
@@ -382,20 +374,16 @@ int main(int argc, char *argv[])
                goto out_main;
        }
 
-       if (verbose != 0)
-               printf("cmd_read: wake size successfully set (%lu)\n",
-                      wake_count);
+       DBG("cmd_read: wake size successfully set (%lu)\n", wake_count);
 
        /* Send the command to the input device */
        ret = a4l_snd_command(&dsc, &cmd);
        if (ret < 0) {
-               fprintf(stderr,
-                       "cmd_read: a4l_snd_command failed (ret=%d)\n", ret);
+               fprintf(stderr, "cmd_read: a4l_snd_command failed (ret=%d)\n", 
ret);
                goto out_main;
        }
 
-       if (verbose != 0)
-               printf("cmd_read: command successfully sent\n");
+       DBG("cmd_read: command successfully sent\n");
 
        if (use_mmap == 0) {
 
@@ -410,6 +398,8 @@ int main(int argc, char *argv[])
                                goto out_main;
                        }
 
+                       DBG("cmd_read: read %d bytes \n", ret);
+
                        /* Display the results */
                        if (dump_function(&dsc, &cmd, buf, ret) < 0) {
                                ret = -EIO;
@@ -419,6 +409,10 @@ int main(int argc, char *argv[])
                        /* Update the counter */
                        cnt += ret;
 
+                       if (ret == 0) {
+                               DBG("cmd_read: no more data in the buffer \n");
+                       }
+
                } while (ret > 0);
 
        } else {
@@ -471,8 +465,7 @@ int main(int argc, char *argv[])
                } while (1);
        }
 
-       if (verbose != 0)
-               printf("cmd_read: %d bytes successfully received\n", cnt);
+       DBG("cmd_read: %d bytes successfully received\n", cnt);
 
        ret = 0;
 
diff --git a/utils/analogy/cmd_write.c b/utils/analogy/cmd_write.c
index 2406230..20ddd49 100644
--- a/utils/analogy/cmd_write.c
+++ b/utils/analogy/cmd_write.c
@@ -439,7 +439,7 @@ out:
 /* --- Acquisition related stuff --- */
 static int run_acquisition(struct config *cfg)
 {
-       int err = 0, elements = 0;
+       int err = 0, elements = BUFFER_DEPTH;
 
        /* The return value of a4l_sizeof_chan() was already
        controlled in init_config so no need to do it twice */
@@ -450,12 +450,9 @@ static int run_acquisition(struct config *cfg)
                err = process_input(cfg, &elements);
                if (err < 0)
                        return err;
+               if (elements == 0)
+                       return -ENOENT;
        }
-       else
-               elements = BUFFER_DEPTH;
-
-       if (elements == 0)
-               return -ENOENT;
 
        fprintf(stderr, "cmd_write: write %d elements [%d bytes per element] on 
"
                        "%d channels \n", elements, chan_size, cfg->chans_count 
);


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to