using interrupts

Hi,
for using interrupts I have two questions:

A) Generally, when using variables which are used within interrupt handlers then access to those variables shall be protected against beeing changed during access by an interrupt.

Here in the forum and some code examples I learned two methods to do so:

  1. enclose the acces code between NVIC_DISABLE_IRQ(interrupt_handler) and NVIC_ENABLE_IRQ(interrupt_handler)
    example:
NVIC_DISABLE_IRQ(myTimer);
    var_copy=var_handler;
    NVIC_ENABLE_IRQ(myTimer);
    // continue using var_copy instead of var_handler
  1. use ATOMIC_BLOCK
    example:
ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
          {
            var_copy=var_handler;
          }
          // continue using var_copy instead of var_handler

Is there a difference what method to use and what is the better method?

B) To set the priority level for an interrupt I need to know what interrupt levels are used elsewhere, e.g. system timer, serial interfaces, libraries, etc.

Is there a rule how to set user interrupt priorities?

Is there a method to find out what interrupts are used elsewhere?

Is there a difference what method to use and what is the better method?

Just use cli() and sei().

Is there a rule how to set user interrupt priorities?

Yes. A very simple rule. You can't.

Is there a method to find out what interrupts are used elsewhere?

Yes, see what code is included and inspect that code to see what interrupts it uses.

Delta_G:
Yes. A very simple rule. You can't.

Perhaps not on an AVR. But certainly on an ARM with NVIC.

gfvalvo:
Perhaps not on an AVR. But certainly on an ARM with NVIC.

When OP doesn't say what they're using I assume it's a normal AVR Arduino. If they're using something else and that answer doesn't fit then perhaps they should have mentioned that they are using something else.