Hello.
I am using EmbOS CortexM GCC V5.02 on an ATSAM4E8C.
I have a function which I would like to take different code paths if called from a thread or from a timer or interrupt handler.
Basically my function is normally called from a task, but because it uses a MUTEX, this will fail with OS Error 161 if called from a timer handler or 160 if called from an ISR.
Is it possible to determine if my function is called from a timer or interrupt handler, so I can take a different code path, avoiding trying to acquire the mutex?
I would like to do something like the following:
if (OS_InTimerHandler() || OS_In_ISR()) {
do_something_special();
} else {
if (0==OS_MUTEX_LockTimed(&my_mutex, 100)) {
error_mutex_timeout();
} else {
do_something_that_requires_mutex();
OS_MUTEX_Unlock(&my_mutex);
}
}
Note: The function also performs a number of other things before and after the mutex, so replacing all calls from within timer and interrupt handlers with a special version is not desirable.
Best regards
Mikkel Holm Olsen