Can I call function outside of ISR,from inside of an ISR which is call by other function(eg. from MAIN) in AT89S52 using C?
Asked
Active
Viewed 153 times
-2
-
Could you please explain with some pseudo code ? – MathiasE Mar 25 '17 at 09:44
1 Answers
1
Calling a function from an ISR in any architecture is legal - though not always advisable.
You need to consider whether the function in question is suitable for execution within interrupts and multiple thread contexts; for example it will need to be reentrant and must access shared resources atomically or in a manner that ensures consistency, and should not of course block or busy-wait indeterminately.
You may also need to consider stack requirement for calling the function and the function call overhead itself in terms of interrupt processing time. In-lining teh function might be considered.

Clifford
- 88,407
- 13
- 85
- 165
-
1Beware that the 8051 doesn't much like reentrant/recursive functions though, due to the architecture's restrictive stack and pointer arithmetic C compilers typically prefer statically allocated overlays in place of true stack storage for local variables. Therefore the callee tree may need to be specially marked to use a reentrant calling convention, depending on the particular compiler and its settings. – doynax Mar 25 '17 at 16:01
-
@doynax : All good points - I did mention the need to consider stack requirement, and suggested that it is not always advisable - even when possible. This is especially true on such constrained environments, and you have elaborated on some of architecture specific considerations. Thanks. – Clifford Mar 25 '17 at 16:13