This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: from ISR to thread
- From: harri dot siirtola at vtt dot fi
- To: Schmidt Henning Larsen <HenningLS at danfoss dot com>, "'ecos-discuss at sources dot redhat dot com'" <ecos-discuss at sources dot redhat dot com>
- Date: Wed, 05 Dec 2001 14:47:16 +0200
- Subject: Re: [ECOS] 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