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

DSW Interrupt

DSW Interrupt Sample Application (SSK 1.x)

Overview

The DSW Interrupt sample application demonstrates how to configure and handle hardware interrupts on Discrete Switch (DSW) 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 Lo-Hi and Hi-Lo transition interrupts on a user-selected range of channels and share the same module-level configuration code in nai_dsw_int.c. The difference is only in how the interrupt notification reaches your application.

This sample supports the following DSW module types: K7, DT2, and DT5.

The sample ships as two separate executables:

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

  • DSW_Interrupt_Ethernet — Ethernet IDR variant. Delivers interrupt notifications over the network using IDR commands. The board automatically reads both Lo-Hi and Hi-Lo transition status registers and sends the results to your application as UDP messages.

DSW modules expose seven latched interrupt status types, each monitoring a different hardware condition:

  • BIT (NAI_DSW_STATUS_BIT_LATCHED) — Built-In Test fault detected

  • Overcurrent (NAI_DSW_STATUS_OVERCURRENT_LATCHED) — output current exceeds threshold

  • Max-Hi threshold (NAI_DSW_STATUS_MAX_HI_LATCHED) — input exceeds upper limit

  • Min-Lo threshold (NAI_DSW_STATUS_MIN_LO_LATCHED) — input below lower limit

  • Mid-range (NAI_DSW_STATUS_MID_RANGE_LATCHED) — input within a defined mid-range band

  • Lo-Hi transition (NAI_DSW_STATUS_LO_HI_TRANS_LATCHED) — rising-edge event on input

  • Hi-Lo transition (NAI_DSW_STATUS_HI_LO_TRANS_LATCHED) — falling-edge event on input

This sample focuses on the Lo-Hi and Hi-Lo transition types. The same configuration pattern (vector, steering, edge/level, enable) applies to all seven types. For basic DSW channel configuration (I/O format, thresholds, debounce), see the DSW BasicOps sample application guide. For a simpler single-channel interrupt example, see the DSW 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 DSW module installed (K7, DT2, or DT5).

  • 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_DSW_Interrupt.txt for the standard variant, default_DSW_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 application prompts you for channel range, trigger mode, and interrupt delivery options, then begins monitoring for interrupt events.

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 DSW. 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 initializeDSWConfigurations() 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 DSW module is installed at the selected slot.

initializeDSWConfigurations(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);
      inputDSWConfig.cardIndex = cardIndex;
      if (stop != TRUE)
      {
         check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
         stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
         inputDSWConfig.module = module;
         if (stop != TRUE)
         {
            inputDSWConfig.modid = naibrd_GetModuleID(cardIndex, module);
            if ((inputDSWConfig.modid != 0))
            {
               Run_DSW_Interrupt();
            }
         }
      }
   }
}

The DswConfig 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;
} DswConfig;

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 DSW module. Use the board menu to verify which slots are populated.

User Configuration Queries

Before configuring interrupts, the standard variant (DSW_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_DSW_GetChannelCount(inputDSWConfig.modid);
bQuit = naiapp_query_ForChannelRange(&inputDSWConfig.minChannel,
                                     &inputDSWConfig.maxChannel,
                                     minChannel, maxChannel);

naibrd_DSW_GetChannelCount() returns the total number of channels available on the module. The channel range determines which channels will have Lo-Hi and Hi-Lo transition interrupts enabled. Consult your module’s manual for the channel count on your specific module type.

Trigger Mode (Edge vs. Level)

bQuit = GetDSWLatchStatusTriggerMode(&inputInterruptConfig.interrupt_Edge_Trigger);

The GetDSWLatchStatusTriggerMode() 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 configureDSWToInterrupt() function clears stale latched status, assigns interrupt vectors, sets the trigger mode, and configures steering for both Lo-Hi and Hi-Lo transition types. Always clear status registers before enabling interrupts — stale latched status from a previous run or power-on state will trigger immediate spurious interrupts.

Clearing Stale Status

/* Clear the Interrupt Status */
check_status(naibrd_DSW_GetGroupStatusRaw(cardIndex, module, 1,
             NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &rawstatus));
check_status(naibrd_DSW_ClearGroupStatusRaw(cardIndex, module, 1,
             NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, rawstatus));
check_status(naibrd_DSW_GetGroupStatusRaw(cardIndex, module, 1,
             NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, &rawstatus));
check_status(naibrd_DSW_ClearGroupStatusRaw(cardIndex, module, 1,
             NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, rawstatus));

The pattern is read-then-clear: naibrd_DSW_GetGroupStatusRaw() reads the current latched status bitmask for a group, then naibrd_DSW_ClearGroupStatusRaw() writes back the same bitmask to clear only those bits that were set. This ensures you do not accidentally clear status bits that were set between the read and the clear.

Interrupt Vectors

Each status type is assigned a unique interrupt vector so the handler can identify which condition triggered the event:

#define NAI_DSW_LOHI_INTERRUPT_VECTOR  0x10
#define NAI_DSW_HILO_INTERRUPT_VECTOR  0x20

check_status(naibrd_DSW_SetGroupInterruptVector(cardIndex, module, 1,
             NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, NAI_DSW_LOHI_INTERRUPT_VECTOR));
check_status(naibrd_DSW_SetGroupInterruptVector(cardIndex, module, 1,
             NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, NAI_DSW_HILO_INTERRUPT_VECTOR));

naibrd_DSW_SetGroupInterruptVector() operates on a group basis (group 1 in this sample), not per-channel. All channels in the group share the same vector for a given status type. In your own application, choose vector values that do not conflict with other modules on the same board.

Trigger Mode

The trigger mode is set per-channel for each status type:

for (chan = 1; chan <= inputDSWConfig.maxChannel; chan++)
{
   check_status(naibrd_DSW_SetEdgeLevelInterrupt(cardIndex, module, chan,
                NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, (nai_dsw_interrupt_t)interrupt_Edge_Trigger));
   check_status(naibrd_DSW_SetEdgeLevelInterrupt(cardIndex, module, chan,
                NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, (nai_dsw_interrupt_t)interrupt_Edge_Trigger));
}

naibrd_DSW_SetEdgeLevelInterrupt() configures whether the interrupt is edge-triggered or level-triggered for the specified channel and status type. Note that this call is per-channel, so all channels in the selected range receive the same trigger mode.

Interrupt Steering

check_status(naibrd_DSW_SetGroupInterruptSteering(cardIndex, module, 1,
             NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, steering));
check_status(naibrd_DSW_SetGroupInterruptSteering(cardIndex, module, 1,
             NAI_DSW_STATUS_HI_LO_TRANS_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_DSW_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 = inputDSWConfig.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*)&inputDSWConfig.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 enableDSWInterrupts(DswConfig inputDSWConfig, bool_t enable) {
   int32_t channel;
   for (channel = inputDSWConfig.minChannel; channel <= inputDSWConfig.maxChannel; channel++)
   {
      check_status(naibrd_DSW_SetInterruptEnable(inputDSWConfig.cardIndex,
                   inputDSWConfig.module, channel,
                   NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, enable));
      check_status(naibrd_DSW_SetInterruptEnable(inputDSWConfig.cardIndex,
                   inputDSWConfig.module, channel,
                   NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, enable));
   }
}

naibrd_DSW_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. Both Lo-Hi and Hi-Lo transition interrupts are enabled for each channel in the range.

Handling Interrupts

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

dswIntProcessFunc = handleDSWInterrupt;

The handleDSWInterrupt() function reads the Lo-Hi transition group status, clears it, and displays the interrupt information:

void handleDSWInterrupt(uint32_t nVector) {
   uint32_t rawstatus = 0;

   printf("\n\nInterrupt Occurred \n\n");
   if (inputInterruptConfig.bPromptForInterruptClear)
   {
      promptUserToClearInterrupt_DSW();
   }
   check_status(naibrd_DSW_GetGroupStatusRaw(inputDSWConfig.cardIndex,
                inputDSWConfig.module, 1,
                NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &rawstatus));
   check_status(naibrd_DSW_ClearGroupStatusRaw(inputDSWConfig.cardIndex,
                inputDSWConfig.module, 1,
                NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, rawstatus));
   printInterruptInformation_DSW(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 to re-arm the interrupt, and display the results. The printInterruptInformation_DSW() 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 Lo-Hi transition condition active.

Cleanup

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

enableDSWInterrupts(inputDSWConfig, 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 signal changes — with level-triggered mode, the interrupt re-asserts immediately if status is not cleared. Ensure the handler calls naibrd_DSW_ClearGroupStatusRaw() 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 (DSW_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 Lo-Hi and Hi-Lo transition status registers.

  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(inputDSWConfig.cardIndex);
if (!bGen4DSWIDRCommands)
{
   printf("DSW 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 two IDR definitions — one for Lo-Hi transitions (DEF_ETHERNET_DSW_LOHI_IDR_ID = 1) and one for Hi-Lo transitions (DEF_ETHERNET_DSW_HILO_IDR_ID = 2).

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

check_status(naibrd_Ether_ClearIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
InitDSWIDRCommands(inputDSWConfig, inputIDRConfig, bGen4DSWIDRCommands, addr);
check_status(naibrd_Ether_SetIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID,
             protocol, ipLength, ipAddress, port, vector1, *cmdcount, *cmdlength, commands));
check_status(naibrd_Ether_ClearIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID));
check_status(naibrd_Ether_SetIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID,
             protocol, ipLength, ipAddress, port, vector2, *cmdcount, *cmdlength, commands));

The IDR commands include a register read that reads DSW_INTERRUPT_RESPONSE_REG_COUNT (2) registers starting at the Lo-Hi transition latched status address, with a stride of 16 bytes. This reads both the Lo-Hi and Hi-Lo latched status registers in a single operation.

After registration, the IDRs are started:

check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,
             (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,
             (uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID));

Decoding IDR Responses

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

void HandleDSWEtherInterrupt(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 < DSW_INTERRUPT_RESPONSE_REG_COUNT)
            dswstatus_int[i] = data;
      }
      break;

   /* Process each status register */
   for (i = 0; i < DSW_INTERRUPT_RESPONSE_REG_COUNT; i++)
   {
      if (dswstatus_int[i] != 0)
      {
         /* Display and clear the interrupt status */
         check_status(naibrd_DSW_ClearGroupStatusRaw(inputDSWConfig.cardIndex,
                      inputDSWConfig.module, 1, dsw_status_type, dswstatus_int[i]));
      }
   }
}

The handler decodes the Gen4 Ethernet response, extracts the two status register values (Lo-Hi and Hi-Lo), displays which type of interrupt occurred, and clears the status 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_DSW_LOHI_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex,
             (uint16_t)DEF_ETHERNET_DSW_LOHI_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_DSW_GetGroupStatusRaw() with the appropriate status type to read the latched group status. If the status bits are changing when the external signal transitions, 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 channel is configured as an input and that a valid signal is present on the channel. For transition events, the signal must actually change state. Consult your module’s manual for signal level thresholds and wiring requirements.

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 DSW module installed at the selected slot, incorrect module number, or a non-DSW module is present

Verify hardware configuration. naibrd_DSW_GetChannelCount() returning 0 indicates the selected module is not a DSW 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 read-then-clear pattern shown in configureDSWToInterrupt().

No transition interrupts despite signal changes

Channel not configured as input, signal below threshold, wrong steering mode

Verify channel I/O configuration. For transition interrupts, the signal must actually change state. 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 signal changes

Level-triggered mode active and status not cleared

Verify the handler calls naibrd_DSW_ClearGroupStatusRaw() 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 — DSW_Interrupt.c (SSK 1.x)
/**************************************************************************************************************/
/**
<summary>

The DSW_Interrupt 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.

This application differs from DSW_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_dsw_int.h"
#include "nai_dsw_cfg.h"
#include "nai_dsw_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_dsw.h"

IntProcessFuncDef dswIntProcessFunc;

/* Extern Functions or Variables*/
extern InterruptConfig inputInterruptConfig;
extern DswConfig inputDSWConfig;

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_DSW_Interrupt.txt";

/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_DSW_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 DSW_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;

   initializeDSWConfigurations(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);
         inputDSWConfig.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);
            inputDSWConfig.module = module;
            if (stop != TRUE)
            {
               inputDSWConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputDSWConfig.modid != 0))
               {
                  Run_DSW_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 interrupt when channel receives DSW message.

   API CALLS - naibrd_DSW_SetInterruptEdgeLevel, naibrd_DSW_SetIntVector, naibrd_DSW_SetInterruptSteering, naibrd_DSW_SetIntEnable

4. Not applicable for DSW 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_DSW_ClearStatus

7. Clear Module Configurations

8. Clear Board Configurations

   API CALLS - naibrd_UninstallISR

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_DSW_Interrupt()
{

    bool_t bQuit = FALSE;

   int32_t minChannel;
   int32_t maxChannel;

   minChannel = 1;
   maxChannel = naibrd_DSW_GetChannelCount(inputDSWConfig.modid);

   /* Query for Channels to Operate on */
   bQuit = naiapp_query_ForChannelRange(&inputDSWConfig.minChannel,&inputDSWConfig.maxChannel,minChannel,maxChannel);
   /* Query for Trigger Status of interrupts */
   if(!bQuit)
   {
      bQuit = GetDSWLatchStatusTriggerMode(&inputInterruptConfig.interrupt_Edge_Trigger);
   }
   /* Query user if theyd 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 = inputDSWConfig.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*)&inputDSWConfig.cardIndex));
      }
      /****3. configure Module to perform interrupts****/
      configureDSWToInterrupt(inputInterruptConfig,inputDSWConfig);

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

      /****Enable Interrupts****/
      enableDSWInterrupts(inputDSWConfig,TRUE);

      /***5. Show Interrupt Handling (contains step 6) ***/
      dswIntProcessFunc  = handleDSWInterrupt;

      /***Request user triggers interrupt ***/
      DisplayMessage_DSWInterrupt(MSG_USER_TRIGGER_DSW_INT);

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

      /*****7. Clear Module Configurations*****/
      enableDSWInterrupts(inputDSWConfig,FALSE);

      /*****8. Clear Board Configurations *****/
      check_status(naibrd_UninstallISR(inputInterruptConfig.cardIndex));
   }
   return bQuit;
}
Full Source — nai_dsw_int.c (SSK 1.x)
/* 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"

/* Common DSW Sample Program include files */
#include "nai_dsw_int.h"
#include "nai_dsw_cfg.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "naibrd_ether.h"
#include "functions/naibrd_dsw.h"
#include "maps/nai_map_dsw.h"

#include <stdlib.h>

bool_t interruptOccured;
int32_t frameCount;
uint32_t interruptVector;
InterruptConfig inputInterruptConfig;

/* Extern Functions or Variables*/
extern DswConfig inputDSWConfig;

void configureDSWToInterrupt(InterruptConfig inputInterruptConfig, DswConfig inputDSWConfig)
{
   int32_t cardIndex = inputDSWConfig.cardIndex;
   int32_t module = inputDSWConfig.module;
   int32_t interrupt_Edge_Trigger = inputInterruptConfig.interrupt_Edge_Trigger;
   int32_t steering = inputInterruptConfig.steering;
   uint32_t rawstatus = 0;
   int32_t chan;

   enableDSWInterrupts(inputDSWConfig, FALSE);

   /* Clear the Interrupt Status */
   check_status(naibrd_DSW_GetGroupStatusRaw(cardIndex, module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &rawstatus));
   check_status(naibrd_DSW_ClearGroupStatusRaw(cardIndex, module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, rawstatus));
   check_status(naibrd_DSW_GetGroupStatusRaw(cardIndex, module, 1, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, &rawstatus));
   check_status(naibrd_DSW_ClearGroupStatusRaw(cardIndex, module, 1, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, rawstatus));

   /* Setup the Interrupt Vector */
   check_status(naibrd_DSW_SetGroupInterruptVector(cardIndex, module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, NAI_DSW_LOHI_INTERRUPT_VECTOR));
   check_status(naibrd_DSW_SetGroupInterruptVector(cardIndex, module, 1, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, NAI_DSW_HILO_INTERRUPT_VECTOR));

   /* Setup the Latched Status Mode */
   for (chan = 1; chan <= inputDSWConfig.maxChannel; chan++)
   {
      check_status(naibrd_DSW_SetEdgeLevelInterrupt(cardIndex, module, chan, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, (nai_dsw_interrupt_t)interrupt_Edge_Trigger));
      check_status(naibrd_DSW_SetEdgeLevelInterrupt(cardIndex, module, chan, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, (nai_dsw_interrupt_t)interrupt_Edge_Trigger));
   }

   check_status(naibrd_DSW_SetGroupInterruptSteering(cardIndex, module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, steering));
   check_status(naibrd_DSW_SetGroupInterruptSteering(cardIndex, module, 1, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, steering));
}

void enableDSWInterrupts(DswConfig inputDSWConfig, bool_t enable) {
   int32_t channel;
   for (channel = inputDSWConfig.minChannel; channel <= inputDSWConfig.maxChannel; channel++)
   {
      check_status(naibrd_DSW_SetInterruptEnable(inputDSWConfig.cardIndex, inputDSWConfig.module, channel, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, enable));
      check_status(naibrd_DSW_SetInterruptEnable(inputDSWConfig.cardIndex, inputDSWConfig.module, channel, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, enable));
   }
}

#if defined (__VXWORKS__)
void basic_ISR_DSW(uint32_t param)
#else
void basic_ISR_DSW(void *param, uint32_t vector)
#endif
{
#if defined (WIN32)
   UNREFERENCED_PARAMETER(param);
#endif

   interruptOccured = TRUE;

#if defined (__VXWORKS__)
   interruptVector = nai_Onboard_GetInterruptVector();
   nai_Onboard_ClearInterrupt();
#else
   interruptVector = vector;
#endif
}

bool_t checkForDSWInterrupt(DswConfig inputDSWConfig) {
   bool_t bQuit;
   int32_t cardIndex;
   int32_t module;
   uint32_t rawstatus = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   cardIndex = inputDSWConfig.cardIndex;
   module = inputDSWConfig.module;
   bQuit = FALSE;
   interruptOccured = FALSE;
   while (!bQuit) {
      printf("\nPress enter to check if Lo-Hi interrupt Occurred (press Q to quit):");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit) {
         if (interruptOccured) {
            check_status(naibrd_DSW_GetGroupStatusRaw(cardIndex, module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &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')
         {
            check_status(naibrd_DSW_ClearGroupStatusRaw(cardIndex, module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, rawstatus));
         }
      }
   }
   return bQuit;
}

bool_t GetDSWLatchStatusTriggerMode(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);
}

void handleDSWInterrupt(uint32_t nVector) {
   uint32_t rawstatus = 0;

   printf("\n\nInterrupt Occurred \n\n");
   if (inputInterruptConfig.bPromptForInterruptClear)
   {
      promptUserToClearInterrupt_DSW();
   }
   check_status(naibrd_DSW_GetGroupStatusRaw(inputDSWConfig.cardIndex, inputDSWConfig.module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &rawstatus));
   check_status(naibrd_DSW_ClearGroupStatusRaw(inputDSWConfig.cardIndex, inputDSWConfig.module, 1, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, rawstatus));
   printInterruptInformation_DSW(nVector, rawstatus, FALSE);
}

void promptUserToClearInterrupt_DSW()
{
   SetUserRequestClearInt(FALSE);
   printf("\n");
   DisplayMessage_DSWInterrupt(MSG_USER_CLEAR_DSW_INT);
   while (!GetUserRequestClearInt())
   {
      nai_msDelay(10);
   }
}

void DisplayMessage_DSWInterrupt(int32_t msgId)
{
   switch (msgId)
   {
      case (int32_t)MSG_BANNER_DSW_INT:
      {
         printf("\n********************************************************************************");
         printf("\n******                        DSW INTERRUPT                               ******");
         printf("\nAn interrupt will occur when the DSW Module receives a Lo-Hi transition status  ");
         printf("\n********************************************************************************");
      }
      break;

      case (int32_t)MSG_USER_TRIGGER_DSW_INT:
      {
         printf("\nPress \"Q\" to quit the application.\nPlease trigger DSW Lo-Hi status interrupt (Recv Msg):");
      }
      break;

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

void printInterruptInformation_DSW(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_dsw_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_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"

/* Common DSW Sample Program include files */
#include "nai_dsw_int_ether.h"
#include "nai_dsw_cfg.h"

/* naibrd include files */
#include "functions/naibrd_dsw.h"
#include "maps/nai_map_dsw.h"
#include "advanced/nai_ether_adv.h"

int32_t command_index_interrupt_status;

/* Extern Functions or Variables*/
extern DswConfig inputDSWConfig;

void setupIDRConfiguration_DSW(DswConfig inputDSWConfig, 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 vector1 = NAI_DSW_LOHI_INTERRUPT_VECTOR;
   int32_t vector2 = NAI_DSW_HILO_INTERRUPT_VECTOR;
   uint8_t *commands = inputIDRConfig->commands;
   uint16_t *cmdcount = &inputIDRConfig->cmdcount;
   uint16_t *cmdlength = &inputIDRConfig->cmdlength;

   uint32_t addr = NAI_DSW_GEN5_REG_LO_HI_TRANS_LATCHED_STATUS_ADD;

   check_status(naibrd_Ether_ClearIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
   InitDSWIDRCommands(inputDSWConfig, inputIDRConfig, bGen4DSWIDRCommands, addr);
   check_status(naibrd_Ether_SetIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID, protocol, ipLength, ipAddress, port, vector1, *cmdcount, *cmdlength, commands));
   check_status(naibrd_Ether_ClearIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID));
   check_status(naibrd_Ether_SetIDRConfig(cardIndex, (uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID, protocol, ipLength, ipAddress, port, vector2, *cmdcount, *cmdlength, commands));
}

void InitDSWIDRCommands(DswConfig inputDSWConfig, IDRConfig* inputIDRConfig, bool_t bGen4DSWIDRCommands, uint32_t addr)
{
   nai_status_t status = NAI_SUCCESS;
   uint16_t msgIndex = 0;
   uint32_t boardAddress;
   uint32_t moduleOffset;

   boardAddress = 0;

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

   if (status == NAI_SUCCESS)
   {
      if (bGen4DSWIDRCommands)
      {
         msgIndex = inputIDRConfig->cmdlength;
         MakeDSWReadRegsCommand(inputIDRConfig, boardAddress, moduleOffset, bGen4DSWIDRCommands, msgIndex, addr);
      }
   }
}

void MakeDSWReadRegsCommand(IDRConfig* inputIDRConfig, uint32_t boardAddress, int32_t moduleOffset, bool_t bGen4Ether, uint16_t startIndex, uint32_t addr)
{
   uint16_t msgIndex = startIndex;
   uint16_t seqno;
   uint32_t count, stride;

   if (bGen4Ether)
   {
      seqno = 0;
      addr = boardAddress + moduleOffset + addr;
      count = DSW_INTERRUPT_RESPONSE_REG_COUNT;
      stride = 16;

      msgIndex = (uint16_t)nai_ether_MakeReadMessage(&inputIDRConfig->commands[startIndex], seqno, NAI_ETHER_GEN4, (nai_intf_t)inputIDRConfig->boardInterface, addr, stride, count, NAI_REG32);
      inputIDRConfig->cmdlength = inputIDRConfig->cmdlength + msgIndex;
      command_index_interrupt_status = inputIDRConfig->cmdcount;
      inputIDRConfig->cmdcount++;
   }
}

void HandleDSWEtherInterrupt(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 dswstatus_int[DSW_INTERRUPT_RESPONSE_REG_COUNT];
   nai_dsw_status_type_t dsw_status_type = NAI_DSW_STATUS_BIT_LATCHED;
   int32_t i;
   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 < DSW_INTERRUPT_RESPONSE_REG_COUNT)
               dswstatus_int[i] = data;
         }
         break;
   }
   printf("\n\n");
   printf("IDR ID : %d\n", tdr_idr_id);

   if (datacnt == DSW_INTERRUPT_RESPONSE_REG_COUNT)
   {
      for (i = 0; i < DSW_INTERRUPT_RESPONSE_REG_COUNT; i++)
      {
         switch (i)
         {
            case 0:
               dsw_status_type = NAI_DSW_STATUS_LO_HI_TRANS_LATCHED;
               break;
            case 1:
               dsw_status_type = NAI_DSW_STATUS_HI_LO_TRANS_LATCHED;
               break;
         }
         if (dswstatus_int[i] != 0)
         {
            switch (i)
            {
               case 0:
                  printf("Received DSW Lo-Hi Interrupt: (Interrupt_status) 0x%08X\n", dswstatus_int[i]);
                  break;
               case 1:
                  printf("Received DSW Hi-Lo Interrupt: (Interrupt_status) 0x%08X\n", dswstatus_int[i]);
                  break;
            }
            check_status(naibrd_DSW_ClearGroupStatusRaw(inputDSWConfig.cardIndex, inputDSWConfig.module, 1, dsw_status_type, dswstatus_int[i]));
            switch (i)
            {
               case 0:
                  printf("Cleared DSW Lo-Hi Interrupt: 0x%08X\n", dswstatus_int[i]);
                  break;
               case 1:
                  printf("Cleared DSW Hi-Lo Interrupt: 0x%08X\n", dswstatus_int[i]);
                  break;
            }
         }
      }
   }
}

void MakeDSWWriteRegsCommand(DswConfig inputDSWConfig, 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 data = 0x1 << (inputDSWConfig.channel - 1);
   uint32_t addr = NAI_DSW_GEN5_REG_BIT_LATCHED_STATUS_ADD;

   if (bGen4Ether)
   {
      seqno = 0;
      regaddr = boardAddress + moduleOffset + addr;
      count = 1;
      stride = 4;

      msgIndex = (uint16_t)nai_ether_BeginWriteMessage(&inputIDRConfig->commands[startIndex], seqno, NAI_ETHER_GEN4, (nai_intf_t)inputIDRConfig->boardInterface, regaddr, stride, count, NAI_REG32);
      if (msgIndex >= 0)
      {
         msgIndex = (uint16_t)nai_ether_WriteMessageData(&inputIDRConfig->commands[startIndex], msgIndex, NAI_REG32, &data, NAI_REG32, count);
         if (msgIndex >= 0)
         {
            msgIndex = (uint16_t)nai_ether_FinishMessage(&inputIDRConfig->commands[startIndex], msgIndex, NAI_ETHER_GEN4);
         }
      }
      inputIDRConfig->cmdlength = inputIDRConfig->cmdlength + msgIndex;
      inputIDRConfig->cmdcount++;
   }
}
Full Source — DSW_Interrupt_Ethernet.c (SSK 1.x)
/**************************************************************************************************************/
/**
<summary>

The DSW_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_dsw_int.h"
#include "nai_dsw_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_dsw_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_dsw.h"

static uint8_t DEF_RX_RESPONSE_IPv4_ADDR[] =   {192,168,1,100};
static uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT];

etherIntFuncDef dswEtherIntFunc;
bool_t bDisplayEtherUPR;
IDRConfig inputIDRConfig;

/* Extern Functions or Variables*/
extern DswConfig inputDSWConfig;
extern InterruptConfig inputInterruptConfig;

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_DSW_Interrupt_Ethernet.txt";

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

#if defined (__VXWORKS__)
int32_t DSW_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;

   initializeDSWConfigurations(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_DSW_LOHI_IDR_ID);

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         inputDSWConfig.cardIndex = cardIndex;
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            inputDSWConfig.module = module;
            if (stop != TRUE)
            {
               inputDSWConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputDSWConfig.modid != 0))
               {
                  Run_DSW_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;
}

static bool_t Run_DSW_Interrupt_Basic_Ethernet()
{
   bool_t bQuit = FALSE;
   bool_t bGen4DSWIDRCommands;

   inputDSWConfig.maxChannel = naibrd_DSW_GetChannelCount(inputDSWConfig.modid);
   inputDSWConfig.minChannel = 1;

   /* check if DSW module supports GEN 4 Ethernet */
   bGen4DSWIDRCommands = SupportsGen4Ether(inputDSWConfig.cardIndex);
   if (!bGen4DSWIDRCommands)
   {
      printf("DSW Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
      bQuit = TRUE;
   }
   if (!bQuit)
   {
      bQuit = naiapp_query_ChannelNumber(inputDSWConfig.maxChannel, inputDSWConfig.minChannel, &inputDSWConfig.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 ****/
      if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
      {
         inputIDRConfig.cardIndex = inputDSWConfig.cardIndex;
         inputIDRConfig.boardInterface = NAI_INTF_ONBOARD;
         inputInterruptConfig.steering = NAIBRD_INT_STEERING_ON_BOARD_1;
      }
      else
      {
         inputIDRConfig.cardIndex = 0;
         inputIDRConfig.boardInterface = NAI_INTF_PCI;
         inputInterruptConfig.steering = NAIBRD_INT_STEERING_CPCI_APP;
      }

      setupIDRConfiguration_DSW(inputDSWConfig, &inputIDRConfig, bGen4DSWIDRCommands);
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID));

      /****3. configure module To Interrupt****/
      configureDSWToInterrupt(inputInterruptConfig, inputDSWConfig);
      enableDSWInterrupts(inputDSWConfig, TRUE);

      /****5. Show Interrupt Handling****/
      dswEtherIntFunc = HandleDSWEtherInterrupt;
      bQuit = runIDRServer(inputIDRConfig);

      /*****7. Clear Module Configurations*****/
      enableDSWInterrupts(inputDSWConfig, FALSE);

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

   return bQuit;
}

Help Bot

X