I'm converting a library from AVR to SAMD. In my original code I'm setting up a hardware timer interrupt. Prior to doing the set up I call cli(); and after completing the set up I call sei(); to temporarily disable and enable interrupts. Is there an equivalent system in Arduino Zero SAMD 21 and related boards?
Yep, there are Cortex M specific functions :
__disable_irq(); //disable all interrupts __enable_irq(); //enable all interrupts
The high level Arduino cross device equivalents defined are :
noInterrupts(); //disable all interrupts interrupts(); //enable all interrupts
The low level assembly equivalents are :
__ASM volatile ("cpsid i"); //disable all interrupts __ASM volatile ("cpsie i"); //enable all interrupts
So I can just replace my cli() with noInterrupts() and sei() with interrupts() and I will be good on either platform?
Those calls to cli and sei were left over from a previous library that I didn't write. So I wasn't really 100% certain of the consequences.
Thanks for the reply.
Yep, absolutely. You can see in arduino.h what interrupts() and noInterrupts() are actually calling. For AVR it is sei() and cli(), and for SAMD core it is __disable_irq() and __enable_irq().