Summary

Keep the following things in mind when dealing with interrupts:

  • Don't take too long in an ISR—perform the minimum amount of work you can get away with. This helps minimize interrupt latency and debugging.
  • Use InterruptAttach() when you need to access the hardware as soon as the interrupt occurs; otherwise, avoid it.
  • Use InterruptAttachEvent() at all other times. The kernel will schedule a thread (based on the event that you passed) to handle the interrupt.
  • Protect variables used by both the interrupt service routine (if using InterruptAttach()) and threads by calling InterruptLock() and InterruptUnlock().
  • Declare variables that are going to be used between the thread and the ISR as volatile so that the compiler isn't caching stale values that have been changed by the ISR.
Page updated: