Next Previous Contents

3.178 set_irq


Set the C level interrupt request vector to the given address.




void __fastcall__ set_irq (irq_handler f, void *stack_addr, size_t stack_size);


set_irq allows a user program to handle interrupt requests (IRQs) within the program code by letting the vector point to a user written C function. The runtime library installs a small stub that saves the zero page registers used by the C runtime before calling the handler function and restores them after the handler function returns. Additionally the stub temporarily switches the C runtime stack to the stack area provided as parameter. If the handler function was set up to handle a "private", "exclusive" interrupt request source it must return the value IRQ_HANDLED if and only if it has verified that the current interrupt request actually stems from that source. In all other cases it must return the value IRQ_NOT_HANDLED.


  • The function is only available as fastcall function, so it may only be used in presence of a prototype.
  • The stub saves the registers and zero page locations used by the C runtime and switches to the provided stack area. As a consequence, there is some runtime overhead, but it it is safe to execute C code, even if other C code was interrupted. Be careful however not to call C library functions, and do not enable stack checks for the handler function or any other function called from it.
  • The interrupt vector is reset on function termination, so it's not strictly necessary to call reset_irq as part of the cleanup when the program terminates.



See also

reset_brk, reset_irq, set_brk



Next Previous Contents