Anonymous user
Interrupt Service Routines: Difference between revisions
Jump to navigation
Jump to search
→Compiler Specific Directives: added clang, cleaned up
[unchecked revision] | [unchecked revision] |
mNo edit summary |
(→Compiler Specific Directives: added clang, cleaned up) |
||
Line 66:
</source>
===Compiler Specific Interrupt Directives===
Some compilers for some processors have directives allowing you to declare a routine interrupt, offer a #pragma interrupt, or a dedicated macro. Borland C, Watcom C/C++, Microsoft C 6.0 and Free Pascal Compiler 1.9.* and up offer this, while VisualC++ and GCC don't:▼
▲Some compilers for some processors have directives allowing you to declare a routine interrupt, offer a #pragma interrupt, or a dedicated macro. Borland C, Watcom C/C++, Microsoft C 6.0 and Free Pascal Compiler 1.9.* and up offer this, while
====Borland C====
<source lang="C">
/* Borland C */
Line 78:
</source>
====Watcom C/C++====
<source lang="C">
/* Watcom C/C++ */
Line 86 ⟶ 87:
</source>
====Naked Functions====
Some Compilers can be used to make interrupt routines, but requires you to manually handle the stack and return operations. Doing so requires that the function be generated without an epilogue or prologue. This is called making the function ''naked'' - this is done in Visual C++ by adding the attribute ''_declspec(naked)'' and in clang-llvm by adding the attribute ''__attribute__((naked))'' to the function. You need to verify that you do include a return operation (such as ''iretd'') as that is part of the prologue that the compiler has now been instructed to not include.
If you intend to use local variables, you must set up the stack frame in the manner which the compiler expects; as ISRs are non-reentrant, however, you can simply use static variables.
=====Visual C++=====
<source lang="C">
Line 102 ⟶ 108:
}
</source>
=====clang-llvm=====
<source lang="C">
/* clang-llvm */
__attribute__((naked)) void interrupt_handler()
{
asm ("pushad");
/* do something */
asm (
"popad" \
"iretd"
);
}
</source>
====gcc / g++====
gcc nor g++ offer any means by which to have an interrupt service routine be only in C/C++ without performing '''black magic'''.
===Black Magic===
|