TTL BasicOps Sample Application (SSK 1.x)

Overview

The TTL BasicOps sample application demonstrates the standard operations for an NAI TTL (Transistor-Transistor Logic) discrete I/O module using the NAI Software Support Kit (SSK 1.x). Each channel on a TTL module can be independently configured as a digital input or a digital output. The sample shows how to set a channel’s I/O direction, drive an output high or low, read an input’s logic state, configure the per-bank supply voltage (VCC) source, and read or clear channel status (BIT, overcurrent, and logic-transition detection).

This sample supports the Gen 5 24-channel TTL modules (TL1–TL8) and the legacy Gen 3 D7 module. 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.

Like several other BasicOps samples, TTL BasicOps operates on one channel at a time: you select a channel, and the menu then displays that channel’s configuration and dispatches commands against it. The commands are:

CommandDescription
FormatSet the channel’s I/O format (input or output)
OutSet an output channel’s drive state (high or low)
StatDisplay the channel’s status (BIT, overcurrent, transitions)
ResetReset an overcurrent condition
ClearClear the channel’s latched status
ConfigConfigure the VCC source (internal or external) for the channel’s bank

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a TTL module installed (TL1–TL8, or a legacy D7).
  • 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.

How to Run

Launch the TTL_BasicOps executable from your build output directory. On startup the application looks for a configuration file (default_TTL_BasicOps.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. After selecting the module you are prompted for a channel, and the TTL Basic Operation Menu opens for that channel.

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 1.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu.
  2. Query the user for a card index with naiapp_query_CardIndex().
  3. Retrieve the module count with naibrd_GetModuleCount() and query for a module slot with naiapp_query_ModuleNumber().
  4. Retrieve the module ID with naibrd_GetModuleID() and, if valid, hand control to Run_TTL_BasicOps().
#if defined (__VXWORKS__)
int32_t TTL_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
                  Run_TTL_BasicOps(cardIndex, module, moduleID);
            }
         }
         printf("\nType Q to quit or Enter key to restart application:\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }
 
   naiapp_access_CloseAllOpenCards();
   return 0;
}

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 selection not recognized as TTL module” — the selected slot does not contain a TTL module. naibrd_TTL_GetChannelCount() returns 0 for non-TTL modules, and the sample rejects the selection.

Program Structure

Entry Point

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

#if defined (__VXWORKS__)
int32_t TTL_BasicOps(void)
#else
int32_t main(void)
#endif

Channel Selection and Banks

Run_TTL_BasicOps() confirms the module is a TTL module via naibrd_TTL_GetChannelCount(), then Cfg_TTL_Channel() prompts for a single channel with naiapp_query_ChannelNumber(). It also computes which VCC bank the channel belongs to. TTL channels are grouped into banks that share a supply-voltage source; the bank number is derived from the channel and the module’s bank size:

naiapp_query_ChannelNumber(MaxChannel, DEF_TTL_CHANNEL, &chan);
ttl_basicops_params->channel = chan;
bank = ((chan - 1) / naibrd_TTL_GetVCCBankSize(ModuleID)) + 1;

The selected card, module, and channel are stored in an naiapp_AppParameters_t struct passed to every command handler.

Note

The VCC configuration command operates on the bank, not the channel. In the VCC handler the channel field of the parameter struct is reused as the bank number, so configuring VCC affects every channel in that bank.

Command Loop

Cfg_TTL_Channel() drives the command loop. On each iteration it displays the selected channel’s configuration via Display_TTL_ChannelCfg(), prints the command menu, and dispatches the selection. The overcurrent reset (Reset) is handled inline; the other commands dispatch through the TTL_BasicOpMenuCmds[] table to their handler functions. The menu-driven structure is a convenience of the sample — in your own application you would call the naibrd_TTL_*() functions directly.

I/O Format

Each channel is independently configured as an input or an output with naibrd_TTL_SetIOFormat(). The output format value differs between module generations, so the sample selects it based on the module ID:

nai_ttl_ioformat_t state;
 
/* Input */
state = NAI_TTL_IOFORMAT_INPUT;
 
/* Output -- Gen 3 (D7) uses a different value than Gen 5 (TL1-TL8) */
if (ModuleID == NAI_MODULE_ID_D7)
   state = NAI_TTL_GEN3_IOFORMAT_OUTPUT;
else
   state = NAI_TTL_GEN5_IOFORMAT_OUTPUT;
 
naibrd_TTL_SetIOFormat(cardIndex, module, channel, state);
  • NAI_TTL_IOFORMAT_INPUT — configures the channel as an input.
  • NAI_TTL_GEN5_IOFORMAT_OUTPUT — configures a Gen 5 (TL1–TL8) channel as an output.
  • NAI_TTL_GEN3_IOFORMAT_OUTPUT — the equivalent value for the legacy Gen 3 D7 module.

The current format is read back for display with naibrd_TTL_GetIOFormat().

Note

Always set a channel’s I/O format before driving its output state. Output state has no effect on a channel that is configured as an input.

Output State

For a channel configured as an output, set its drive state with naibrd_TTL_SetOutputState():

naibrd_TTL_SetOutputState(cardIndex, module, channel, NAI_TTL_STATE_HI);   /* drive high */
naibrd_TTL_SetOutputState(cardIndex, module, channel, NAI_TTL_STATE_LO);   /* drive low */
  • NAI_TTL_STATE_HI — drive the output high.
  • NAI_TTL_STATE_LO — drive the output low.

The configured output state is read back with naibrd_TTL_GetOutputState(). This setting does not apply to channels configured as inputs.

Reading Channel State

Display_TTL_ChannelCfg() reads back and prints the channel’s complete configuration on each loop iteration — the same calls you would use in your own application to read a channel’s state:

nai_ttl_ioformat_t ioformat = 0;
nai_ttl_state_t outputstate = 0;
nai_ttl_state_t inputstate = 0;
nai_ttl_vcc_t vccConfig = 0;
 
naibrd_TTL_GetIOFormat(cardIndex, module, channel, &ioformat);
naibrd_TTL_GetOutputState(cardIndex, module, channel, &outputstate);
naibrd_TTL_GetInputState(cardIndex, module, channel, &inputstate);
naibrd_TTL_GetBankVCCSource(cardIndex, module, bank, &vccConfig);
  • naibrd_TTL_GetIOFormat() — whether the channel is an input or output.
  • naibrd_TTL_GetOutputState() — the commanded output state (for output channels).
  • naibrd_TTL_GetInputState() — the actual logic level present on the channel. This is the read-back you use to sense a digital input.
  • naibrd_TTL_GetBankVCCSource() — the VCC source for the channel’s bank.

VCC Configuration

TTL channels are organized into VCC banks, each of which can draw its supply voltage from an internal source or an externally supplied one. Set a bank’s source with naibrd_TTL_SetBankVCCSource():

naibrd_TTL_SetBankVCCSource(cardIndex, module, bank, NAI_TTL_VCC_INTERNAL);   /* internal supply */
naibrd_TTL_SetBankVCCSource(cardIndex, module, bank, NAI_TTL_VCC_EXTERNAL);   /* external supply */
  • bank — the VCC bank number (computed from the channel and naibrd_TTL_GetVCCBankSize()).
  • NAI_TTL_VCC_INTERNAL / NAI_TTL_VCC_EXTERNAL — the supply source.

The module also exposes naibrd_TTL_GetVCCBankCount(), naibrd_TTL_GetVCCBankSize(), and naibrd_TTL_GetBankVCCReading() to query the bank layout and measured bank voltage.

Important

VCC configuration applies to an entire bank, so it affects every channel that shares that bank. Choose the source that matches how the bank is wired in your system — selecting external VCC without an external supply present will leave those channels unpowered.

Status and Overcurrent Reset

Reading Status

naibrd_TTL_GetStatus() reads a channel’s status conditions, selected by a nai_ttl_status_type_t. Most conditions have both a latched and a real-time variant (the real-time variants are Gen 5 only and return NAI_ERROR_NOT_SUPPORTED on Gen 3):

nai_status_bit_t statusread;
 
naibrd_TTL_GetStatus(cardIndex, module, channel, NAI_TTL_STATUS_BIT_LATCHED,          &statusread);
naibrd_TTL_GetStatus(cardIndex, module, channel, NAI_TTL_STATUS_OVERCURRENT_LATCHED,  &statusread);
naibrd_TTL_GetStatus(cardIndex, module, channel, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED,  &statusread);
naibrd_TTL_GetStatus(cardIndex, module, channel, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED,  &statusread);
  • BIT — a built-in-test fault on the channel.
  • Overcurrent — the output channel is sourcing more current than allowed.
  • Lo-Hi / Hi-Lo transition — a low-to-high or high-to-low logic transition was detected on the channel.

The sample reads each condition in both latched and real-time form, printing N/A where the real-time variant is not supported by the module.

Clearing Status

Latched status bits are cleared with naibrd_TTL_ClearStatus(), one status type at a time. The sample clears all four latched conditions together:

naibrd_TTL_ClearStatus(cardIndex, module, channel, NAI_TTL_STATUS_BIT_LATCHED);
naibrd_TTL_ClearStatus(cardIndex, module, channel, NAI_TTL_STATUS_OVERCURRENT_LATCHED);
naibrd_TTL_ClearStatus(cardIndex, module, channel, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED);
naibrd_TTL_ClearStatus(cardIndex, module, channel, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED);

Resetting an Overcurrent Condition

When an output draws too much current, the channel latches an overcurrent condition and stops driving. After correcting the wiring or load, reset it with naibrd_TTL_ResetAll() (all channels) and/or naibrd_TTL_Reset() (per channel on Gen 5):

naibrd_TTL_ResetAll(cardIndex, module, NAI_TTL_RESET_OVERCURRENT);                 /* reset all channels */
naibrd_TTL_Reset(cardIndex, module, channel, NAI_TTL_RESET_OVERCURRENT);           /* reset one channel (Gen 5) */

Important

Common Errors

  • Real-time status shows N/A — the real-time status variants are Gen 5 only. On a Gen 3 D7 module they return NAI_ERROR_NOT_SUPPORTED; only the latched variants are available.
  • Overcurrent keeps re-latching — resetting the overcurrent condition does not fix the underlying cause. Verify the load and wiring on the channel before resetting.
  • Output channel does nothing — confirm the channel’s I/O format is set to output, and that its VCC bank source is configured correctly.

Troubleshooting Reference

This table summarizes common errors and symptoms covered in the sections above. Consult your module’s manual for hardware-specific diagnostic procedures.

Error / SymptomPossible CausesSuggested Resolution
No board found or connection timeoutBoard not powered, incorrect or missing configuration file, network issueVerify hardware is powered and connected. If default_TTL_BasicOps.txt exists, check that it lists the correct interface and address; otherwise configure and save your connection in the board menu.
”Module selection not recognized as TTL module”Selected slot is not a TTL module, or wrong module numbernaibrd_TTL_GetChannelCount() returns 0 for non-TTL modules. Verify the slot contains a TL1–TL8 or D7.
Output state has no effectChannel configured as an inputSet the channel’s I/O format to output before setting its output state.
Real-time status shows N/AReal-time status variants are Gen 5 onlyExpected on the Gen 3 D7; use the latched variants.
Overcurrent status keeps returningUnderlying overload not correctedFix the load/wiring, then reset with naibrd_TTL_ResetAll() / naibrd_TTL_Reset().
Output channels unpoweredVCC bank set to external with no external supplySet the bank’s VCC source to match how it is wired (naibrd_TTL_SetBankVCCSource()).

Full Source

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

Full Source — TTL_BasicOps.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
 
/* Common Sample Program include files */
#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"
#include "functions/naibrd_ttl.h"
#include "advanced/nai_ether_adv.h"
 
static const int8_t *CONFIG_FILE = (const int8_t *)"default_TTL_BasicOps.txt";
 
/* Function prototypes */
int32_t Run_TTL_BasicOps(int32_t cardIndex, int32_t module, uint32_t ModuleID);
static void Cfg_TTL_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
 
static void Display_TTL_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, int32_t bank, uint32_t ModuleID);
static nai_status_t Display_TTL_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Clear_TTL_Status(int32_t paramCount, int32_t* p_params);
 
static nai_status_t Configure_TTL_IOFormat(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_OutputState(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_VCCConfig(int32_t paramCount, int32_t* p_params);
 
static const int32_t DEF_TTL_CHANNEL = 1;
 
/****** Command Table *******/
enum dt_basicops_commands
{
   TTL_BASICOP_CMD_IOFORMAT,
   TTL_BASICOP_CMD_OUTPUTSTATE,
   TTL_BASICOP_CMD_STATUS,
   TTL_BASICOP_CMD_ROC,
   TTL_BASICOP_CMD_STATUS_CLEAR,
   TTL_BASICOP_CMD_VCC_CFG,
   TTL_BASICOP_CMD_COUNT
};
 
/****** Command Tables *******/
naiapp_cmdtbl_params_t TTL_BasicOpMenuCmds[] = {
   {"Format",     "TTL Set IO Format",         TTL_BASICOP_CMD_IOFORMAT,         Configure_TTL_IOFormat},
   {"Out",        "TTL Set Output State",      TTL_BASICOP_CMD_OUTPUTSTATE,      Configure_TTL_OutputState},
   {"Stat",       "TTL Display Status",        TTL_BASICOP_CMD_STATUS,           Display_TTL_Status},
   {"Reset",      "TTL Reset Overcurrent",     TTL_BASICOP_CMD_ROC,              NULL},
   {"Clear",      "TTL Clear Status",          TTL_BASICOP_CMD_STATUS_CLEAR,     Clear_TTL_Status},
   {"Config",     "TTL VCC Configuration",     TTL_BASICOP_CMD_VCC_CFG,          Configure_TTL_VCCConfig}
};
 
/**************************************************************************************************************/
/** \defgroup TTL_BasicOps TTL Basic Operations
The purpose of the TTL_BasicOps is to illustrate the naibrd library methods for standard TTL
operations with the module, including configuration setup, controlling drive outputs, and reading the logic
state of the channels.
*/
/**************************************************************************************************************/
 
#if defined (__VXWORKS__)
int32_t TTL_BasicOps(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
   if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
   {
      while (stop != TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
 
            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_TTL_BasicOps(cardIndex, module, moduleID);
               }
            }
         }
 
         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;
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
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 discrete module.
\param cardIndex (Input) Logical Card Index assigned to connection with the NAI_BOARD (0 - NAI_MAX_CARDS-1).
\param module    (Input) Module Number of the module to access (1 - [max modules for board]).
\param ModuleID  (Input) The ID of the module.
*/
/**************************************************************************************************************/
int32_t Run_TTL_BasicOps(int32_t cardIndex, int32_t module, uint32_t ModuleID)
{
   int32_t MaxChannel;
 
   MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);
   if (MaxChannel == 0)
   {
      printf(" *** Module selection not recognized as TTL module. ***\n\n");
   }
   else
   {
      Cfg_TTL_Channel(cardIndex, module, ModuleID, MaxChannel);
   }
   return cardIndex;
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Handles calling the Display_TTL_ChannelCfg routine to display the discrete channel configuration
and prompts the user to enter in a menu command from the following:
\verbatim
TTL Set IO Format
   > Configure the Input/Outpt configuration for the selected channel.
TTL Set Output State
   > Configure the output state (i.e. high, low).
TTL Display Status
   > Print TTL modules statuses.
TTL Clear Status
   > Clear latched TTL module statuses.
TTL VCC Configuration
   > Configure the VCC state (i.e. internal, external).
TTL Reset Overcurrent
   > Reset overcurrent status.
\endverbatim
\param cardIndex  (Input) Logical Card Index assigned to connection with the NAI_BOARD (0 - NAI_MAX_CARDS-1).
\param module     (Input) Module Number of the module to access (1 - [max modules for board]).
\param ModuleID   (Input) The ID of the module.
\param MaxChannel (Input) The maximum number of channels the module has.
*/
/**************************************************************************************************************/
static void Cfg_TTL_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   nai_status_t status = 0;
   int32_t chan, defaultchan = 1;
   int32_t bank = 0;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
   naiapp_AppParameters_t  ttl_params;
   p_naiapp_AppParameters_t ttl_basicops_params = &ttl_params;
   ttl_basicops_params->cardIndex = cardIndex;
   ttl_basicops_params->module = module;
 
   while (bContinue)
   {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");
      defaultchan = DEF_TTL_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      ttl_basicops_params->channel = chan;
      bank = ((chan - 1) / naibrd_TTL_GetVCCBankSize(ModuleID)) + 1;
 
      naiapp_utils_LoadParamMenuCommands(TTL_BASICOP_CMD_COUNT, TTL_BasicOpMenuCmds);
      while (bContinue)
      {
         Display_TTL_ChannelCfg(cardIndex, module, chan, bank, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"TTL Basic Operation Menu");
         printf("\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_BASICOP_CMD_IOFORMAT:
                  case TTL_BASICOP_CMD_OUTPUTSTATE:
                  case TTL_BASICOP_CMD_STATUS_CLEAR:
                  case TTL_BASICOP_CMD_STATUS:
                     TTL_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_basicops_params);
                     break;
                  case TTL_BASICOP_CMD_VCC_CFG:
                     TTL_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_basicops_params);
                     break;
                  case TTL_BASICOP_CMD_ROC:
                     status = NAI_SUCCESS;
                     status |= check_status(naibrd_TTL_ResetAll(cardIndex, module, NAI_TTL_RESET_OVERCURRENT));   /*This resets all channels*/
                     status |= check_status(naibrd_TTL_Reset(cardIndex, module, chan, (nai_ttl_reset_type_t)NAI_TTL_RESET_OVERCURRENT)); /*This alternate function resets channel 1 only on Gen5 modules. */
                     if (status == NAI_SUCCESS)
                        printf("Overcurrent condition reset completed \n");
                     break;
                  default:
                     printf("Invalid command entered\n");
                     break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}
 
/**************************************************************************************************************/
/**
\ingroup TTL_BasicOps
Display_TTL_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
\param cardIndex  (Input) Logical Card Index assigned to connection with the NAI_BOARD (0 - NAI_MAX_CARDS-1).
\param module     (Input) Module Number of the module to access (1 - [max modules for board]).
\param chan       (Input) Channel Number of the channel to access (1 - [max channels for module]).
\param bank       (Input) Number of the bank set (1 - [max banks for module]).
\param ModuleID   (Input) The ID of the module.
*/
/**************************************************************************************************************/
static void Display_TTL_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, int32_t bank, uint32_t ModuleID)
{
   uint32_t ioformat = 0;
   nai_ttl_state_t outputstate = 0;
   nai_ttl_state_t inputstate = 0;
   nai_ttl_vcc_t vccConfig = 0;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
 
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
   check_status(naibrd_TTL_GetIOFormat(cardIndex, module, chan, &ioformat));
   check_status(naibrd_TTL_GetOutputState(cardIndex, module, chan, &outputstate));
   check_status(naibrd_TTL_GetInputState(cardIndex, module, chan, &inputstate));
   check_status(naibrd_TTL_GetBankVCCSource(cardIndex, module, bank, &vccConfig));
 
   printf("\n === Channel %d ===\n\n", chan);
   printf(" IOFormat  Output Input  Bank  VCCConfig\n");
   printf(" --------- ------ -----  ----- ---------\n");
   if (ModuleID == NAI_MODULE_ID_D7)
   {
      /*For all Gen3 and prior modules, I/O output mode configuration control setting is different.*/
      switch (ioformat)
      {
      case NAI_TTL_IOFORMAT_INPUT:
         printf("  Input   ");
         break;
      case NAI_TTL_GEN3_IOFORMAT_OUTPUT:
         printf("  Output  ");
         break;
      default:
         printf(" Unknown  ");
         break;
      }
   }
   else
   {
      switch (ioformat)
      {
      case NAI_TTL_IOFORMAT_INPUT:
         printf("  Input   ");
         break;
      case NAI_TTL_GEN5_IOFORMAT_OUTPUT:
         printf("  Output  ");
         break;
      default:
         printf(" Unknown  ");
         break;
      }
   }
   if (ioformat != NAI_TTL_IOFORMAT_INPUT)
   {
      switch (outputstate)
      {
      case NAI_TTL_STATE_LO:
         printf("  Low ");
         break;
      case NAI_TTL_STATE_HI:
         printf("  High");
         break;
         /* undefined value read back */
      default:
         printf("  UNK ");
         break;
      }
   }
   else
      printf("  --- ");
 
   printf("  %3i   ", inputstate);
   printf("  %2i   ", bank);
 
   switch (vccConfig)
   {
   case NAI_TTL_VCC_INTERNAL:
      printf("Internal");
      break;
   case NAI_TTL_VCC_EXTERNAL:
      printf("External");
      break;
   default:
      printf("Unknown  ");
      break;
   }
 
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Display_TTL_Status illustrate the methods to call in the naibrd library to retrieve the status states.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params   (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Display_TTL_Status(int32_t paramCount, int32_t* p_params)
{
   nai_status_bit_t statusread;
   nai_status_t status = 0;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t chan = p_ttl_params->channel;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
 
   /* Available statusread:
         NAI_TTL_STATUS_BIT_LATCHED,
         NAI_TTL_STATUS_BIT_REALTIME,            (GEN5 only)
         NAI_TTL_STATUS_OVERCURRENT_LATCHED,
         NAI_TTL_STATUS_OVERCURRENT_REALTIME,    (GEN5 only)
         NAI_TTL_STATUS_LO_HI_TRANS_LATCHED,
         NAI_TTL_STATUS_LO_HI_TRANS_REALTIME,    (GEN5 only)
         NAI_TTL_STATUS_HI_LO_TRANS_LATCHED,
         NAI_TTL_STATUS_HI_LO_TRANS_REALTIME,    (GEN5 only)
    */
   printf("\n");
   printf(" ------------------------- Status ----------------------------\n");
   printf(" |    BIT      |      OC       |  Lo-Hi Trans |  Hi-Lo Trans |\n");
   printf("  Latch   RT      Latch   RT      Latch   RT      Latch   RT  \n");
   printf(" -------------- --------------- -------------- ---------------\n");
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_REALTIME, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else if (status == NAI_ERROR_NOT_SUPPORTED)
      printf("  N/A   "); /*not available*/
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_REALTIME, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else if (status == NAI_ERROR_NOT_SUPPORTED)
      printf("  N/A   "); /*not available*/
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_REALTIME, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else if (status == NAI_ERROR_NOT_SUPPORTED)
      printf("  N/A   "); /*not available*/
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else
      printf(" Err %3i", status);
 
   status = check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_REALTIME, &statusread));
   if (status == NAI_SUCCESS)
      printf("  %3i   ", statusread);
   else if (status == NAI_ERROR_NOT_SUPPORTED)
      printf("  N/A   "); /*not available*/
   else
      printf(" Err %3i", status);
   printf("\n\n");
   return NAI_ERROR_UNKNOWN;
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Clear_TTL_Status illustrate the methods to call in the naibrd library to clear the latched status states.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params   (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Clear_TTL_Status(int32_t paramCount, int32_t* p_params)
{
   nai_status_t status = 0;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t chan = p_ttl_params->channel;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
 
   /* Available status:
        NAI_TTL_STATUS_BIT_LATCHED,
        NAI_TTL_STATUS_OVERCURRENT_LATCHED,
        NAI_TTL_STATUS_LO_HI_TRANS_LATCHED,
        NAI_TTL_STATUS_HI_LO_TRANS_LATCHED,
   */
   /*Clear latched status - move this to separate operator option selection */
   status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED));
   status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED));
   status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED));
   status |= check_status(naibrd_TTL_ClearStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED));
   if (status == NAI_SUCCESS)
      printf("Latched Status cleared \n\n");
   return NAI_ERROR_UNKNOWN;
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Configure_TTL_IOFormat handles the user request to configure the Input/Output configuration for the selected
channel and calls the method in the naibrd library to set the Input/Output mode.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params   (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_IOFormat(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateIOCfg = FALSE;
   uint32_t state = 0;
   int8_t iofmtreq;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t chan = p_ttl_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
 
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
 
   /*  Set I/O format configuration for channel. Available configurations include:
            NAI_TTL_IOFORMAT_INPUT
            NAI_TTL_GEN3_IOFORMAT_OUTPUT
            NAI_TTL_GEN5_IOFORMAT_OUTPUT
            NAI_TTL_IOFORMAT_OUTPUT
   */
   printf("Type the desired IO configuration ");
   printf("(I=Input, Out=Output): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         iofmtreq = (int8_t)toupper(inputBuffer[0]);
         if (iofmtreq == 'I')
         {
            state = NAI_TTL_IOFORMAT_INPUT;
            bUpdateIOCfg = TRUE;
         }
         else if (iofmtreq == 'O')
         {
            if (ModuleID == NAI_MODULE_ID_D7)
               state = NAI_TTL_GEN3_IOFORMAT_OUTPUT;
            else
               state = NAI_TTL_GEN5_IOFORMAT_OUTPUT;
            bUpdateIOCfg = TRUE;
         }
         else
         {
            printf("ERROR: Invalid selection\n");
         }
      }
      if (!bQuit)
      {
         if (bUpdateIOCfg)
            check_status(naibrd_TTL_SetIOFormat(cardIndex, module, chan, state));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Configure_TTL_OutputState handles the user request to set the Output state for the selected
channel and calls the method in the naibrd library to set the Output state.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params   (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_OutputState(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_ttl_state_t outputstate = 0;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t chan = p_ttl_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
 
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
 
   /* Set the output state (high or low) on output channels.
      This is not applicable for channels configured as inputs.
   */
   printf("\nEnter the desired output state ");
   printf("(L=low output, H=high output): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'L':
            outputstate = 0;
            bUpdateOutput = TRUE;
            break;
         case 'H':
            outputstate = 1;
            bUpdateOutput = TRUE;
            break;
         default:
            printf("ERROR: Invalid Output State Format Entry\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_TTL_SetOutputState(cardIndex, module, chan, outputstate));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
 
/**************************************************************************************************************/
/** \ingroup TTL_BasicOps
Configure_TTL_VCCConfig handles the user request to set the VCC configuration for the selected
bank and calls the method in the naibrd library to set the configuration to external or internal.
\param paramCount (Input) Number of parameter variables in p_params.
\param p_params   (Input) Pointer to a naiapp_AppParameters struct containing information about the card and module.
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_VCCConfig(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateVccCfg = FALSE;
   nai_ttl_vcc_t vccCfg = 0;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   p_naiapp_AppParameters_t p_ttl_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_ttl_params->cardIndex;
   int32_t module = p_ttl_params->module;
   int32_t bank = p_ttl_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
 
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
 
   /* Set the vcc config (external or internal) on bank.*/
   printf("\nEnter the desired VCC configuration ");
   printf("(E=external, I=internal): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'E':
            vccCfg = NAI_TTL_VCC_EXTERNAL;
            bUpdateVccCfg = TRUE;
            break;
         case 'I':
            vccCfg = NAI_TTL_VCC_INTERNAL;
            bUpdateVccCfg = TRUE;
            break;
         default:
            printf("ERROR: Invalid VCC Configuration Entry\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateVccCfg)
         check_status(naibrd_TTL_SetBankVCCSource(cardIndex, module, bank, vccCfg));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}