Main Content

Hardware Interrupt

Trigger the downstream function-call subsystem from an interrupt service routine.

Add-On Required: This feature requires the Embedded Coder Support Package for ARM Cortex-M Processors add-on.

Description

Create an Interrupt Service Routine (ISR) automatically in the generated code in your model. The ISR executes the downstream function-call subsystem associated with the block.

You can use this block for the following purposes:

  • Use this block to build a processor specific, an ARM® Cortex®-M based core, hardware interrupt block.

    You can customize the block to processor specific interrupts by providing an XML based interrupt description file. See Create Hardware Interrupt Block for an ARM Cortex-M Based Processor Using an Interrupt Description File.

    Use this block as is, in code generation to respond to the Fault and NMI interrupt service routines and trigger a downstream function-call subsystem. Make sure the FaultISR and NmiISR are available in your interrupt vector table.

Using this block, you can:

  • Create ISRs on ARM Cortex-M based processors.

  • Set ISR priority.

  • Enable or disable interrupt pre-emption.

  • Simulate the trigger of the interrupt and the downstream subsystem using a simulation input.

For hardware support packages, processor specific blocks are provided with interrupt description files. In the interrupt description file, the mask parameters are updated with interrupt groups, names, and interrupt numbers that match the processor characteristics.

 

This block only generates code for the specified ISR. The configuration to enable the interrupt and specific triggering options should be done in the peripheral settings.

Dialog Box

Interrupt group

Select an interrupt group.

Interrupt group lists all the interrupt groups from your interrupt description file. Selecting an interrupt group changes the list of values in the Interrupt name parameter.

Interrupt name

Select an interrupt service routine (ISR) to be generated.

The Interrupt name corresponds to the specific entry in the processor interrupt vector table.

Interrupt number

This read-only parameter indicates the position of the selected ISR in the interrupt vector table of your target hardware.

Disable interrupt pre-emption

By default, an interrupt can be pre-empted by a higher priority interrupt. Selecting this option allows low priority interrupts to complete their execution without being pre-empted by other interrupts.

Add simulation input port

Select this option to enable the SimIRQ block input. The interrupt block initiates a function-call in simulation when the SimIRQ input is true. However, SimIRQ is ignored in the generated code.

Create Hardware Interrupt Block for an ARM Cortex-M Based Processor Using an Interrupt Description File

You can create your own interrupt block for ARM Cortex-M targets using the existing Hardware Interrupt block from the Embedded Coder® Support Package for ARM Cortex-M Processors library. This block supports NVIC (Nested Vectored Interrupt Controller) of ARM Cortex-M core that can handle interrupts from different peripherals such as ADC, DMA, Watchdog.

To create an interrupt block for an ARM Cortex Cortex-M target:

  1. Install Embedded Coder Support Package for ARM Cortex-M Processors.

  2. Create an XML interrupt description file with details of the interrupt groups and the interrupts under them, based on the interrupt vector table of your ARM Cortex-M based processor. You can find an example of an interrupt XML file in the path: ARM Cortex-M support package root directory > registry > interrupts>.

    • Use the groups (IrqGroup) to bundle interrupts of the same type. This will allow you to limit to size of the Interrupt name list. The IrqName inside one group will populate the "Interrupt name" dropdown list. This name is also used in code generation and has to match the entry in your interrupt vector table. The IrqNumber corresponds to the ARM Cortex-M vector table position and has to match the mapping of the specified interrupt by the silicon vendor. Cortex-M based processor can use up to 8 priority bits.

    • Refer to your Silicon vendor specifications to specify NumberOfPriorityBits.

    • You can disable "Disable interrupt pre-emption" check box by specifying ShowPreemptionOption as this functionality may not be available on your device.

  3. Copy the ARM Cortex-M Interrupt block from the Embedded Coder Support Package for ARM Cortex-M Processors library into new library model or your processor block library.

  4. Register your XML description file along with its path using the command set_param(<hardware interrupt block>, ‘InterruptsXMLPath’, <interrupt descritpion file>) in the MATLAB® command prompt, where the <hardware interrupt block> > corresponds to the block handle in the library (gcb can be used if the block is selected), the <interrupt XML file> corresponds to your interrupt description file with full path.

  5. Double click on the ARM Cortex-M Interrupt block to open the mask dialog window that shows the entries of your interrupt description file. The interrupt groups, interrupt names, and the interrupt numbers specified in your interrupt description file appear in the corresponding block parameters.

  6. Save the library. You can now place the newly created hardware interrupt block and use it in your application models.

A sample XML interrupt description file with the entries mapped to the parameters on the mask dialog window is shown below.