This is the mail archive of the ecos-discuss@sources.redhat.com 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: Blocking design


On Mon, 2004-02-09 at 15:37, Matt Jerdonek wrote:
> Hi Folks,
> 
> I'd like to have my device driver block while waiting
> for the hardware to complete its task.  My basic
> design is this:
> 
> void invoke_hardware(void)
> {
>      cyg_drv_mutex_lock(&mutex);
>      done = false;
>      start_hardware();
>      while (!done)
>         cyg_drv_cond_wait(&cond);
>      cyg_drv_mutex_unlock(&mutex);
> }
> 
> void hardware_complete_dsr(void)
> {
>       done = true;
>       cyg_drv_cond_signal(&cond);
> }
> 
> Here's my concern ... The code appears to work fine,
> but I think there is a window (albeit small) between
> the start_hardware() and the cyg_drv_cond_wait() where
> the hardware could complete, trigger the DSR, and
> signal the condition variable before the thread has
> done the cyg_drv_cond_wait().  If this occurred, the
> thread would block indefinitely.
> 
> I'd like to find a way to guarantee the thread is
> waiting on the condition variable before starting the
> hardware.  I can't disable the scheduler, ISRs or DSRs
> because the cyg_drv_cond_wait will block and prevent
> me from re-enabling them.
> 
> Is this a realistic concern?  Any suggestions?

Yes, but your concerns are a bit unfounded.  Use "cyg_drv_dsr_lock()"
and "cyg_drv_dsr_unlock()" [which are just calls to lock/unlock the
scheduler, but it's best to follow the same API].  When your thread
blocks by calling 'cyg_drv_cond_wait()', the scheduler will be unlocked
as necessary.

You also may need to consider adding a call to 'cyg_drv_isr_lock()'
around the 'start_hardware()' call, otherwise an interrupt [from your
device] could occur before that function completes.

-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss


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