libtonc
Interrupt

Hardware interrupt management. More...

Data Structures

struct  IRQ_REC
 Struct for prioritized irq table. More...
 

Typedefs

typedef enum eIrqIndex eIrqIndex
 IRQ indices, to be used in most functions.
 

Enumerations

enum  eIrqIndex {
  II_VBLANK =0 , II_HBLANK , II_VCOUNT , II_TIMER0 ,
  II_TIMER1 , II_TIMER2 , II_TIMER3 , II_SERIAL ,
  II_DMA0 , II_DMA1 , II_DMA2 , II_DMA3 ,
  II_KEYPAD , II_GAMEPAK , II_MAX
}
 IRQ indices, to be used in most functions.
 

Variables

u32 IRQ_REC::flag
 Flag for interrupt in REG_IF, etc.
 
fnptr IRQ_REC::isr
 Pointer to interrupt routine.
 

Options for irq_set

typedef struct IRQ_REC IRQ_REC
 Struct for prioritized irq table.
 
IRQ_REC __isr_table [II_MAX+1]
 Last isr in line (Lowest priority)
 
IWRAM_CODE void isr_master (void)
 Last isr in line (Lowest priority)
 
IWRAM_CODE void isr_master_nest (void)
 Last isr in line (Lowest priority)
 
void irq_init (fnptr isr)
 Initialize irq business.
 
fnptr irq_set_master (fnptr isr)
 Set a master ISR.
 
fnptr irq_add (enum eIrqIndex irq_id, fnptr isr)
 Add a specific ISR.
 
fnptr irq_delete (enum eIrqIndex irq_id)
 Remove an ISR.
 
fnptr irq_set (enum eIrqIndex irq_id, fnptr isr, u32 opts)
 General IRQ manager.
 
void irq_enable (enum eIrqIndex irq_id)
 Last isr in line (Lowest priority)
 
void irq_disable (enum eIrqIndex irq_id)
 Last isr in line (Lowest priority)
 
#define ISR_LAST   0x0040
 Last isr in line (Lowest priority)
 
#define ISR_REPLACE   0x0080
 Replace old isr if existing (prio ignored)
 
#define ISR_PRIO_MASK   0x003F
 Last isr in line (Lowest priority)
 
#define ISR_PRIO_SHIFT   0
 Last isr in line (Lowest priority)
 
#define ISR_PRIO(n)   ((n)<<ISR_PRIO_SHIFT)
 Last isr in line (Lowest priority)
 
#define ISR_DEF   (ISR_LAST|ISR_REPLACE)
 Last isr in line (Lowest priority)
 
#define IRQ_INIT()   irq_init(NULL)
 Default irq_init() call: use irq_master_nest() for switchboard.
 
#define IRQ_SET(irq_id)   irq_set(II_##irq_id, NULL, ISR_DEF)
 Default irq_set() call: no isr, add to back of priority stack.
 
#define IRQ_ADD(irq_id)   irq_add(II_##irq_id, NULL)
 Last isr in line (Lowest priority)
 

Detailed Description

Hardware interrupt management.

For details, see tonc:irq

Function Documentation

◆ irq_add()

fnptr irq_add ( enum eIrqIndex  irq_id,
fnptr  isr 
)

Add a specific ISR.

Special case of irq_set. If the interrupt has an ISR already it'll be replaced; if not it will add it in the back.

Parameters
irq_idIndex of irq.
isrInterrupt service routine for this irq; can be NULL
Returns
Previous ISR
Note
irq_id is NOT a bit-mask, it is an index!

References __isr_table, BIT, IRQ_REC::flag, IRQ_SENDER::flag, IRQ_REC::isr, REG_BASE, REG_IE, REG_IME, and IRQ_SENDER::reg_ofs.

◆ irq_delete()

fnptr irq_delete ( enum eIrqIndex  irq_id)

Remove an ISR.

it'll be replaced; if not it will add it in the back.

Parameters
irq_idIndex of irq.
Returns
Previous ISR
Note
irq_id is NOT a bit-mask, it is an index!

References __isr_table, BIT, IRQ_REC::flag, IRQ_SENDER::flag, IRQ_REC::isr, REG_BASE, REG_IE, REG_IME, and IRQ_SENDER::reg_ofs.

◆ irq_init()

void irq_init ( fnptr  isr)

Initialize irq business.

Clears ISR table and sets up a master isr.

Parameters
isrMaster ISR. If NULL, isr_master_nest is used

References __isr_table, isr_master(), memset32(), REG_IME, and REG_ISR_MAIN.

◆ irq_set()

fnptr irq_set ( enum eIrqIndex  irq_id,
fnptr  isr,
u32  opts 
)

General IRQ manager.

This routine manages the ISRs of interrupts and their priorities.

Parameters
irq_idIndex of irq.
isrInterrupt service routine for this irq; can be NULL
optsISR options
Returns
Previous specific ISR
Note
irq_id is NOT a bit-mask, it is an index!

References __isr_table, BIT, IRQ_REC::flag, IRQ_SENDER::flag, IRQ_REC::isr, ISR_LAST, ISR_PRIO_MASK, ISR_REPLACE, REG_BASE, REG_IE, REG_IME, and IRQ_SENDER::reg_ofs.

◆ irq_set_master()

fnptr irq_set_master ( fnptr  isr)

Set a master ISR.

Parameters
isrMaster ISR. If NULL, isr_master_multi is used
Returns
Previous master ISR

References isr_master(), REG_IME, and REG_ISR_MAIN.