Skip to content

File scopedirqblocker.h

File List > external-docs > libDaisy > src > util > scopedirqblocker.h

Go to the documentation of this file

Source Code

#pragma once

#include <stdint.h>

#ifndef UNIT_TEST // provide dummy implementation for unit tests
extern "C"
{
#include <cmsis_gcc.h>
}

namespace daisy
{
class ScopedIrqBlocker
{
  public:
    ScopedIrqBlocker()
    {
        prim_ = __get_PRIMASK();
        __disable_irq();
    }

    ~ScopedIrqBlocker()
    {
        if(!prim_)
            __enable_irq();
    }

  private:
    uint32_t prim_;
};
} // namespace daisy

#else // ifndef UNIT_TEST

namespace daisy
{
class ScopedIrqBlocker
{
  public:
    ScopedIrqBlocker(){};
    ~ScopedIrqBlocker() = default;
};
} // namespace daisy

#endif