how to set different interrupt priority in the code

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,
I want to set SIG_INPUT_CAPTURE1 to have the first priority and SIG_INPUT_CAPTURE3 the second and SIG_OVERFLOW3 the third, but I think INTERRUPT and SIGNAL will only allow me to have two different type of priorities, so how can I have another type?

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You cannot change the priorities of interrupts on the AVR.. they are fixed. The AVR really only has 2 operating levels. Interrupts enabled, and Interrupts Disabled. In theory one could create a priority system through software, but it is unlikely to be worth the overhead.

INTERRUPT and SIGNAL have little to do with priority. If you define your handler using INTERRUPT, it means that interrupts are enabled while it is executing, allowing ANY other interrupt to preempt it, including one with lower priority.

Using SIGNAL, on the other hand, leaves interrupts disabled for the duration of execution of the handler. This means that NO other interrupt, higher, or lower, can preempt it's execution.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, glitch, then I will try to think of another way around

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Keep your interrupts crisp and short. Just capture the data and get out. Do any processing outside the interrupts.

Laurence Boyd II

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
In theory one could create a priority system through software, but it is unlikely to be worth the overhead.

Actually it only takes a few instructions, not much overhead. It is, however, something that should probably be done in assembler, to make sure you get exactly what you expect with minimum overhead. You wouldn't want the compiler to call a couple of nested subroutines to modify the mask, for example.

Enter ISR - interrupts are disabled
  [Save registers as required]
  1  Read/save interrupt mask register(s)
  2  Clear bits in mask register(s) for lower priority interrupt(s)
  3  Enable interrupts (SEI)
  [body of ISR]
  4  Disable interrupts (CLI)
  5  Restore original mask register(s)
  [Restore registers as required]
RETI