InterruptController Class Reference

yasimavr: InterruptController Class Reference
yasimavr
Loading...
Searching...
No Matches

Generic interrupt controller. More...

#include <sim_interrupt.h>

Inheritance diagram for InterruptController:
Peripheral IORegHandler ArchAVR_IntCtrl ArchXT_IntCtrl

Classes

struct  IRQ_t
 

Public Types

enum  SignalId { Signal_StateChange }
 
enum  State {
  State_Raised = 0x01 , State_Cancelled = 0x10 , State_Acknowledged = 0x20 , State_Returned = 0x30 ,
  State_RaisedFromSleep = 0x41 , State_Reset = 0x50
}
 

Public Member Functions

 InterruptController (unsigned int vector_count)
 
virtual void reset (int flags) override
 
virtual bool ctlreq (ctlreq_id_t req, ctlreq_data_t *data) override
 
virtual void sleep (bool on, SleepMode mode) override
 
bool cpu_has_irq () const
 
IRQ_t cpu_get_irq () const
 
void cpu_ack_irq ()
 
virtual void cpu_reti ()
 
- Public Member Functions inherited from Peripheral
 Peripheral (ctl_id_t id)
 
virtual ~Peripheral ()
 
ctl_id_t id () const
 Unique identifier of the peripheral.
 
std::string name () const
 The name of the peripheral.
 
virtual bool init (Device &device)
 
virtual uint8_t ioreg_read_handler (reg_addr_t addr, uint8_t value) override
 
virtual uint8_t ioreg_peek_handler (reg_addr_t addr, uint8_t value) override
 
virtual void ioreg_write_handler (reg_addr_t addr, const ioreg_write_t &data) override
 
 Peripheral (const Peripheral &)=delete
 
Peripheraloperator= (const Peripheral &)=delete
 
- Public Member Functions inherited from IORegHandler
virtual ~IORegHandler ()=default
 

Static Public Attributes

static constexpr IRQ_t NO_INTERRUPT = { AVR_INTERRUPT_NONE, 0, false }
 

Protected Member Functions

bool interrupt_raised (int_vect_t vector) const
 Interrupt state getter.
 
int_vect_t intr_count () const
 Interrupt table size getter.
 
void set_interrupt_raised (int_vect_t vector, bool raised)
 Interrupt state setter.
 
virtual void cpu_ack_irq (int_vect_t vector)
 
virtual IRQ_t get_next_irq () const =0
 
void update_irq ()
 
- Protected Member Functions inherited from Peripheral
Devicedevice () const
 Access to the device. It is null before init() is called.
 
Loggerlogger ()
 Logging object associated with this peripheral.
 
bool register_interrupt (int_vect_t vector, InterruptHandler &handler) const
 
Signalget_signal (ctl_id_t ctl_id) const
 
void add_ioreg (const regmask_t &rm, IORegister::BitMode bitmode=IORegister::RW)
 
void add_ioreg (const regbit_compound_t &rbc, IORegister::BitMode bitmode=IORegister::RW)
 
void add_ioreg (reg_addr_t addr, IORegister::BitMode bitmode=IORegister::RW)
 
void add_ioreg (reg_addr_t addr, bitmask_t mask, IORegister::BitMode bitmode=IORegister::RW)
 
uint8_t read_ioreg (const regbit_t &rb) const
 
uint64_t read_ioreg (const regbit_compound_t &rbc) const
 
uint8_t read_ioreg (reg_addr_t addr) const
 
uint8_t read_ioreg (reg_addr_t addr, const bitspec_t &bs) const
 
bool test_ioreg (const regbit_t &rb) const
 
bool test_ioreg (const regbit_compound_t &rbc) const
 
bool test_ioreg (reg_addr_t addr, const bitspec_t &bs) const
 
bool test_ioreg (reg_addr_t addr, bitmask_t bm=0xFF) const
 
void write_ioreg (reg_addr_t addr, bitmask_t bm, uint8_t value)
 
void write_ioreg (const regbit_t &rb, uint8_t value)
 
void write_ioreg (const regbit_compound_t &rbc, uint64_t value)
 
void write_ioreg (reg_addr_t addr, uint8_t value)
 
void write_ioreg (reg_addr_t addr, const bitspec_t &bs, uint8_t value)
 
void set_ioreg (reg_addr_t addr, bitmask_t bm=0xFF)
 
void set_ioreg (const regbit_t &rb)
 
void set_ioreg (const regbit_compound_t &rbc)
 
void set_ioreg (reg_addr_t addr, const bitspec_t &bs)
 
void clear_ioreg (reg_addr_t addr, bitmask_t bm=0xFF)
 
void clear_ioreg (const regbit_t &rb)
 
void clear_ioreg (const regbit_compound_t &rbc)
 
void clear_ioreg (reg_addr_t addr, const bitspec_t &bs)
 

Friends

class InterruptHandler
 

Detailed Description

Generic interrupt controller.

It manages an interrupt vector table that the CPU can access to know if a interrupt routine should be executed. Each interrupt vector may be allocated by a interrupt handler which controls the raise (or cancellation) of the interrupt.

The arbitration of priorities between vectors is left to concrete sub-classes.

See also
AVR_InterruptHandler

Member Enumeration Documentation

◆ SignalId

Enumerator
Signal_StateChange 

Signal ID for indicating that the state of an interrupt has changed. index is the vector index.

◆ State

Enumerator
State_Raised 

The interrupt is raised.

State_Cancelled 

The interrupt is cancelled.

State_Acknowledged 

The interrupt is acknowledged by the CPU and it's about to jump to the corresponding vector.

State_Returned 

The CPU returned from the interrupt routine.

State_RaisedFromSleep 

The interrupt is raised after leaving a sleep mode where it was masked.

State_Reset 

The interrupt is reset because the MCU is reset.

Constructor & Destructor Documentation

◆ InterruptController()

YASIMAVR_USING_NAMESPACE InterruptController::InterruptController ( unsigned int  vector_count)
explicit

Construct the controller with the given vector table size

Member Function Documentation

◆ cpu_ack_irq() [1/2]

void InterruptController::cpu_ack_irq ( )

Used by the CPU to acknowledge the IRQ obtained with cpu_get_irq().

◆ cpu_ack_irq() [2/2]

void InterruptController::cpu_ack_irq ( int_vect_t  vector)
protectedvirtual

Called by the CPU when it acknowledges a vector, i.e. it is about to execute the vector address in the flash.
The base implementation calls the ACK handler of the vector and raise the signal with the "Acknowledged" state.

Reimplemented in ArchXT_IntCtrl.

◆ cpu_get_irq()

InterruptController::IRQ_t InterruptController::cpu_get_irq ( ) const
inline

Used by the CPU to interrogate the controller whether an interrupt is raised.
If a valid vector is returned and the Global Interrupt Enable flag is set, the CPU initiates a jump to the corresponding routine.

Returns
a vector index if there is an IRQ raised, AVR_INTERRUPT_NONE if not.

◆ cpu_has_irq()

bool InterruptController::cpu_has_irq ( ) const
inline

Used by the CPU to do a quick test whether an interrupt is raised.

Returns
true if there is an IRQ raised.

◆ cpu_reti()

void InterruptController::cpu_reti ( )
virtual

Called by the CPU when returning from an ISR (executing a RETI instruction).
The base implementation calls update_irq to determine the next vector to be given to the CPU.

Reimplemented in ArchXT_IntCtrl.

◆ ctlreq()

bool InterruptController::ctlreq ( ctlreq_id_t  req,
ctlreq_data_t data 
)
overridevirtual

Virtual method called for a CTL request. The method must return true if the request has been processed.

Reimplemented from Peripheral.

◆ get_next_irq()

virtual IRQ_t InterruptController::get_next_irq ( ) const
protectedpure virtual

Abstract method indicating which vector should be executed next. Architecture specific behaviors can be implemented here to take into account priority arbitration between vectors.

Note
implementations should assume the GIE flag is set.
Returns
IRQ to be executed next or NO_INTERRUPT

Implemented in ArchXT_IntCtrl.

◆ interrupt_raised()

bool InterruptController::interrupt_raised ( int_vect_t  vector) const
inlineprotected

Interrupt state getter.

◆ intr_count()

int_vect_t InterruptController::intr_count ( ) const
inlineprotected

Interrupt table size getter.

◆ reset()

void InterruptController::reset ( int  flags)
overridevirtual

Virtual method called when the device is reset. Note that resetting I/O registers is only necessary here if their reset value is not zero.

Parameters
flagsReset flags (OR'ed combination of Device::ResetFlag enumeration values)

Reimplemented from Peripheral.

◆ set_interrupt_raised()

void InterruptController::set_interrupt_raised ( int_vect_t  vector,
bool  raised 
)
protected

Interrupt state setter.

◆ sleep()

void InterruptController::sleep ( bool  on,
SleepMode  mode 
)
overridevirtual

Virtual method called when the device enters or exits a sleep mode.

Parameters
ontrue when entering a sleep mode, false when exiting it.
modeone of the enum SleepMode values

Reimplemented from Peripheral.

◆ update_irq()

void InterruptController::update_irq ( )
protected

Update the controller, by storing the next vector to be given to the CPU

Friends And Related Symbol Documentation

◆ InterruptHandler

friend class InterruptHandler
friend

Member Data Documentation

◆ NO_INTERRUPT

constexpr IRQ_t InterruptController::NO_INTERRUPT = { AVR_INTERRUPT_NONE, 0, false }
staticconstexpr

The documentation for this class was generated from the following files: