* CAN waking calls
@ 2007-08-06 3:48 Alexey Shusharin
2007-08-10 14:18 ` Andrew Lunn
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Shusharin @ 2007-08-06 3:48 UTC (permalink / raw)
To: ecos-patches
[-- Attachment #1: Type: text/plain, Size: 199 bytes --]
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.
Best regards
Alexey Shusharin
[-- Attachment #2: iocan_waking.patch.tar.gz --]
[-- Type: application/x-compressed-tar, Size: 2193 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: CAN waking calls
2007-08-06 3:48 CAN waking calls Alexey Shusharin
@ 2007-08-10 14:18 ` Andrew Lunn
2007-08-13 4:30 ` Alexey Shusharin
0 siblings, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2007-08-10 14:18 UTC (permalink / raw)
To: Alexey Shusharin; +Cc: ecos-patches
[-- Attachment #1: Type: text/plain, Size: 718 bytes --]
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
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.
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.
Do you think you could add a testcase to the can loop back driver
which uses this feature?
Thanks
Andrew
[-- Attachment #2: can_callback.diff --]
[-- Type: text/x-diff, Size: 7409 bytes --]
Index: io/can/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/can/current/ChangeLog,v
retrieving revision 1.10
diff -u -r1.10 ChangeLog
--- io/can/current/ChangeLog 31 Jul 2007 09:04:16 -0000 1.10
+++ io/can/current/ChangeLog 10 Aug 2007 14:15:06 -0000
@@ -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
Index: io/can/current/cdl/io_can.cdl
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/can/current/cdl/io_can.cdl,v
retrieving revision 1.4
diff -u -r1.4 io_can.cdl
--- io/can/current/cdl/io_can.cdl 3 Jul 2007 14:42:18 -0000 1.4
+++ io/can/current/cdl/io_can.cdl 10 Aug 2007 14:15:06 -0000
@@ -217,7 +217,18 @@
which allows clients to switch read() and write() call
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
Index: io/can/current/include/can.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/can/current/include/can.h,v
retrieving revision 1.3
diff -u -r1.3 can.h
--- io/can/current/include/can.h 26 Mar 2007 10:43:36 -0000 1.3
+++ io/can/current/include/can.h 10 Aug 2007 14:15:06 -0000
@@ -168,15 +168,23 @@
//
struct can_channel
{
- can_lowlevel_funs *funs;
- can_callbacks_t *callbacks;
- void *dev_priv; // Whatever is needed by actual device routines
- cyg_can_info_t config; // Current configuration
- 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
+ can_lowlevel_funs *funs;
+ can_callbacks_t *callbacks;
+ void *dev_priv; // Whatever is needed by actual device routines
+ cyg_can_info_t config; // Current configuration
+ 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}
+#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 \
};
Index: io/can/current/include/canio.h
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/can/current/include/canio.h,v
retrieving revision 1.6
diff -u -r1.6 canio.h
--- io/can/current/include/canio.h 31 Jul 2007 09:04:16 -0000 1.6
+++ io/can/current/include/canio.h 10 Aug 2007 14:15:06 -0000
@@ -327,6 +327,23 @@
#define CYGNUM_CAN_HDI_TIMESTAMP 0x10 // driver supports timestamps
+//
+// Callback configuration structure.
+//
+
+typedef void (*cyg_can_event_cb_t)(cyg_uint16);
+//
+// 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_uint16 flag_mask; // flags mask
+} cyg_can_callback_cfg;
+
+
//===========================================================================
// CAN MESSAGE ACCESS MACROS
//
Index: io/can/current/src/can.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/io/can/current/src/can.c,v
retrieving revision 1.4
diff -u -r1.4 can.c
--- io/can/current/src/can.c 26 Mar 2007 10:43:36 -0000 1.4
+++ io/can/current/src/can.c 10 Aug 2007 14:15:07 -0000
@@ -665,6 +665,27 @@
}
break;
+
+#ifdef CYGOPT_IO_CAN_SUPPORT_CALLBACK
+ //
+ // Set waking calls configuration
+ // To disable waking calls set waking_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
@@ -722,7 +746,11 @@
prxbuf[cbuf->put].flags |= CYGNUM_CAN_EVENT_OVERRUN_RX;
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);
+ }
+#endif
}
cyg_drv_dsr_unlock();
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: CAN waking calls
2007-08-10 14:18 ` Andrew Lunn
@ 2007-08-13 4:30 ` Alexey Shusharin
2007-08-13 7:40 ` Andrew Lunn
0 siblings, 1 reply; 4+ messages in thread
From: Alexey Shusharin @ 2007-08-13 4:30 UTC (permalink / raw)
To: Andrew Lunn; +Cc: ecos-patches
[-- Attachment #1: Type: text/plain, Size: 1087 bytes --]
Ð ÐÑн, 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
[-- Attachment #2: can_callback2.diff --]
[-- Type: text/x-patch, Size: 6501 bytes --]
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
[-- Attachment #3: iocommon_keys.diff --]
[-- Type: text/x-patch, Size: 539 bytes --]
--- /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 ===================================================
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: CAN waking calls
2007-08-13 4:30 ` Alexey Shusharin
@ 2007-08-13 7:40 ` Andrew Lunn
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Lunn @ 2007-08-13 7:40 UTC (permalink / raw)
To: Alexey Shusharin; +Cc: ecos-patches
> 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.
Thanks for testing it and adding the data pointer. I have committed
the patch now.
Andrew
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-08-13 7:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-06 3:48 CAN waking calls Alexey Shusharin
2007-08-10 14:18 ` Andrew Lunn
2007-08-13 4:30 ` Alexey Shusharin
2007-08-13 7:40 ` Andrew Lunn
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).