This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CAN waking calls


Ð ÐÑÐ, 10/08/2007 Ð 16:18 +0200, Andrew Lunn ÐÐÑÐÑ:
> On Mon, Aug 06, 2007 at 10:47:03AM +0700, Alexey Shusharin wrote:
> > Hello all,
> > 
> > This patch adds waking calls functionality to CAN I/O driver. Now CAN
> > application can wake up threads, when CAN event is arrived, without
> > accessory thread.
> > 
> Hi Alexey

Hello Andrew

> I reworked your patch a little. I renamed wake to callback, which is
> more generic. You can do real work in DSRs, you just have to be
> careful. So you don't always need to wake up a thread.

Thanks for your changes.

> Since there is no test case for this new feature, it is possible i
> have broken it. So please can you test it. If it all works i will then
> commit it.

It works fine, but while I was working with this stuff I decided that it
lacks of user data parameter in callback function. So I've added and
tested it. It works fine too.

> Do you think you could add a testcase to the can loop back driver
> which uses this feature?

OK, I will do when I find a free time.

Best regards
Alexey Shusharin

diff -bur /opt/ecos-repo/cvs/ecos/packages/io/can/current/cdl/io_can.cdl ./io/can/current/cdl/io_can.cdl
--- /opt/ecos-repo/cvs/ecos/packages/io/can/current/cdl/io_can.cdl	2007-07-03 21:42:18.000000000 +0700
+++ ./io/can/current/cdl/io_can.cdl	2007-08-13 09:37:09.000000000 +0700
@@ -218,6 +218,17 @@
             semantics from blocking to non-blocking."
     }
     
+    cdl_option CYGOPT_IO_CAN_SUPPORT_CALLBACK {
+        display       "Support callback on events"
+        default_value 0
+        description   "
+            This option enables extra code in the generic CAN driver
+            which allows application to register a callback for
+            events. The callback function is called from DSR
+            context so you should be careful to only call API
+            functions that are safe in DSR context."
+    }
+
     cdl_component CYGOPT_IO_CAN_SUPPORT_TIMEOUTS {
         display       "Support read/write timeouts"
         flavor        bool
diff -bur /opt/ecos-repo/cvs/ecos/packages/io/can/current/ChangeLog ./io/can/current/ChangeLog
--- /opt/ecos-repo/cvs/ecos/packages/io/can/current/ChangeLog	2007-08-01 13:35:58.000000000 +0700
+++ ./io/can/current/ChangeLog	2007-08-13 09:49:42.000000000 +0700
@@ -1,3 +1,17 @@
+2007-08-06 Alexey Shusharin <mrfinch@mail.ru>
+           Andrew Lunn <andrew.lunn@ascom.ch>
+	
+	* cdl/io_can.cdl: Added option CYGOPT_IO_CAN_SUPPORT_CALLBACK
+      
+	* include/canio.h: Added struct cyg_can_callback_cfg for setting
+          callback configurations.
+       
+	* include/can.h: Added declaration and initialization of callback 
+          configuration in struct can_channel.
+      
+	* src/can.c: Added callback configuration changing and
+          application function call.
+
 2007-07-02 Uwe Kindler <uwe_kindler@web.de>
     
 	* cdl/io_can.cdl: Added interface CYGINT_IO_CAN_CHANNELS for
ÐÐÐÑÐÐ Ð ./io/can/current/CVS: Entries.Log
diff -bur /opt/ecos-repo/cvs/ecos/packages/io/can/current/include/can.h ./io/can/current/include/can.h
--- /opt/ecos-repo/cvs/ecos/packages/io/can/current/include/can.h	2007-03-26 17:43:36.000000000 +0700
+++ ./io/can/current/include/can.h	2007-08-13 10:29:23.000000000 +0700
@@ -175,8 +175,16 @@
     bool                init;      // true if driver is already initialized
     can_cbuf_t          out_cbuf;  // buffer for transmit can messages
     can_cbuf_t          in_cbuf;   // buffer with received can events
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+    cyg_can_callback_cfg callback_cfg; // Callback configuration
+#endif
 };
 
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+#define CYG_CAN_CALLBACK_INIT  , {(cyg_can_event_cb_t) 0, 0, 0}
+#else
+#define CYG_CAN_CALLBACK_INIT
+#endif
 
 
 #define CAN_CHANNEL_USING_INTERRUPTS(_l,                                \
@@ -193,6 +201,7 @@
     false,                                                              \
     CBUF_INIT(_out_buf, _out_buflen, _TX_TIMEOUT),                      \
     CBUF_INIT(_in_buf, _in_buflen, _RX_TIMEOUT)                         \
+    CYG_CAN_CALLBACK_INIT                                               \
 };
 
 
diff -bur /opt/ecos-repo/cvs/ecos/packages/io/can/current/include/canio.h ./io/can/current/include/canio.h
--- /opt/ecos-repo/cvs/ecos/packages/io/can/current/include/canio.h	2007-08-01 13:35:59.000000000 +0700
+++ ./io/can/current/include/canio.h	2007-08-13 10:31:48.000000000 +0700
@@ -327,6 +327,24 @@
 #define CYGNUM_CAN_HDI_TIMESTAMP               0x10 // driver supports timestamps
 
 
+//
+// Callback configuration structure.
+//
+
+typedef void (*cyg_can_event_cb_t)(cyg_uint16, cyg_addrword_t);
+//
+// flag_mask should be set with a combination of CYGNUM_CAN_EVENT_* flags.
+// If one of these events happens, the callback function will be called,
+// with the actually event flags passed as a parameter.
+//
+typedef struct cyg_can_callback_cfg_st
+{
+    cyg_can_event_cb_t callback_func;              // callback function
+    cyg_addrword_t  callback_data;                 // data that will be passed to callback function
+    cyg_uint16  flag_mask;                         // flags mask
+} cyg_can_callback_cfg;
+
+
 //===========================================================================
 //                      CAN MESSAGE ACCESS MACROS
 //
diff -bur /opt/ecos-repo/cvs/ecos/packages/io/can/current/src/can.c ./io/can/current/src/can.c
--- /opt/ecos-repo/cvs/ecos/packages/io/can/current/src/can.c	2007-03-26 17:43:36.000000000 +0700
+++ ./io/can/current/src/can.c	2007-08-13 10:52:10.000000000 +0700
@@ -665,6 +665,27 @@
              }
              break;
         
+
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+        //
+        // Set callback configuration
+        // To disable callback set flag_mask = 0
+        //
+        case CYG_IO_SET_CONFIG_CAN_CALLBACK:
+             {
+                 if (*len != sizeof(cyg_can_callback_cfg))
+                 {
+                         return -EINVAL;
+                 }
+            
+                 // Copy data under DSR locking
+                 cyg_drv_dsr_lock();
+                 chan->callback_cfg = *((cyg_can_callback_cfg*) xbuf);
+                 cyg_drv_dsr_unlock();
+             }
+             break;
+#endif //CYGOPT_IO_CAN_SUPPORT_CALLBACK
+
         default:
             //
             // pass down to lower layers
@@ -695,6 +716,9 @@
 {
     can_cbuf_t       *cbuf   = &chan->in_cbuf;
     CYG_CAN_EVENT_T  *prxbuf = (CYG_CAN_EVENT_T *)cbuf->pdata;
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+    cyg_uint16        flags;
+#endif
     
     //
     // cbuf is a ring buffer - if the buffer is full, then we overwrite the
@@ -723,6 +747,10 @@
             cbuf->get = (cbuf->get + 1) % cbuf->len;
         }
         
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+        flags = prxbuf[cbuf->put].flags;
+#endif
+
         cbuf->put = (cbuf->put + 1) % cbuf->len;
         
         if (cbuf->waiting) 
@@ -730,6 +758,15 @@
             cbuf->waiting = false;
             cyg_drv_cond_broadcast(&cbuf->wait);
         }
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+        // Call application callback function, if any of the flag events 
+        // are unmasked.
+        if((flags & chan->callback_cfg.flag_mask) &&
+           (chan->callback_cfg.callback_func))
+        {
+            chan->callback_cfg.callback_func(flags, chan->callback_cfg.callback_data);
+        }
+#endif
     }
     
     cyg_drv_dsr_unlock();
ÐÐÐÑÐÐ Ð ./io/can/CVS: Entries.Log
--- /opt/ecos-repo/cvs/ecos/packages/io/common/current/include/config_keys.h	2006-09-21 23:34:21.000000000 +0700
+++ ./io/common/current/include/config_keys.h	2007-08-13 10:18:45.000000000 +0700
@@ -149,6 +149,7 @@
 #define CYG_IO_SET_CONFIG_CAN_MSGBUF                0x0886
 #define CYG_IO_SET_CONFIG_CAN_MODE                  0x0887
 #define CYG_IO_SET_CONFIG_CAN_ABORT                 0x0888
+#define CYG_IO_SET_CONFIG_CAN_CALLBACK              0x0889
 
 
 // ======== 0x1000 Generic ===================================================

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]