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

TTL Interrupt Ethernet

TTL Interrupt Ethernet Sample Application (SSK 1.x)

Overview

The TTL Interrupt Ethernet sample application demonstrates how to receive TTL (Transistor-Transistor Logic) digital I/O interrupt notifications over an Ethernet network using the NAI Software Support Kit (SSK 1.x) Interrupt Driven Response (IDR) mechanism. When a configured interrupt condition occurs on a TTL channel — such as a signal transition, BIT failure, or overcurrent detection — the board generates an interrupt and sends a UDP packet to a remote host containing the interrupt status and any embedded read/write command results. Your application runs an IDR server that listens for these packets and decodes the status information.

This is the Ethernet IDR-only variant of the TTL interrupt handling samples. It delivers all interrupt information in a single UDP message to a remote host using the shared TTL interrupt and IDR utility framework. For the full-featured ISR-based variant that supports both local ISR delivery and Ethernet IDR in a single application, see the TTL Interrupt guide. For a simplified ISR-only starting point with no Ethernet involvement, see the TTL Interrupt Basic guide.

This sample supports the following TTL module types: D7, TL1, TL2, TL3, TL4, TL5, TL6, TL7, and TL8.

TTL modules support multiple interrupt sources including BIT (Built-In Test) status, overcurrent detection, low-to-high transitions, and high-to-low transitions. This sample configures two separate IDR IDs — one for low-to-high transitions (DEF_ETHERNET_TTL_LOHI_IDR_ID) and one for high-to-low transitions (DEF_ETHERNET_TTL_HILO_IDR_ID) — enabling your application to distinguish the direction of signal transitions in the IDR response.

Why Ethernet IDR?

Standard interrupt delivery (ISR) requires your application to run on the same board or be connected via a backplane bus (PCI/PCIe/cPCI). Ethernet IDR removes that constraint entirely:

  • Remote monitoring — your application can run on any host reachable over the network. There is no need for a physical bus connection to the board.

  • All status in one message — the IDR packet contains the interrupt status register value and any read/write command results you configured, eliminating the need for separate register reads after the interrupt fires.

  • Automatic re-arming — you can include a write command in the IDR configuration that clears the latched status register as part of the response, so interrupts re-arm without a separate API call from the host.

  • Reduced host-side complexity — no ISR installation, no IRQ management, no thread synchronization. Your application simply listens on a UDP socket.

The tradeoff is that Ethernet IDR is only available on Gen4 and later boards, and network latency is inherently higher than a local ISR. For latency-critical applications where the host is directly connected to the board, standard ISR delivery may be more appropriate.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a TTL module installed (D7, TL1-TL8).

  • A Gen4 or later board with Ethernet connectivity. Earlier board generations do not support the Ethernet IDR protocol.

  • 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.

  • Network connectivity between the host running this sample and the board. The host must be reachable at the IP address configured in the IDR settings (default: 192.168.1.100).

How to Run

Launch the TTL_Interrupt_Ethernet executable from your build output directory. On startup the application looks for a configuration file (default_TTL_Interrupt.txt). 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 selection, IDR network settings, onboard/offboard processing mode, and interrupt display options, then begins listening for IDR packets from the board.

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 TTL. For details on board connection configuration, see the First Time Setup Guide.

The main() function follows a standard SSK 1.x startup flow:

  1. Initialize TTL, interrupt, and IDR configuration structures with defaults using initializeTTLConfigurations(), initializeInterruptConfigurations(), and initializeIDRConfigurations(). The IDR initialization sets the default response IP address (192.168.1.100), UDP port (52802), and protocol (ETHER_GEN4_UDP_PROTOCOL).

  2. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_TTL_Interrupt.txt) 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.

  3. Query the user for card index and module number.

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

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

   initializeTTLConfigurations(0, 0, 0, 0, 0, 0);
   initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, NAIBRD_INT_STEERING_ON_BOARD_1, 0, 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_TTL_LOHI_IDR_ID);

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

Note the three initialization calls before the board menu. initializeIDRConfigurations() is unique to the Ethernet variant — it populates the IDRConfig structure with default network settings that are used later when configuring the board’s IDR engine. The initial IDR ID is set to DEF_ETHERNET_TTL_LOHI_IDR_ID (the low-to-high transition IDR); the high-to-low IDR is configured separately during IDR setup.

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

Program Structure

The TTL Interrupt Ethernet sample is split across multiple source files:

  • TTL_Interrupt_Ethernet.c — the application entry point. Contains main() and Run_TTL_Interrupt_Ethernet(), which orchestrates the Gen4 check, user prompts, IDR setup, interrupt configuration, IDR server execution, and cleanup.

  • nai_ttl_int_ether.c — Ethernet IDR-specific code shared with the TTL_Interrupt full variant. Contains setupIDRConfiguration_TTL(), IDR command construction functions, and HandleTTLEtherInterrupt() which decodes incoming IDR packets.

  • nai_ttl_int.c — shared interrupt configuration logic. Contains configureTTLToInterrupt(), enableTTLInterrupts(), and ClearInterrupt_TTL().

  • nai_ttl_cfg.c — shared TTL configuration. Contains initializeTTLConfigurations().

Shared Data Structures

The sample uses three key structures to track configuration state:

  • TtlConfig — captures the TTL module identification (card index, module number, module ID) and channel settings (selected channel, min/max channel range).

  • InterruptConfig — captures the interrupt delivery preferences: trigger mode, steering destination, and whether data should be displayed to the console.

  • IDRConfig — captures the Ethernet IDR network settings: protocol, destination IP address and port, command buffer, and command count/length.

The menu system is a sample convenience — in your own code, call the same API functions directly with your own configuration values.

Gen4 Ethernet Requirement Check

The first thing Run_TTL_Interrupt_Ethernet() does after determining the channel count is verify that the connected board supports Gen4 Ethernet commands. This is a hard requirement — earlier board generations do not have the IDR engine.

bGen4ttlIDRCommands = SupportsGen4Ether(inputTTLConfig.cardIndex);

if (!bGen4ttlIDRCommands)
{
   printf("TTL Ethernet Interrupt Support Prior to Generation 4 Ethernet "
          "commands currently not supported\n");
   bQuit = TRUE;
}

SupportsGen4Ether() is a shared utility function that queries the board’s Ethernet generation capability. If the board does not support Gen4, the application exits the interrupt flow immediately with an error message. There is no fallback to an older protocol — you must use a Gen4 or later board for Ethernet IDR.

In your own application, always call SupportsGen4Ether() before attempting any IDR configuration. Calling naibrd_Ether_SetIDRConfig() on a pre-Gen4 board will fail.

Important

Common Errors

  • "Generation 4 Ethernet commands currently not supported" — the connected board does not support IDR. Verify you are using a Gen4 or later board. Check the board’s firmware version if you believe the hardware should support Gen4.

User Configuration Prompts

After the Gen4 check passes, the sample prompts the user for several configuration parameters before setting up the IDR and interrupt system. In your own application, you would set these values programmatically rather than prompting interactively.

bQuit = naiapp_query_ChannelNumber(maxChannel, minChannel, &inputTTLConfig.channel);
inputTTLConfig.maxChannel = inputTTLConfig.channel;
inputTTLConfig.minChannel = inputTTLConfig.channel;

bQuit = QueryIDRConfigInformation(&inputIDRConfig);

bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);

bQuit = QueryUserForEtherIDRMsgDisplay(&bDisplayEtherUPR);

The prompts collect:

  • Channel number — which TTL channel to monitor for interrupts (1 through the module’s maximum channel count). Both minChannel and maxChannel are set to the selected channel, limiting monitoring to a single channel.

  • IDR configuration — QueryIDRConfigInformation() prompts for the destination IP address, port, and protocol. Defaults are 192.168.1.100, port 52802, UDP protocol.

  • Onboard/offboard processing — determines the board interface and interrupt steering. Onboard uses NAI_INTF_ONBOARD with NAIBRD_INT_STEERING_ON_BOARD_1 steering. Offboard uses NAI_INTF_PCI with NAIBRD_INT_STEERING_CPCI_APP steering.

  • IDR message display — whether to show the raw Ethernet IDR message on the console.

IDR Configuration

The IDR (Interrupt Driven Response) is the core mechanism that makes Ethernet-based interrupt delivery work. When an interrupt fires, the board’s IDR engine executes a preconfigured sequence of register read/write commands, packages the results into a UDP packet, and sends it to the specified IP address and port.

The TTL sample configures two separate IDR IDs — one for low-to-high transitions (DEF_ETHERNET_TTL_LOHI_IDR_ID) and one for high-to-low transitions (DEF_ETHERNET_TTL_HILO_IDR_ID). This allows your application to distinguish transition direction from the IDR ID in the received packet, without needing to decode the raw status register.

Setting Up the IDR

After the user selects onboard or offboard processing, the sample configures the board interface and steering, then calls setupIDRConfiguration_TTL() to build and install both IDR command sets:

if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
   inputIDRConfig.cardIndex = inputTTLConfig.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_TTL(inputTTLConfig, &inputIDRConfig, bGen4ttlIDRCommands);
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,
   (uint16_t)DEF_ETHERNET_TTL_LOHI_IDR_ID));
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,
   (uint16_t)DEF_ETHERNET_TTL_HILO_IDR_ID));

The key points are:

  • Two IDR starts — both the low-to-high and high-to-low IDR IDs are started separately. Each IDR ID has its own command buffer and is bound to a different interrupt vector.

  • setupIDRConfiguration_TTL() — this shared utility function (in nai_ttl_int_ether.c) clears any previous IDR configurations, constructs the read/write command buffers for both transition types, and installs them with naibrd_Ether_SetIDRConfig().

  • Board interface selection — NAI_INTF_ONBOARD directs the IDR read/write commands through the board’s onboard interface. NAI_INTF_PCI routes through the PCI bus for offboard configurations.

IDR Command Structure

Each IDR configuration contains embedded Ethernet commands that the board executes when the associated interrupt fires. For TTL modules, the typical IDR command set includes:

  1. Read command — reads the transition status register to determine which channels experienced a signal transition.

  2. Write command — writes to the same status register to clear the latched status and re-arm the interrupt.

The read command is constructed using nai_ether_MakeReadMessage() and the write command uses the three-step pattern: nai_ether_BeginWriteMessage(), nai_ether_WriteMessageData(), and nai_ether_FinishMessage().

Important

Common Errors

  • naibrd_Ether_SetIDRConfig() fails — verify the IDR ID is valid and that no other IDR is already configured with the same ID. Always call naibrd_Ether_ClearIDRConfig() first.

  • Incorrect register address — the module offset must be queried at runtime with naibrd_GetModuleOffset(). Hardcoded offsets will fail on different board configurations.

  • Only one transition direction generates IDR packets — verify both IDR IDs were started with naibrd_Ether_StartIDR(). A missing start call for either IDR ID will prevent that transition direction from generating notifications.

Interrupt Configuration

After the IDR is configured and started, the sample configures the TTL module to generate interrupts on the selected channel:

/****3. configure module To Interrupt****/
configureTTLToInterrupt(inputInterruptConfig, inputTTLConfig);
enableTTLInterrupts(inputTTLConfig, TRUE);

configureTTLToInterrupt() in nai_ttl_int.c performs the following steps:

  1. Set trigger mode — naibrd_TTL_SetInterruptEdgeLevel() configures edge or level triggering for the selected channel on each interrupt type. Edge triggering fires once per transition; level triggering fires continuously while the condition persists.

  2. Set vector — naibrd_TTL_SetIntVector() assigns an interrupt vector to each TTL status type. The low-to-high and high-to-low transitions use different vectors, which must match the vectors specified in the respective IDR configurations.

  3. Set steering — naibrd_TTL_SetInterruptSteering() routes the interrupt to the appropriate destination. For Ethernet IDR, this is NAIBRD_INT_STEERING_ON_BOARD_1 (onboard) so the interrupt reaches the IDR engine.

enableTTLInterrupts() then enables the configured interrupt sources for the selected channel using naibrd_TTL_SetIntEnable().

Important

Common Errors

  • No interrupts received — verify that naibrd_TTL_SetInterruptSteering() used the correct steering constant for Ethernet IDR (NAIBRD_INT_STEERING_ON_BOARD_1 for onboard). Using the wrong steering routes the interrupt to a different destination.

  • Interrupt vector mismatch — the vectors passed to naibrd_TTL_SetIntVector() must match the vectors in the respective naibrd_Ether_SetIDRConfig() calls. The low-to-high and high-to-low transitions use separate vectors and separate IDR IDs.

  • Stale interrupts fire immediately — always clear status before enabling interrupts. Latched status from a previous run will trigger immediately if not cleared.

IDR Server and UDP Message Handling

Once the IDR is started and interrupts are enabled, the sample launches the IDR server to listen for incoming UDP packets from the board:

TTL_ClearInterrupt = ClearInterrupt_TTL;
ttlEtherIntFunc = HandleTTLEtherInterrupt;
bQuit = runIDRServer(inputIDRConfig);

The two function pointer assignments register the callback functions used by the IDR server framework:

  • TTL_ClearInterrupt — points to ClearInterrupt_TTL(), which reads and clears the latched status register. This is called to re-arm interrupts after each notification is processed.

  • ttlEtherIntFunc — points to HandleTTLEtherInterrupt(), the main handler that decodes each incoming IDR UDP packet.

runIDRServer() is a shared utility that opens a UDP socket on the configured port and enters a receive loop. Each time a packet arrives, it dispatches to the registered handler function.

Decoding IDR Packets

HandleTTLEtherInterrupt() in nai_ttl_int_ether.c processes each incoming IDR packet. The IDR response contains one or more embedded command results corresponding to the read/write commands configured during IDR setup. The handler uses nai_ether_DecodeMessageHeader() to extract the sequence number and type code, then processes each response:

  • Read responses (NAI_ETHER_TYPECODE_RSP_COMMAND_COMPLETE_READ_4) contain the TTL status register value. The handler extracts the status bitmask where each bit corresponds to a channel.

  • Write responses (NAI_ETHER_TYPECODE_RSP_COMMAND_COMPLETE_WRITE_4) confirm the status register was cleared.

The IDR ID can be determined from the sequence number’s ID field (bits 13-10), allowing your application to distinguish between low-to-high and high-to-low transition events without decoding the raw status register.

Important

Common Errors

  • No IDR packets received — verify the destination IP address matches the host running the application. Check that no firewall is blocking UDP port 52802. Confirm the board has network connectivity.

  • IDR packets arrive but show status 0x0 — the interrupt may have already been cleared, or no transition has occurred. Apply a signal transition to the configured TTL channel.

  • Only one transition direction shows up — verify both IDR IDs were started with naibrd_Ether_StartIDR(). Check that both transition types have matching vectors and steering.

Cleanup

When the user quits the IDR server loop, the sample performs orderly cleanup of both module and board configurations:

/***** 7. Clear Module Configurations *****/
enableTTLInterrupts(inputTTLConfig, FALSE);

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

The cleanup sequence is:

  1. Disable interrupts — enableTTLInterrupts() with FALSE disables the TTL interrupt enable for the selected channel.

  2. Stop both IDRs — naibrd_Ether_StopIDR() halts both the low-to-high and high-to-low IDR engines. After these calls, the board will no longer send UDP notifications for either transition direction.

  3. Clear both IDR configurations — naibrd_Ether_ClearIDRConfig() removes the command buffers and network settings for both IDR IDs.

Always stop the IDR before clearing its configuration. Clearing the configuration while the IDR is still running can result in undefined behavior. Note that both IDR IDs must be cleaned up independently.

Troubleshooting Reference

Note
This section summarizes errors covered in the preceding sections and provides additional diagnostics. Consult your module’s manual for hardware-specific diagnostics.
Error / Symptom Possible Causes Suggested Resolution

"Generation 4 Ethernet commands currently not supported"

Board does not support Gen4 Ethernet protocol.

Use a Gen4 or later board. Check firmware version with your NAI support contact.

No IDR packets received

Destination IP address does not match the host. Firewall blocking UDP port. Board has no network connectivity. IDR not started.

Verify IP address matches the host running the application. Open UDP port 52802 in the firewall. Ping the board to confirm connectivity. Confirm naibrd_Ether_StartIDR() was called for both IDR IDs.

IDR packets arrive but show status 0x0

Interrupt already cleared. No signal transition on the monitored channel.

Apply a signal transition to the configured TTL channel to trigger the interrupt.

Only one transition direction generates notifications

Only one IDR ID was started. Missing naibrd_Ether_StartIDR() call for the other transition direction.

Verify both DEF_ETHERNET_TTL_LOHI_IDR_ID and DEF_ETHERNET_TTL_HILO_IDR_ID are started.

Interrupts fire continuously without stopping

Level-triggered mode selected and signal stays in the triggering state. Status cleared but condition persists.

Switch to edge triggering or remove the triggering signal. Disable interrupts for the affected channel if needed.

Overcurrent detection not triggering IDR

Overcurrent interrupt vector not mapped to an IDR ID. Overcurrent steering not set.

Verify the overcurrent status type has a matching IDR configuration with the correct vector.

naibrd_Ether_SetIDRConfig() returns error

Stale IDR configuration not cleared. Invalid IDR ID. Board does not support IDR.

Call naibrd_Ether_ClearIDRConfig() before naibrd_Ether_SetIDRConfig(). Verify the IDR ID is within the valid range for your board.

No board found / Connection timeout

Board not powered or connected. Incorrect interface or address in configuration file.

Verify physical connection. Delete the configuration file and re-run to enter settings interactively.

Invalid card or module index

Zero-based card index or one-based module index mismatch.

Cards are zero-indexed, modules are one-indexed. Verify values match your hardware setup.

Module not present at selected slot

TTL module not installed in the selected slot.

Use the board menu to verify which slots are populated with D7 or TL1-TL8 modules.

Full Source

Full Source — TTL_Interrupt_Ethernet.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/*Common Module Specific Sample Program include files*/
#include "nai_ttl_int.h"
#include "nai_ttl_cfg.h"
#include "nai_ttl_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_ttl.h"

IDRConfig inputIDRConfig;
InterruptConfig inputInterruptConfig;
etherIntFuncDef ttlEtherIntFunc;
ClearInterrupt TTL_ClearInterrupt;
bool_t bDisplayEtherUPR;

/* Extern Functions or Variables*/
extern TtlConfig inputTTLConfig;

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/

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

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

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];

/**************************************************************************************************************/
/*****                                     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 TTL_Interrupt_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;

   initializeTTLConfigurations(0, 0, 0, 0, 0, 0);
   initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, NAIBRD_INT_STEERING_ON_BOARD_1, 0, 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_TTL_LOHI_IDR_ID);

   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         inputTTLConfig.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);
            inputTTLConfig.module = module;
            if (stop != TRUE)
            {
               inputTTLConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputTTLConfig.modid != 0))
               {
                  Run_TTL_Interrupt_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 interrupt when channel receives TTL message.

   API CALLS - naibrd_TTL_SetInterruptEdgeLevel, naibrd_TTL_SetIntVector, naibrd_TTL_SetInterruptSteering, naibrd_TTL_SetIntEnable

4. Not applicable to this 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_TTL_SetRxEnable, naibrd_TTL_ClearStatus

8. Clear Board Configurations

   API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_TTL_Interrupt_Ethernet()
{
   bool_t bQuit = FALSE;
   bool_t bGen4ttlIDRCommands;
   int32_t maxChannel = naibrd_TTL_GetChannelCount(inputTTLConfig.modid);
   int32_t minChannel = 1;

    bGen4ttlIDRCommands = SupportsGen4Ether(inputTTLConfig.cardIndex);

    if(!bGen4ttlIDRCommands)
   {
         printf("TTL Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
         bQuit = TRUE;
   }
   if(!bQuit){
      bQuit = naiapp_query_ChannelNumber(maxChannel,minChannel,&inputTTLConfig.channel);
      inputTTLConfig.maxChannel = inputTTLConfig.channel;
      inputTTLConfig.minChannel = inputTTLConfig.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 = inputTTLConfig.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_TTL(inputTTLConfig,&inputIDRConfig,bGen4ttlIDRCommands);
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_TTL_LOHI_IDR_ID));
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,(uint16_t)DEF_ETHERNET_TTL_HILO_IDR_ID));

      /****3. configure module To Interrupt****/
      configureTTLToInterrupt(inputInterruptConfig,inputTTLConfig);
      enableTTLInterrupts(inputTTLConfig,TRUE);

      /****5. Show Interrupt Handling****/
      TTL_ClearInterrupt = ClearInterrupt_TTL;
      ttlEtherIntFunc = HandleTTLEtherInterrupt;
      bQuit = runIDRServer(inputIDRConfig);

      /***** 7. Clear Module Configurations *****/
      enableTTLInterrupts(inputTTLConfig,FALSE);

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

   }

   return bQuit;

}

Help Bot

X