This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: mbox, ISR and DSR...
Andrew Lunn <andrew.lunn@ascom.ch> writes:
> > Hi,
> >
> > Is it safe to use mbox function in an ISR? and in a DSR?
>
> I've used cyg_mbox_tryput() in a DSR. Its worked so far. It seems a
> genaral rule of thumb is you can use anything that does not block in a
> DSR.
Absolutely right.
The reason we have ISRs and DSRs is to allow exactly that:
o ISRs are called right now regardless of kernel state, therefore you
cannot do calls into the kernel from an ISR.
o DSRs are called (when requested) as soon as possible after the
associated ISR, when the kernel state is such that it's safe to call
into the kernel.
A DSR still cannot sleep, because it is not a thread context; only threads
can sleep. Therefore only operations which cannot block may be called from
a DSR.
For example, Andrew says cyg_mbox_tryput() is OK. Correct. But
cyg_mbox_put() is NOT OK because it can block if the queue is full.
NB eCos does not (cannot) police this very well; you don't necessarily get
a neat assertion failure if you do call any old thing from an ISR, or if
you call sleep() from a DSR. Your app will go wrong, that's all; if it
appears to work, it's not working the way you think ;-) Just don't do it.
- Huge