====== Introduction ======

The core module (acronym: core) should provide the functionality of a CPU core.

====== Basic assumptions ======

The microcontroller has at least one CPU core.
The microcontroller can have many CPU cores.
The core module should provide functionality to:
  * globally enable and disable all interrupts (done)
  * mask only desired interrupts (maybe up to some level? maybe this should go to a specialized interrupt controller class?)
  * deliver nestable critical sections (still TODO)

====== Class diagram ======

<uml>
class Core {
virtual void enableInterrupts() = 0
virtual void disableInterrupts() = 0
}
namespace stm32 {
class Core {
virtual void inline enableInterrupts();
virtual void inline disableInterrupts();
}
.Core <|-- Core
}
</uml>

====== Performance requirement ======

Let's assume that the Core class is somehow instantiated, and the resulting object is named: core.
This should always inline:
<code cpp>
core.enableInterrupts();
</code>
So for example, an an ARM Cortex-Mx, this should boil down to a single ASM instruction:
<code asm>
cpsie	i
</code>

====== The proposed solution ======

Here's the proposed solution in C++11:

<code cpp>
namespace hal {

/// Base core interface class
class Core
{
public:
    virtual inline void enableInterrupts() const = 0;
    virtual inline void disableInterrupts() const  = 0;
};

} // namespace hal
</code>


<code cpp>
namespace hal {

namespace stm32f4 {

class Core : public hal::Core
{
public:
    inline void enableInterrupts() const override __attribute__((always_inline))
    {
        asm volatile ("cpsie i");
    }
    inline void disableInterrupts() const override __attribute__((always_inline))
    {
	asm volatile ("cpsid i");
    }
    constexpr Core() { ; }
};

const extern Core core;

} // namespace stm32f4

} // namespace hal
</code>

Usage:

<code cpp>
using namespace hal::stm32f4;

core.enableInterrupts();
core.disableInterrupts();
</code>

====== The virtual-inline-singleton problem ======

Here's the thing that I haven't figured out yet:
How to declare a class that is a singleton, derrived from a base class and which methods can be inlined.

====== Open questions ======

Should an interrupt controller be a part of the core module or does it deserve a separate module ?