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 BasicOps

TTL BasicOps Sample Application (SSK 2.x)

Overview

The TTL BasicOps sample application demonstrates how to configure and control TTL-level digital I/O channels using the NAI Software Support Kit (SSK 2.x). It covers the core TTL operations you will need in your own application: setting I/O format (input or output), controlling output state, configuring debounce time, enabling floating-point mode, setting BIT error thresholds, managing channel status, reading status registers, resetting overcurrent conditions, running watchdog operations, and managing module power reset.

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 BasicOps (SSK 1.x). For detailed module specifications, refer to the TL1 Manual.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a TTL module installed (TL1 or 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.

How to Run

Launch the ttl_basic_ops 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. Once connected, the application prompts for a channel number and presents a command menu for configuring TTL operations.

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_BasicOps.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 adapt to the specific TTL variant installed.

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t TTL_BasicOps(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_BasicOps(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;
}

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, Windows) the entry point is main(). On VxWorks the entry point is TTL_BasicOps():

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

Command Loop

After connecting to the board and selecting a module, the application calls Run_TTL_BasicOps(), which validates the module and delegates to Cfg_TTL_Channel(). The command loop prompts for a channel number, then displays the current channel configuration and presents the command menu.

The command table defines the following operations:

Command Description

IO

Set I/O format (Input or Output).

OUT

Set output state (High or Low).

D

Set debounce time in milliseconds.

OVER

Reset overcurrent condition for all channels.

STAT

Display status registers (Low-Hi transition, Hi-Lo transition, BIT, overcurrent, summary, watchdog, inter-FPGA).

Float

Enable or disable hardware floating-point mode.

THRESH

Set BIT error threshold voltage.

CHANSTAT

Enable or disable channel status monitoring.

POWER

Check power-on BIT completion status.

BIT

Clear module BIT logic.

RESET

Enter the module power reset submenu.

WATCHDOG

Enter the watchdog submenu (not available on DEOS).

Displaying Channel Configuration

Before each command prompt, Display_TTL_ChannelCfg() reads the I/O format, output/input state, debounce time, VCC voltage, and VCC source:

  • naibrd_TTL_GetIOFormat() — Reads the I/O format (input or output).

  • naibrd_TTL_GetOutputState() / naibrd_TTL_GetInputState() — Reads the output or input logic state.

  • naibrd_TTL_GetDebounceTime() — Reads the debounce time.

  • naibrd_TTL_GetBankVCCReading() — Reads the VCC voltage for the channel bank.

  • naibrd_TTL_GetBankVCCSource() — Reads whether VCC is internal or external.

Configuring I/O Format and Output State

  • naibrd_TTL_SetIOFormat(cardIndex, module, channel, format) — Sets the I/O format. Use NAIBRD_TTL_IOFORMAT_INPUT or NAIBRD_TTL_IOFORMAT_OUTPUT.

  • naibrd_TTL_SetOutputState(cardIndex, module, channel, state) — Sets the output state. Use NAIBRD_TTL_STATE_LO or NAIBRD_TTL_STATE_HI.

Reading and Clearing Status

The Display_TTL_Status() function reads latched status registers and clears them after reading. Available status types include: NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED, NAIBRD_TTL_STATUS_BIT_LATCHED, NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED, NAIBRD_TTL_STATUS_SUMMARY_LATCHED, NAIBRD_TTL_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, and NAIBRD_TTL_STATUS_INTER_FPGA_FAULT_LATCHED.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

Module selection not recognized as TTL module

The selected slot does not contain a TTL module.

Verify that a TL1 or TL2 module is installed in the selected slot.

No board found

Board not powered, cable disconnected, or wrong interface selected.

Verify power, cables, and interface type.

Output state has no effect

Channel is configured as input.

Set I/O format to output first using the IO command.

Overcurrent status stuck

Fault condition persists or has not been reset.

Use OVER command. If it reoccurs, check wiring and load.

VCC reads as zero

No external VCC applied and internal VCC not enabled.

Verify VCC source configuration and external power.

Watchdog fault status set

Strobe thread was killed or missed a window.

Restart strobe thread via watchdog submenu.

Debounce time not taking effect

Value outside supported range.

Consult the TL1 Manual for valid ranges.

Inter-FPGA fault status set

Communication issue between FPGAs on the module.

Check module seating. May require module replacement if persistent.

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_ops.c (SSK 2.x)
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
#include <pthread.h>
#endif

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
#include <taskLib.h>
#endif

/* 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"

static const int8_t *DEF_CONFIG_FILE = (const int8_t *)"default_TTL_BasicOps.txt";

/* Function prototypes */
static int32_t Run_TTL_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
static void Verify_TTL_ParamCnt(int32_t paramCnt);
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, uint32_t ModuleID);

static nai_status_t Display_TTL_Status(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_IOFormat(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_OutputState(int32_t paramCnt, int32_t* p_params);

static nai_status_t Configure_TTL_Debounce(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_Floating(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_BITThresholds(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_TTL_ChannelStatusEnable(int32_t paramCount, int32_t* params);
static nai_status_t Configure_TTL_CheckPBITComplete(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_ClearModuleBITLogic(int32_t paramCount, int32_t* p_params);

static nai_status_t Configure_TTL_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_TTL_SetModulePowerReset(int32_t paramCount, int32_t* p_params);

/* DEOS does not support threading, hence you won't be able to pet the watchdog. */
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
static nai_status_t Handle_TTL_WatchdogShowMenu(int32_t paramCount, int32_t* params);
static nai_status_t Handle_TTL_WatchDogQuietTime(int32_t paramCount, int32_t* params);
static nai_status_t Handle_TTL_WatchDogWindowTime(int32_t paramCount, int32_t* params);
static nai_status_t Handle_TTL_DisplayWatchdog(int32_t paramCount, int32_t* params);
static nai_status_t Handle_TTL_StrobeWatchdog(int32_t paramCount, int32_t* params);
static nai_status_t Handle_TTL_kill_WDStrobe_Thread(int32_t paramCount, int32_t* params);
static void naiapp_kill_WDStrobe_Thread();

static bool_t terminateThread;
static const int8_t *SAMPLE_WD_PGM_NAME = (const int8_t*)"TTL Watchdog Operations";
#endif

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;


#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
DWORD WINAPI WD_Strobe_ThreadEntryPoint(LPVOID param);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
void* WD_Strobe_ThreadEntryPoint(void* arg);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static int WD_Strobe_ThreadEntryPoint(int32_t nParam);
#endif
/* TX Thread */
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
static HANDLE thread = NULL;
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static pthread_t thread;
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static TASK_ID thread;
#endif
/****** Command Table *******/
enum ttl_basicops_commands
{
   TTL_BASICOP_CMD_IOFORMAT,
   TTL_BASICOP_CMD_OUTPUTSTATE,
   TTL_BASICOP_CMD_DEBOUNCE,
   TTL_BASICOP_CMD_RESET_OC,
   TTL_BASICOP_CMD_STATUS,
   TTL_BASICOP_CMD_FLOAT,
   TTL_BASICOP_CMD_BIT_THRESHOLD,
   TTL_BASICOP_CMD_CHANNEL_STATUS_ENABLE,
   TTL_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE,
   TTL_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC,
   TTL_BASICOP_CMD_MODULE_POWER_RESET,
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   TTL_BASICOP_CMD_WD_MENU,
#endif
   TTL_BASICOP_CMD_COUNT
};

#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
enum ttl_gen5_ttl_watchdog_commands
{
   TTL_COMMON_CMD_WD_QUIETTIME,
   TTL_COMMON_CMD_WD_WINDOWTIME,
   TTL_COMMON_CMD_WD_DISPLAY,
   TTL_COMMON_CMD_WD_STROBE,
   TTL_COMMON_CMD_WD_KILL,
   TTL_COMMON_CMD_WD_BACK,
   TTL_COMMON_CMD_WD_COUNT
};
#endif

enum ttl_module_power_reset_commands
{
   TTL_MODULE_POWER_RESET_CMD_BACK,
   TTL_MODULE_POWER_RESET_CMD_CLEAR_MODULE_POWER_RESET_STATUS,
   TTL_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET,
   TTL_MODULE_POWER_RESET_CMD_COUNT
};

/****** Command Tables *******/
static naiapp_cmdtbl_params_t TTL_BasicOpMenuCmds[] = {
   {"IO",         "TTL Set IO Format",                   TTL_BASICOP_CMD_IOFORMAT,                    Configure_TTL_IOFormat},
   {"OUT",        "TTL Set Output State",                TTL_BASICOP_CMD_OUTPUTSTATE,                 Configure_TTL_OutputState},

   {"D",          "TTL Set Debounce Time",               TTL_BASICOP_CMD_DEBOUNCE,                    Configure_TTL_Debounce},
   {"OVER",      "TTL Reset Overcurrent",                TTL_BASICOP_CMD_RESET_OC,                    NULL},
   {"STAT",       "TTL Display Status",                  TTL_BASICOP_CMD_STATUS,                      Display_TTL_Status},
   {"Float",      "TTL Enable/Disable Floating Point",   TTL_BASICOP_CMD_FLOAT,                       Configure_TTL_Floating},
   {"THRESH",     "TTL Set BIT Error Threshold",         TTL_BASICOP_CMD_BIT_THRESHOLD,               Configure_TTL_BITThresholds},
   {"CHANSTAT",   "TTL Enable/Disable Channel Status",   TTL_BASICOP_CMD_CHANNEL_STATUS_ENABLE,       Configure_TTL_ChannelStatusEnable},
   {"POWER",      "TTL Check Power-On BIT Completed",    TTL_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE, Configure_TTL_CheckPBITComplete},
   {"BIT",    "TTL Clear Module BIT Logic",              TTL_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC,      Configure_TTL_ClearModuleBITLogic},
   {"RESET",  "Show Module Power Reset Menu Options",   TTL_BASICOP_CMD_MODULE_POWER_RESET,          Configure_TTL_ModulePowerResetMenu},
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   {"WATCHDOG",   "Show Watchdog Menu Options",         TTL_BASICOP_CMD_WD_MENU,                Handle_TTL_WatchdogShowMenu}
#endif
};

#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
naiapp_cmdtbl_params_t TTL_WatchdogOpMenuCmds[TTL_COMMON_CMD_WD_COUNT] =
{
   {"BACK",           "Back to Main Menu",                             0,                                      NULL},
   {"DISPLAY",        "Display Watchdog Settings",                     TTL_COMMON_CMD_WD_DISPLAY,                  Handle_TTL_DisplayWatchdog},
   {"TIME QUIET",     "Set Watchdog Quiet Time",                       TTL_COMMON_CMD_WD_QUIETTIME,                Handle_TTL_WatchDogQuietTime},
   {"WINDOW",         "Set Watchdog Window Time",                      TTL_COMMON_CMD_WD_WINDOWTIME,               Handle_TTL_WatchDogWindowTime},
   {"STROBE",         "Start thread to continuously strobe watchdog",  TTL_COMMON_CMD_WD_STROBE,                   Handle_TTL_StrobeWatchdog},
   {"KILL",           "Kill Watchdog strobing thread",                 TTL_COMMON_CMD_WD_KILL,                     Handle_TTL_kill_WDStrobe_Thread}
};
#endif
naiapp_cmdtbl_params_t TTL_ModulePowerResetMenuCmds[TTL_MODULE_POWER_RESET_CMD_COUNT] =
{
   {"BACK",  "Back to Main Menu",               TTL_MODULE_POWER_RESET_CMD_BACK,                            NULL},
   {"CLEAR", "Clear Module Power Reset Status", TTL_MODULE_POWER_RESET_CMD_CLEAR_MODULE_POWER_RESET_STATUS, Configure_TTL_ClearModulePowerResetStatus},
   {"SET",   "Set Module Power Reset Request",  TTL_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET,          Configure_TTL_SetModulePowerReset}
};
/**************************************************************************************************************/
/**
 * <summary>
 * The purpose of the TTL_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
 * operations with the discrete 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_BasicOps(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_BasicOps(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>
 * Run_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.
 * </summary>
 */
/**************************************************************************************************************/
static int32_t Run_TTL_BasicOps(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, modid, maxchannel);
      }
   }
   return cardIndex;
}

/**************************************************************************************************************/
/**
 * <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>
 * Cfg_TTL_Channel handles calling the Display_TTL_ChannelCfg routine to display the discrete 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, uint32_t ModuleID, 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;
      ttlParams->modId = ModuleID;

      naiapp_utils_LoadParamMenuCommands(TTL_BASICOP_CMD_COUNT, TTL_BasicOpMenuCmds);
      while (bContinue)
      {
         Display_TTL_ChannelCfg(cardIndex, module, chan, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"TTL Basic Operation 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_BASICOP_CMD_IOFORMAT:
                     case TTL_BASICOP_CMD_OUTPUTSTATE:
                     case TTL_BASICOP_CMD_STATUS:
                     case TTL_BASICOP_CMD_DEBOUNCE:
                     case TTL_BASICOP_CMD_FLOAT:
                     case TTL_BASICOP_CMD_BIT_THRESHOLD:
                     case TTL_BASICOP_CMD_CHANNEL_STATUS_ENABLE:
                     case TTL_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE:
                     case TTL_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC:
                     case TTL_BASICOP_CMD_MODULE_POWER_RESET:
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
                     case TTL_BASICOP_CMD_WD_MENU:
#endif
                        TTL_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttlParams);
                        break;
                     case TTL_BASICOP_CMD_RESET_OC:
                        check_status(naibrd_TTL_ResetAll(cardIndex, module, NAIBRD_TTL_RESET_OVERCURRENT));  /* This resets all channels */
                        check_status(naibrd_TTL_Reset(cardIndex, module, 1, NAIBRD_TTL_RESET_OVERCURRENT));  /* This alternate function resets                                                                  */
                        naiif_printf("Reset completed.\r\n\r\n");
                        break;
                     default:
                        naiif_printf("Invalid command entered\r\n");
                        break;
                  }
               }
               else
               {
                  naiif_printf("Invalid command entered\r\n");
               }
            }
         }
         else
         {
            bContinue = NAI_FALSE;
         }
      }
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
      naiapp_kill_WDStrobe_Thread();
#endif
   }
}

/**************************************************************************************************************/
/**
 * <summary>
 * Display_TTL_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
 * for basic operation.
 * </summary>
 */
/**************************************************************************************************************/
static void Display_TTL_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   naibrd_ttl_ioformat_t ioformat = NAIBRD_TTL_IOFORMAT_INPUT;
   naibrd_ttl_state_t outputstate = NAIBRD_TTL_STATE_LO;
   naibrd_ttl_state_t inputstate = NAIBRD_TTL_STATE_LO;
   naibrd_ttl_vcc_t vccSource = NAIBRD_TTL_VCC_INVALID;
   float64_t voltage = 0.0, vcc = 0.0, debounceTime = 0.0;
   int32_t MaxChannel;
   uint32_t bank;
   bool_t fpEnable = NAI_FALSE;

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

   /* Get the number of VCC banks for the module */
   bank = naibrd_TTL_GetVCCBankCount(ModuleID);
   MaxChannel = naibrd_TTL_GetChannelCount(ModuleID);
   /*read channel voltage and Vcc*/
   check_status(naibrd_TTL_GetDebounceTime(cardIndex, module, chan, &debounceTime));
   check_status(naibrd_TTL_GetBankVCCReading(cardIndex, module, ((chan - 1) / (MaxChannel / bank) + 1), &vcc));
   check_status(naibrd_TTL_GetBankVCCSource(cardIndex, module, ((chan - 1) / (MaxChannel / bank) + 1), &vccSource));
   naiif_printf("\r\n === Channel %d ===\r\n\r\n", chan);
   naiif_printf(" IOFormat  Output Input Debounce\r\n");
   naiif_printf(" --------- ------ ----- -------\r\n");

   switch (ioformat)
   {
      case NAIBRD_TTL_IOFORMAT_INPUT:
         naiif_printf("  Input   ");
         break;
      case NAIBRD_TTL_IOFORMAT_OUTPUT:
         naiif_printf(" Output");
         break;
      default:
         naiif_printf(" Unknown  ");
         break;
   }

   if (ioformat != NAIBRD_TTL_IOFORMAT_INPUT)
   {
      switch (outputstate)
      {
         case NAIBRD_TTL_STATE_LO:
            naiif_printf("  Low ");
            break;
         case NAIBRD_TTL_STATE_HI:
            naiif_printf("  High");
            break;
         /* undefined value read back */
         default:
            naiif_printf("  UNK ");
            break;
      }
   }
   else
   {
      naiif_printf("  --- ");
   }

   naiif_printf("  %3i   ", inputstate);
   naiif_printf("%+6.1f    ", voltage);
   naiif_printf("%+6.1f    ", debounceTime);
   naiif_printf("\r\n\r\n");
   naiif_printf("  VCC      VCC Source\r\n");
   naiif_printf(" ------   ------------\r\n");
   naiif_printf("%+6.1f    ", vcc);
    switch (vccSource)
      {
         case NAIBRD_TTL_VCC_EXTERNAL:
            naiif_printf("   External ");
            break;
         case NAIBRD_TTL_VCC_INTERNAL:
            naiif_printf("   Internal");
            break;
         /* undefined value read back */
         default:
            naiif_printf("  UNK ");
            break;
      }
   check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &fpEnable));
   naiif_printf("\r\nH/W Floating Point Mode: %s\r\n", (fpEnable == NAI_FALSE ? "DISABLED" : "ENABLED"));
}

/**************************************************************************************************************/
/**
 * <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)
{
   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;
   bool_t chanStatusEnabled = NAI_TRUE;

  /*  Available status:
   *    NAIBRD_TTL_STATUS_BIT_LATCHED,
   *    NAIBRD_TTL_STATUS_BIT_REALTIME,
   *    NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED,
   *    NAIBRD_TTL_STATUS_OVERCURRENT_REALTIME,
   *    NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED,
   *    NAIBRD_TTL_STATUS_LO_HI_TRANS_REALTIME,
   *    NAIBRD_TTL_STATUS_HI_LO_TRANS_LATCHED,
   *    NAIBRD_TTL_STATUS_HI_LO_TRANS_REALTIME
   */

   Verify_TTL_ParamCnt(paramCnt);
   naiif_printf("\r\n");
   /*check_status(naibrd_TTL_GetChanStatusEnable(cardIndex, module, chan, &chanStatusEnabled));*/
   naiif_printf(" CHANNEL STATUS ENABLED: %s\r\n  ", (chanStatusEnabled == NAI_FALSE) ? "NO- Below Statuses are always 0 " : "YES");
   naiif_printf("------------------ Status ----------------------------\r\n");
   naiif_printf(" Low-Hi   Hi-Lo    BIT     OC   Summary  Watchdog  Inter-FPGA\r\n");
   naiif_printf(" ------- -------- ------ ------ -------  --------  ----------\r\n");

   status = check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_LO_HI_TRANS_LATCHED, &statusBit));
   naiif_printf("  %3i   ", 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));
   naiif_printf("  %3i   ", 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));
   naiif_printf("  %3i   ", 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));
   naiif_printf("  %3i   ", statusBit);
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_OVERCURRENT_LATCHED));
   }

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_SUMMARY_LATCHED, &statusBit));
   naiif_printf(" %3i    ", statusBit);
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_SUMMARY_LATCHED));
   }

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &statusBit));
   naiif_printf("  %3i    ", statusBit);
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_WATCHDOG_TIMER_FAULT_LATCHED));
   }

   check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_INTER_FPGA_FAULT_LATCHED, &statusBit));
   naiif_printf("    %3i ", statusBit);
   if (status == NAI_SUCCESS)
   {
      check_status(naibrd_TTL_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_INTER_FPGA_FAULT_LATCHED));
   }

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

   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * 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.
 * </summary>
 */
/**************************************************************************************************************/
nai_status_t Configure_TTL_IOFormat(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   naibrd_ttl_ioformat_t ioformat = NAIBRD_TTL_IOFORMAT_INPUT;
   uint32_t ModuleID;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateIOCfg = NAI_FALSE;
   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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /*  Set I/O format configuration for channel. Available configurations include:
    *       NAIBRD_TTL_IOFORMAT_INPUT
    *       NAIBRD_TTL_IOFORMAT_OUTPUT_LOW
    *       NAIBRD_TTL_IOFORMAT_OUTPUT_HIGH
    *       NAIBRD_TTL_IOFORMAT_OUTPUT_PUSHPULL
    */
   Verify_TTL_ParamCnt(paramCnt);
   check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));

      naiif_printf("Type the desired IO configuration ");
      naiif_printf("(i=input,o=output): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case 'I':
                  naiif_printf("Setting to input\r\n");
                  ioformat = NAIBRD_TTL_IOFORMAT_INPUT;
                  bUpdateIOCfg = NAI_TRUE;
                  break;
               case 'O':
                  naiif_printf("Setting to output\r\n");
                  ioformat = NAIBRD_TTL_IOFORMAT_OUTPUT;
                  bUpdateIOCfg = NAI_TRUE;
                  break;
               default:
                  naiif_printf("ERROR: Invalid Output State Format Entry\r\n");
                  bUpdateIOCfg = NAI_FALSE;
                  break;
            }

            if (bUpdateIOCfg)
            {
               status = check_status(naibrd_TTL_SetIOFormat(cardIndex, module, chan, ioformat));
            }
         }
      }
   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * 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.
 * </summary>
 */
/**************************************************************************************************************/
static nai_status_t Configure_TTL_OutputState(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   naibrd_ttl_state_t outputstate = NAIBRD_TTL_STATE_LO;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   uint32_t ModuleID;
   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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Set the output state (high or low) on output channels.
    * This is not applicable for channels configured as inputs.
    */
   Verify_TTL_ParamCnt(paramCnt);
   check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));

      naiif_printf("\r\nType the desired output state ");
      naiif_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 = NAIBRD_TTL_STATE_LO;
                  bUpdateOutput = NAI_TRUE;
                  break;
               case 'H':
                  outputstate = NAIBRD_TTL_STATE_HI;
                  bUpdateOutput = NAI_TRUE;
                  break;
               default:
                  naiif_printf("ERROR: Invalid Output State Format Entry\r\n");
                  bUpdateOutput = NAI_FALSE;
                  break;
            }

         if (bUpdateOutput)
         {
            check_status(naibrd_TTL_SetOutputState(cardIndex, module, chan, outputstate));
         }
      }
   }
   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * Configure_TTL_Threshold handles the user request to configure the selected threshold configuration and
 * channel and calls the method in the naibrd library to set the threshold voltage.
 * </summary>
 */
 /**************************************************************************************************************/
nai_status_t Configure_TTL_Debounce(int32_t paramCnt, int32_t* p_params)
{
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   bool_t bQuit = NAI_FALSE;
   float64_t debounceTime = 0.0;
   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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_ParamCnt(paramCnt);
   naiif_printf("\r\nEnter the desired Debounce time (ms): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         debounceTime = atof((const char *)inputBuffer);
         status = check_status(naibrd_TTL_SetDebounceTime(cardIndex, module, chan, debounceTime));
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
 * <summary>
 * Configure_TTL_Floating handles the user request to set the floating point enable
 * and calls the method in the naibrd library to set the floating point state.
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Configure_TTL_Floating(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = ttlParams->cardIndex;
   int32_t module = ttlParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_ParamCnt(paramCnt);
   naiif_printf("Warning: TTL does not yet support floating point mode.\r\n");
   naiif_printf("Select Floating-Point Mode to set ('0' for DISABLED, '1' for ENABLED): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputBuffer[0] == '0')
      {
         status = check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, 0x0));
      }
      else if (inputBuffer[0] == '1')
      {
         status = check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, 0x1));
      }
      naiif_printf("Returned status %s\r\n", naibrd_GetStatusString(status));
   }
   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * Configure_TTL_BITThresholds() allows the user to set and get the BIT error thresholds.
 * This is an advanced feature.
 * </summary>
 */
/**************************************************************************************************************/
static nai_status_t Configure_TTL_BITThresholds(int32_t paramCnt, int32_t* p_params)
{
   p_naiapp_AppParameters_t ttlParams = (p_naiapp_AppParameters_t)p_params;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   uint32_t bitThreshold = 0u;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_TTL_ParamCnt(paramCnt);

         naiif_printf("Set or Get BIT Error Threshold? ('S' = Set, 'G' = Get, 'C' = Clear BIT Counter): ");
         naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);

         if (inputBuffer[0] == 'S')
         {
            naiif_printf("\r\nType the desired BIT Error Threshold (Default = 5): ");
            naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
            naiif_printf("\r\n");
            bitThreshold = atoi((const char*)inputBuffer);
            status = naibrd_TTL_SetModuleBITErrorThreshold(ttlParams->cardIndex, ttlParams->module, bitThreshold);
         }
         else if (inputBuffer[0] == 'G')
         {
            status = naibrd_TTL_GetModuleBITErrorThreshold(ttlParams->cardIndex, ttlParams->module, &bitThreshold);
            naiif_printf("\r\nBIT Error threshold: %d", bitThreshold);
         }
         else if (inputBuffer[0] == 'C')
         {
            int32_t ch;
            int32_t channels = naibrd_TTL_GetChannelCount(ttlParams->modId);

            naiif_printf("\r\nClearing BIT counters on all channels.\r\n");
            for (ch = 1; ch <= channels; ch++)
               status = naibrd_TTL_ClearModuleBITLogic(ttlParams->cardIndex, ttlParams->module, ch);
         }
         else
         {
            naiif_printf("\r\nSelection not recognized.\r\n");
         }

   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * This function Enables\Disables the reporting of the Channel Status. When enabled, the user will get status
 * updates. When disabled, the statuses will not report and status-based interrupts will not assert.
 * </summary>
 */
/**************************************************************************************************************/
static nai_status_t Configure_TTL_ChannelStatusEnable(int32_t paramCount, int32_t* params)
{
   p_naiapp_AppParameters_t ttl_params = (p_naiapp_AppParameters_t)params;
   bool_t bQuit = NAI_FALSE;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (APP_PARAM_COUNT == paramCount)
   {
      bQuit = naiapp_query_ChannelNumber(ttl_params->maxChannels, ttl_params->channel, &(ttl_params->channel));
      if (!bQuit)
      {
         naiif_printf("Enable Channel Status (Y = YES, [any other key] = NO: ");
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            status = check_status(naibrd_TTL_SetChanStatusEnable(ttl_params->cardIndex, ttl_params->module, ttl_params->channel,
               ((inputResponseCnt > 0) && (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')) ? NAI_TRUE : NAI_FALSE));
         }
      }
   }

   Display_TTL_Status(paramCount, params);

   return status;
}

#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
/**************************************************************************************************************/
/**
 * <summary>
 * This function displays the menu for watchdog commands
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Handle_TTL_WatchdogShowMenu(int32_t paramCount, int32_t* params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd = 0;
   int32_t numMenuCmds = 0;
   p_naiapp_AppParameters_t ttl_params = (p_naiapp_AppParameters_t)params;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   numMenuCmds = TTL_COMMON_CMD_WD_COUNT;

   naiapp_utils_LoadParamMenuCommands(numMenuCmds, TTL_WatchdogOpMenuCmds);
   while (bContinue)
   {
      Handle_TTL_DisplayWatchdog(paramCount, params);
      naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_WD_PGM_NAME);
      naiif_printf("\r\nType TTL Watchdog command or %c to quit : main > watchdog >", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if (inputBuffer[0] == 'B' || inputBuffer[0] == 'b')
            {
               bContinue = NAI_FALSE;
               bContinue = NAI_FALSE;
               numMenuCmds = TTL_BASICOP_CMD_COUNT;
               naiapp_utils_LoadParamMenuCommands(numMenuCmds, TTL_BasicOpMenuCmds);
            }
            else
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  TTL_WatchdogOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ttl_params);
               }
               else
               {
                  naiif_printf("Invalid command entered\r\n");
               }
            }
         }
         else
            naiif_printf("Invalid command entered\r\n");
      }
      else
         bContinue = NAI_FALSE;
   }
   return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
 * <summary>
 * This function sets the watchdog quiet time for the module. The user is prompted for the value in ms.
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Handle_TTL_WatchDogQuietTime(int32_t paramCount, int32_t* params)
{
   p_naiapp_AppParameters_t ttl_params = (p_naiapp_AppParameters_t)params;
   bool_t bQuit = NAI_FALSE;
   uint32_t quietTime = 0;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (APP_PARAM_COUNT == paramCount)
   {
      naiif_printf("\r\n*** To use this sample strobe it is recommended to set a quiet time > 500 ms **");
      naiif_printf("\r\nEnter the desired Watchdog Quiet Time (ms): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            quietTime = atoi((const char *)inputBuffer);
            status = check_status(naibrd_TTL_SetWatchdogQuietTime(ttl_params->cardIndex, ttl_params->module, quietTime * 1000));
         }
      }
   }

   return status;
}
/**************************************************************************************************************/
/**
 * <summary>
 * This function sets the watchdog window time for the module. The user is prompted for the value in ms.
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Handle_TTL_WatchDogWindowTime(int32_t paramCount, int32_t* params)
{
   p_naiapp_AppParameters_t ttl_params = (p_naiapp_AppParameters_t)params;
   bool_t bQuit = NAI_FALSE;
   uint32_t windowTime = 0;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (APP_PARAM_COUNT == paramCount)
   {
      naiif_printf("\r\n*** To use this sample strobe it is recommended to set a window time > 500 ms **");
      naiif_printf("\r\nEnter the desired Watchdog Quiet Time (ms): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            windowTime = atoi((const char *)inputBuffer);
            status = check_status(naibrd_TTL_SetWatchdogWindow(ttl_params->cardIndex, ttl_params->module, windowTime * 1000));
         }
      }
   }

   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * This function displays the TTL Watchdog Operations data.
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Handle_TTL_DisplayWatchdog(int32_t paramCount, int32_t* params)
{
   nai_status_bit_t wdStatLatched = 0;
   nai_status_bit_t wdStatRT = 0;
   uint32_t windowTime = 0;
   uint32_t quietTime = 0;
   p_naiapp_AppParameters_t ttl_params = (p_naiapp_AppParameters_t)params;

   if (APP_PARAM_COUNT == paramCount)
   {
      naiif_printf("\r\n\r\nTTL Watchdog Data:\r\n");
      check_status(naibrd_TTL_GetWatchdogQuietTime(ttl_params->cardIndex, ttl_params->module, &quietTime));
      quietTime = quietTime / 1000;
      naiif_printf("Quiet Time: %dmS\r\n", quietTime);
      check_status(naibrd_TTL_GetWatchdogWindow(ttl_params->cardIndex, ttl_params->module, &windowTime));
      windowTime = windowTime / 1000;
      naiif_printf("Window Time: %dmS\r\n", windowTime);

      check_status(naibrd_TTL_GetChanMappedStatus(ttl_params->cardIndex, ttl_params->module, 1, NAIBRD_TTL_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &wdStatLatched));
      check_status(naibrd_TTL_GetChanMappedStatus(ttl_params->cardIndex, ttl_params->module, 1, NAIBRD_TTL_STATUS_WATCHDOG_TIMER_FAULT_REALTIME, &wdStatRT));
      naiif_printf("WatchDog Status (R/L):  (%1d/%1d)\r\n", wdStatRT, wdStatLatched);

      naiif_printf("\r\n");
   }
   return NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
 * <summary>
 * This function will start a thread to continuously Strobe the watchdog. The user is prompted for the value in ms.
 * NOTE: When this thread/application exits the module will shut off all outputs and will need to be power cycled
 *       in order to be operational.
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Handle_TTL_StrobeWatchdog(int32_t paramCount, int32_t* params)
{
   p_naiapp_AppParameters_t ttl_params = (p_naiapp_AppParameters_t)params;
   bool_t bQuit = NAI_FALSE;
   nai_status_t status = NAI_ERROR_UNKNOWN;
   int32_t* arg = (int32_t*)malloc(sizeof(int32_t) * 3);
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (APP_PARAM_COUNT == paramCount)
   {
      naiif_printf("\r\n**NOTE: When this thread/application exits the module will shut off all outputs and will need to be power cycled in order to be operational **");
      naiif_printf("\r\nEnter Y if you want to continue and N to go back: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')
            {
               naiif_printf("\r\nStrobing Watchdog every (QuietTime) + (Window)/2...");
               naiif_printf("\r\nStarting thread...");
               /* Spawn thread here */

               arg[0] = ttl_params->cardIndex;
               arg[1] = ttl_params->module;

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
               if (thread == 0)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
                  if (thread != (int32_t*)NULL)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
                  if (thread != (pthread_t)NULL)
#endif
               {
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
                  LPDWORD threadID = 0;
                  thread = CreateThread(NULL, 0, WD_Strobe_ThreadEntryPoint, arg, 0, threadID);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
                  pthread_create(&thread, NULL, WD_Strobe_ThreadEntryPoint, arg);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
                  thread = taskSpawn("WD_Strobe_Thread", 100, 0, 10000, (FUNCPTR)WD_Strobe_ThreadEntryPoint, (int32_t)arg, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
#error Unsupported OS
#endif
                  if (thread != 0) {}
                  else
                  {
                     free(arg);
                     naiif_printf("\r\nFailed to Create Thread");
                  }
               }
               else
               {
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
                  LPDWORD threadID = 0;
#endif
                  /* kill previous thread and create new one. Report this to them. */

                  naiapp_kill_WDStrobe_Thread();

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
                  thread = CreateThread(NULL, 0, WD_Strobe_ThreadEntryPoint, arg, 0, threadID);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
                  pthread_create(&thread, NULL, WD_Strobe_ThreadEntryPoint, arg);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
                  thread = taskSpawn("WD_Strobe_Thread", 100, 0, 10000, (FUNCPTR)WD_Strobe_ThreadEntryPoint, (int32_t)arg, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
#error Unsupported OS
#endif

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
                  if (thread != 0) {}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
                  if (thread != (int32_t*)NULL) {}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
                  if (thread != (pthread_t)NULL) {}
#endif
                  else
                  {

                     free(arg);
                     naiif_printf("\r\nFailed to Create Thread");
                  }

               }

            }
            else
            {
               naiif_printf("\r\nReturning to Menu...");
            }

         }
      }
   }

   return status;
}

/**************************************************************************************************************/
/**
 * <summary>
 * This function will terminate the WD strobing thread. Module will shut off outputs at this state and
 * will need to be power cycled to be operational.
 * </summary>
 */
 /**************************************************************************************************************/
static void naiapp_kill_WDStrobe_Thread()
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
   if (thread != 0)
   {
      terminateThread = NAI_TRUE;
      thread = 0;
   }
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   if (thread != ((int32_t*)NULL))
   {
      terminateThread = NAI_TRUE;
      thread = ((int32_t*)NULL);
   }
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
   if (thread != (pthread_t)NULL)
   {
      terminateThread = NAI_TRUE;
      thread = (pthread_t)NULL;
   }
#else
#error Unspported OS
#endif
}
/**************************************************************************************************************/
/**
 * <summary>
 * This function will continuously loop, strobing the watchdog every QuietTime + Window/2.
 * </summary>
 */
 /**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
DWORD WINAPI WD_Strobe_ThreadEntryPoint(LPVOID param)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
void* WD_Strobe_ThreadEntryPoint(void* param)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static int WD_Strobe_ThreadEntryPoint(int32_t param)
#else
#error Unsupported OS
#endif
{
   uint32_t windowTime = 0;
   uint32_t quietTime = 0;
   int32_t delayTime = 0;
   int32_t* modInfo = (int32_t*)param;
   int32_t cardIndex = modInfo[0];
   int32_t module = modInfo[1];
   terminateThread = NAI_FALSE;
   free(modInfo);

   check_status(naibrd_TTL_GetWatchdogQuietTime(cardIndex, module, &quietTime));
   check_status(naibrd_TTL_GetWatchdogWindow(cardIndex, module, &windowTime));
   quietTime = quietTime / 1000;
   windowTime = windowTime / 1000;
   delayTime = quietTime + (windowTime / 2);
   naibrd_TTL_WatchdogStrobe(cardIndex, module);
   do
   {
      naiif_msDelay(delayTime);
      check_status(naibrd_TTL_WatchdogStrobe(cardIndex, module));
   } while (!terminateThread);
   return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
 * <summary>
 * This function will terminate the WD Strobing thread. Module will shut off outputs at this state and
 * will need to be power cycled to be operational.
 * </summary>
 */
 /**************************************************************************************************************/
static nai_status_t Handle_TTL_kill_WDStrobe_Thread(int32_t paramCount, int32_t* params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
   NAIBSP_UNREFERENCED_PARAMETER(paramCount);
   NAIBSP_UNREFERENCED_PARAMETER(params);
#endif

   naiapp_kill_WDStrobe_Thread();
   return NAI_SUCCESS;
}
#endif
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_CheckPBITComplete handles the user request to check the module power-on BIT completed state
and calls the method in the naibrd library to check the power-on BIT completed state. If the power-on BIT
completed state is set, meaning that power-on BIT has completed, the Latched BIT Status of each channel
is checked by calling the method in the naibrd library to read the BIT Status.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_CheckPBITComplete(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   int32_t channelCount = 0;
   bool_t pBitComplete = NAI_FALSE;
   nai_status_bit_t bitStatus = 0u;
   char strBitStatus[12] = "";
   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 modid = p_ttl_params->modId;
   int32_t chan = 0;

   NAIBSP_UNREFERENCED_PARAMETER(paramCount);

     channelCount = naibrd_TTL_GetChannelCount(modid);

      /* Check to see if PBIT ran for the module. */
      naiif_printf("\r\nChecking if the Power-On BIT test has run...\r\n");
      check_status(naibrd_TTL_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
      switch (pBitComplete)
      {
      case 0u:
         naiif_printf("\r\nPBIT Complete: NOT COMPLETED\r\n");
         break;
      case 1u:
         naiif_printf("\r\nPBIT Complete: COMPLETED\r\n");
         break;
      default:
         naiif_printf("\r\nPBIT Complete: UNKNOWN\r\n");
         break;
      }

      if (pBitComplete)
      {
         /* Read the BIT status */
         naiif_printf("\r\nChecking the result of the Power-on BIT test...\r\n");
         for (chan = 1; chan <= channelCount; chan++)
         {
            check_status(naibrd_TTL_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_TTL_STATUS_BIT_LATCHED, &bitStatus));
            switch (bitStatus)
            {
            case (nai_status_bit_t)0u:
               naiif_printf(strBitStatus, "BIT Passed");
               break;
            case (nai_status_bit_t)1u:
               naiif_printf(strBitStatus, "BIT FAILED");
               break;
            default:
               naiif_printf(strBitStatus, "Unknown");
               break;
            }
            naiif_printf("Ch. %d: %s\r\n", chan, strBitStatus);
         }
      }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_TTL_ClearModuleBITLogic handles the user request to clear the module BIT logic,
which resets the Continuous BIT internal circuitry and counter, and calls the method
in the naibrd library to clear the module BIT logic.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_ClearModuleBITLogic(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_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;
   int32_t chan = p_ttl_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   NAIBSP_UNREFERENCED_PARAMETER(paramCount);

      naiif_printf("\r\nAre you sure you want to reset the Continuous BIT internal circuitry and counter? (Y for Yes or N for No): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
      {
         check_status(naibrd_TTL_ClearModuleBITLogic(cardIndex, module, chan));
      }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_TTL_ModulePowerResetMenu displays the menu for module power reset commands.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t cmd = 0;
   int32_t numMenuCmds = 0;
   bool_t poweredDownStatus = 0u;
   bool_t notDetectedStatus = 0u;
   bool_t notLinkInitStatus = 0u;
   bool_t notFWNotStatus = 0u;
   bool_t commErrorStatus = 0u;
   bool_t resetRequest = 0u;
   bool_t powerDownRequest = 0u;
   bool_t powerUpRequest = 0u;
   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;

   numMenuCmds = TTL_MODULE_POWER_RESET_CMD_COUNT;
   naiapp_utils_LoadParamMenuCommands(numMenuCmds, TTL_ModulePowerResetMenuCmds);
   while (bContinue)
   {
      naiif_printf("\r\n\r\n\r\n");
      naiif_printf(" -----------------------------Status------------------------------    ----------Request----------\r\n");
      naiif_printf(" Powered Down  Not Detected  Not Link Init  Not FW Not  Comm Error    Reset  Power Down  Power Up\r\n");
      naiif_printf(" ------------  ------------  -------------  ----------  ----------    -----  ----------  --------\r\n");
      check_status(naibrd_TTL_GetModulePowerResetStatus(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_STATUS_POWERED_DOWN, &poweredDownStatus));
      check_status(naibrd_TTL_GetModulePowerResetStatus(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_STATUS_NOT_DETECTED, &notDetectedStatus));
      check_status(naibrd_TTL_GetModulePowerResetStatus(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT, &notLinkInitStatus));
      check_status(naibrd_TTL_GetModulePowerResetStatus(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_STATUS_FW_NOT_READY, &notFWNotStatus));
      check_status(naibrd_TTL_GetModulePowerResetStatus(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_STATUS_COMM_ERROR, &commErrorStatus));
      check_status(naibrd_TTL_GetModulePowerReset(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_REQUEST_RESET, &resetRequest));
      check_status(naibrd_TTL_GetModulePowerReset(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_REQUEST_POWER_DOWN, &powerDownRequest));
      check_status(naibrd_TTL_GetModulePowerReset(cardIndex, module, NAIBRD_TTL_MODULE_POWER_RESET_REQUEST_POWER_UP, &powerUpRequest));
      naiif_printf("      %1d             %1d              %1d            %1d           %1d           %1d        %1d          %1d\r\n",
         poweredDownStatus, notDetectedStatus, notLinkInitStatus, notFWNotStatus, commErrorStatus, resetRequest, powerDownRequest, powerUpRequest);
      naiapp_display_ParamMenuCommands((int8_t*)"TTL Power Reset Operation Menu");
      naiif_printf("\r\nType TTL Module Power Reset command or %c to quit : main > module power reset >", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if ((inputBuffer[0] == 'B') || (inputBuffer[0] == 'b'))
            {
               bContinue = NAI_FALSE;
            }
            else
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  TTL_ModulePowerResetMenuCmds[cmd].func(paramCount, p_params);
               }
               else
               {
                  naiif_printf("\r\nInvalid command entered\r\n");
               }
            }
         }
      }
      else
         bContinue = NAI_FALSE;
   }
   numMenuCmds = TTL_BASICOP_CMD_COUNT;
   naiapp_utils_LoadParamMenuCommands(numMenuCmds, TTL_BasicOpMenuCmds);
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Handle_TTL_ClearModulePowerResetStatus handles the user request to clear the module power reset status
and calls the method in the naibrd library to clear the module power reset status. The user is
prompted for the module power reset status type to clear.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   naibrd_ttl_module_power_reset_status_type_t statusTypeToClear = 0u;
   bool_t modulePowerResetStatusRead = 0u;
   char statusTypeStr[14] = "";
   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;

   NAIBSP_UNREFERENCED_PARAMETER(paramCount);

   naiif_printf("\r\nSelect Module Power Reset Status type to clear: (0 for Powered Down, 1 for Not Detected, 2 for Not Link Init, 3 for Not FW Not, 4 for Comm Error, q for quit): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      switch (inputBuffer[0])
      {
      case '0':
         statusTypeToClear = NAIBRD_TTL_MODULE_POWER_RESET_STATUS_POWERED_DOWN;
         naiif_printf(statusTypeStr, "Powered Down");
         break;
      case '1':
         statusTypeToClear = NAIBRD_TTL_MODULE_POWER_RESET_STATUS_NOT_DETECTED;
         naiif_printf(statusTypeStr, "Not Detected");
         break;
      case '2':
         statusTypeToClear = NAIBRD_TTL_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT;
         naiif_printf(statusTypeStr, "Not Link Init");
         break;
      case '3':
         statusTypeToClear = NAIBRD_TTL_MODULE_POWER_RESET_STATUS_FW_NOT_READY;
         naiif_printf(statusTypeStr, "Not FW Not");
         break;
      case '4':
         statusTypeToClear = NAIBRD_TTL_MODULE_POWER_RESET_STATUS_COMM_ERROR;
         naiif_printf(statusTypeStr, "Comm Error");
         break;
      case 'q':
      case 'Q':
         bQuit = NAI_TRUE;
         break;
      default:
         bQuit = NAI_TRUE;
         naiif_printf("\r\nInvalid module power reset status type entered\r\n");
         break;
      }

      if (!bQuit)
      {
         naiif_printf("\r\nAre you sure you want to clear the %s status? (Y for Yes or N for No): ", statusTypeStr);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
         {
            check_status(naibrd_TTL_GetModulePowerResetStatus(cardIndex, module, statusTypeToClear, &modulePowerResetStatusRead));
            if (modulePowerResetStatusRead == 1u)
            {
               check_status(naibrd_TTL_ClearModulePowerResetStatus(cardIndex, module, statusTypeToClear));
            }
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Handle_TTL_SetModulePowerReset handles the user request to set the module power reset request
and calls the method in the naibrd library to set the module power reset request. The user is
prompted for the module power reset request type to set, and then the user is prompted to set
or reset the request bit.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_TTL_SetModulePowerReset(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   naibrd_ttl_module_power_reset_type_t resetTypeToSet = 0u;
   char resetTypeStr[11] = "";
   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;

   NAIBSP_UNREFERENCED_PARAMETER(paramCount);

   naiif_printf("\r\nSelect Module Power Reset Request type to set: (0 for Reset, 1 for Power Down, 2 for Power Up, q for quit): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if ((!bQuit) && (inputResponseCnt > 0))
   {
      switch (inputBuffer[0])
      {
      case '0':
         resetTypeToSet = NAIBRD_TTL_MODULE_POWER_RESET_REQUEST_RESET;
         naiif_printf(resetTypeStr, "Reset");
         break;
      case '1':
         resetTypeToSet = NAIBRD_TTL_MODULE_POWER_RESET_REQUEST_POWER_DOWN;
         naiif_printf(resetTypeStr, "Power Down");
         break;
      case '2':
         resetTypeToSet = NAIBRD_TTL_MODULE_POWER_RESET_REQUEST_POWER_UP;
         naiif_printf(resetTypeStr, "Power Up");
         break;
      case 'q':
      case 'Q':
         bQuit = NAI_TRUE;
         break;
      default:
         bQuit = NAI_TRUE;
         naiif_printf("\r\nInvalid module power reset request type entered\r\n");
         break;
      }

      if (!bQuit)
      {
         naiif_printf("\r\nDo you want to set or reset the %s request? (1 to set, 0 to reset): ", resetTypeStr);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if ((!bQuit) && (inputResponseCnt > 0))
         {
            if (inputBuffer[0] == '0')
            {
               check_status(naibrd_TTL_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)NAI_FALSE));
            }
            else if (inputBuffer[0] == '1')
            {
               check_status(naibrd_TTL_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)NAI_TRUE));
            }
            else
            {
               naiif_printf("\r\nInvalid selection entered\r\n");
            }
         }
      }
   }

   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

Help Bot

X