This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
RE: ISR+thread synchronization problem
- From: Schmidt Henning Larsen <HenningLS at danfoss dot com>
- To: 'jagadisha maiya' <pjmaiya at c4 dot com>, ecos-discuss at sources dot redhat dot com
- Date: Fri, 25 Jan 2002 09:09:15 +0100
- Subject: RE: [ECOS] ISR+thread synchronization problem
Hi.
I've made myself a generic buffer that I use everytime I have to get data
from ISR to thread.
Any comments to the code are welcome.
Henning
#include "include/cyg/kernel/kapi.h"
/*
irquffer is a fifo-buffer, that can be used to send data from a ISR to a
thread
can only be used in one to one communication
Caution: put(T x) must be called from the ISR
notify() must be called from the DSR
get() must be called from the thread
*/
template <class T, int size>
class irqbuffer
{
private:
T arr[size];
int fsize, inn, out,fmax;
cyg_sem_t seEmpty;
public:
irqbuffer();
~irqbuffer();
void put(T x);
void notify();
T get();
};
template<class T, int size>
irqbuffer<T, size>::irqbuffer():fsize(0), fmax(size)
{
cyg_semaphore_init(&seEmpty, 0);
inn=out=0;
}
template<class T, int size>
irqbuffer<T, size>::~irqbuffer()
{
// NOP;
}
template<class T, int size>
void irqbuffer<T, size>::put(T x)
{
// If full then there perhaps should be som handling
arr[inn++]=x;
inn %= fmax;
++fsize;
}
template<class T, int size>
void irqbuffer<T, size>::notify()
{
cyg_semaphore_post(&seEmpty);
}
template<class T, int size>
T irqbuffer<T, size>::get()
{
cyg_semaphore_wait(&seEmpty);
T result = arr[out++];
out %= fmax;
--fsize;
return result;
}
> -----Original Message-----
> From: jagadisha maiya [mailto:pjmaiya@c4.com]
> Sent: 25. januar 2002 02:25
> To: ecos-discuss@sources.redhat.com
> Subject: [ECOS] ISR+thread synchronization problem
>
>
> hi,
>
> I was reading the mailing list regarding the ISR and thread
> synchronization problem. In my project also I am also facing
> the same problem. But mine is quite strange..
>
> I am not using DSR.
>
> ISR uses semaphore to post the event and task uses semaphore
> wait for receiving the event.
>
> I am using counting semaphore with inital value '0' to use as
> a binary semaphore.
>
>
>
> When an ISR post an event through semaphore, the task which
> waits on the semaphore gets triggered and it services the data.
>
>
>
> After long time task stops accepting the event and found to
> be gone for blocking state.
>
> From there onwards any posting of the event from ISR never
> invokes the thread.
>
>
>
> Can U give some suggestion to over come this apart from DSR.
> Can any body tell me why the task went into blocking state
> even if it could have been unblocked after receiving posted events.
>
>
>
> thanx for help,
>
> pjmaiya
>
>
>
> --------------------------------------------------
>
>
>
> Totally Amazing Search Results - Just C4 Yourself!
>
>
>
> http://www.C4.com - Total Search Technology
>