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.

#### ctl_set_isr

    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.

- CTL_ISR_TRIGGER_FIXED the trigger type is not programmable.
- CTL_ISR_TRIGGER_LOW_LEVEL generates an interrupt when the signal is low.
- CTL_ISR_TRIGGER_HIGH_LEVEL generates an interrupt when the signal is high.
- CTL_ISR_TRIGGER_NEGATIVE_EDGE generates an interrupt on a falling edge.
- CTL_ISR_TRIGGER_POSITIVE_EDGE generates an interrupt on a rising edge.
- CTL_ISR_TRIGGER_DUAL_EDGE generates an interrupt on either a falling or a rising edge.

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.

#### ctl_unmask_isr

    int

    ctl_unmask_isr(unsigned int vector);

This function enables an interrupt source. The vector argument specifies the interrupt source to unmask.

#### ctl_mask_isr

    int

    ctl_mask_isr(unsigned int vector);

This function disables an interrupt source. The vector argument specifies the interrupt source to mask.

#### ctl_isr_enable_interrupts

    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.

#### ctl_isr_disable_interrupts

    void

    ctl_isr_disable_interrupts();

This function disables interrupts from within an interrupt service routine..

#### Interrupt Service Routine example

    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.