This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: driver development, how to make timeouts?
- From: Sergei Gavrikov <sergei dot gavrikov at gmail dot com>
- To: Richard Rauch <rrauch at itrgmbh dot de>
- Cc: ecos-discuss at ecos dot sourceware dot org
- Date: Sat, 28 May 2011 20:15:12 +0300 (EEST)
- Subject: Re: [ECOS] driver development, how to make timeouts?
- References: <3B339ECBEFEE4E77BA2D6A564C8F9C8F@DESKTOPITRGMBH>
On Sat, 28 May 2011, Richard Rauch wrote:
> Hi all,
>
> How I have to implement a timeout inside an eCos Driver?
>
> I have following code, which is waiting on an interrupt event:
>
> cyg_drv_mutex_lock(&(extra->i2c_lock));
> cyg_drv_dsr_lock();
> while (!extra->i2c_completed) {
> cyg_drv_cond_wait(&(extra->i2c_wait));
> }
> cyg_drv_dsr_unlock();
> cyg_drv_mutex_unlock(&(extra->i2c_lock));
>
>
> The cyg_drv_cond_wait() never returns, as long as no interrupt occurs. But
> in special cases (if the hardware is not wired properly), there will be
> never an interrupt.
>
> How can I break in this function after a while?
>
> In normal user API, there is a function cyg_cond_timed_wait() which is able
> to return in case of timeout.
> I haven't found a similar function in driver's kernel API!
>
> Who knows a solution?
Hi,
There is such a precedent in io/can/current/src/can.c:
69 #ifdef CYGOPT_IO_CAN_SUPPORT_TIMEOUTS
70 #define CYG_DRV_COND_WAIT(_cond, _time) cyg_cond_timed_wait(_cond, cyg_current_time() + (_time))
71 #else
72 #define CYG_DRV_COND_WAIT(_cond, _time) cyg_drv_cond_wait(_cond)
But, keep in a mind that needs eCos kernel packages:
cdl_component CYGOPT_IO_CAN_SUPPORT_TIMEOUTS {
display "Support read/write timeouts"
flavor bool
default_value 0
active_if CYGPKG_KERNEL
^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
HTH
Sergei
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss