Re-added callback data pointer, because it is necessary for some applications.
authorFlorian Pose <fp@igh-essen.com>
Wed, 29 Jul 2009 09:19:53 +0000
changeset 1513 60ca68d853b8
parent 1512 388901f44a5e
child 1514 85ac1c91045d
Re-added callback data pointer, because it is necessary for some applications.
examples/dc_rtai/dc_rtai_sample.c
examples/mini/mini.c
examples/rtai/rtai_sample.c
include/ecrt.h
master/cdev.c
master/master.c
master/master.h
--- a/examples/dc_rtai/dc_rtai_sample.c	Tue Jul 28 16:06:21 2009 +0000
+++ b/examples/dc_rtai/dc_rtai_sample.c	Wed Jul 29 09:19:53 2009 +0000
@@ -238,24 +238,28 @@
 
 /*****************************************************************************/
 
-void send_callback(ec_master_t *master)
-{
+void send_callback(void *cb_data)
+{
+    ec_master_t *m = (ec_master_t *) cb_data;
+
     // too close to the next real time cycle: deny access...
     if (get_cycles() - t_last_cycle <= t_critical) {
         rt_sem_wait(&master_sem);
-        ecrt_master_send_ext(master);
+        ecrt_master_send_ext(m);
         rt_sem_signal(&master_sem);
     }
 }
 
 /*****************************************************************************/
 
-void receive_callback(ec_master_t *master)
-{
+void receive_callback(void *cb_data)
+{
+    ec_master_t *m = (ec_master_t *) cb_data;
+
     // too close to the next real time cycle: deny access...
     if (get_cycles() - t_last_cycle <= t_critical) {
         rt_sem_wait(&master_sem);
-        ecrt_master_receive(master);
+        ecrt_master_receive(m);
         rt_sem_signal(&master_sem);
     }
 }
@@ -281,7 +285,7 @@
         goto out_return;
     }
 
-    ecrt_master_callbacks(master, send_callback, receive_callback);
+    ecrt_master_callbacks(master, send_callback, receive_callback, master);
 
     printk(KERN_INFO PFX "Registering domain...\n");
     if (!(domain1 = ecrt_master_create_domain(master))) {
--- a/examples/mini/mini.c	Tue Jul 28 16:06:21 2009 +0000
+++ b/examples/mini/mini.c	Wed Jul 29 09:19:53 2009 +0000
@@ -354,19 +354,21 @@
 
 /*****************************************************************************/
 
-void send_callback(ec_master_t *master)
-{
-    down(&master_sem);
-    ecrt_master_send_ext(master);
-    up(&master_sem);
-}
-
-/*****************************************************************************/
-
-void receive_callback(ec_master_t *master)
-{
-    down(&master_sem);
-    ecrt_master_receive(master);
+void send_callback(void *cb_data)
+{
+    ec_master_t *m = (ec_master_t *) cb_data;
+    down(&master_sem);
+    ecrt_master_send_ext(m);
+    up(&master_sem);
+}
+
+/*****************************************************************************/
+
+void receive_callback(void *cb_data)
+{
+    ec_master_t *m = (ec_master_t *) cb_data;
+    down(&master_sem);
+    ecrt_master_receive(m);
     up(&master_sem);
 }
 
@@ -392,7 +394,7 @@
     }
 
     init_MUTEX(&master_sem);
-    ecrt_master_callbacks(master, send_callback, receive_callback);
+    ecrt_master_callbacks(master, send_callback, receive_callback, master);
 
     printk(KERN_INFO PFX "Registering domain...\n");
     if (!(domain1 = ecrt_master_create_domain(master))) {
--- a/examples/rtai/rtai_sample.c	Tue Jul 28 16:06:21 2009 +0000
+++ b/examples/rtai/rtai_sample.c	Wed Jul 29 09:19:53 2009 +0000
@@ -243,24 +243,28 @@
 
 /*****************************************************************************/
 
-void send_callback(ec_master_t *master)
-{
+void send_callback(void *cb_data)
+{
+    ec_master_t *m = (ec_master_t *) cb_data;
+
     // too close to the next real time cycle: deny access...
     if (get_cycles() - t_last_cycle <= t_critical) {
         rt_sem_wait(&master_sem);
-        ecrt_master_send_ext(master);
+        ecrt_master_send_ext(m);
         rt_sem_signal(&master_sem);
     }
 }
 
 /*****************************************************************************/
 
-void receive_callback(ec_master_t *master)
-{
+void receive_callback(void *cb_data)
+{
+    ec_master_t *m = (ec_master_t *) cb_data;
+
     // too close to the next real time cycle: deny access...
     if (get_cycles() - t_last_cycle <= t_critical) {
         rt_sem_wait(&master_sem);
-        ecrt_master_receive(master);
+        ecrt_master_receive(m);
         rt_sem_signal(&master_sem);
     }
 }
@@ -288,7 +292,7 @@
         goto out_return;
     }
 
-    ecrt_master_callbacks(master, send_callback, receive_callback);
+    ecrt_master_callbacks(master, send_callback, receive_callback, master);
 
     printk(KERN_INFO PFX "Registering domain...\n");
     if (!(domain1 = ecrt_master_create_domain(master))) {
--- a/include/ecrt.h	Tue Jul 28 16:06:21 2009 +0000
+++ b/include/ecrt.h	Wed Jul 29 09:19:53 2009 +0000
@@ -477,8 +477,10 @@
  */
 void ecrt_master_callbacks(
         ec_master_t *master, /**< EtherCAT master */
-        void (*send_cb)(ec_master_t *), /**< Datagram sending callback. */
-        void (*receive_cb)(ec_master_t *) /**< Receive callback. */
+        void (*send_cb)(void *), /**< Datagram sending callback. */
+        void (*receive_cb)(void *), /**< Receive callback. */
+        void *cb_data /**< Arbitraty pointer passed to the callback functions.
+                       */
         );
 
 #endif /* __KERNEL__ */
--- a/master/cdev.c	Tue Jul 28 16:06:21 2009 +0000
+++ b/master/cdev.c	Wed Jul 29 09:19:53 2009 +0000
@@ -1622,7 +1622,7 @@
     }
 
     ecrt_master_callbacks(master, ec_master_internal_send_cb,
-            ec_master_internal_receive_cb);
+            ec_master_internal_receive_cb, master);
 
     ret = ecrt_master_activate(master);
     if (ret < 0)
--- a/master/master.c	Tue Jul 28 16:06:21 2009 +0000
+++ b/master/master.c	Wed Jul 29 09:19:53 2009 +0000
@@ -168,8 +168,10 @@
     init_MUTEX(&master->io_sem);
     master->send_cb = NULL;
     master->receive_cb = NULL;
+    master->cb_data = NULL;
     master->app_send_cb = NULL;
     master->app_receive_cb = NULL;
+    master->app_cb_data = NULL;
 
     INIT_LIST_HEAD(&master->sii_requests);
     init_waitqueue_head(&master->sii_queue);
@@ -382,9 +384,10 @@
 /** Internal sending callback.
  */
 void ec_master_internal_send_cb(
-        ec_master_t *master /**< EtherCAT master. */
-        )
-{
+        void *cb_data /**< Callback data. */
+        )
+{
+    ec_master_t *master = (ec_master_t *) cb_data;
     down(&master->io_sem);
     ecrt_master_send_ext(master);
     up(&master->io_sem);
@@ -395,9 +398,10 @@
 /** Internal receiving callback.
  */
 void ec_master_internal_receive_cb(
-        ec_master_t *master /**< EtherCAT master. */
-        )
-{
+        void *cb_data /**< Callback data. */
+        )
+{
+    ec_master_t *master = (ec_master_t *) cb_data;
     down(&master->io_sem);
     ecrt_master_receive(master);
     up(&master->io_sem);
@@ -473,6 +477,7 @@
 
     master->send_cb = ec_master_internal_send_cb;
     master->receive_cb = ec_master_internal_receive_cb;
+    master->cb_data = master;
 
     master->phase = EC_IDLE;
     ret = ec_master_thread_start(master, ec_master_idle_thread,
@@ -574,6 +579,7 @@
     master->phase = EC_OPERATION;
     master->app_send_cb = NULL;
     master->app_receive_cb = NULL;
+    master->app_cb_data = NULL;
     return ret;
     
 out_allow:
@@ -606,6 +612,7 @@
     
     master->send_cb = ec_master_internal_send_cb;
     master->receive_cb = ec_master_internal_receive_cb;
+    master->cb_data = master;
     
     down(&master->master_sem);
     ec_master_clear_domains(master);
@@ -1130,7 +1137,7 @@
             goto schedule;
 
         // receive datagrams
-        master->receive_cb(master);
+        master->receive_cb(master->cb_data);
 
         // actual EoE processing
         sth_to_send = 0;
@@ -1150,7 +1157,7 @@
             }
             // (try to) send datagrams
             down(&master->ext_queue_sem);
-            master->send_cb(master);
+            master->send_cb(master->cb_data);
             up(&master->ext_queue_sem);
         }
 
@@ -1659,6 +1666,7 @@
 
     master->send_cb = master->app_send_cb;
     master->receive_cb = master->app_receive_cb;
+    master->cb_data = master->app_cb_data;
     
     ret = ec_master_thread_start(master, ec_master_operation_thread,
                 "EtherCAT-OP");
@@ -1836,15 +1844,16 @@
 /*****************************************************************************/
 
 void ecrt_master_callbacks(ec_master_t *master,
-        void (*send_cb)(ec_master_t *), void (*receive_cb)(ec_master_t *))
+        void (*send_cb)(void *), void (*receive_cb)(void *), void *cb_data)
 {
     if (master->debug_level)
         EC_DBG("ecrt_master_callbacks(master = 0x%x, send_cb = 0x%x, "
-                " receive_cb = 0x%x)\n", (u32) master, (u32) send_cb,
-                (u32) receive_cb);
+                " receive_cb = 0x%x, cb_data = 0x%x)\n", (u32) master,
+                (u32) send_cb, (u32) receive_cb, (u32) cb_data);
 
     master->app_send_cb = send_cb;
     master->app_receive_cb = receive_cb;
+    master->app_cb_data = cb_data;
 }
 
 /*****************************************************************************/
--- a/master/master.h	Tue Jul 28 16:06:21 2009 +0000
+++ b/master/master.h	Wed Jul 29 09:19:53 2009 +0000
@@ -166,12 +166,14 @@
 
     struct semaphore io_sem; /**< Semaphore used in \a IDLE phase. */
 
-    void (*send_cb)(ec_master_t *); /**< Current send datagrams callback. */
-    void (*receive_cb)(ec_master_t *); /**< Current receive datagrams callback. */
-    void (*app_send_cb)(ec_master_t *); /**< Application's send datagrams
+    void (*send_cb)(void *); /**< Current send datagrams callback. */
+    void (*receive_cb)(void *); /**< Current receive datagrams callback. */
+    void *cb_data; /**< Current callback data. */
+    void (*app_send_cb)(void *); /**< Application's send datagrams
                                           callback. */
-    void (*app_receive_cb)(ec_master_t *); /**< Application's receive datagrams
+    void (*app_receive_cb)(void *); /**< Application's receive datagrams
                                       callback. */
+    void *app_cb_data; /**< Application callback data. */
 
     struct list_head sii_requests; /**< SII write requests. */
     wait_queue_head_t sii_queue; /**< Wait queue for SII
@@ -247,9 +249,9 @@
 
 void ec_master_calc_dc(ec_master_t *);
 
-void ec_master_internal_send_cb(ec_master_t *);
-void ec_master_internal_receive_cb(ec_master_t *);
-
-/*****************************************************************************/
-
-#endif
+void ec_master_internal_send_cb(void *);
+void ec_master_internal_receive_cb(void *);
+
+/*****************************************************************************/
+
+#endif