Module: xenomai-abe
Branch: comedi
Commit: b661d4b3efc3682c273e501df78ba0cc002ac57b
URL:    
http://git.xenomai.org/?p=xenomai-abe.git;a=commit;h=b661d4b3efc3682c273e501df78ba0cc002ac57b

Author: Alexis Berlemont <alexis.berlem...@gmail.com>
Date:   Fri Sep 11 01:15:24 2009 +0200

Improve comedi_buf_evt(): remove ugly subdevice guessing based on
flags.

---

 include/comedi/buffer.h                            |    5 +--
 ksrc/drivers/comedi/buffer.c                       |   32 ++++++-------------
 ksrc/drivers/comedi/driver_facilities.c            |   21 +++----------
 ksrc/drivers/comedi/intel/8255.c                   |    2 +-
 .../comedi/national_instruments/tio_common.c       |    9 ++++--
 ksrc/drivers/comedi/testing/fake.c                 |   10 ++++--
 ksrc/drivers/comedi/testing/loop.c                 |   32 +++++++++++++-------
 7 files changed, 51 insertions(+), 60 deletions(-)

diff --git a/include/comedi/buffer.h b/include/comedi/buffer.h
index 1044aeb..02f74e3 100644
--- a/include/comedi/buffer.h
+++ b/include/comedi/buffer.h
@@ -325,10 +325,9 @@ int comedi_buf_commit_get(struct comedi_device *dev, 
unsigned long count);
 int comedi_buf_get(struct comedi_device *dev,
                   void *bufdata, unsigned long count);
 
-int comedi_buf_evt(struct comedi_device *dev,
-                  unsigned int type, unsigned long evts);
+int comedi_buf_evt(struct comedi_subdevice *subd, unsigned long evts);
 
-unsigned long comedi_buf_count(struct comedi_device *dev, unsigned int type);
+unsigned long comedi_buf_count(struct comedi_subdevice *subd);
 
 /* --- Current Command management function --- */
 
diff --git a/ksrc/drivers/comedi/buffer.c b/ksrc/drivers/comedi/buffer.c
index 2555a0a..eec10a3 100644
--- a/ksrc/drivers/comedi/buffer.c
+++ b/ksrc/drivers/comedi/buffer.c
@@ -243,24 +243,14 @@ int comedi_buf_get(comedi_dev_t * dev, void *bufdata, 
unsigned long count)
        return ret;
 }
 
-int comedi_buf_evt(comedi_dev_t * dev, unsigned int type, unsigned long evts)
+int comedi_buf_evt(comedi_subd_t *subd, unsigned long evts)
 {
-       unsigned int idx_subd;
-       comedi_buf_t *buf;
+       comedi_dev_t *dev = subd->dev;
+       comedi_buf_t *buf = dev->transfer.bufs[subd->idx];
        int tmp;
 
-       /* Retrieves the subdevice's index */
-       if (type == COMEDI_BUF_PUT)
-               idx_subd = dev->transfer.idx_read_subd;
-       else if (type == COMEDI_BUF_GET)
-               idx_subd = dev->transfer.idx_write_subd;
-       else
-               return -EINVAL;
-
-       buf = dev->transfer.bufs[idx_subd];
-
        /* Basic checking */
-       if (!test_bit(COMEDI_TSF_BUSY, &(dev->transfer.status[idx_subd])))
+       if (!test_bit(COMEDI_TSF_BUSY, &(dev->transfer.status[subd->idx])))
                return -ENOENT;
 
        /* Even if it is a little more complex,
@@ -277,18 +267,16 @@ int comedi_buf_evt(comedi_dev_t * dev, unsigned int type, 
unsigned long evts)
        return 0;
 }
 
-unsigned long comedi_buf_count(comedi_dev_t * dev, unsigned int type)
+unsigned long comedi_buf_count(comedi_subd_t *subd)
 {
        unsigned long ret = 0;
-       comedi_buf_t *buf;
+       comedi_dev_t *dev = subd->dev;
+       comedi_buf_t *buf = dev->transfer.bufs[subd->idx];
 
-       if (type == COMEDI_BUF_PUT) {
-               buf = dev->transfer.bufs[dev->transfer.idx_read_subd];
+       if (subd->flags & COMEDI_SUBD_MASK_READ)
                ret = __count_to_put(buf);
-       } else if (type == COMEDI_BUF_GET) {
-               buf = dev->transfer.bufs[dev->transfer.idx_write_subd];
-               ret = __count_to_get(buf);
-       }
+       else if (subd->flags & COMEDI_SUBD_MASK_WRITE)
+               ret = __count_to_get(buf);      
 
        return ret;
 }
diff --git a/ksrc/drivers/comedi/driver_facilities.c 
b/ksrc/drivers/comedi/driver_facilities.c
index 0702a37..3753c38 100644
--- a/ksrc/drivers/comedi/driver_facilities.c
+++ b/ksrc/drivers/comedi/driver_facilities.c
@@ -139,6 +139,7 @@ EXPORT_SYMBOL(range_bipolar5);
 EXPORT_SYMBOL(range_unipolar10);
 EXPORT_SYMBOL(range_unipolar5);
 EXPORT_SYMBOL(range_unknown);
+EXPORT_SYMBOL(range_fake);
 
 /**
  * @brief Add a subdevice to the driver descriptor
@@ -461,12 +462,7 @@ EXPORT_SYMBOL(comedi_buf_get);
  * - To notify the user-process an error has occured during the
  *   acquistion.
  *
- * @param[in] dev Device descriptor structure
- * @param[in] type Buffer transfer type:
- * - COMEDI_BUF_PUT for device -> Comedi buffer -> user-process
- *   transfer.
- * - COMEDI_BUF_GET for user-process -> Comedi_buffer -> device
- *   transfer
+ * @param[in] subd Subdevice descriptor structure
  * @param[in] evts Some specific event to notify:
  * - COMEDI_BUF_ERROR to indicate some error has occured during the
  *   transfer
@@ -476,25 +472,18 @@ EXPORT_SYMBOL(comedi_buf_get);
  * @return 0 on success, otherwise negative error code.
  *
  */
-int comedi_buf_evt(comedi_dev_t * dev, unsigned int type, unsigned long evts);
+int comedi_buf_evt(comedi_subd_t *subd, unsigned long evts);
 EXPORT_SYMBOL(comedi_buf_evt);
 
 /**
  * @brief Get the data amount available in the Comedi buffer 
  *
- * @param[in] dev Device descriptor structure
- * @param[in] type Buffer transfer type:
- * - COMEDI_BUF_PUT for device -> Comedi buffer -> user-process
- *   transfer; in this case, the returned count is the free space in
- *   the Comedi buffer in which the driver can put acquired data.
- * - COMEDI_BUF_GET for user-process -> Comedi_buffer -> device
- *   transfer; in that case, the returned count is the data amount
- *   available for sending to the device.
+ * @param[in] subd Subdevice descriptor structure
  *
  * @return the amount of data available in the Comedi buffer.
  *
  */
-unsigned long comedi_buf_count(comedi_dev_t * dev, unsigned int type);
+unsigned long comedi_buf_count(comedi_subd_t *subd);
 EXPORT_SYMBOL(comedi_buf_count);
 
 /**
diff --git a/ksrc/drivers/comedi/intel/8255.c b/ksrc/drivers/comedi/intel/8255.c
index 1f5905d..e2c136f 100644
--- a/ksrc/drivers/comedi/intel/8255.c
+++ b/ksrc/drivers/comedi/intel/8255.c
@@ -62,7 +62,7 @@ void subdev_8255_interrupt(comedi_subd_t *subd)
        /* ...and send it */
        comedi_buf_put(subd->dev, &d, sizeof(sampl_t));
 
-       comedi_buf_evt(subd->dev, COMEDI_BUF_PUT, 0);
+       comedi_buf_evt(subd, 0);
 }
 
 static int subdev_8255_cb(int dir, int port, int data, unsigned long arg)
diff --git a/ksrc/drivers/comedi/national_instruments/tio_common.c 
b/ksrc/drivers/comedi/national_instruments/tio_common.c
index 76605d4..6ab66f4 100644
--- a/ksrc/drivers/comedi/national_instruments/tio_common.c
+++ b/ksrc/drivers/comedi/national_instruments/tio_common.c
@@ -43,6 +43,7 @@
 #include <comedi/comedi_driver.h>
 
 #include "ni_tio.h"
+#include "ni_mio.h"
 
 static inline void write_register(struct ni_gpct *counter, 
                                  unsigned int bits, enum ni_gpct_register reg)
@@ -1899,15 +1900,17 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter, 
comedi_dev_t *dev)
        int gate_error;
        int tc_error;
        int perm_stale_data;
+       comedi_subd_t *subd = 
+               comedi_get_subd(dev, NI_GPCT_SUBDEV(counter->counter_index));
 
        ni_tio_acknowledge_and_confirm(counter, &gate_error, &tc_error,
                &perm_stale_data, NULL);
        if (gate_error) {
                __comedi_err("%s: Gi_Gate_Error detected.\n", __FUNCTION__);
-               comedi_buf_evt(dev, COMEDI_BUF_PUT, COMEDI_BUF_ERROR);
+               comedi_buf_evt(subd, COMEDI_BUF_ERROR);
        }
        if (perm_stale_data) {
-               comedi_buf_evt(dev, COMEDI_BUF_PUT, COMEDI_BUF_ERROR);
+               comedi_buf_evt(subd, COMEDI_BUF_ERROR);
        }
        switch (counter->counter_dev->variant) {
        case ni_gpct_variant_m_series:
@@ -1916,7 +1919,7 @@ void ni_tio_handle_interrupt(struct ni_gpct *counter, 
comedi_dev_t *dev)
                                  
NITIO_Gi_DMA_Status_Reg(counter->counter_index)) 
                    & Gi_DRQ_Error_Bit) {
                        __comedi_err("%s: Gi_DRQ_Error detected.\n", 
__FUNCTION__);
-                       comedi_buf_evt(dev, COMEDI_BUF_PUT, COMEDI_BUF_ERROR);
+                       comedi_buf_evt(subd, COMEDI_BUF_ERROR);
                }
                break;
        case ni_gpct_variant_e_series:
diff --git a/ksrc/drivers/comedi/testing/fake.c 
b/ksrc/drivers/comedi/testing/fake.c
index d40a9d6..e5c3bfb 100644
--- a/ksrc/drivers/comedi/testing/fake.c
+++ b/ksrc/drivers/comedi/testing/fake.c
@@ -4,6 +4,8 @@
 #define TEST_TASK_PERIOD 1000000
 #define TEST_NB_BITS 16
 
+#define TEST_INPUT_SUBD 0
+
 /* --- Driver related structures --- */
 
 /* Device private structure */
@@ -98,7 +100,7 @@ static sampl_t test_output(tstprv_t *priv)
 static void test_task_proc(void *arg)
 {
        comedi_dev_t *dev = (comedi_dev_t*)arg;
-       comedi_subd_t *subd = comedi_get_subd(dev, 0);
+       comedi_subd_t *subd = comedi_get_subd(dev, TEST_INPUT_SUBD);
        tstprv_t *priv = (tstprv_t *)dev->priv;
        comedi_cmd_t *cmd = NULL;
        u64 now_ns, elapsed_ns=0;
@@ -137,7 +139,7 @@ static void test_task_proc(void *arg)
                        priv->current_ns += i * priv->scan_period_ns;
                        priv->reminder_ns = elapsed_ns;
 
-                       comedi_buf_evt(dev, COMEDI_BUF_PUT, 0);
+                       comedi_buf_evt(subd, 0);
                }
 
                comedi_task_sleep(TEST_TASK_PERIOD);
@@ -266,8 +268,8 @@ int test_attach(comedi_dev_t *dev, comedi_lnkdesc_t *arg)
                return -ENOMEM;
 
        ret = comedi_add_subd(dev, subd);
-       if(ret < 0)
-               return ret;
+       if(ret != TEST_INPUT_SUBD)
+               return (ret < 0) ? ret : -EINVAL;
 
        priv->timer_running = 0;
 
diff --git a/ksrc/drivers/comedi/testing/loop.c 
b/ksrc/drivers/comedi/testing/loop.c
index ac0c2a4..731ba09 100644
--- a/ksrc/drivers/comedi/testing/loop.c
+++ b/ksrc/drivers/comedi/testing/loop.c
@@ -4,6 +4,9 @@
 #define LOOP_TASK_PERIOD 1000000
 #define LOOP_NB_BITS 16
 
+#define LOOP_INPUT_SUBD 0 
+#define LOOP_OUTPUT_SUBD 1
+
 /* Channels descriptor */
 static comedi_chdesc_t loop_chandesc = {
        .mode = COMEDI_CHAN_GLOBAL_CHANDESC,
@@ -60,11 +63,20 @@ static void loop_task_proc(void *arg);
 static void loop_task_proc(void *arg)
 {
        comedi_dev_t *dev = (comedi_dev_t*)arg;
+       comedi_subd_t *input_subd, *output_subd;
        lpprv_t *priv = (lpprv_t *)dev->priv;
     
        while (!comedi_check_dev(dev))
                comedi_task_sleep(LOOP_TASK_PERIOD);
 
+       input_subd = comedi_get_subd(dev, LOOP_INPUT_SUBD);
+       output_subd = comedi_get_subd(dev, LOOP_OUTPUT_SUBD);
+
+       if (input_subd == NULL || output_subd == NULL) {
+               comedi_err(dev, "loop_task_proc: subdevices unavailable\n");
+               return;
+       }
+
        while (1) {
        
                if (priv->loop_running) {
@@ -82,16 +94,14 @@ static void loop_task_proc(void *arg)
                                                    "loop_task_proc: "
                                                    "data available\n");
 
-                                       comedi_buf_evt(dev, COMEDI_BUF_GET, 0);
+                                       comedi_buf_evt(output_subd, 0);
                    
-                                       ret=comedi_buf_put(dev, 
-                                                          &value, 
-                                                          sizeof(sampl_t));
+                                       ret = comedi_buf_put(dev, 
+                                                            &value, 
+                                                            sizeof(sampl_t));
 
                                        if (ret==0)
-                                               comedi_buf_evt(dev, 
-                                                              COMEDI_BUF_PUT, 
-                                                              0);
+                                               comedi_buf_evt(input_subd, 0);
                                }
                        }
                }
@@ -199,9 +209,9 @@ int loop_attach(comedi_dev_t *dev,
                return -ENOMEM;  
 
        ret = comedi_add_subd(dev, subd);
-       if (ret < 0)
+       if (ret != LOOP_INPUT_SUBD)
                /* Let Comedi free the lately allocated subdevice */
-               return ret;
+               return (ret < 0) ? ret : -EINVAL;
 
        /* Add the fake output subdevice */
        subd = comedi_alloc_subd(0, setup_output_subd); 
@@ -210,9 +220,9 @@ int loop_attach(comedi_dev_t *dev,
                return -ENOMEM;  
 
        ret = comedi_add_subd(dev, subd);
-       if (ret < 0)
+       if (ret != LOOP_OUTPUT_SUBD)
                /* Let Comedi free the lately allocated subdevices */
-               return ret;
+               return (ret < 0) ? ret : -EINVAL;
 
        priv->loop_running = 0;
        priv->loop_insn_value = 0;


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to