The CrossWorks tasking library provides an optional set of functions for establishing C functions as interrupt service routines. These functions are available on systems that have programmable interrupt controller hardware. On systems that have fixed interrupt schemes you should use the facilities described in low level interrupts when you create your interrupt service routines.
The function ctl_set_isr is used to establish a C function as an interrupt service routine.
You must enable an interrupt source using ctl_unmask_isr and you can disable an interrupt source using ctl_mask_isr.
The C function you have established is called when the interrupt occurs. On entry to this function interrupts will still be disabled. To allow interrupts of a higher priority to occur you should enable interrupts on entry by calling ctl_isr_enable_interrupts and disable interrupts on exit by calling ctl_isr_disable_interrupts. Note that the pending interrupt flag in the interrupt controller hardware will be cleared by the CrossWorks tasking library when your interrupt service routine returns.
int ctl_set_isr(unsigned int vector, unsigned int priority, CTL_ISR_TRIGGER_t trigger, CTL_ISR_FN_t isr, CTL_ISR_FN_t *oldisr);
This function takes the interrupt vector number and priority as arguments. These number will vary from system to system - check the data sheet of the system you are using for information. The trigger defines the type of interrupt that will trigger the interrupt service routine.
On many systems the interrupt controller doesn't have a programmable trigger type - use the CTL_ISR_TRIGGER_FIXED on these systems.
The isr parameter is the C function to call on interrupt and if oldisr is non zero then the existing interrupt handler is returned in *oldisr.
int ctl_unmask_isr(unsigned int vector);
This function enables an interrupt source. The vector argument specifies the interrupt source to unmask.
int ctl_mask_isr(unsigned int vector);
This function disables an interrupt source. The vector argument specifies the interrupt source to mask.
void ctl_isr_enable_interrupts();
This function can be used to re-enable interrupts from within an interrupt service routine in order to permit higher priority interrupts to interrupt the ISR. A call to this function must be coupled with a call to ctl_isr_disable_interrupts before the ISR exits.
void ctl_isr_disable_interrupts();
This function disables interrupts from within an interrupt service routine..
void isr(void) { ctl_isr_enable_interrupts(); .... // do interrupt handling stuff in here // including clearing the source of the interrupt .... ctl_isr_disable_interrupts(); } int main(void) { ..... ctl_set_isr(11, 11, CTL_ISR_TRIGGER_FIXED, isr, 0); ctl_unmask_isr(11); ..... }
The isr function is triggered from interrupt vector 11 and will run at priority 11. When the function is run it enables interrupts which will allow higher priority interrupts to trigger whilst it is executing.