Yes, you can. You just have to make sure your function is reentrant. If
If it accesses no memory beyond its parameters and (non static) local variables
variables, you should be fine. But bewareIf it accesses global variables, hardware
registers, or static locals, it is unlikely to be, and only detailed
analysis will tell you for sure.
Beware also of the library functions you call: some of them are not themselves
themselves reentrant and should therefore be avoided. See for example
the manual of strtok(), which explicitly addresses the
reentrancy problem.