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 BasicInterrupt

TTL BasicInterrupt Sample Application (SSK 2.x)

Overview

The TTL BasicInterrupt sample application demonstrates how to configure and handle hardware interrupts on TTL (transistor-transistor logic) I/O modules using the NAI Software Support Kit (SSK 2.x). It covers the complete interrupt lifecycle: connecting an ISR callback, configuring the trigger type and steering, assigning an interrupt vector, enabling per-channel interrupts, reading and clearing latched status, and receiving the interrupt in a callback function. The sample monitors the low-to-high transition latched status type and waits for a signal transition on the selected channel to trigger the interrupt.

This sample supports the following TTL module types: TL1 and TL2. It serves as a practical API reference — each menu command maps directly to one or more naibrd_TTL_*() API calls that you can lift into your own code.

For the SSK 1.x version, see TTL Interrupt (SSK 1.x).

Note
This sample is not available on DEOS. The interrupt callback mechanism requires POSIX thread support, which DEOS does not provide. Consult the SSK 2.x Software Development Guide for platform-specific build configuration.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a TTL module installed (TL1, TL2).

  • SSK 2.x installed on your development host.

  • The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.

  • A platform that supports hardware interrupts (Petalinux or VxWorks).

How to Run

Launch the ttl_basic_interrupt executable from your build output directory. On startup the application looks for a configuration file (default_TTL_BasicInterrupt.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, select a channel and use the command menu to configure interrupts, display status, and clear status.

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.

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

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

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleName() so downstream code can verify the selected slot contains a TTL module.

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t TTL_BasicInterrupt(void)
#else
int32_t main(void)
#endif
{
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   bool_t stop = NAI_FALSE;
   uint32_t moduleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(),
            DEF_TTL_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, DEF_TTL_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_TTL_BasicInterrupt(cardIndex, module, moduleID);
               }
            }
         }
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}

Note the SSK 2.x differences from SSK 1.x in this startup sequence:

  • The VxWorks preprocessor guard uses NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS (SSK 1.x uses __VXWORKS__).

  • The module identifier is retrieved with naibrd_GetModuleName() (SSK 1.x uses naibrd_GetModuleID()).

  • Boolean constants are NAI_TRUE / NAI_FALSE (SSK 1.x uses TRUE / FALSE).

  • Console output uses naiif_printf() from the platform abstraction layer (SSK 1.x uses printf() directly).

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

Entry Point

On standard platforms (Petalinux) the entry point is main(). On VxWorks the entry point is TTL_BasicInterrupt() — the SSK 2.x build system selects the correct variant via a preprocessor guard:

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t TTL_BasicInterrupt(void)
#else
int32_t main(void)
#endif

The startup flow is the same in both cases:

  1. Attempt to load the saved configuration file via naiapp_RunBoardMenu(DEF_CONFIG_FILE). If the file does not yet exist, the interactive board menu is presented instead.

  2. Enter a loop that queries for card index and module slot.

  3. Validate the detected module by calling naibrd_GetModuleName() and checking the returned ID. If the ID is zero, no valid module was found.

  4. Call Run_TTL_BasicInterrupt() to verify TTL channel support and enter the command loop.

  5. On exit, close all open board connections with naiapp_access_CloseAllOpenCards().

Module Validation

Before entering the command loop, Run_TTL_BasicInterrupt() calls naibrd_TTL_GetChannelCount() with the module ID to confirm the selected slot contains a TTL-capable module. If the channel count is zero, the function prints an error and returns:

maxchannel = naibrd_TTL_GetChannelCount(modid);
if (maxchannel == 0)
{
   naiif_printf(" *** Module selection not recognized as TTL module. ***\r\n\r\n");
}
else
{
   Cfg_TTL_Channel(cardIndex, module, maxchannel);
}

Command Loop

Cfg_TTL_Channel() drives the interactive command loop. It first prompts for a channel number, then on each iteration it prints the command menu and dispatches the user’s selection to the matching handler function:

naiapp_utils_LoadParamMenuCommands(TTL_BASIC_INTERRUPT_CMD_COUNT,
   TTL_BasicInterruptMenuCmds);
while (bContinue)
{
   naiapp_display_ParamMenuCommands((int8_t *)"TTL Basic Interrupt Menu");
   naiif_printf("\r\nType TTL command or %c to quit : ", NAI_QUIT_CHAR);
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR,
      inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt,
            inputBuffer, &cmd);
         if (bCmdFound)
         {
            switch (cmd)
            {
            case TTL_BASIC_INTERRUPT_CMD_CONFIGURE:
            case TTL_BASIC_INTERRUPT_CMD_STATUS_READ:
            case TTL_BASIC_INTERRUPT_CMD_STATUS_CLEAR:
               TTL_BasicInterruptMenuCmds[cmd].func(APP_PARAM_COUNT,
                  (int32_t*)ttlParams);
               break;
            default:
               naiif_printf("Invalid command entered\r\n");
               break;
            }
         }
      }
   }
   else
   {
      bContinue = NAI_FALSE;
   }
}

The available commands are registered in the TTL_BasicInterruptMenuCmds[] table:

Command Description

INT

Configure interrupt (connect ISR, set trigger/steering/vector, enable)

STAT

Display latched status for the selected channel

CLEAR

Clear all latched status for the selected channel

The menu-driven structure is a convenience of the sample application. In your own application, you would call the same underlying naibrd_TTL_*() and naibrd_ConnectISR() API functions directly.

Interrupt Configuration

This section covers the core interrupt setup pattern in SSK 2.x. The Configure_TTL_Interrupt() function performs all the steps required to receive a hardware interrupt: connecting the ISR callback, setting the trigger type, configuring steering, assigning a vector, and enabling the interrupt on a specific channel and status type.

Connecting the ISR Callback

The first step in any interrupt setup is to register your callback function with the board. Call naibrd_ConnectISR() once per card — it does not need to be called for each channel or interrupt type:

status = naibrd_ConnectISR(cardIndex, SampleCallBack);
if (status == NAI_ERROR_NOT_SUPPORTED)
{
   naiif_printf("\r\n**Interrupts are either not supported on this platform or not enabled**\r\n");
}

Setting Trigger Type, Steering, and Vector

After the ISR is connected, configure the interrupt delivery parameters. The sample configures the interrupt for the low-to-high transition latched status:

uint32_t vector = 0xB0u;

/* Set edge triggering for HI-LO transition latched status */
check_status(naibrd_TTL_SetChanMappedInterruptTriggerType(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED, NAIBRD_INT_TRIGGER_TYPE_EDGE));

/* Steer interrupts to onboard ARM */
check_status(naibrd_TTL_SetChanMappedInterruptSteering(cardIndex, module,
   NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, NAIBRD_INT_STEERING_ONBOARD_ARM));

/* Assign the interrupt vector */
check_status(naibrd_TTL_SetChanMappedInterruptVector(cardIndex, module,
   NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, vector));

/* Enable the interrupt on this channel */
check_status(naibrd_TTL_SetChanMappedInterruptEnable(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, NAI_TRUE));
  • naibrd_TTL_SetChanMappedInterruptTriggerType() — selects edge or level triggering. Edge triggering (NAIBRD_INT_TRIGGER_TYPE_EDGE) fires once when the status transitions; level triggering fires continuously while the status is asserted.

  • naibrd_TTL_SetChanMappedInterruptSteering() — routes the interrupt to the appropriate bus. Use NAIBRD_INT_STEERING_ONBOARD_ARM for onboard ARM processing. Other options include VME, CPCI, and PCIe. Steering is set per module and status type, not per channel.

  • naibrd_TTL_SetChanMappedInterruptVector() — assigns a vector number that the ISR receives when the interrupt fires. Choose a unique vector for each interrupt source you need to distinguish. Vector assignment is per module and status type.

  • naibrd_TTL_SetChanMappedInterruptEnable() — enables interrupt generation for the specified channel and status type. All other configuration must be in place before enabling.

This is the SSK 2.x "ChanMapped" interrupt pattern. Each API call targets a specific naibrd_ttl_chan_mapped_status_type_t value, allowing you to configure different interrupt behavior for different status types on the same module.

ISR Callback

The ISR callback is the function that executes when a hardware interrupt fires. It receives the interrupt vector as its only parameter:

static void SampleCallBack(uint32_t vector)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
   logMsg("\r\n\r\nInterrupt Received!!! Vector:0x%x\n Clear Status to receive new interrupt!!!\r\n",
      vector, 0, 0, 0, 0, 0);
#else
   naibsp_printf("\r\n\r\nInterrupt Received!!! Vector:0x%x\r\n Clear Status to receive new interrupt!!!\r\n",
      vector);
#endif
}

Platform-Specific Behavior

  • VxWorks — uses logMsg() from logLib.h, a deferred logging function that queues messages rather than printing directly from interrupt context. The logMsg() call requires six variadic arguments even when unused (the trailing zeros).

  • Petalinux — uses naibsp_printf(), a BSP-level print function safe to call from interrupt context.

Note
The callback uses naibsp_printf() (BSP layer), not naiif_printf() (application layer). BSP-level print functions are designed for use in interrupt context where the full I/O abstraction layer may not be available.

Status Display and Clearing

The sample provides two commands for working with latched status: STAT to display the current latched status values, and CLEAR to reset them. After an interrupt fires on a latched status type, you must clear the latch before a new interrupt of the same type can occur.

Displaying Latched Status

To read the current latched status for a channel, call naibrd_TTL_GetChanMappedStatus() with each latched status type:

nai_status_bit_t statusBit;

check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusBit));
naiif_printf("  %3i   ", statusBit);

check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED, &statusBit));
naiif_printf("  %3i   ", statusBit);

check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_BIT_LATCHED, &statusBit));
naiif_printf("  %3i   ", statusBit);

check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED, &statusBit));
naiif_printf("  %3i   ", statusBit);

The four latched status types displayed are:

  • NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED — a low-to-high transition was detected.

  • NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED — a high-to-low transition was detected.

  • NAIBRD_TTL_STATUS_BIT_LATCHED — a BIT (built-in test) fault was detected.

  • NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED — an overcurrent condition was detected.

Clearing Latched Status

To clear latched status, the sample reads each status type with naibrd_TTL_GetChanMappedStatus(), then clears it with naibrd_TTL_ClearChanMappedStatus() only if the read was successful:

status = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusBit));
if (status == NAI_SUCCESS)
{
   check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan,
      NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED));
}

The sample repeats this read-then-clear pattern for all four latched status types. Clearing a latched status is essential for edge-triggered interrupts. Once a latched status asserts and triggers an interrupt, the latch remains set until explicitly cleared. No new interrupt of the same type will fire until the latch is cleared.

Troubleshooting Reference

This table summarizes common errors and symptoms. Consult the TL1 Manual for hardware-specific diagnostic procedures.

Error / Symptom Possible Causes Suggested Resolution

No board found or connection timeout

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

Verify hardware is powered and connected. If default_TTL_BasicInterrupt.txt exists, check that it lists the correct interface and address.

Module not detected at selected slot

No module installed at the specified slot, incorrect module number entered

Verify hardware configuration and module slot assignment

Module not recognized as TTL

Selected slot contains a non-TTL module, or module ID not in the supported list

Verify the slot contains a TTL module (TL1 or TL2)

NAI_ERROR_NOT_SUPPORTED from naibrd_ConnectISR()

Platform does not support hardware interrupts, or interrupt support not enabled

Verify you are running on Petalinux or VxWorks with interrupt support compiled in. This sample is not available on DEOS.

Interrupt configured but never fires

Missing a configuration step (trigger, steering, vector, or enable), or the hardware condition has not occurred

Verify all steps are complete. Apply a signal transition on the selected channel to trigger the interrupt.

Interrupt fires once but never again

Latched status not cleared after interrupt

Use the CLEAR command or call naibrd_TTL_ClearChanMappedStatus() to clear the latch and re-arm the interrupt

Wrong vector received in ISR

Vector mismatch between configuration and ISR logic

Verify the vector passed to naibrd_TTL_SetChanMappedInterruptVector() matches the value your ISR expects

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail.

Full Source — ttl_basic_interrupt.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"

/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_ttl.h"

/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"

/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
#include "logLib.h"
#endif
static const int8_t *DEF_CONFIG_FILE = (const int8_t *)"default_TTL_BasicInterrupt.txt";

/* Function prototypes */
static int32_t Run_TTL_BasicInterrupt(int32_t cardIndex, int32_t module, uint32_t modid);
static void Cfg_TTL_Channel(int32_t cardIndex, int32_t module, int32_t MaxChannel);
static void Verify_TTL_ParamCnt(int32_t paramCnt);
static nai_status_t Display_TTL_Status(int32_t paramCnt, int32_t* p_params);
static nai_status_t Clear_TTL_Status(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_Interrupt(int32_t paramCnt, int32_t* p_params);
static void SampleCallBack(uint32_t vector);

static const int32_t DEF_TTL_CARD_INDEX    = 0;
static const int32_t DEF_TTL_MODULE        = 1;
static const int32_t DEF_TTL_CHANNEL       = 1;

/****** Command Table *******/
enum ttl_basic_interrupt_commands
{
   TTL_BASIC_INTERRUPT_CMD_CONFIGURE,
   TTL_BASIC_INTERRUPT_CMD_STATUS_READ,
   TTL_BASIC_INTERRUPT_CMD_STATUS_CLEAR,
   TTL_BASIC_INTERRUPT_CMD_COUNT
};

/****** Command Tables *******/
static naiapp_cmdtbl_params_t TTL_BasicInterruptMenuCmds[] = {
   {"INT",      "TTL Configure Interrupt",    TTL_BASIC_INTERRUPT_CMD_CONFIGURE,        Configure_TTL_Interrupt},
   {"STAT",     "TTL Display Status",         TTL_BASIC_INTERRUPT_CMD_STATUS_READ,      Display_TTL_Status},
   {"CLEAR",    "TTL Clear Status",           TTL_BASIC_INTERRUPT_CMD_STATUS_CLEAR,     Clear_TTL_Status},
};

/**************************************************************************************************************/
/**
 * <summary>
 * The purpose of the TTL_BasicInterrupt is to illustrate the methods to call in the naibrd library to perform basic
 * operations with the ttl modules for configuration setup, controlling the drive outputs, and reading
 * the channels.
 *
 * The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
 * setup for this program prior to calling the naibrd TTL routines.
 *  - ClearDeviceCfg
 *  - QuerySystemCfg
 *  - DisplayDeviceCfg
 *  - GetBoardSNModCfg
 *  - SaveDeviceCfg
 * </summary>
 */
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t TTL_BasicInterrupt(void)
#else
int32_t main(void)
#endif
{
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   bool_t stop = NAI_FALSE;
   uint32_t moduleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Select Card Index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_TTL_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Select Module */
            stop = naiapp_query_ModuleNumber(moduleCnt, DEF_TTL_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_TTL_BasicInterrupt(cardIndex, module, moduleID);
                  naiif_printf("\r\nType Q to quit or Enter to continue:\r\n");
                  stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               }
            }
         }
      }
   }

   naiif_printf("\r\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();
   return 0;
}
/**************************************************************************************************************/
/**
 * <summary>
 * Verify_TTL_ParamCnt verifies parameter count and displays error message if invalid.
 * </summary>
 */
 /**************************************************************************************************************/
static void Verify_TTL_ParamCnt(int32_t paramCnt)
{
   if (paramCnt != APP_PARAM_COUNT)
   {
      naiif_printf(" *** Parameter count specified is incorrect!!! ***\r\n");
   }
}
/**************************************************************************************************************/
/**
 * <summary>
 * Run_TTL_BasicInterrupt prompts the user for the card, module and channel to use for the application and calls
 * Cfg_TTL_Channel if the card, module, channel is valid for as a ttl module.
 * </summary>
 */
/**************************************************************************************************************/
static int32_t Run_TTL_BasicInterrupt(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = NAI_FALSE;
   int32_t maxchannel;

   if (!bQuit)
   {
      maxchannel = naibrd_TTL_GetChannelCount(modid);
      if (maxchannel == 0)
      {
         naiif_printf(" *** Module selection not recognized as TTL module. ***\r\n\r\n");
      }
      else
      {
         Cfg_TTL_Channel(cardIndex, module, maxchannel);
      }
   }
   return cardIndex;
}

/**************************************************************************************************************/
/**
 * <summary>
 * Cfg_TTL_Channel handles calling the Display_TTL_ChannelCfg routine to display the ttl channel configuration
 * and calling the routines associated with the user's menu commands.
 * </summary>
 */
/**************************************************************************************************************/
static void Cfg_TTL_Channel(int32_t cardIndex, int32_t module, int32_t MaxChannel)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t chan, defaultchan = 1;
   int32_t cmd;
   naiapp_AppParameters_t  ttlparams;
   p_naiapp_AppParameters_t ttlParams = &ttlparams;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      naiif_printf("\r\n\r\n");
      naiif_printf("Channel selection\r\n");
      naiif_printf("=================\r\n");
      defaultchan = DEF_TTL_CHANNEL;

      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      ttlParams->cardIndex = cardIndex;
      ttlParams->module = module;
      ttlParams->channel = chan;

      naiapp_utils_LoadParamMenuCommands(TTL_BASIC_INTERRUPT_CMD_COUNT, TTL_BasicInterruptMenuCmds);
      while (bContinue)
      {
         naiapp_display_ParamMenuCommands((int8_t *)"TTL Basic Interrupt Menu");
         naiif_printf("\r\nType TTL command or %c to quit : ", NAI_QUIT_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                  case TTL_BASIC_INTERRUPT_CMD_CONFIGURE:
                  case TTL_BASIC_INTERRUPT_CMD_STATUS_READ:
                  case TTL_BASIC_INTERRUPT_CMD_STATUS_CLEAR:
                     TTL_BasicInterruptMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttlParams);
                     break;
                  default:
                     naiif_printf("Invalid command entered\r\n");
                     break;
                  }
               }
               else
               {
                  naiif_printf("Invalid command entered\r\n");
               }
            }
         }
         else
         {
            bContinue = NAI_FALSE;
         }
      }
   }
}

/**************************************************************************************************************/
/**
 * <summary>
 * Display_TTL_Status illustrate the methods to call in the naibrd library to retrieve the status states.
 * </summary>
 */
/**************************************************************************************************************/
static nai_status_t Display_TTL_Status(int32_t paramCnt, int32_t* p_params)
{
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   nai_status_bit_t statusBit;
   Verify_TTL_ParamCnt(paramCnt);
   /* Available status:
    *    NAIBRD_TTL_STATUS_BIT,
    *    NAIBRD_TTL_STATUS_OVER_CURRENT,

    *    NAIBRD_TTL_STATUS_LO_HI_TRANS,
    *    NAIBRD_TTL_STATUS_HI_LO_TRANS,
    */

   naiif_printf("\r\n");
   naiif_printf("  -----------Latched Status Channel %d-------------------\r\n", chan);
   naiif_printf(" Low-Hi   Hi-Lo    BIT     OC\r\n");
   naiif_printf(" ------- -------- ------ ------\r\n");


   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusBit));
   naiif_printf("  %3i   ", statusBit);

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED, &statusBit));
   naiif_printf("  %3i   ", statusBit);

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_BIT_LATCHED, &statusBit));
   naiif_printf("  %3i   ", statusBit);

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED, &statusBit));
   naiif_printf("  %3i   ", statusBit);

   naiif_printf("\r\n\r\n");

   return NAI_SUCCESS;
}

static nai_status_t Clear_TTL_Status(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   nai_status_bit_t statusBit;
   Verify_TTL_ParamCnt(paramCnt);
   /* Available status:
    *    NAIBRD_TTL_STATUS_BIT,
    *    NAIBRD_TTL_STATUS_OVER_CURRENT,
    *    NAIBRD_TTL_STATUS_MAX_HI,
    *    NAIBRD_TTL_STATUS_MIN_LO,
    *    NAIBRD_TTL_STATUS_MID_RANGE,
    *    NAIBRD_TTL_STATUS_LO_HI_TRANS,
    *    NAIBRD_TTL_STATUS_HI_LO_TRANS,
    */


   status = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusBit));
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED));
   }

   status = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED, &statusBit));
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED));
   }

   status = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_BIT_LATCHED, &statusBit));
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_BIT_LATCHED));
   }

   status = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED, &statusBit));
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED));
   }

   if (status == NAI_SUCCESS)
   {
      naiif_printf("Cleared statuses for channel %d...\r\n", chan);
   }

   return status;
}

static nai_status_t Configure_TTL_Interrupt(int32_t paramCnt, int32_t* p_params)
{
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int32_t chan = ttlParams->channel;
   uint32_t vector = 0xB0u;
   nai_status_t status;
   Verify_TTL_ParamCnt(paramCnt);

   /* Specify callback function for interrupt type */
   status = naibrd_ConnectISR(cardIndex, SampleCallBack); /* Invoked once per card, not per interrupt type */
   if (status == NAI_ERROR_NOT_SUPPORTED)
   {
      naiif_printf("\r\n**Interrupts are either not supported on this platform or not enabled**\r\n");
   }

   check_status(naibrd_TTL_SetChanMappedInterruptTriggerType(cardIndex, module, chan, NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED,
         NAIBRD_INT_TRIGGER_TYPE_EDGE));
   check_status(naibrd_TTL_SetChanMappedInterruptSteering(cardIndex, module, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED,
         NAIBRD_INT_STEERING_ONBOARD_ARM));
   check_status(naibrd_TTL_SetChanMappedInterruptVector(cardIndex, module, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, vector));
   check_status(naibrd_TTL_SetChanMappedInterruptEnable(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, NAI_TRUE));

   naiif_printf("\r\nInterrupt Configuration\r\n");
   naiif_printf("=======================\r\n");
   naiif_printf("Card Index:%d\r\n", cardIndex);
   naiif_printf("Module Number:%d\r\n", module);
   naiif_printf("Channel:%d\r\n", chan);
   naiif_printf("Vector:0x%X\r\n", vector);
   naiif_printf("Status:LO-HI Transition\r\n");
   naiif_printf("\r\n\r\n Waiting for LO-HI Transition Latched interrupt on channel %d...\r\n", chan);

   return NAI_SUCCESS;
}

static void SampleCallBack(uint32_t vector)
{
   /* Printing in an ISR is always a bad idea. For demonstration purposes only.
    * logMsg & naibsp_printf are a little better since they queue up messages. */
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
   logMsg("\r\n\r\nInterrupt Received!!! Vector:0x%x\n Clear Status to receive new interrupt!!!\r\n",vector,0,0,0,0,0);
#else
   naibsp_printf("\r\n\r\nInterrupt Received!!! Vector:0x%x\r\n Clear Status to receive new interrupt!!!\r\n", vector);
#endif
}

Help Bot

X