[ECOS] from ISR to thread

harri.siirtola@vtt.fi harri.siirtola@vtt.fi
Wed Dec 5 04:48:00 GMT 2001

At 13:28 5.12.2001 +0100, Schmidt Henning Larsen wrote:
>Condition variable: cond
>Hardware data: hw
>Ringbuffer: rbuf
>  while(1)
>  {
>    cyg_drv_cond_wait(cond)
>    data = rbuf.getdata()
>    doSomething(data)
>  }
>ISR code:
>  rbuf.putdata(hw.data)
>  cyg_drv_interrupt_mask() // don't allow interrupt on this device
>  cyg_drv_interrupt_acknowledge()
>  return cyg_isr_call_dsr
>DSR code
>  cyg_drv_cond_signal(cond)
>  cyg_drv_interrupt_unmask() // allow interrupt on this device
>This will not work, because if a new interrupt appears while the thread is
>"doingSomething", the thread will not be notified because it hasn't returned
>to the condition variable. When the tread returns to the condition variable
>it has missed the notify, and don't know that it actually should run once
>more. The problem is that we can't call a counting semaphore.

Yes it does, eCos has counting semaphores, too. The type cyg_sem_t is such,
and all you have to do in your thread is something like this:

while (cyg_sem_trywait(sem)) Counter++;

for (i=0; i<Counter; i++)

in your DSR:


every post increments "sem" so you won't miss any. I'm using this all the

>I hope someone can tell me if I'm wrong.

Hope I succeeded ;)

Happy coding,

More information about the Ecos-discuss mailing list