[ECOS] why is it wrong to call cyg_semaphore_post() in ISR???

Gary Thomas gary@mlbassoc.com
Thu Jun 8 18:06:00 GMT 2006


On Thu, 2006-06-08 at 18:41 +0200, Monica Dsz wrote:
> Hallo all,
> 
> I am new to eCos(and also to embedded). The eCos documentation says that ISR 
> should not involve any kernel calls.But I want to know why 
> cyg_semaphore_post() is not allowed in ISR(Interrupt service routine). It 
> doesnt block. and i tried to use it though documentation says we shouldnt. 
> It worked for me with the following code.
> 
> cyg_uint32 timer_isr(cyg_vector_t vector,cyg_addrword_t data)
> {
>   led_toggle();                    //Toggle the LED
> 
>   isr_counter++;                //32 bit ISR counter
> 
>   cyg_interrupt_acknowledge( vector ); //acknowledge the Interrupt to the 
> processor
> 
>   cyg_semaphore_post( &intr_occured );   //give the semaphore,so that task 
> waiting for it wakes up
> 
>   return( CYG_ISR_HANDLED  );          // Inform the kernel that ISR is 
> handled
> }
> 
> I wonder why in eCos,a semaphore cannot be posted in ISR. In VxWorks we can 
> give a semaphore in ISR. Can anybody give me a pointer to documentation or 
> an explanation for this.

ISR functions can be called at any time, so it's possible that you could
be executing code within the scheduler or even semaphore handling when
the ISR runs.  In this case, the various state [variables] in the system
may not be in a consistent state and allowing the ISR to change them 
would be catastrophic.

It's a trade off - do you prevent interrupts (hence ISR routines) from
running during all data critical sections or do you simply not allow
those [ISR] functions to execute code that might perturb critical data?
eCos chooses the latter method which allows for lower interrupt latency
by putting off things until the DSR can be safely run.

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------


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



More information about the Ecos-discuss mailing list