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: from ISR to thread


At 13:28 5.12.2001 +0100, Schmidt Henning Larsen wrote:
>Hi
>...
>Condition variable: cond
>Hardware data: hw
>Ringbuffer: rbuf
>
>Threadcode:
>{
>  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++)
  dosomething(data);

in your DSR:

cyg_semaphore_post(sem)

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


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

Hope I succeeded ;)

Happy coding,
	Harri


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