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

Author: Alexis Berlemont <alexis.berlem...@gmail.com>
Date:   Mon May 17 23:58:52 2010 +0200

analogy: update cancel functions (broken)

---

 ksrc/drivers/analogy/buffer.c   |   58 ++++++++++++++++++++++++++++---------
 ksrc/drivers/analogy/transfer.c |   61 ---------------------------------------
 2 files changed, 44 insertions(+), 75 deletions(-)

diff --git a/ksrc/drivers/analogy/buffer.c b/ksrc/drivers/analogy/buffer.c
index 92f1f4e..cb4beb7 100644
--- a/ksrc/drivers/analogy/buffer.c
+++ b/ksrc/drivers/analogy/buffer.c
@@ -91,10 +91,8 @@ out_virt_contig_alloc:
        return ret;
 }
 
-int a4l_init_buffer(a4l_buf_t * buf_desc)
+void a4l_init_buffer(a4l_buf_t * buf_desc)
 {
-       int err;
-       
        /* No command to process yet */
        buf_desc->cur_cmd = NULL;
 
@@ -111,13 +109,11 @@ int a4l_init_buffer(a4l_buf_t * buf_desc)
        /* Flush pending events */
        buf_desc->flags = 0;
        a4l_flush_sync(&buf_desc->sync);
-
-       return err;
 }
 
 int a4l_setup_buffer(a4l_cxt_t *cxt, a4l_cmd_t *cmd)
 {
-       a4l_buf_t * buf_desc = cxt->buffer;
+       a4l_buf_t *buf_desc = cxt->buffer;
        int i;
 
        /* Retrieve the related subdevice */
@@ -152,6 +148,40 @@ int a4l_setup_buffer(a4l_cxt_t *cxt, a4l_cmd_t *cmd)
        return 0;
 }
 
+int a4l_cancel_buffer(a4l_cxt_t *cxt)
+{
+       a4l_buf_t *buf_desc = cxt->buffer;
+       a4l_subd_t *subd = buf_desc->subd;
+       
+       int err = 0;
+       
+       if (!subd !! !a4l_check_subd(subd))
+               return 0;
+
+       /* If a "cancel" function is registered, call it
+          (Note: this function is called before having checked 
+          if a command is under progress; we consider that 
+          the "cancel" function can be used as as to (re)initialize 
+          some component) */
+       if (subd->cancel != NULL && (err = subd->cancel(subd)) < 0) {
+               __a4l_err("a4l_cancel: "
+                         "subdevice %d cancel handler failed (err=%d)\n",
+                         idx_subd, err);
+       }
+
+       a4l_release_subd(subd);
+
+       if (buf_desc->cur_cmd != NULL) {
+               a4l_free_cmddesc(buf_desc->cur_cmd);
+               rtdm_free(buf_desc->cur_cmd);
+               buf_desc->cur_cmd = NULL;
+       }
+
+       a4l_init_buffer(buf_desc);
+
+       return err;
+}
+
 /* --- current Command management function --- */
 
 a4l_cmd_t *a4l_get_cmd(a4l_subd_t *subd)
@@ -646,13 +676,13 @@ int a4l_ioctl_bufinfo(a4l_cxt_t * cxt, void *arg)
 
                if ((ret < 0 && ret != -ENOENT) ||
                    (ret == -ENOENT && tmp_cnt == 0)) {
-                       a4l_cancel_transfer(cxt, info.idx_subd);
+                       a4l_cancel_buffer(cxt);
                        return ret;
                }
        } else if (info.idx_subd == dev->transfer.idx_write_subd) {
 
                if (ret < 0) {
-                       a4l_cancel_transfer(cxt, info.idx_subd);
+                       a4l_cancel_buffer(cxt);
                        if (info.rw_count != 0)
                                return ret;
                }
@@ -744,14 +774,14 @@ ssize_t a4l_read(a4l_cxt_t * cxt, void *bufdata, size_t 
nbytes)
 
                /* We check whether there is an error */
                if (ret < 0 && ret != -ENOENT) {
-                       a4l_cancel_transfer(cxt, idx_subd);
+                       a4l_cancel_buffer(cxt);
                        count = ret;
                        goto out_a4l_read;                      
                }
                
                /* We check whether the acquisition is over */
                if (ret == -ENOENT && tmp_cnt == 0) {
-                       a4l_cancel_transfer(cxt, idx_subd);
+                       a4l_cancel_buffer(cxt);
                        count = 0;
                        goto out_a4l_read;
                }
@@ -846,7 +876,7 @@ ssize_t a4l_write(a4l_cxt_t *cxt,
                        tmp_cnt = nbytes - count;
 
                if (ret < 0) {
-                       a4l_cancel_transfer(cxt, idx_subd);
+                       a4l_cancel_buffer(cxt);
                        count = (ret == -ENOENT) ? -EINVAL : ret;
                        goto out_a4l_write;
                }
@@ -993,20 +1023,20 @@ int a4l_ioctl_poll(a4l_cxt_t * cxt, void *arg)
 
                /* Check if some error occured */
                if (ret < 0 && ret != -ENOENT) {
-                       a4l_cancel_transfer(cxt, poll.idx_subd);
+                       a4l_cancel_buffer(cxt);
                        return ret;
                }
 
                /* Check whether the acquisition is over */
                if (ret == -ENOENT && tmp_cnt == 0) {
-                       a4l_cancel_transfer(cxt, poll.idx_subd);
+                       a4l_cancel_buffer(cxt);
                        return 0;
                }
        } else {
 
                /* If some error was detected, cancel the transfer */
                if (ret < 0) {
-                       a4l_cancel_transfer(cxt, poll.idx_subd);
+                       a4l_cancel_buffer(cxt);
                        return ret;
                }
 
diff --git a/ksrc/drivers/analogy/transfer.c b/ksrc/drivers/analogy/transfer.c
index 9fc279a..aa0ae82 100644
--- a/ksrc/drivers/analogy/transfer.c
+++ b/ksrc/drivers/analogy/transfer.c
@@ -152,67 +152,6 @@ out_setup_tsf:
        return ret;
 }
 
-int a4l_cancel_transfer(a4l_cxt_t * cxt, int idx_subd)
-{
-       int ret = 0;
-       a4l_subd_t *subd;
-       a4l_dev_t *dev = a4l_get_dev(cxt);
-
-       /* Basic checking */
-       if (!test_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd])))
-               return 0;
-
-       /* Retrieves the proper subdevice pointer */
-       subd = dev->transfer.subds[idx_subd];
-
-       /* If a "cancel" function is registered, call it
-          (Note: this function is called before having checked 
-          if a command is under progress; we consider that 
-          the "cancel" function can be used as as to (re)initialize 
-          some component) */
-       if (subd->cancel != NULL && (ret = subd->cancel(subd)) < 0) {
-               __a4l_err("a4l_cancel: "
-                         "subdevice %d cancel handler failed (ret=%d)\n",
-                         idx_subd, ret);
-       }
-
-       /* Clears the "busy" flag */
-       clear_bit(A4L_TSF_BUSY, &(dev->transfer.status[idx_subd]));
-
-       /* If the subdevice is command capable and 
-          if a command is under progress, 
-          disable it and free it... */
-       if (dev->transfer.bufs != NULL &&
-           dev->transfer.bufs[idx_subd] != NULL &&
-           dev->transfer.bufs[idx_subd]->cur_cmd != NULL) {
-
-               a4l_free_cmddesc(dev->transfer.bufs[idx_subd]->cur_cmd);
-               rtdm_free(dev->transfer.bufs[idx_subd]->cur_cmd);
-               dev->transfer.bufs[idx_subd]->cur_cmd = NULL;
-
-               /* ...we must also clean the events flags */
-               dev->transfer.bufs[idx_subd]->evt_flags = 0;
-       }
-
-       return ret;
-}
-
-int a4l_cancel_transfers(a4l_cxt_t * cxt)
-{
-       a4l_dev_t *dev = a4l_get_dev(cxt);
-       int i, ret = 0;
-
-       /* The caller of a4l_cancel_transfers is bound not to have
-          checked whether the subdevice was attached; so we do it here */
-       if (!test_bit(A4L_DEV_ATTACHED, &dev->flags))
-               return 0;
-
-       for (i = 0; i < dev->transfer.nb_subd && ret == 0; i++)
-               ret = a4l_cancel_transfer(cxt, i);
-
-       return ret;
-}
-
 /* --- IRQ handling section --- */
 
 int a4l_request_irq(a4l_dev_t * dev,


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

Reply via email to