GCC provides a couple of special builtin functions to aid in the writing of interrupt handlers in C.
__bic_SR_register_on_exit (int mask)
__bis_SR_register_on_exit (int mask)
__delay_cycles (long long cycles)
cyclescycles (between 0 and about 17E9) to complete. The inserted sequence may use jumps, loops, or no-ops, and does not interfere with any other instructions. Note that
cyclesmust be a compile-time constant integer - that is, you must pass a number, not a variable that may be optimized to a constant later. The number of cycles delayed by this builtin is exact.