Class InterruptFlag

Inheritance Relationships

Base Type

Class Documentation

class InterruptFlag : public InterruptHandler

Generic helper to manage an Interrupt Flag/Enable in a I/O register.

The flag is made of one or several bits of a I/O register, along with corresponding enable bit(s).

The interrupt is raised if and only if at least one flag bit and its corresponding enable bit are set.

The flag can be configured to clear-on-ack. If enabled, the flag will be cleared when the interrupt is ACK’ed by the CPU. If disabled, the flag will be unchanged by a CPU ACK’ed. The effect is to keep the interrupt raised until the flag is cleared directly in the register.

Public Functions

explicit InterruptFlag(bool clear_on_ack = false)

Construct an Interrupt Flag.

Parameters:

clear_on_ack – if true, the flag will be cleared when the interrupt is ACK’ed by the CPU. If false, (default) the flag can only be cleared by writing to the register.

InterruptFlag(const InterruptFlag &other)
bool init(Device &device, const regbit_t &rb_enable, const regbit_t &rb_flag, int_vect_t vector)

Initialise an Interrupt Flag. Allocates the registers for the flag and the enable register fields and register with the interrupt controller for a particular vector.

Note

If the vector is < 0, then no interrupt is registered. (can be used for future or unsupported features)

Note

Registering with the reset vector (vector 0) is an error.

Parameters:
  • rb_enable – register location for the flag enable bits

  • rb_flag – register location for the flag state bits

  • vector – interrupt vector index

Returns:

true if allocations and registrations are successful, false otherwise

void set_clear_on_ack(bool clear_on_ack)

Set the clear_on_ack mode.

Parameters:

clear_on_ack – if true, the flag will be cleared when the interrupt is ACK’ed by the CPU. If false, (default) the flag can only be cleared by writing to the register.

int update_from_ioreg()

Update the state of the interrupt flag according to the value of the I/O registers. This should be called whenever the flag registers are written. Allocates the registers for the flag and the enable register fields.

Returns:

+1 if the interrupt has been raised as a result of the update, -1 if it has been cleared, 0 if unchanged.

bool set_flag(uint8_t mask = 0xFF)

Set the interrupt flag bits by OR’ing them with the mask argument.

Returns:

true if the interrupt is raised as a result of the flag bit changes, false if the interrupt is unchanged.

bool clear_flag(uint8_t mask = 0xFF)

Clear the interrupt flag bits by AND’ing them with the mask argument.

Returns:

true if the interrupt is canceled as a result of the flag bit changes, false if the interrupt is unchanged.

inline bool raised() const

Returns the raised state of the interrupt flag.

virtual void interrupt_ack_handler(int_vect_t vector) override

Callback method called when a vector has been ACK’ed by the CPU. (i.e. the CPU is about to jump to the corresponding vector table entry)

The default implementation does nothing.