Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

RLY Interrupt

RLY Interrupt Sample Application (SSK 1.x)

Overview

The RLY Interrupt sample application demonstrates how to configure and handle hardware interrupts on Relay (RLY) modules using the NAI Software Support Kit (SSK 1.x). The sample covers two interrupt delivery mechanisms: standard (onboard ISR with a message queue and thread-based processing) and Ethernet IDR (Interrupt Driven Response, network-based). Both variants configure BIT latched status interrupts on a user-selected range of channels and share the same module-level configuration code in nai_rly_int.c. The difference is only in how the interrupt notification reaches your application.

This sample supports the following RLY module types: KN, KL, RY1, and RY2.

The sample ships as two separate executables:

  • RLY_Interrupt — standard interrupt delivery. Installs a hardware ISR (onboard or offboard), enables BIT latched status interrupts on a user-selected channel range, and processes interrupt events through a message queue and handler thread. Unlike RLY_Interrupt_Basic, this variant handles multiple simultaneous interrupts across a range of channels and supports both onboard and offboard ISR routing.

  • RLY_Interrupt_Ethernet — Ethernet IDR variant. Delivers interrupt notifications over the network using IDR commands. The board automatically reads the BIT latched status register and sends the results to your application as UDP messages.

RLY modules expose a single latched interrupt status type:

  • BIT (NAI_RLY_BIT_STATUS_LATCHED) — Built-In Test fault detected on a relay channel.

This is the simplest interrupt status set among NAI modules — there is only one status type to configure, making relay interrupt handling straightforward. The same configuration pattern (vector, steering, edge/level, enable) used here applies to more complex modules with multiple status types. For basic relay channel configuration, see the RLY BasicOps sample application guide. For a simpler single-channel interrupt example, see the RLY Interrupt Basic guide. For background on interrupt concepts — including edge vs. level triggering, interrupt vector numbering, steering architecture, and latency measurement — see the Interrupts API Guide.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a RLY module installed (KN, KL, RY1, or RY2).

  • SSK 1.x installed on your development host.

  • The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.

  • For the Ethernet IDR variant: a Gen4 or later board with an Ethernet connection.

How to Run

Launch either executable from your build output directory. On startup the application looks for a configuration file (default_RLY_Interrupt.txt for the standard variant, default_RLY_Interrupt_Ethernet.txt for the Ethernet variant). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, the standard variant prompts you for channel range, trigger mode, and interrupt delivery options, then begins monitoring for interrupt events. The Ethernet variant prompts for a single channel number and IDR configuration parameters.

Board Connection and Module Selection

Note
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to RLY. For details on board connection configuration, see the First Time Setup Guide.

Both variants follow the standard SSK 1.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file or present the interactive board menu. The configuration file is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Initialize module and interrupt configuration structures with initializeRLYConfigurations() and initializeInterruptConfigurations().

  3. Query the user for card index with naiapp_query_CardIndex().

  4. Query the user for module number with naiapp_query_ModuleNumber().

  5. Retrieve the module ID with naibrd_GetModuleID() to verify a RLY module is installed at the selected slot.

initializeRLYConfigurations(0, 0, 0, 0, 0, 0);
initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, 0, 0, 0);

if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
   while (stop != TRUE)
   {
      stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
      inputRLYConfig.cardIndex = cardIndex;
      if (stop != TRUE)
      {
         check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
         stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
         inputRLYConfig.module = module;
         if (stop != TRUE)
         {
            inputRLYConfig.modid = naibrd_GetModuleID(cardIndex, module);
            if ((inputRLYConfig.modid != 0))
            {
               Run_RLY_Interrupt();
            }
         }
      }
   }
}

The RlyConfig structure tracks the board and module context throughout the application:

typedef struct
{
   int32_t cardIndex;
   int32_t module;
   uint32_t modid;
   int32_t channel;
   int32_t maxChannel;
   int32_t minChannel;
} RlyConfig;

In your own application, you will track the same values — card index, module slot number, module ID, and the channel range you intend to monitor.

Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain a RLY module. Use the board menu to verify which slots are populated.

User Configuration Queries

Before configuring interrupts, the standard variant (RLY_Interrupt) queries the user for several configuration parameters. These queries are a sample convenience — in your own application, you would set these values directly.

Channel Range

The sample prompts for a minimum and maximum channel number. All channels in this range will have interrupts enabled:

maxChannel = naibrd_RLY_GetChannelCount(inputRLYConfig.modid);
bQuit = naiapp_query_ForChannelRange(&inputRLYConfig.minChannel,
                                     &inputRLYConfig.maxChannel,
                                     minChannel, maxChannel);

naibrd_RLY_GetChannelCount() returns the total number of channels available on the module. The channel range determines which channels will have BIT latched status interrupts enabled. Consult your module’s manual for the channel count on your specific module type.

Trigger Mode (Edge vs. Level)

bQuit = GetRLYLatchStatusTriggerMode(&inputInterruptConfig.interrupt_Edge_Trigger);

The GetRLYLatchStatusTriggerMode() function prompts for edge-triggered (0) or level-triggered (1) operation:

  • Edge-triggered (0) — the interrupt fires once when the status bit transitions from 0 to 1. This produces a single notification per event and is the default.

  • Level-triggered (1) — the interrupt continues to assert as long as the status condition remains active. This ensures your application does not miss events, but the interrupt will keep firing until you clear the status register.

Interrupt Clear Prompting

bQuit = QueryUserForClearingInterruptPrompts(&inputInterruptConfig.bPromptForInterruptClear);

When enabled, the handler pauses after each interrupt and waits for the user to press "C" before clearing the status register. This is useful for debugging — it lets you observe the interrupt state before re-arming. In a production application, you would clear the status automatically.

Onboard vs. Offboard ISR

bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);

This selects whether the ISR runs on the board’s onboard processor or on an external host connected via cPCI/PCIe. Onboard processing is the typical configuration for Ethernet-connected boards. Offboard processing is used when the board is installed in a CompactPCI or PCIe chassis and the host processor handles interrupts directly.

Interrupt Steering

bQuit = GetIntSteeringTypeFromUser(&inputInterruptConfig.steering);

Interrupt steering determines the physical path by which the interrupt signal reaches your handler:

  • Onboard (NAIBRD_INT_STEERING_ON_BOARD_0 or ON_BOARD_1) — handled locally on the board’s processor.

  • cPCI offboard (NAIBRD_INT_STEERING_CPCI_APP) — routes the interrupt to the CompactPCI backplane host.

  • PCIe offboard (NAIBRD_INT_STEERING_PCIE_APP) — routes the interrupt to the PCIe host.

Clearing Status and Configuring Interrupts

Before enabling interrupts, the configureRLYToInterruptOnRx() function clears stale latched status, assigns an interrupt vector, sets the trigger mode, and configures steering for the BIT latched status type. Always clear status registers before enabling interrupts — stale latched status from a previous run or power-on state will trigger immediate spurious interrupts.

Disabling Existing Interrupts

The configuration function first disables any previously enabled interrupts to ensure a clean state:

enableRLYInterrupts(inputRLYConfig, FALSE);

Interrupt Vector

The BIT latched status type is assigned a single interrupt vector so the handler can identify which condition triggered the event:

#define NAI_RLY_INTERRUPT_VECTOR  0xA0

check_status(naibrd_RLY_SetGroupInterruptVector(cardIndex, module, 1,
             NAI_RLY_BIT_STATUS_LATCHED, vector));

naibrd_RLY_SetGroupInterruptVector() operates on a group basis (group 1 in this sample), not per-channel. All channels in the group share the same vector for the BIT status type. Since RLY modules have only one status type, only one vector is needed. In your own application, choose a vector value that does not conflict with other modules on the same board.

Clearing Stale Status and Setting Trigger Mode

The configuration function clears stale status and sets the trigger mode per-channel:

for (chan = 1; chan <= inputRLYConfig.maxChannel; chan++)
{
   /* Clear the Interrupt Status */
   check_status(naibrd_RLY_ClearStatus(cardIndex, module, chan,
                NAI_RLY_BIT_STATUS_LATCHED));
   /* Setup the Latched Status Mode */
   check_status(naibrd_RLY_SetEdgeLevelInterrupt(cardIndex, module, chan,
                NAI_RLY_BIT_STATUS_LATCHED,
                (nai_rly_interrupt_t)interrupt_Edge_Trigger));
}

naibrd_RLY_ClearStatus() clears the latched BIT status for each channel to prevent spurious interrupts when they are enabled. naibrd_RLY_SetEdgeLevelInterrupt() configures whether the interrupt is edge-triggered or level-triggered for the specified channel and status type.

Interrupt Steering

check_status(naibrd_RLY_SetGroupInterruptSteering(cardIndex, module, 1,
             NAI_RLY_BIT_STATUS_LATCHED, steering));

Like vectors, steering is set per-group and applies to all channels in the group. The steering value must match the interrupt delivery mechanism you are using: NAIBRD_INT_STEERING_ON_BOARD_0 for the standard onboard ISR, NAIBRD_INT_STEERING_ON_BOARD_1 for Ethernet IDR, or NAIBRD_INT_STEERING_CPCI_APP / NAIBRD_INT_STEERING_PCIE_APP for offboard delivery.

Important

Common Errors

  • NAI_ERROR_NOT_SUPPORTED — the selected module does not support the specified status type or interrupt configuration. Verify the module type and consult the module manual.

  • Interrupts fire immediately after enable — stale latched status was not cleared before enabling. Always clear status registers before calling naibrd_RLY_SetInterruptEnable().

  • Wrong steering mode — if using the Ethernet IDR variant, steering must be set to NAIBRD_INT_STEERING_ON_BOARD_1, not ON_BOARD_0. Using ON_BOARD_0 with the Ethernet variant will deliver interrupts to the onboard ISR instead of generating IDR messages.

ISR Installation and Interrupt Handling (Standard Variant)

The standard variant installs a hardware ISR, initializes a message queue and processing thread, and then enables interrupts. This approach handles multiple simultaneous interrupts across a range of channels.

Installing the ISR

The ISR is installed based on whether the user selected onboard or offboard processing:

setIRQ(inputInterruptConfig.steering, &inputInterruptConfig.irq);
inputInterruptConfig.cardIndex = inputRLYConfig.cardIndex;

if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
   check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex,
                inputInterruptConfig.irq, (nai_isr_t)IntOnboardIsr, NULL));
}
else
{
   check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex,
                inputInterruptConfig.irq, (nai_isr_t)IntOffboardIsr,
                (void*)&inputRLYConfig.cardIndex));
}

setIRQ() maps the steering value to the appropriate IRQ number. naibrd_InstallISR() registers the ISR callback with the board driver. The IntOnboardIsr and IntOffboardIsr functions are shared SSK utilities that post the interrupt vector to a message queue for asynchronous processing.

In your own application, call naibrd_InstallISR() with your own ISR callback. The ISR should be minimal — set a flag, post to a queue, or signal an event. Do not call blocking functions or perform lengthy operations inside the ISR.

Message Queue and Handler Thread

After installing the ISR and configuring the module, the sample initializes a message queue and a processing thread:

InitInterruptAppThread(ONBOARD_INT, 0);
nai_msDelay(10);
UpdateThreadState(RUN);

InitInterruptAppThread() creates a background thread that waits on the message queue for interrupt events. When the ISR fires, it posts the interrupt vector to the queue. The thread dequeues the vector and calls the registered handler function.

Enabling Interrupts

With the ISR installed and the handler thread running, interrupts are enabled on all channels in the selected range:

void enableRLYInterrupts(RlyConfig inputRLYConfig, bool_t enable) {
   int32_t channel;
   for (channel = inputRLYConfig.minChannel;
        channel <= inputRLYConfig.maxChannel; channel++)
   {
      check_status(naibrd_RLY_SetInterruptEnable(inputRLYConfig.cardIndex,
                   inputRLYConfig.module, channel,
                   NAI_RLY_BIT_STATUS_LATCHED, enable));
   }
}

naibrd_RLY_SetInterruptEnable() operates per-channel, unlike the vector and steering functions which operate per-group. This allows you to selectively enable interrupts on specific channels while sharing the same vector and steering configuration across the group. Only the BIT latched status type is enabled — RLY modules do not have additional status types.

Handling Interrupts

The handler function assigned to rlyIntProcessFunc is called by the background thread when an interrupt event arrives:

rlyIntProcessFunc = handleRLYInterrupt;

The handleRLYInterrupt() function reads the BIT latched group status, clears it for all channels, and displays the interrupt information:

void handleRLYInterrupt(uint32_t nVector) {
   uint32_t rawstatus = 0;
   int32_t chan = 1;
   int32_t maxChannel;
   nai_rly_status_type_t rly_status_type;
   rly_status_type = NAI_RLY_BIT_STATUS_LATCHED;
   maxChannel = inputRLYConfig.maxChannel;

   printf("\n\nInterrupt Occurred \n\n");
   if (inputInterruptConfig.bPromptForInterruptClear)
   {
      promptUserToClearInterrupt_RLY();
   }
   check_status(naibrd_RLY_GetGroupRaw(inputRLYConfig.cardIndex,
                inputRLYConfig.module, 1, rly_status_type, &rawstatus));

   for (chan = 1; chan <= maxChannel; chan++)
   {
      check_status(naibrd_RLY_ClearStatus(inputRLYConfig.cardIndex,
                   inputRLYConfig.module, chan, rly_status_type));
   }
   printInterruptInformation_RLY(nVector, rawstatus, FALSE);
}

The handler pattern is: optionally pause for user acknowledgment (debugging feature), read the group status to identify which channels triggered, clear the status for all channels to re-arm the interrupt, and display the results. The printInterruptInformation_RLY() function prints the interrupt vector, status bitmask, and frame count.

In the status bitmask, each bit corresponds to a channel. For example, if rawstatus is 0x05, channels 1 and 3 (bits 0 and 2) have the BIT fault condition active.

Cleanup

When the user exits, the application disables interrupts and uninstalls the ISR:

enableRLYInterrupts(inputRLYConfig, FALSE);
check_status(naibrd_UninstallISR(inputInterruptConfig.cardIndex));

Always disable interrupts before uninstalling the ISR. If you uninstall the ISR while interrupts are still enabled, the board may attempt to deliver interrupts to a handler that no longer exists.

Important

Common Errors

  • ISR never fires — verify that steering is set correctly for your interrupt delivery mechanism and that naibrd_InstallISR() succeeded. Check that the IRQ number matches the steering configuration.

  • Handler not called despite ISR firing — the message queue or handler thread may not be initialized. Ensure InitInterruptAppThread() is called before enabling interrupts and that UpdateThreadState(RUN) activates the thread.

  • Continuous interrupts without new BIT faults — with level-triggered mode, the interrupt re-asserts immediately if status is not cleared. Ensure the handler calls naibrd_RLY_ClearStatus() for all channels to re-arm the interrupt.

  • Thread never terminates — the background thread runs until the user presses "Q". Ensure the application checks isThreadStateTerminated() and cleanly exits the wait loop.

Ethernet IDR Interrupt Handling

The Ethernet IDR variant (RLY_Interrupt_Ethernet) delivers interrupt notifications over the network instead of through a local ISR. Use this approach when your application runs on a remote host connected via Ethernet, when a hardware ISR is not available or practical for your deployment, or when you want the board to automatically read status registers and package the results into UDP messages.

How the Ethernet IDR Mechanism Works

The Ethernet IDR mechanism works as follows:

  1. Your application configures an IDR definition on the board that specifies: a trigger vector, a response IP address and port, a transport protocol (UDP), and a set of Ethernet commands (register reads) to execute when the interrupt fires.

  2. When the specified interrupt vector fires on the board, the board’s onboard processor automatically executes the pre-configured Ethernet commands — reading the BIT latched status register.

  3. The board packages the results into Ethernet messages and sends them to the configured IP address and port.

  4. Your application runs a listener (IDR server) that receives and decodes these messages.

This approach eliminates the need for your host application to poll registers over the network. The board does the register reads locally (fast) and sends only the results over the network, reducing round-trips and latency.

Prerequisites

Ethernet IDR requires a Generation 4 or later board with Ethernet support. The Ethernet variant verifies this at startup:

bGen4DSWIDRCommands = SupportsGen4Ether(inputRLYConfig.cardIndex);
if (!bGen4DSWIDRCommands)
{
   printf("RLY Ethernet Interrupt Support Prior to Generation 4 "
          "Ethernet commands currently not supported\n");
   bQuit = TRUE;
}

If the check fails, the board’s firmware does not support the Gen4 Ethernet protocol and IDR commands will not work. You may need to update the board firmware.

IDR Configuration

The Ethernet variant prompts the user for the IDR response IP address and port (defaults: 192.168.1.100:52802), then builds and registers a single IDR definition for BIT latched status (DEF_ETHERNET_RLY_IDR_ID = 10). Since RLY modules have only one interrupt status type, only one IDR definition is needed — unlike modules such as DSW that require separate IDRs for each status type.

The setupIDRConfiguration_RLY() function constructs Ethernet commands and registers the IDR:

check_status(naibrd_Ether_ClearIDRConfig(cardIndex,
             (uint16_t)DEF_ETHERNET_RLY_IDR_ID));
InitRLYIDRCommands(inputRLYConfig, inputIDRConfig, bGen4DSWIDRCommands);
check_status(naibrd_Ether_SetIDRConfig(cardIndex,
             (uint16_t)DEF_ETHERNET_RLY_IDR_ID,
             protocol, ipLength, ipAddress, port, vector,
             *cmdcount, *cmdlength, commands));

The IDR commands include a register read that reads RLY_INTERRUPT_RESPONSE_REG_COUNT (1) register starting at the BIT latched status address. Because there is only one status type, the command set is minimal — a single read operation.

The InitRLYIDRCommands() function constructs the Ethernet read command by resolving the board address and module offset:

status = check_status(naibrd_GetModuleOffset(inputRLYConfig.cardIndex,
         inputRLYConfig.module, &moduleOffset));
if (status == NAI_SUCCESS)
   status = check_status(naibrd_GetAddress(inputRLYConfig.cardIndex,
            &boardAddress));

These addresses are combined with the BIT latched status register offset (NAI_RLY_GEN5_REG_BIT_LATCHED_STATUS_ADD) to form the full register address for the Ethernet read command.

After registration, the IDR is started:

check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,
             (uint16_t)DEF_ETHERNET_RLY_IDR_ID));

Decoding IDR Responses

When the IDR server receives a message, it calls HandleRLYEtherInterrupt() to decode and process the results:

void HandleRLYEtherInterrupt(uint16_t msglen, uint8_t msg[],
                             uint16_t tdr_idr_id)
{
   /* Decode message header */
   offset = nai_ether_DecodeMessageHeader(msg, msglen, &seq, &tc, gen, &size);

   /* Extract register values from read response */
   case NAI_ETHER_TYPECODE_RSP_COMMAND_COMPLETE_READ_4:
      datacnt = (msglen - 10) / NAI_REG32;
      for (i = 0; i < datacnt; i++)
      {
         data = msg[offset++] << 24;
         data |= msg[offset++] << 16;
         data |= msg[offset++] << 8;
         data |= msg[offset++];
         if (i < RLY_INTERRUPT_RESPONSE_REG_COUNT)
            rlystatus_int[i] = data;
      }
      break;

   /* Process the status register */
   if (rlystatus_int[i] != 0)
   {
      printf("Received RLY Bit Interrupt: (Interrupt_status) 0x%08X\n",
             rlystatus_int[i]);
      /* Clear the status to re-arm */
      for (chan = 1; chan <= inputRLYConfig.maxChannel; chan++)
      {
         check_status(naibrd_RLY_ClearStatus(inputRLYConfig.cardIndex,
                      inputRLYConfig.module, chan,
                      NAI_RLY_BIT_STATUS_LATCHED));
      }
   }
}

The handler decodes the Gen4 Ethernet response, extracts the BIT latched status register value, displays which interrupt occurred, and clears the status for all channels to re-arm the interrupt. The IDR ID (tdr_idr_id) identifies which IDR definition triggered the response.

Stopping the IDR

When the user exits, the IDR must be stopped and cleaned up:

check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex,
             (uint16_t)DEF_ETHERNET_RLY_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex,
             (uint16_t)DEF_ETHERNET_RLY_IDR_ID));

Always stop the IDR before closing the connection. If you close the connection without stopping the IDR, the board will continue sending messages to an address that is no longer listening.

Important

Common Ethernet IDR Errors

  • "Generation 4 Ethernet commands currently not supported" — the board firmware is older than Generation 4 and does not support IDR commands. Update the board firmware to Gen4 or later to use Ethernet IDR.

  • No IDR messages received — verify that the response IP address and port configured in the IDR match the address your application is listening on. Check that no firewall is blocking inbound UDP traffic on port 52802, and confirm that naibrd_Ether_StartIDR() was called after naibrd_Ether_SetIDRConfig().

  • Message parsing errors — if the typecode is not NAI_ETHER_TYPECODE_RSP_COMMAND_COMPLETE_READ_4, the board may have returned an error response. Verify that the protocol generation matches (NAI_ETHER_GEN4) and that the IDR commands were constructed with the correct register addresses.

  • Status always zero in IDR response — the register address may be incorrect. Verify that naibrd_GetModuleOffset() succeeded and that the module offset is correct for your board configuration.

  • Socket bind failure — the configured response port (52802) is already in use by another application or a previous instance that did not shut down cleanly. Change the port or terminate the conflicting process.

Troubleshooting Reference

This table summarizes common errors and symptoms covered in the sections above. For detailed context, refer to the relevant section. Consult your module’s manual for hardware-specific diagnostic procedures.

Debugging Interrupts That Are Not Firing

When interrupts are not being delivered, use this two-step approach to isolate the problem:

  1. Check whether the status registers are changing. Call naibrd_RLY_GetGroupRaw() with NAI_RLY_BIT_STATUS_LATCHED to read the latched group status. If the status bits are changing when a BIT fault condition occurs, the module is detecting events correctly — the issue is in your interrupt delivery path (steering, ISR installation, or IDR configuration).

  2. If the status registers are NOT changing, the issue is at the hardware or channel configuration level. Verify that the relay module is installed correctly and that the channels are functional. Consult your module’s manual for BIT fault conditions and diagnostic procedures.

Error / Symptom Possible Causes Suggested Resolution

No board found or connection timeout

Board not powered, incorrect or missing configuration file, network issue

Verify hardware is powered and connected. If the configuration file exists, check that it lists the correct interface and address. If it does not exist, the board menu will appear — configure and save your connection settings.

Module not detected or channel count is 0

No RLY module installed at the selected slot, incorrect module number, or a non-RLY module is present

Verify hardware configuration. naibrd_RLY_GetChannelCount() returning 0 indicates the selected module is not a RLY type.

Spurious interrupts immediately after enable

Stale latched status from previous run or power-on state

Always clear all status registers before enabling interrupts. Use the clear-then-configure pattern shown in configureRLYToInterruptOnRx().

No BIT fault interrupts

No fault condition present, wrong steering mode, ISR not installed

Verify that a BIT fault condition is actually occurring on the relay channels. Confirm steering matches your delivery mechanism.

ISR never fires

Wrong IRQ, steering mismatch, naibrd_InstallISR() failed

Verify that setIRQ() mapped the correct IRQ for your steering value and that naibrd_InstallISR() returned success.

Handler thread not processing interrupts

Message queue not initialized, thread not in RUN state

Ensure InitInterruptAppThread() is called before enabling interrupts and UpdateThreadState(RUN) activates the thread.

Continuous interrupts without new BIT faults

Level-triggered mode active and status not cleared

Verify the handler calls naibrd_RLY_ClearStatus() for all channels after processing each interrupt. Consider switching to edge-triggered mode.

Ethernet IDR: no messages received

Wrong response IP/port, firewall blocking, IDR not started, Gen4 not supported

Verify IP address and port match your listener. Confirm naibrd_Ether_StartIDR() was called. Check firewall rules for the configured port.

Steering mismatch

Steering set to wrong destination for the chosen delivery mechanism

Match steering to where your application executes. Standard onboard ISR: ON_BOARD_0. Ethernet IDR: ON_BOARD_1. External PCI: CPCI_APP. External PCIe: PCIE_APP.

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail. This sample consists of the main application file and three shared utility files.

Full Source — RLY_Interrupt.c (SSK 1.x)
/**************************************************************************************************************/
/**
<summary>

The RLY_Interrupt program demonstrates how to perform an interrupt when a single channel receives
a rly message. The purpose of this program is to demonstrate the method calls in the naibrd library for performing
the interrupt. More information on this process can be found in the naibrd SSK Quick Guide(Interrupts) file.

This application differs from RLY_Interrupt_Basic in that it could handle multiple interrupts at once.
It also queries the user for the edge trigger value and whether the user should be prompted to clear an interrupt.
The application also has support for offboard interrupts.

</summary>
*/
/**************************************************************************************************************/

/************************/
/* Include Declarations */
/************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*Common Module Specific Sample Program include files*/
#include "nai_rly_int.h"
#include "nai_rly_cfg.h"
#include "nai_rly_int_ether.h"
/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.h"
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"

/* Module Specific NAI Board Library files */
#include "functions/naibrd_rly.h"

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
/*
static const int8_t *App_Name = "RLY Interrupt Basic";
static const int8_t *App_Rev = "1.0";
*/

static const int8_t *CONFIG_FILE = (const int8_t *)"default_RLY_Interrupt.txt";

/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_RLY_Interrupt();

/**************************************************************************************************************/
/*****                                     Main Routine                                                   *****/
/**************************************************************************************************************/
/**************************************************************************************************************/
/**
<summary>

The main routine assists in gaining access to the board.

The following routines from the nai_sys_cfg.c file are
called to assist with accessing and configuring the board.

 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule

</summary>
*/
/*****************************************************************************/

#if defined (__VXWORKS__)
int32_t RLY_Interrupt(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   initializeRLYConfigurations(0, 0, 0, 0, 0, 0);
   initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, 0, 0, 0);

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         inputRLYConfig.cardIndex = cardIndex;
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            inputRLYConfig.module = module;
            if (stop != TRUE)
            {
               inputRLYConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputRLYConfig.modid != 0))
               {
                  Run_RLY_Interrupt();
               }
            }
         }
         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   printf("\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}
/**************************************************************************************************************/
/**
<summary>

This function is broken into the following major steps. These steps correspond with the steps provided
in the naibrd SSK Quick Guide(Interrupts) file.

2. Bus Interrupt Handling - Install ISR

   API CALLS - naibrd_InstallISR

3. Enable Module Interrupts- Configures module to interrupter when channel receives RLY message.

   API CALLS - naibrd_RLY_SetInterruptEdgeLevel, naibrd_RLY_SetIntVector, naibrd_RLY_SetInterruptSteering, naibrd_RLY_SetIntEnable

4. Not applicable to RLY module

5. Show Interrupt Handling - Check the mailbox to see if any interrupts occurred.

6. Re-arming Interrupts - Clear the status register to allow interrupts to occur again. This is done by writing to the status register.
   In this program, we use an API call to do this.

   API CALLS - naibrd_RLY_ClearStatus

7. Clear Module Configurations

   API CALLS - naibrd_RLY_SetRxEnable

8. Clear Board Configurations

   API CALLS - naibrd_UninstallISR

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_RLY_Interrupt()
{
   bool_t bQuit = FALSE;

   int32_t minChannel;
   int32_t maxChannel;

   minChannel = 1;
   maxChannel = naibrd_RLY_GetChannelCount(inputRLYConfig.modid);

   /* Query for Channels to Operate on */
   bQuit = naiapp_query_ForChannelRange(&inputRLYConfig.minChannel, &inputRLYConfig.maxChannel, minChannel, maxChannel);

   /* Query for Trigger Status of interrupts */
   if (!bQuit)
   {
      bQuit = GetRLYLatchStatusTriggerMode(&inputInterruptConfig.interrupt_Edge_Trigger);
   }
   /* Query user if they'd like to be prompted for clearing interrupts */
   if (!bQuit) {
      bQuit = QueryUserForClearingInterruptPrompts(&inputInterruptConfig.bPromptForInterruptClear);
   }
   if (!bQuit) {
      bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
   }

   /* Query user for location interrupt will be sent out to */
   if (!bQuit)
   {
      bQuit = GetIntSteeringTypeFromUser(&inputInterruptConfig.steering);
   }

   if (!bQuit)
   {

      /**** 2. Implement Bus Interrupt Handling****/
      setIRQ(inputInterruptConfig.steering, &inputInterruptConfig.irq);
      inputInterruptConfig.cardIndex = inputRLYConfig.cardIndex;

      if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
      {
         check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOnboardIsr, NULL));
      }
      else
      {
         check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOffboardIsr, (void*)&inputRLYConfig.cardIndex));
      }
      /****3. configure Module to perform interrupts****/
      configureRLYToInterruptOnRx(inputInterruptConfig, inputRLYConfig);

      /****Initialize Message Queue ****/
      InitInterruptAppThread(ONBOARD_INT, 0);
      nai_msDelay(10);
      UpdateThreadState(RUN);

      /****Enable Interrupts****/
      enableRLYInterrupts(inputRLYConfig, TRUE);

      /***5. Show Interrupt Handling (contains step 6) ***/
      rlyIntProcessFunc = handleRLYInterrupt;

      /***Request user triggers interrupt ***/
      DisplayMessage_RLYInterrupt(MSG_USER_TRIGGER_RLY_INT);

      /****Wait on program threads****/
      while (!isThreadStateTerminated()) {
      }
      bQuit = TRUE;

      /*****7. Clear Module Configurations*****/
      enableRLYInterrupts(inputRLYConfig, FALSE);

      /*****8. Clear Board Configurations *****/
      check_status(naibrd_UninstallISR(inputInterruptConfig.cardIndex));
   }

   return bQuit;
}
Full Source — nai_rly_int.c (SSK 1.x)
#include <stdlib.h>
#include <stdio.h>

/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* Common DSW Sample Program include files */
#include "nai_rly_int.h"
#include "nai_rly_cfg.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "naibrd_ether.h"
#include "functions/naibrd_rly.h"
#include "maps/nai_map_rly.h"

bool_t interruptOccured; /* used by checkForInterrupt to see if interrupt occurred*/
int32_t frameCount;	/* counter increment when frames are found*/
uint32_t interruptVector; /* used by checkForInterrupt to get vector of the interrupt that occurred in myIsr */
InterruptConfig inputInterruptConfig;

/* Extern Functions or Variables*/
extern RlyConfig inputRLYConfig;

/**************************************************************************************************************/
/**
<summary>
This function configures an interrupt to occur when a message is received on any of the relay channels.
</summary>
*/
/**************************************************************************************************************/
void configureRLYToInterruptOnRx(InterruptConfig inputInterruptConfig, RlyConfig inputRLYConfig)
{
   int32_t cardIndex = inputRLYConfig.cardIndex;
   int32_t module = inputRLYConfig.module;
   int32_t vector = NAI_RLY_INTERRUPT_VECTOR;
   int32_t interrupt_Edge_Trigger = inputInterruptConfig.interrupt_Edge_Trigger;
   int32_t steering = inputInterruptConfig.steering;
   int32_t chan = 1;

   enableRLYInterrupts(inputRLYConfig, FALSE);

   /* Setup the Interrupt Vector - map to the same vector */
   check_status(naibrd_RLY_SetGroupInterruptVector(cardIndex, module, 1, NAI_RLY_BIT_STATUS_LATCHED, vector));

   for (chan = 1; chan <= inputRLYConfig.maxChannel; chan++)
   {
     /* Clear the Interrupt Status (Read the status and write back "1" to statuses which are set to clear the status) */
      check_status(naibrd_RLY_ClearStatus(cardIndex, module, chan, NAI_RLY_BIT_STATUS_LATCHED));
       /* Setup the Latched Status Mode */
      check_status(naibrd_RLY_SetEdgeLevelInterrupt(cardIndex, module, chan, NAI_RLY_BIT_STATUS_LATCHED, (nai_rly_interrupt_t)interrupt_Edge_Trigger));
   }
   check_status(naibrd_RLY_SetGroupInterruptSteering(cardIndex, module, 1, NAI_RLY_BIT_STATUS_LATCHED, steering));

}
/**************************************************************************************************************/
/**
<summary>
Enables the channels within the (minChannel,maxChannel) range to interrupt
if enable is true and disables them otherwise.
</summary>
*/
/**************************************************************************************************************/
void enableRLYInterrupts(RlyConfig inputRLYConfig, bool_t enable) {
   int32_t channel;
   for (channel = inputRLYConfig.minChannel; channel <= inputRLYConfig.maxChannel; channel++)
   {
      check_status(naibrd_RLY_SetInterruptEnable(inputRLYConfig.cardIndex, inputRLYConfig.module, channel, NAI_RLY_BIT_STATUS_LATCHED, enable));
   }
}

/**************************************************************************************************************/
/**
<summary>
The routine is called to handle a interrupt. This function alerts checkForInterrupt that an interrupt has occurred.
In vxWorks you must clear the Interrupt on the board within the ISR.
</summary>
*/
/**************************************************************************************************************/

#if defined (__VXWORKS__)
void basic_ISR_RLY(uint32_t param)
#else
void basic_ISR_RLY(void *param, uint32_t vector)
#endif
{
   interruptOccured = TRUE;

#if defined (__VXWORKS__)
   interruptVector = nai_Onboard_GetInterruptVector();
   nai_Onboard_ClearInterrupt();
#elif defined (WIN32)
   UNREFERENCED_PARAMETER(param);
   interruptVector = vector;
#else
   interruptVector = vector;
#endif
}

/**************************************************************************************************************/
/**
<summary>
Prompts user to check if an interrupt has occurred. MyIsr() should be installed if using this function.
</summary>
*/
/**************************************************************************************************************/
bool_t checkForRLYInterrupt(RlyConfig inputRLYConfig)
{
   bool_t bQuit;
   int32_t cardIndex;
   int32_t module;
   int32_t channel;
   uint32_t rawstatus = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   cardIndex = inputRLYConfig.cardIndex;
   module = inputRLYConfig.module;
   channel = inputRLYConfig.channel;
   bQuit = FALSE;
   interruptOccured = FALSE;
   while (!bQuit) {
      printf("\nPress enter to check if RLY interrupt Occurred (press Q to quit):");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit) {
         if (interruptOccured) {

            check_status(naibrd_RLY_GetGroupRaw(cardIndex, module, 1, NAI_RLY_RAW_GROUP_BIT_LATCHED_STATUS, &rawstatus));
            printf("\nVector = %#x \n", interruptVector);
            printf("Status = %#x \n", rawstatus);
            interruptOccured = FALSE;
         }
         else {
            printf("\nNo Interrupt Occurred");
         }
         printf("\n\nWould you like to clear the status register? (default:N):");

         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (inputBuffer[0] == 'y' || inputBuffer[0] == 'Y')
         {
            for (channel = 1; channel <= inputRLYConfig.maxChannel; channel++)
            {
                 /* Clear the Interrupt Status (Read the status and write back "1" to statuses which are set to clear the status) */
               check_status(naibrd_RLY_ClearStatus(cardIndex, module, channel, NAI_RLY_BIT_STATUS_LATCHED));
            }
         }
      }
   }
   return bQuit;
}

/**************************************************************************************************************/
/**
<summary>
GetDSWLatchStatusTriggerMode handles prompting the user for the trigger mode for the latched status register
(Edge Triggered or Level Triggered).
</summary>
*/
/**************************************************************************************************************/
bool_t GetRLYLatchStatusTriggerMode(int32_t* interrupt_Edge_Trigger)
{
   bool_t bQuit;
   uint32_t temp;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nEnter Latched Status Trigger Mode (Edge=0, Level=1) (Default=0): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         temp = (int32_t)atol((const char*)inputBuffer);

         if (temp == 0 || temp == 1)
         {
            *interrupt_Edge_Trigger = temp;
         }
         else
         {
            printf("ERROR: Invalid Interrupt Trigger Mode.\n");
         }
      }
      else
         *interrupt_Edge_Trigger = 0;
   }
   return(bQuit);
}

/**************************************************************************************************************/
/**
<summary>
This routine takes in the vector of the RLY RX interrupt that has just occurred. A
</summary>
*/
/**************************************************************************************************************/
void handleRLYInterrupt(uint32_t nVector) {

   uint32_t rawstatus = 0;
   int32_t chan = 1;
   int32_t maxChannel;
   nai_rly_status_type_t rly_status_type;
   rly_status_type = NAI_RLY_BIT_STATUS_LATCHED;
   maxChannel = inputRLYConfig.maxChannel;

   printf("\n\nInterrupt Occurred \n\n");
   if (inputInterruptConfig.bPromptForInterruptClear)
   {
      promptUserToClearInterrupt_RLY();
   }
   check_status(naibrd_RLY_GetGroupRaw(inputRLYConfig.cardIndex, inputRLYConfig.module, 1, rly_status_type, &rawstatus));

   for (chan = 1; chan <= maxChannel; chan++)
   {

      check_status(naibrd_RLY_ClearStatus(inputRLYConfig.cardIndex, inputRLYConfig.module, chan, rly_status_type));
   }
   printInterruptInformation_RLY(nVector, rawstatus, FALSE);

}

void promptUserToClearInterrupt_RLY()
{

   /* Prompt the user to clear the interrupt received */
   SetUserRequestClearInt(FALSE);
   printf("\n");
   DisplayMessage_RLYInterrupt(MSG_USER_CLEAR_RLY_INT);

   /* Wait for the user to respond */
   while (!GetUserRequestClearInt())
   {
      nai_msDelay(10);
   }
}
/**************************************************************************************************************/
/**
<summary>
DisplayMessage_DSWInterrupt handles displaying the messages associated with the msgId passed in.
</summary>
*/
/**************************************************************************************************************/

void DisplayMessage_RLYInterrupt(int32_t msgId)
{
   switch (msgId)
   {
      case (int32_t)MSG_BANNER_RLY_INT:
      {
         printf("\n********************************************************************************");
         printf("\n******                        RLY INTERRUPT                               ******");
         printf("\nAn interrupt will occur when the RLY Module receives a BIT FAult status         ");
         printf("\n********************************************************************************");
      }
      break;

      case (int32_t)MSG_USER_TRIGGER_RLY_INT:
      {
         printf("\nPress \"Q\" to quit the application.\nPlease trigger RLY BIT Fault status interrupt (Recv Msg):");
      }
      break;

      case (int32_t)MSG_USER_CLEAR_RLY_INT:
      {
         printf("Press \"C\" to clear interrupts... ");
      }
      break;

   }
}

/**************************************************************************************************************/
/**
<summary>
Function will print the Data provided for each channel that has been set in the status register.
It will also print the status and idr id or vector.
</summary>
*/
/**************************************************************************************************************/

void printInterruptInformation_RLY(int32_t interruptID, uint32_t status, bool_t isEther)
{
   printf("Interrupt Information\n");
   printf("-----------------------------------\n");
   if (isEther)
      printf("\nIDR ID = %#x \n", interruptID);
   else
      printf("\nVector = %#x \n", interruptID);
   printf("Status = %#x \n", status);

   printf("\nFrames Rx = %d", frameCount);
   printf("\n-----------------------------------\n");

}
Full Source — nai_rly_int_ether.c (SSK 1.x)
/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"

/* Common DSW Sample Program include files */
#include "nai_rly_int_ether.h"
#include "nai_rly_cfg.h"
/* naibrd include files */
#include "functions/naibrd_rly.h"
#include "maps/nai_map_rly.h"
#include "advanced/nai_ether_adv.h"

uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT];
int32_t command_index_interrupt_status;

/* Extern Functions or Variables*/
extern RlyConfig inputRLYConfig;

/**************************************************************************************************************/
/**
<summary>
Constructs the ethernet commands that are part of the IDR. Configures the IDR on the board.
</summary>
*/
/**************************************************************************************************************/
void setupIDRConfiguration_RLY(RlyConfig inputRLYConfig, IDRConfig* inputIDRConfig, bool_t bGen4DSWIDRCommands)
{

   int32_t cardIndex = inputIDRConfig->cardIndex;
   uint16_t protocol = inputIDRConfig->protocol;
   uint16_t port = inputIDRConfig->port;
   uint8_t* ipAddress = inputIDRConfig->ipAddress;
   uint8_t ipLength = inputIDRConfig->ipLength;

   int32_t vector = NAI_RLY_INTERRUPT_VECTOR;
   uint8_t *commands = inputIDRConfig->commands;    /* Stores the ethernet commands that are going to be executed as part of the IDR */
   uint16_t *cmdcount = &inputIDRConfig->cmdcount;
   uint16_t *cmdlength = &inputIDRConfig->cmdlength;

   check_status(naibrd_Ether_ClearIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_RLY_IDR_ID));   /* clear IDR config */
   InitRLYIDRCommands(inputRLYConfig, inputIDRConfig, bGen4DSWIDRCommands);
   check_status(naibrd_Ether_SetIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_RLY_IDR_ID, protocol, ipLength, ipAddress, port, vector, *cmdcount, *cmdlength, commands));

}
/**************************************************************************************************************/
/**
<summary>
This function constructs an ethernet read reg command and stores it in the IDR Configuration. The read will be performed
on the modules latched status interrupt register.
</summary>
*/
/**************************************************************************************************************/
void MakeRLYReadRegsCommand(IDRConfig* inputIDRConfig, uint32_t boardAddress, int32_t moduleOffset, bool_t bGen4Ether, uint16_t startIndex)
{

   uint16_t msgIndex = startIndex;
   uint16_t seqno;
   uint32_t count, stride;
   uint32_t regaddr;
   uint32_t addr = NAI_RLY_GEN5_REG_BIT_LATCHED_STATUS_ADD;
   if (bGen4Ether)
   {

      seqno = 0;
      regaddr = boardAddress + moduleOffset + addr;
      count = RLY_INTERRUPT_RESPONSE_REG_COUNT;
      stride = 4;

      msgIndex = (uint16_t)nai_ether_MakeReadMessage(&inputIDRConfig->commands[startIndex], seqno, NAI_ETHER_GEN4, (nai_intf_t)inputIDRConfig->boardInterface, regaddr, stride, count, NAI_REG32);
      inputIDRConfig->cmdlength = inputIDRConfig->cmdlength + msgIndex;
      command_index_interrupt_status = inputIDRConfig->cmdcount;
      inputIDRConfig->cmdcount++;
   }
}
/**************************************************************************************************************/
/**
<summary>
This function configures the IDR (Interrupt Driven Response) commands when a DSW Rx interrupt occurs.
There are four Ethernet commands that will be processed by the board when a RLY interrupt occurs.

</summary>
*/
/**************************************************************************************************************/
void InitRLYIDRCommands(RlyConfig inputRLYConfig, IDRConfig* inputIDRConfig, bool_t bGen4DSWIDRCommands)
{
   nai_status_t status = NAI_SUCCESS;

   uint16_t msgIndex = 0;
   uint32_t boardAddress;
   uint32_t moduleOffset;

   boardAddress = 0;

   status = check_status(naibrd_GetModuleOffset(inputRLYConfig.cardIndex, inputRLYConfig.module, &moduleOffset));
   if (status == NAI_SUCCESS)
      status = check_status(naibrd_GetAddress(inputRLYConfig.cardIndex, &boardAddress));

   if (status == NAI_SUCCESS)
   {
      if (bGen4DSWIDRCommands)
      {

         msgIndex = inputIDRConfig->cmdlength;
         MakeRLYReadRegsCommand(inputIDRConfig, boardAddress, moduleOffset, bGen4DSWIDRCommands, msgIndex);

      }
   }
}

/**************************************************************************************************************/
/**
<summary>
HandleDSWEtherInterrupt is called by the decodeUPRIDRMessages() routine in nai_sys_int_ether.c when an
unprompted (UPR) Ethernet message is received with the TDR/IDR Index equal to DEF_ETHERNET_DT_IDR_ID.
This routine will parse the message to retrieve the information requested in the SetupDTEtherIDRconfig()
routine.
</summary>
*/
/**************************************************************************************************************/
void HandleRLYEtherInterrupt(uint16_t msglen, uint8_t msg[], uint16_t tdr_idr_id)
{
   uint16_t seq;
   nai_ether_typecode_t tc;
   nai_ether_gen_t gen = NAI_ETHER_GEN4;
   int32_t size;
   int32_t offset;
   uint16_t datacnt = 0;
   uint32_t data;
   uint32_t rlystatus_int[RLY_INTERRUPT_RESPONSE_REG_COUNT];
   int32_t i = 0;
   int32_t chan = inputRLYConfig.channel;
   offset = nai_ether_DecodeMessageHeader(msg, msglen, &seq, &tc, gen, &size);

   switch (tc)
   {
      case NAI_ETHER_TYPECODE_RSP_COMMAND_COMPLETE_READ_4:
         datacnt = (msglen - 10) / NAI_REG32;
         for (i = 0; i < datacnt; i++)
         {
            data = 0;
            data = msg[offset++] << 24;
            data |= msg[offset++] << 16;
            data |= msg[offset++] << 8;
            data |= msg[offset++];
            if (i < RLY_INTERRUPT_RESPONSE_REG_COUNT)
               rlystatus_int[i] = data;
         }
         break;
   }
   printf("\n\n");
   printf("IDR ID : %d\n", tdr_idr_id);

   /* Check to make sure we got all 4 status elements (BIT, Lo-Hi, Hi-Lo, Overcurrent) */
   if (datacnt == RLY_INTERRUPT_RESPONSE_REG_COUNT)
   {
      printf("\n\n");

      if (rlystatus_int[i] != 0)
      {
         printf("Received RLY Bit Interrupt: (Interrupt_status) 0x%08X\n", rlystatus_int[i]);

         /* Clear the status state to re-arm the interrupts */
         for (chan = 1; chan <= inputRLYConfig.maxChannel; chan++)
         {
            /* Clear the Interrupt Status (Read the status and write back "1" to statuses which are set to clear the status) */
            check_status(naibrd_RLY_ClearStatus(inputRLYConfig.cardIndex, inputRLYConfig.module, chan, NAI_RLY_BIT_STATUS_LATCHED));

         }
         printf("Cleared DSW Bit Interrupt: 0x%08X\n", rlystatus_int[i]);
      }
   }
}
Full Source — RLY_Interrupt_Ethernet.c (SSK 1.x)
/**************************************************************************************************************/
/**
<summary>

The RLY_Interrupt_Ethernet program demonstrates how to perform an interrupt when a single channel receives
a message. The purpose of this program is to demonstrate the method calls in the naibrd library for performing
the interrupt. More information on this process can be found in the naibrd SSK Quick Guide(Interrupts) file.

</summary>
*/
/**************************************************************************************************************/

/************************/
/* Include Declarations */
/************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/*Common Module Specific Sample Program include files*/
#include "nai_rly_int.h"
#include "nai_rly_cfg.h"

/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.h"
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai_rly_int_ether.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"

/* Module Specific NAI Board Library files */
#include "functions/naibrd_dsw.h"
#include "maps/nai_map_rly.h"

IDRConfig inputIDRConfig;
bool_t bDisplayEtherUPR;
etherIntFuncDef rlyEtherIntFunc;

/* Extern Functions or Variables*/
extern InterruptConfig inputInterruptConfig;
extern RlyConfig inputRLYConfig;
extern uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT];

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
/*
static const int8_t *App_Name = "RLY Interrupt Ethernet";
static const int8_t *App_Rev = "1.0";
*/

static const int8_t *CONFIG_FILE = (int8_t *)"default_RLY_Interrupt_Ethernet.txt";
static uint8_t DEF_RX_RESPONSE_IPv4_ADDR[] = { 192,168,1,100 };

/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_RLY_Interrupt_Basic_Ethernet();

/**************************************************************************************************************/
/*****                                     Main Routine                                                   *****/
/**************************************************************************************************************/

/**************************************************************************************************************/
/**
<summary>

The main routine assists in gaining access to the board.

The following routines from the nai_sys_cfg.c file are
called to assist with accessing and configuring the board.

 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule

</summary>

*/
/*****************************************************************************/
#if defined (__VXWORKS__)
int32_t RLY_Interrupt_Basic_Ethernet(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         inputRLYConfig.cardIndex = cardIndex;
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            inputRLYConfig.module = module;
            if (stop != TRUE)
            {
               inputRLYConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputRLYConfig.modid != 0))
               {
                  Run_RLY_Interrupt_Basic_Ethernet();
               }
            }
         }
         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   printf("\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}
/**************************************************************************************************************/
/**
<summary>
This function is broken into the following major steps. These steps correspond with the steps provided
in the naibrd SSK Quick Guide(Interrupts) file.

2a. Ethernet Interrupt Handling - Setup IDR to handle interrupt

   API CALLS - naibrd_Ether_SetIDRConfig, naibrd_Ether_StartIDR,naibrd_Ether_ClearIDRConfig

3. Enable Module Interrupts- Configures module to interrupter when channel receives DSW message.

   API CALLS - naibrd_DSW_SetInterruptEdgeLevel, naibrd_DSW_SetIntVector, naibrd_DSW_SetInterruptSteering, naibrd_DSW_SetIntEnable

4. Not applicable to DSW module

5. Show Interrupt Handling - The IDR server will listen on the boards ports for IDRs indicating an interrupt.
   These results will be decoded and displayed to the user.

6. Re-arming Interrupts - Clear the status register to allow interrupts to occur again. This is done by writing to the status register.
   In this program, the write command is included in the IDR.

   API CALLS - nai_ether_BeginWriteMessage, nai_ether_WriteMessageData, nai_ether_FinishMessage

7. Clear Module Configurations

   API CALLS - naibrd_DSW_SetRxEnable, naibrd_DSW_ClearStatus

8. Clear Board Configurations

   API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_RLY_Interrupt_Basic_Ethernet()
{
   bool_t bQuit = FALSE;
   bool_t bGen4DSWIDRCommands;

   inputRLYConfig.maxChannel = naibrd_RLY_GetChannelCount(inputRLYConfig.modid);
   inputRLYConfig.minChannel = 1;

   initializeRLYConfigurations(0, 0, 0, 0, 0, 0);
   initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, NAIBRD_INT_STEERING_ON_BOARD_1, -1, 0);
   initializeIDRConfigurations(0, 0, DEF_RX_RESPONSE_PROTOCOL, DEF_RX_RESPONSE_PORT, DEF_RX_RESPONSE_IPv4_ADDR, DEF_RX_RESPONSE_IPv4_LENGTH, COMMANDS, 0, 0, DEF_ETHERNET_CAN_IDR_ID);

   /* check if DSW module supports GEN 4 Ethernet */
   bGen4DSWIDRCommands = SupportsGen4Ether(inputRLYConfig.cardIndex);
   if (!bGen4DSWIDRCommands) {

      printf("RLY Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
      bQuit = TRUE;
   }

   if (!bQuit) {
      bQuit = naiapp_query_ChannelNumber(inputRLYConfig.maxChannel, inputRLYConfig.minChannel, &inputRLYConfig.channel);
   }
   if (!bQuit) {
      bQuit = QueryIDRConfigInformation(&inputIDRConfig);

   }
   if (!bQuit) {
      bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
   }
   if (!bQuit)
   {
      bQuit = QueryUserForEtherIDRMsgDisplay(&bDisplayEtherUPR);
   }

   if (!bQuit)
   {
     /****2. Setup IDR to Handle Interrupt (also contains step 6) ****/
      if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
      {
         inputIDRConfig.cardIndex = inputRLYConfig.cardIndex;
         inputIDRConfig.boardInterface = NAI_INTF_ONBOARD;
         inputInterruptConfig.steering = NAIBRD_INT_STEERING_ON_BOARD_1;
      }
      else /*OffBoard Interrupt*/
      {
         inputIDRConfig.cardIndex = 0;
         inputIDRConfig.boardInterface = NAI_INTF_PCI;
         inputInterruptConfig.steering = NAIBRD_INT_STEERING_CPCI_APP;
      }

      setupIDRConfiguration_RLY(inputRLYConfig, &inputIDRConfig, bGen4DSWIDRCommands);
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RLY_IDR_ID));

      /****3. configure module To Interrupt****/
      configureRLYToInterruptOnRx(inputInterruptConfig, inputRLYConfig);
      enableRLYInterrupts(inputRLYConfig, TRUE);

      /****5. Show Interrupt Handling****/
      rlyEtherIntFunc = HandleRLYEtherInterrupt;
      bQuit = runIDRServer(inputIDRConfig);

       /*****7. Clear Module Configurations*****/
      enableRLYInterrupts(inputRLYConfig, FALSE);

      /*****8. Clear Board Configurations *****/
      check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RLY_IDR_ID));
      check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RLY_IDR_ID));
   }

   return bQuit;

}

Help Bot

X