TTL Pattern Generator Sample Application (SSK 1.x)

Overview

The TTL Pattern Generator sample application demonstrates how to drive an NAI TTL (Transistor-Transistor Logic) discrete I/O module from a stored pattern rather than by commanding each output individually. You load a sequence of output-state words into the module’s pattern RAM, define which region of that RAM to play and how fast, and the module clocks the pattern out on its own — either continuously or as a fixed-length burst.

This is another of the TTL channel’s enhanced operating modes, alongside PWM (TTL PWM). Where PWM produces a single repeating pulse shape, the pattern generator plays an arbitrary bit pattern across the module’s channels. Two things make it distinct from the other TTL samples:

  • The pattern, playback window, period, and burst count are configured per module (cardIndex, module), not per channel. The pattern RAM is shared; individual channels are switched into pattern mode with naibrd_TTL_SetOpMode(... NAI_TTL_MODE_OUTPUT_PATTERN_RAM).
  • Playback is governed by three control bits — enable, burst, and pause — set with naibrd_TTL_SetPatternGenCtrl().

The menu commands map directly to naibrd_TTL_*() calls:

CommandDescription
ModeContinuous vs. Burst playback (the burst control bit)
StartAddr / EndAddrSet the pattern-RAM playback window
PeriodSet the pattern step period, in milliseconds
CountSet the burst count (patterns per trigger)
LoadLoad pattern data from a file into pattern RAM
CONtrolEnable or disable pattern output
Pause/PlayPause or resume pattern output
Reset / RAllReturn the channel / all channels to standard I/O
SEtallPut all channels into pattern mode
Display / StatShow the pattern configuration / channel status

Note

Pattern generation is an enhanced-timing feature. The address- and period-range checks in this sample handle the enhanced-timing TTL modules (TL2, TL4, TL6, TL8); consult your module’s manual to confirm support and valid ranges.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with an enhanced-timing TTL module installed (TL2, TL4, TL6, TL8).
  • SSK 1.x installed on your development host, with the sample applications built.
  • A pattern data file named TestRAMPattern.txt in the working directory (see Loading the Pattern).

How to Run

Launch the TTL_PatternGenerator executable from your build output directory. On startup the application looks for a configuration file (default_TTL_PatternGenerator.txt). On the first run this file will not exist — the application presents an interactive board menu where you configure a board connection, card index, and module slot. After selecting the module you are prompted for a channel (which is switched into pattern mode), and the pattern-generator command menu opens.

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 the standard SSK 1.x startup flow — naiapp_RunBoardMenu(), then naiapp_query_CardIndex(), naibrd_GetModuleCount(), naiapp_query_ModuleNumber(), and naibrd_GetModuleID() — handing a valid module to Run_TTL_PatternGenerator(), which confirms it is a TTL module:

MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);
if (MaxChannel == 0)
   printf(" *** Module selection not recognized as TTL module. ***\n\n");
else
   Cfg_TTL_PatternGen_Channel(cardIndex, module, ModuleID, MaxChannel);
  • int32_t naibrd_TTL_GetChannelCount(uint32_t modid) — number of TTL channels for the module, or 0 if it is not a TTL module.

Important

Common connection errors you may encounter at this stage:

  • No board found / connection timeout — verify the board is powered and connected; check default_TTL_PatternGenerator.txt or reconfigure in the board menu.
  • Invalid card or module index — indices are zero-based for cards and one-based for modules.
  • “Module selection not recognized as TTL module” — the slot does not contain a TTL module; naibrd_TTL_GetChannelCount() returned 0.

Program Structure

On standard platforms the entry point is main(); on VxWorks it is TTL_PatternGenerator(), selected by a preprocessor guard. Cfg_TTL_PatternGen_Channel() prompts for a channel, immediately switches it into pattern mode, and then runs the command loop:

naiapp_query_ChannelNumber(MaxChannel, defaultchan, &ttl_patgen_params->channel);
 
/* Configure the selected channel for Pattern Generator Mode */
naibrd_TTL_SetOpMode(cardIndex, module, ttl_patgen_params->channel, NAI_TTL_MODE_OUTPUT_PATTERN_RAM);
  • nai_status_t naibrd_TTL_SetOpMode(int32_t cardIndex, int32_t module, int32_t channel, nai_ttl_enhanced_mode_t mode) — sets the channel operating mode. NAI_TTL_MODE_OUTPUT_PATTERN_RAM puts the channel into pattern-playback mode.

The loop displays the channel’s configuration via Display_TTL_PatternGen_ChannelCfg(), prints the menu, and dispatches commands through the TTL_PatternGen_MenuCmds[] table.

Loading the Pattern

The Load command reads pattern data from a file named TestRAMPattern.txt and writes it into the module’s pattern RAM. Each line of the file is an address,data pair in hex; the data values are collected into an array and loaded in one call:

uint32_t dataPattern[MAX_TTL_PATTERN_GENERATOR_ENTRIES];   /* up to 4092 entries */
/* ... parse each "addr,data" line, storing data words into dataPattern[entryCnt] ... */
 
naibrd_TTL_SetPatternGenBuf(cardIndex, module, entryCnt, &dataPattern[0]);
  • nai_status_t naibrd_TTL_SetPatternGenBuf(int32_t cardIndex, int32_t module, int32_t dataPatternLen, uint32_t* dataPattern) — loads dataPatternLen pattern words into the module’s pattern RAM. The pattern is module-wide — each word’s bits map to the module’s channels, so one buffer drives every channel that is in pattern mode. The buffer can hold up to MAX_TTL_PATTERN_GENERATOR_ENTRIES (4092) entries.

The loaded RAM can be read back with naibrd_TTL_GetPatternGenBuf().

Defining the Playback Window and Timing

Playback runs over a region of pattern RAM, at a set step period, optionally for a fixed number of bursts.

Start and End Address

StartAddr and EndAddr bound the region of RAM that is played. The sample range-checks the entry (for TL2/TL4/TL6/TL8, 0x000400000x0007FFFC) before applying it:

naibrd_TTL_SetPatternGenStartAddr(cardIndex, module, startAddr);
naibrd_TTL_SetPatternGenEndAddr(cardIndex, module, endAddr);
  • nai_status_t naibrd_TTL_SetPatternGenStartAddr(int32_t cardIndex, int32_t module, uint32_t startAddr) — sets the first pattern-RAM address to play.
  • nai_status_t naibrd_TTL_SetPatternGenEndAddr(int32_t cardIndex, int32_t module, uint32_t EndAddr) — sets the last pattern-RAM address to play.
  • uint32_t naibrd_TTL_GetValidPatternGenStart(uint32_t modid) / uint32_t naibrd_TTL_GetValidPatternGenEnd(uint32_t modid) — return the valid start/end address bounds for the module. (The sample hard-codes the TL2/4/6/8 bounds inline and shows these calls in comments as the proper way to obtain them.)

Period

Period sets how long each pattern step is held, in milliseconds. As in the PWM sample, the module’s timebase LSB derives the valid range:

lsb = naibrd_TTL_GetTimebaseLSB(ModuleID);       /* finest timing step, ms */
/* ... range-check ... */
naibrd_TTL_SetPatternGenPeriod(cardIndex, module, 1, time);
  • float64_t naibrd_TTL_GetTimebaseLSB(uint32_t modid) — the module’s finest timing increment, used to bound the period.
  • nai_status_t naibrd_TTL_SetPatternGenPeriod(int32_t cardIndex, int32_t module, int32_t channel, float64_t period_mS) — sets the per-step period in milliseconds.

Burst Count

For burst playback, Count sets how many times the pattern runs per trigger (minimum 1):

naibrd_TTL_SetPatternGen_BurstNum(cardIndex, module, burstcount);
  • nai_status_t naibrd_TTL_SetPatternGen_BurstNum(int32_t cardIndex, int32_t module, uint32_t burstNum) — sets the burst count for the module. Has no effect in continuous mode.

Selecting Mode and Controlling Output

Playback is governed by three control bits, all set with the same call:

  • nai_status_t naibrd_TTL_SetPatternGenCtrl(int32_t cardIndex, int32_t module, nai_ttl_pattern_ctrl_t controlBit, nai_ttl_enable_t state) — sets one pattern-generator control bit to enabled or disabled.

The three control bits are:

  • NAI_TTL_CTRL_PATTERN_BURST — the Mode command. Disabled = continuous playback; enabled = burst playback (respecting the burst count).
  • NAI_TTL_CTRL_PATTERN_ENABLE — the CONtrol command. Enables or disables pattern output.
  • NAI_TTL_CTRL_PATTERN_PAUSE — the Pause/Play command. Enabling this bit pauses output; disabling it (NAI_TTL_ENHANCED_OP_DISABLE) resumes.
/* Continuous vs burst */
naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST,  NAI_TTL_ENHANCED_OP_DISABLE);        /* continuous */
naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST,  NAI_TTL_OUTPUT_ENHANCED_OP_ENABLE);  /* burst */
 
/* Enable output */
naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_ENABLE, NAI_TTL_OUTPUT_ENHANCED_OP_ENABLE);

Current control-bit states are read back for display with naibrd_TTL_GetPatternGenCtrl().

Note

A typical run: switch the channel to pattern mode, Load the pattern, set StartAddr/EndAddr and Period, choose Mode (and Count for burst), then CONtrol → Enable to start output. Use Pause/Play to hold and resume, and Reset when done.

Reading Back Configuration and Status

The Display command reads back the pattern configuration with the matching getters:

naibrd_TTL_GetPatternGenPeriod(cardIndex, module, 1, &period);
naibrd_TTL_GetPatternGen_BurstNum(cardIndex, module, &burstnumber);
naibrd_TTL_GetPatternGenStartAddr(cardIndex, module, &startaddr);
naibrd_TTL_GetPatternGenEndAddr(cardIndex, module, &endaddr);

The Stat command reads the channel’s latched status conditions (BIT, overcurrent, Lo-Hi/Hi-Lo transitions) with naibrd_TTL_GetStatus():

  • nai_status_t naibrd_TTL_GetStatus(int32_t cardIndex, int32_t module, int32_t channel, nai_ttl_status_type_t type, nai_status_bit_t* outstatusVal) — reads one status condition, selected by type.

Resetting

Three commands return channels to a normal state:

  • Reset — disables the enhanced trigger and the three pattern control bits, and returns the selected channel to standard I/O: naibrd_TTL_SetEnhanceTriggerEnable(... NAI_TTL_ENHANCED_OP_DISABLE), naibrd_TTL_SetOpMode(... NAI_TTL_MODE_STD_INPUT_OUTPUT), and naibrd_TTL_SetPatternGenCtrl() for the enable/burst/pause bits.

  • RAll — the same reset applied to every channel, plus naibrd_TTL_Reset(... NAI_TTL_RESET_TIMER_ONLY).

  • SEtall — the inverse: drives every channel low, sets it to output format, and puts it into NAI_TTL_MODE_OUTPUT_PATTERN_RAM so the whole module plays the pattern.

  • nai_status_t naibrd_TTL_SetEnhanceTriggerEnable(int32_t cardIndex, int32_t module, int32_t channel, nai_ttl_enable_t enable) — enables/disables the channel’s enhanced operation.

  • nai_status_t naibrd_TTL_Reset(int32_t cardIndex, int32_t module, int32_t channel, nai_ttl_reset_type_t resetType) — resets the channel; NAI_TTL_RESET_TIMER_ONLY clears timer state without disturbing other configuration.

Troubleshooting Reference

This table summarizes common errors and symptoms covered above. Consult your module’s manual for hardware-specific diagnostics.

Error / SymptomPossible CausesSuggested Resolution
No board found or connection timeoutBoard not powered, incorrect or missing config file, network issueVerify hardware; check default_TTL_PatternGenerator.txt or reconfigure in the board menu.
”Unable to open Pattern file”TestRAMPattern.txt missing from the working directoryPlace a valid TestRAMPattern.txt (hex addr,data lines) beside the executable before running Load.
Pattern loads but nothing outputsOutput not enabled, or channel not in pattern modeSet the channel to pattern mode and issue CONtrol → Enable (NAI_TTL_CTRL_PATTERN_ENABLE).
”Entry out of range” on Start/End AddressAddress outside the module’s pattern-RAM boundsUse an address within the valid range (naibrd_TTL_GetValidPatternGenStart()/GetValidPatternGenEnd(); 0x000400000x0007FFFC on TL2/4/6/8).
”Entry out of range” on PeriodValue smaller than one timebase LSB or larger than the counter maxChoose a period within the printed range (derived from naibrd_TTL_GetTimebaseLSB()).
Burst count ignoredModule in continuous modeSet burst mode via Mode (NAI_TTL_CTRL_PATTERN_BURST enabled) before the burst count takes effect.

Full Source

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

Full Source — TTL_PatternGenerator.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 = (int8_t *)"default_TTL_PatternGenerator.txt";
 
/* Function prototypes */
void Run_TTL_PatternGenerator(int32_t cardIndex, int32_t module, int32_t ModuleID);
void Cfg_TTL_PatternGen_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
void Display_TTL_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Configure_TTL_PatternGen_StartAddr(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_PatternGen_EndAddr(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_PatternGen_Period(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_PatternGen_Burstcount(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_PatternGen_Mode(int32_t paramCount, int32_t* p_params);
static nai_status_t Load_TTL_PatternGenArray(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_ControlEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_ControlPause(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_TTL_PatternGen_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_TTL_Status(int32_t paramCount, int32_t* p_params);
 
static const int32_t DEF_TTL_CHANNEL = 1;
#define MAX_TTL_PATTERN_GENERATOR_ENTRIES    4092
 
/****** Command Table *******/
enum ttl_patterngen_commands
{
   TTL_PATTERNGEN_CMD_MODE,
   TTL_PATTERNGEN_CMD_STARTADDR,
   TTL_PATTERNGEN_CMD_ENDADDR,
   TTL_PATTERNGEN_CMD_PERIOD,
   TTL_PATTERNGEN_CMD_BURSTCOUNT,
   TTL_PATTERNGEN_CMD_LOAD_DATA,
   TTL_PATTERNGEN_CMD_ENABLE,
   TTL_PATTERNGEN_CMD_PAUSE_DATA,
   TTL_PATTERNGEN_CMD_RESETMODE,
   TTL_PATTERNGEN_CMD_RESETALL,
   TTL_PATTERNGEN_CMD_SETALL,
   TTL_PATTERNGEN_CMD_DISP,
   TTL_PATTERNGEN_CMD_STATUS,
   TTL_PATTERNGEN_CMD_LAST
};
 
/****** Command Tables *******/
naiapp_cmdtbl_params_t TTL_PatternGen_MenuCmds[] = {
 
   {"Mode",			   "TTL Select Pattern Mode",                        TTL_PATTERNGEN_CMD_MODE,              Configure_TTL_PatternGen_Mode},
   {"StartAddr",     "TTL Set Start Address",                          TTL_PATTERNGEN_CMD_STARTADDR,         Configure_TTL_PatternGen_StartAddr},
   {"EndAddr",       "TTL Set End Address",                            TTL_PATTERNGEN_CMD_ENDADDR,           Configure_TTL_PatternGen_EndAddr},
   {"Period",        "TTL Pattern Generator Period",                   TTL_PATTERNGEN_CMD_PERIOD,            Configure_TTL_PatternGen_Period},
   {"Count",         "TTL Pattern Generator Burst count",              TTL_PATTERNGEN_CMD_BURSTCOUNT,        Configure_TTL_PatternGen_Burstcount},
   {"Load",          "TTL Load Pattern Generator Data",                TTL_PATTERNGEN_CMD_LOAD_DATA,         Load_TTL_PatternGenArray},
   {"CONtrol",       "TTL Enable or Disable Pattern Generator Output", TTL_PATTERNGEN_CMD_ENABLE,            Configure_TTL_ControlEnable},
   {"Pause/Play",    "TTL Pause or Resume Pattern Gen Output",         TTL_PATTERNGEN_CMD_PAUSE_DATA,        Configure_TTL_ControlPause},
   {"Reset",         "TTL Reset Chan Mode, Input",                     TTL_PATTERNGEN_CMD_RESETMODE,         NULL},
   {"RAll",          "TTL Reset All Channels, Input",                  TTL_PATTERNGEN_CMD_RESETALL,          NULL},
   {"SEtall",        "TTL Set All Channels to Pattern Gen",            TTL_PATTERNGEN_CMD_SETALL,            NULL},
   {"Display",       "TTL Display channel Pattern Generator Info",     TTL_PATTERNGEN_CMD_DISP,              Display_TTL_PatternGen_Configuration},
   {"Stat",          "TTL Display Status",                             TTL_PATTERNGEN_CMD_STATUS,                   Display_TTL_Status},
};
 
/**************************************************************************************************************/
/**
<summary>
The purpose of the TTL_PatternGenerator is to illustrate the methods to call in the naibrd library to perform configuration
 setup for output in Pattern Generator operation mode.  Pattern generator period setting is configurable.
 
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 (__VXWORKS__)
int32_t TTL_PatternGenerator(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_PatternGenerator(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;
}
 
/**************************************************************************************************************/
/**
<summary>
Run_TTL_PatternGenerator prompts the user for the card, module and channel to use for the application and calls
Cfg_TTL_PatternGen_Channel if the card, module, channel is valid for as a TLL module.
</summary>
*/
/**************************************************************************************************************/
void Run_TTL_PatternGenerator(int32_t cardIndex, int32_t module, int32_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_PatternGen_Channel(cardIndex, module, ModuleID, MaxChannel);
   }
}
 
/**************************************************************************************************************/
/**
<summary>
Cfg_TTL_PatternGen_Channel handles calling the Display_TTL_PatternGen_ChannelCfg routine to display the TTL
channel configuration and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
void Cfg_TTL_PatternGen_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;
   int32_t defaultchan = 1;
   int32_t cmd;
   int32_t ch_loop;
   int32_t status = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
   naiapp_AppParameters_t  ttl_params;
   p_naiapp_AppParameters_t ttl_patgen_params = &ttl_params;
   ttl_patgen_params->cardIndex = cardIndex;
   ttl_patgen_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, &ttl_patgen_params->channel);
 
      /* Configure the selected channel for Pattern Generator Mode */
 
      check_status(naibrd_TTL_SetOpMode(cardIndex, module, ttl_patgen_params->channel, NAI_TTL_MODE_OUTPUT_PATTERN_RAM));
 
      naiapp_utils_LoadParamMenuCommands(TTL_PATTERNGEN_CMD_LAST, TTL_PatternGen_MenuCmds);
      while (bContinue)
      {
         Display_TTL_PatternGen_ChannelCfg(cardIndex, module, ttl_patgen_params->channel, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"TTL Pattern Generator 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_PATTERNGEN_CMD_LOAD_DATA:
                  case TTL_PATTERNGEN_CMD_PERIOD:
                  case TTL_PATTERNGEN_CMD_STARTADDR:
                  case TTL_PATTERNGEN_CMD_ENDADDR:
                  case TTL_PATTERNGEN_CMD_BURSTCOUNT:
                  case TTL_PATTERNGEN_CMD_MODE:
                  case TTL_PATTERNGEN_CMD_ENABLE:
                  case TTL_PATTERNGEN_CMD_PAUSE_DATA:
                  case TTL_PATTERNGEN_CMD_DISP:
                  case TTL_PATTERNGEN_CMD_STATUS:
                     TTL_PatternGen_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_patgen_params);
                     break;
                  case TTL_PATTERNGEN_CMD_RESETMODE:
                  {
                     status |= check_status(naibrd_TTL_SetEnhanceTriggerEnable(cardIndex, module, ttl_patgen_params->channel, NAI_TTL_ENHANCED_OP_DISABLE));
                     status |= check_status(naibrd_TTL_SetOpMode(cardIndex, module, ttl_patgen_params->channel, NAI_TTL_MODE_STD_INPUT_OUTPUT));
                     status |= check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_ENABLE, NAI_TTL_ENHANCED_OP_DISABLE));
                     status |= check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST, NAI_TTL_ENHANCED_OP_DISABLE));
                     status |= check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_PAUSE, NAI_TTL_ENHANCED_OP_DISABLE));
 
                     if (status == NAI_SUCCESS)
                        printf("Reset completed \n");
                     else
                        printf("Error %2X on set \n", status);
                  }
                  break;
                  case TTL_PATTERNGEN_CMD_RESETALL:
                  {
                     status = NAI_SUCCESS;
                     for (ch_loop = 1; ch_loop <= MaxChannel; ch_loop++)
                     {
                        status |= check_status(naibrd_TTL_SetEnhanceTriggerEnable(cardIndex, module, ch_loop, NAI_TTL_ENHANCED_OP_DISABLE));
                        status |= check_status(naibrd_TTL_SetOpMode(cardIndex, module, ch_loop, NAI_TTL_MODE_STD_INPUT_OUTPUT));
                        status |= check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_ENABLE, NAI_TTL_ENHANCED_OP_DISABLE));
                        status |= check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST, NAI_TTL_ENHANCED_OP_DISABLE));
                        status |= check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_PAUSE, NAI_TTL_ENHANCED_OP_DISABLE));
                        status |= check_status(naibrd_TTL_Reset(cardIndex, module, ch_loop, NAI_TTL_RESET_TIMER_ONLY));
                     }
                     if (status == NAI_SUCCESS)
                        printf("Reset All completed \n");
                     else
                        printf("Error %2X on set \n", status);
                  }
                  break;
                  case TTL_PATTERNGEN_CMD_SETALL:
                  {
                     status = NAI_SUCCESS;
                     for (ch_loop = 1; ch_loop <= MaxChannel; ch_loop++)
                     {
                        status |= check_status(naibrd_TTL_SetOutputState(cardIndex, module, ch_loop, NAI_TTL_STATE_LO));
                        status |= check_status(naibrd_TTL_SetIOFormat(cardIndex, module, ch_loop, NAI_TTL_GEN5_IOFORMAT_OUTPUT));
                        status |= check_status(naibrd_TTL_SetOpMode(cardIndex, module, ch_loop, NAI_TTL_MODE_OUTPUT_PATTERN_RAM));
                     }
                     if (status == NAI_SUCCESS)
                        printf("Set on all channels completed \n");
                     else
                        printf("Error %2X on set \n", status);
                  }
                  break;
                  default:
                     printf("Invalid command entered\n");
                     break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}
 
/**************************************************************************************************************/
/**
<summary>
Display_TTL_PatternGen_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
void Display_TTL_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   uint32_t ioformat = 0;
   nai_ttl_state_t outputstate = 0;
   nai_ttl_state_t inputstate = 0;
   nai_ttl_enhanced_mode_t opmode = 0;
   nai_ttl_enable_t enablebit = 0;
   nai_ttl_enable_t burstbit = 0;
   nai_ttl_enable_t pausebit = 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_GetOpMode(cardIndex, module, chan, &opmode));
 
   check_status(naibrd_TTL_GetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_ENABLE, &enablebit));
   check_status(naibrd_TTL_GetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST, &burstbit));
   check_status(naibrd_TTL_GetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_PAUSE, &pausebit));
 
   printf("\n === Channel %d ===\n\n", chan);
 
   /*read PWM configuration values here, Period, Pulsewidth, Continuous/Burst Mode, */
   {
      printf("  I/O       Output    Input                                                         \n");
      printf(" Format     State     State    Enhanced Mode Selection            Pattern Gen Mode  \n");
      printf("--------   -------   -------  -------------------------      -----------------------\n");
   }
 
   /*display configuration settings here- */
   switch (ioformat)
   {
   case NAI_TTL_IOFORMAT_INPUT:
      printf("  Input   ");
      break;
   case NAI_TTL_GEN3_IOFORMAT_OUTPUT:
   case NAI_TTL_GEN5_IOFORMAT_OUTPUT:
      printf(" High-side"); /*may want add check for proper value depending on whether gen3 or gen5; for now, assume it correctly matches module*/
      break;
   default:
      printf(" Unknown  ");
      break;
   }
   switch (outputstate)
   {
   case NAI_TTL_STATE_LO:
      printf("  LOW     ");
      break;
   case NAI_TTL_STATE_HI:
      printf("  HIGH    ");
      break;
   default:
      printf(" Unknown  ");
      break;
   }
 
   switch (inputstate)
   {
   case NAI_TTL_STATE_LO:
      printf(" LOW Input  ");
      break;
   case NAI_TTL_STATE_HI:
      printf("HIGH Input  ");
      break;
   default:
      printf("Unknown     ");
      break;
   }
   switch (opmode)
   {
   case NAI_TTL_MODE_STD_INPUT_OUTPUT:
      printf("STD_INPUT_OUTPUT   ");
      break;
   case NAI_TTL_MODE_MEASURE_HIGH_TIME:
      printf("NAI_TTL_MODE_MEASURE_HIGH_TIME   ");
      break;
   case NAI_TTL_MODE_MEASURE_LOW_TIME:
      printf("NAI_TTL_MODE_MEASURE_LOW_TIME   ");
      break;
   case NAI_TTL_MODE_TIMESTAMP_RISING_EDGES:
      printf("NAI_TTL_MODE_TIMESTAMP_RISING_EDGES   ");
      break;
   case NAI_TTL_MODE_TIMESTAMP_FALLING_EDGES:
      printf("NAI_TTL_MODE_TIMESTAMP_FALLING_EDGES   ");
      break;
   case NAI_TTL_MODE_TIMESTAMP_ALL_EDGES:
      printf("NAI_TTL_MODE_TIMESTAMP_ALL_EDGES   ");
      break;
   case NAI_TTL_MODE_COUNT_RISING_EDGES:
      printf("NAI_TTL_MODE_COUNT_RISING_EDGES   ");
      break;
   case NAI_TTL_MODE_COUNT_FALLING_EDGES:
      printf("NAI_TTL_MODE_COUNT_FALLING_EDGES   ");
      break;
   case NAI_TTL_MODE_COUNT_ALL_EDGES:
      printf("NAI_TTL_MODE_COUNT_ALL_EDGES   ");
      break;
   case NAI_TTL_MODE_MEASURE_PERIOD_FROM_RISING_EDGE:
      printf("NAI_TTL_MODE_MEASURE_PERIOD_FROM_RISING_EDGE   ");
      break;
   case NAI_TTL_MODE_MEASURE_FREQUENCY:
      printf("NAI_TTL_MODE_MEASURE_FREQUENCY   ");
      break;
   case NAI_TTL_MODE_OUTPUT_PWM_FOREVER:
      printf("NAI_TTL_MODE_OUTPUT_PWM_FOREVER   ");
      break;
   case NAI_TTL_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES:
      printf("NAI_TTL_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES   ");
      break;
   case NAI_TTL_MODE_OUTPUT_PATTERN_RAM:
      printf("NAI_TTL_MODE_OUTPUT_PATTERN_RAM   ");
      break;
   default:
      printf("Unknown    ");
      break;
   }
 
   switch (enablebit)
   {
   case NAI_TTL_STATE_LO:
      printf("  Disabled");
      break;
   case NAI_TTL_STATE_HI:
      printf("   Enabled");
      break;
      /* undefined value read back */
   default:
      printf("   UNK  ");
      break;
   }
   switch (burstbit)
   {
   case NAI_TTL_STATE_LO:
      printf(" Continuous Mode");
      break;
   case NAI_TTL_STATE_HI:
      printf(" Burst Mode");
      break;
      /* undefined value read back */
   default:
      printf(" UNK  ");
      break;
   }
   switch (pausebit)
   {
   case NAI_TTL_STATE_LO:
      break;
   case NAI_TTL_STATE_HI:
      printf(" PAUSED");
      break;
      /* undefined value read back */
   default:
      printf(" UNK  ");
      break;
   }
 
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_PatternGen_StartAddr handles the user request to configure the time values for period on the selected
channel and calls the method in the naibrd library to set the period.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_PatternGen_StartAddr(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t startAddr = 0;
   uint32_t min = 0;
   uint32_t max = 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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired Start Address: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         startAddr = strtol(((const char *)inputBuffer), NULL, 16);
         switch (ModuleID)
         {
         case NAI_MODULE_ID_TL2:
         case NAI_MODULE_ID_TL4:
         case NAI_MODULE_ID_TL6:
         case NAI_MODULE_ID_TL8:
            min = 0x00040000; /* naibrd_TTL_GetValidPatternGenStart(ModuleID); */
            max = 0x0007FFFC; /* naibrd_TTL_GetValidPatternGenEnd(ModuleID); */
         default:
            break;
         }
         if (startAddr > max || startAddr < min)
            printf(" Entry out of range.  Range %08X to %08X \n", min, max);
         else
         {
            check_status(naibrd_TTL_SetPatternGenStartAddr(cardIndex, module, startAddr));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_PatternGen_EndAddr handles the user request to configure the time values for period on the selected
channel and calls the method in the naibrd library to set the period.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_PatternGen_EndAddr(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t endAddr = 0;
   uint32_t min = 0;
   uint32_t max = 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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired End Address: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         endAddr = strtol(((const char *)inputBuffer), NULL, 16);;
         switch (ModuleID)
         {
         case NAI_MODULE_ID_TL2:
         case NAI_MODULE_ID_TL4:
         case NAI_MODULE_ID_TL6:
         case NAI_MODULE_ID_TL8: 
            min = 0x00040000; /*naibrd_TTL_GetValidPatternGenStart(ModuleID); */
            max = 0x0007FFFC; /* naibrd_TTL_GetValidPatternGenEnd(ModuleID); */
         default:
            break;
         }
         if (endAddr > max || endAddr < min)
            printf(" Entry out of range.  Range 0x%08X to 0x%08X \n", min, max);
         else
         {
            check_status(naibrd_TTL_SetPatternGenEndAddr(cardIndex, module, endAddr));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
 
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_PatternGen_Period handles the user request to configure the time values for period on the selected
channel and calls the method in the naibrd library to set the period.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_TTL_PatternGen_Period(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   float64_t time = 0.0;
   float64_t lsb = 0;
   float64_t min = 1;
   float64_t max = -1;
   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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired period in ms: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         time = atof((const char *)inputBuffer); /*entry in milliseconds*/
         lsb = naibrd_TTL_GetTimebaseLSB(ModuleID);
         switch (ModuleID)
         {
         case NAI_MODULE_ID_TL2:
         case NAI_MODULE_ID_TL4:
         case NAI_MODULE_ID_TL6:
         case NAI_MODULE_ID_TL8:
            min = (float64_t)(0x2u * lsb);
            max = (float64_t)(0xFFFFFFFF * lsb);
         default:
            break;
         }
         if (time > max || time < min)
            printf(" Entry out of range.  Range %7.3f to %7.3f ms\n", min, max);
         else
         {
            check_status(naibrd_TTL_SetPatternGenPeriod(cardIndex, module, 1, time));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handles the user request to set the burst count value for the number of pulses to be issued upon trigger in
PWM burst mode operation on the selected channel, calling the method in the naibrd library to set the burst number.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_PatternGen_Burstcount(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t burstcount;
   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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired burst count: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         burstcount = atoi((const char *)inputBuffer);
         switch (ModuleID)
         {
         case NAI_MODULE_ID_TL2:
         case NAI_MODULE_ID_TL4:
         case NAI_MODULE_ID_TL6:
         case NAI_MODULE_ID_TL8:
            if (burstcount < 1)
            {
               burstcount = 1; /*minimum count is one*/
               printf("Setting burstcount to minimum of 1.\n");
            }
            check_status(naibrd_TTL_SetPatternGen_BurstNum(cardIndex, module, burstcount));
            break;
         default:
            printf("Unsupported function for this module.\n");
            break;
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_PatternGen_Mode handles the user request to select the PWM mode for the selected channel
and calls the method in the naibrd library to set the mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_PatternGen_Mode(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;  
   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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\n == Pattern Gen Mode Selection == \n C  Continuous Pattern Gen mode \n Burst  Burst Pattern Gen mode  \n\n Type TTL command : ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if ((toupper(inputBuffer[0]) == 'C'))
         {
            naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST, NAI_TTL_ENHANCED_OP_DISABLE);
         }
         else if ((toupper(inputBuffer[0]) == 'B'))
         {
            naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_BURST, NAI_TTL_OUTPUT_ENHANCED_OP_ENABLE);
         }
 
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Load_TTL_PatternGenArray loads the pattern from a file and illustrate the methods to call in the naibrd library to
set the pattern data. Channel independent, array covers all channels
</summary>
*/
/**************************************************************************************************************/
nai_status_t Load_TTL_PatternGenArray(int32_t paramCount, int32_t* p_params)
{
   bool_t patternLoaded = FALSE;
   uint32_t dataPattern[MAX_TTL_PATTERN_GENERATOR_ENTRIES];
   int32_t i, j, len;
   int32_t entryCnt = 0;
   FILE* patternfile = NULL;
   int8_t* filename = (int8_t*)"TestRAMPattern.txt";
   int8_t buffer[256];
   int8_t addr[256];
   int8_t data[256];
   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;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
 
   for (i = 0; i < MAX_TTL_PATTERN_GENERATOR_ENTRIES; i++)
      dataPattern[i] = 0;
 
   patternfile = fopen((const char *)filename, "r");
   if (patternfile != NULL)
   {
      while (fgets((char*)buffer, sizeof(buffer), patternfile))
      {
         if (entryCnt > MAX_TTL_PATTERN_GENERATOR_ENTRIES)
            break;
         else
         {
            /* Entries in the RAMPattern.txt are expected to be addr,data */
            len = (int32_t)strlen((const char*)buffer);
            i = 0;
            j = 0;
            /* read the addr entry */
            while ((buffer[i] != ',') && (i < len))
            {
               if (isdigit(buffer[i]) || isalpha(buffer[i]))
                  addr[j++] = buffer[i];
               i++;
            }
            addr[i] = '\0';
            /* Increment i to skip the comma */
            i++;
            j = 0;
            /* read the data entry */
            while (i < len)
            {
               if (isdigit(buffer[i]) || isalpha(buffer[i]))
                  data[j++] = buffer[i];
               i++;
            }
            data[j] = '\0';
            if ((strlen((const char*)addr) > 0) && (strlen((const char*)data) > 0))
            {
               dataPattern[entryCnt] = naiapp_utils_HexStrToDecUInt32(data);
               entryCnt++;
            }
         }
      }
      if (entryCnt > 0)
      {
         /* Load the pattern into memory */
         check_status(naibrd_TTL_SetPatternGenBuf(cardIndex, module, entryCnt, &dataPattern[0]));
         patternLoaded = TRUE;
      }
      else
      {
         printf("ERROR: No pattern data has been loaded from Pattern file: %s\n", filename);
      }
      fclose(patternfile);
   }
   else
      printf("ERROR: Unable to open Pattern file: %s\n", filename);
 
   return (patternLoaded) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_ControlEnable handles the user request to change the switch state for the selected
channel and calls the method in the naibrd library to set the state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_ControlEnable(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_ttl_state_t enState = 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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the switch state (open or closed).
   */
   printf("\n Type the desired Enable Bit Value, Enable or Disable \n ");
   printf(" Enter Enable or Disable: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'E':
            enState = NAI_TTL_OUTPUT_ENHANCED_OP_ENABLE;
            bUpdateOutput = TRUE;
            break;
         case 'D':
            enState = NAI_TTL_ENHANCED_OP_DISABLE;
            bUpdateOutput = TRUE;
            break;
         default:
            printf("ERROR: Invalid switch state selection\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_ENABLE, enState));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_ControlPause handles the user request to change the switch state for the selected
channel and calls the method in the naibrd library to set the state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_ControlPause(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_ttl_state_t enState = 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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the switch state (open or closed).
   */
   printf("\n Type PAUSE or RESUME to Control Pattern Generator Output\n ");
   printf(" Enter PAUSE or RESUME: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'P':
            enState = NAI_TTL_OUTPUT_ENHANCED_OP_ENABLE;
            bUpdateOutput = TRUE;
            break;
         case 'R':
            enState = NAI_TTL_OUTPUT_ENHANCED_OP_ENABLE;
            bUpdateOutput = TRUE;
            break;
         default:
            printf("ERROR: Invalid switch state selection\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_TTL_SetPatternGenCtrl(cardIndex, module, NAI_TTL_CTRL_PATTERN_PAUSE, enState));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Display_TTL_PatternGen_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_TTL_PatternGen_Configuration(int32_t paramCount, int32_t* p_params)
{
   float64_t period;
   uint32_t burstnumber;
   uint32_t startaddr;
   uint32_t endaddr;
   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;
 
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\n");
   printf("  ----------PatternGen Configuration Settings-------------\n");
   printf("  Period (ms)      Burst Cnt      StartAddr     EndAddr  \n");
   printf("  -------------   -----------    -----------   ----------\n");
 
   check_status(naibrd_TTL_GetPatternGenPeriod(cardIndex, module, 1, &period));
   printf(" %10.6f   ", period);
 
   check_status(naibrd_TTL_GetPatternGen_BurstNum(cardIndex, module, &burstnumber));
   printf("    0x%08X   ", burstnumber);
 
   check_status(naibrd_TTL_GetPatternGenStartAddr(cardIndex, module, &startaddr));
   printf("  0x%08X   ", startaddr);
 
   check_status(naibrd_TTL_GetPatternGenEndAddr(cardIndex, module, &endaddr));
   printf("  0x%08X   ", endaddr);
 
   printf("\n\n");
   return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Display_DSW_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 paramCount, int32_t* p_params)
{
   nai_status_bit_t status;
   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,
   */
   printf("\n");
   printf("  ----------------- Status ----------------------------\n");
   printf("   BIT      OC    Lo-Hi   Hi-Lo  \n");
   printf(" ------- -------- ------ ------- \n");
 
   check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_BIT_LATCHED, &status));
   printf("  %3i   ", status);
 
   check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_OVERCURRENT_LATCHED, &status));
   printf("  %3i   ", status);
 
   check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_LO_HI_TRANS_LATCHED, &status));
   printf("  %3i   ", status);
 
   check_status(naibrd_TTL_GetStatus(cardIndex, module, chan, NAI_TTL_STATUS_HI_LO_TRANS_LATCHED, &status));
   printf("  %3i   ", status);
 
   printf("\n\n");
 
   return NAI_ERROR_UNKNOWN;
}