Skip to content

Latest commit

 

History

History
36 lines (30 loc) · 1.01 KB

README.md

File metadata and controls

36 lines (30 loc) · 1.01 KB

SimplyAtomic

Finally a portable way to implement atomic blocks of code within Arduino projects.

Background

Many projects need a way to disable interrupts, perform some atomic operation, then restore the interrupt register to its previous state. A common solution is found in the AVRs util/atomic.h using these macros:

ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
{
  // Do some atomic operation inside here
}

The problem is this method only works on AVRs. Nowdays the Arduino ecosystem has expanded to many different architectures. SimplyAtomic creates one easy to use portable macro that accomplishes the same thing as ATOMIC_BLOCK(ATOMIC_RESTORESTATE)

Usage

Simply surround the critical sections of your program with the following macro:

// The interrupt status register will be saved here
ATOMIC()
{
  // Do some atomic operation inside here
}
// The interrupt status register will be restored here

Supported Platforms

  • AVR (Uno, Mega, etc...)
  • ARM (Zero, Due, etc...)
  • ESP8266
  • ESP32

License

BSD