Products & Services Solutions Academia Support User Community Company

Learn more about xPC Target   

Adding Interrupt Support

Introduction

To add interrupt handling for a custom driver, you must create

Include the following functions. See Hook Function Prototypes — Alphabetical List for the prototype details.

FunctionDescription
PreHookRuns just before either a function-call subsystem or entire model is called. Program this function to acknowledge the interrupt and cause the board to stop issuing the interrupt signal.
PostHookRuns after return from function call on interrupt, and before model execution. It is typically not used.
StartRuns as the last item when starting a model, just before the model runs. It is typically used to turn on interrupt generation. Program this function to enable interrupts on the board and start any action.
StopRuns at the beginning of a stop request, before any mdlTerminate entries for any block in the model runs. It is typically used to turn off interrupt generation. Program this function to disable interrupts from the board and stop any action. This is the first action called, when a target application stops executing.

To add interrupts for your custom driver, use the following general steps:

  1. Create a hook file in the following directory:

    matlabroot\toolbox\rtw\targets\xpc\target\build\
    xpcblocks\thirdpartydrivers

    Hook files are C files (.c). For example, look at files in matlabroot\toolbox\rtw\targets\xpc\target\build\src, such as xpc6804hooks.c.

  2. Name the hook file something like:

    your_company_name_board_hook.c
  3. As necessary, create the interrupt functions the PreHook, PostHook, Start, and Stop functions and add them to the hook file. See Guidelines for Creating Interrupt Functions for information on how to create these functions.

  4. Copy the file sample_int.m to a unique file name in the following directory:

    matlabroot\toolbox\rtw\targets\xpc\target\build\
    xpcblocks\thirdpartydrivers

    For example:

    your_company_name_int.m

    The xPC Target software searches in this directory for file names that end with _int.m and looks for board interrupt descriptions.

  5. Open and edit the following file:

    matlabroot\toolbox\rtw\targets\xpc\target\build\
    xpcblocks\thirdpartydrivers\your_company_name_int.m

    Add to this file a board structure for each xPC Target supported board for which interrupt functions have been written. See Filling in the Driver board Structure for a description of how to fill in a board structure.

  6. Save and close the file.

  7. At the MATLAB Command Window, type:

    rehash toolbox
  8. Restart the MATLAB interface to update the Async IRQ Source block and Configuration Parameters dialogs.

Guidelines for Creating Interrupt Functions

xPC Target interrupt functions have predefined purposes and typically follow a particular order. This section describes the guidelines on creating interrupt functions. See Hook Function Prototypes — Alphabetical List for the prototypes for these functions.

To prepare for the creation of the hook file, examine the existing xPC Target hook files (matlabroot\toolbox\rtw\targets\xpc\target\build\src) and copy and modify one that is the same board type, PCI or ISA, as the board for which you are creating a custom driver. For example, xpc6804hooks.c is for an ISA board. Place your new file in

matlabroot\toolbox\rtw\targets\xpc\target\build\
xpcblocks\thirdpartydrivers\

When modifying an existing hook file:

When writing the interrupt functions, note the following:

Filling in the Driver board Structure

This section describes how to fill in a driver board structure, element by element.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS