From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8114 invoked by alias); 13 Aug 2007 04:30:39 -0000 Received: (qmail 6935 invoked by uid 22791); 13 Aug 2007 04:30:31 -0000 X-Spam-Status: No, hits=-0.8 required=5.0 tests=AWL,BAYES_00,DK_POLICY_SIGNSOME,SARE_FREE_WEBM_RuMail,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx28.mail.ru (HELO mx28.mail.ru) (194.67.23.67) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 13 Aug 2007 04:30:27 +0000 Received: from mx27.mail.ru (mx27.mail.ru [194.67.23.64]) by mx28.mail.ru (mPOP.Fallback_MX) with ESMTP id 34AA66C4802 for ; Mon, 13 Aug 2007 08:30:23 +0400 (MSD) Received: from [85.195.160.38] (port=45857 helo=[10.0.0.3]) by mx27.mail.ru with asmtp id 1IKRZD-000G1x-00; Mon, 13 Aug 2007 08:30:11 +0400 Subject: Re: CAN waking calls From: Alexey Shusharin To: Andrew Lunn Cc: ecos-patches@sourceware.org In-Reply-To: <20070810141846.GI13510@lunn.ch> References: <1186372023.14247.14.camel@killix> <20070810141846.GI13510@lunn.ch> Content-Type: multipart/mixed; boundary="=-IoSQtSLXCCzlIZIHhCN2" Date: Mon, 13 Aug 2007 04:30:00 -0000 Message-Id: <1186979203.9271.30.camel@killix> Mime-Version: 1.0 X-Mailer: Evolution 2.10.2 (2.10.2-2.fc7) X-Virus-Checked: Checked by ClamAV on sourceware.org X-IsSubscribed: yes Mailing-List: contact ecos-patches-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: ecos-patches-owner@ecos.sourceware.org X-SW-Source: 2007-08/txt/msg00015.txt.bz2 --=-IoSQtSLXCCzlIZIHhCN2 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-length: 1067 В Птн, 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 --=-IoSQtSLXCCzlIZIHhCN2 Content-Disposition: attachment; filename=can_callback2.diff Content-Type: text/x-patch; name=can_callback2.diff; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-length: 6473 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 + Andrew Lunn + + * 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 * 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 --=-IoSQtSLXCCzlIZIHhCN2 Content-Disposition: attachment; filename=iocommon_keys.diff Content-Type: text/x-patch; name=iocommon_keys.diff; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 539 --- /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 =================================================== --=-IoSQtSLXCCzlIZIHhCN2--