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

ENC BasicOps

ENC BasicOps Sample Application (SSK 2.x)

Overview

The ENC BasicOps sample application demonstrates how to configure and operate encoder (ENC) modules using the NAI Software Support Kit (SSK 2.x). It covers the core encoder operations you will need in your own application: configuring the interval timer, setting global registers, configuring common channel settings (input config, encoder mode, debounce), setting counter parameters (preload, index control, clock divide, polarity, compare), and configuring SSI interface settings (mode, clock, data bits, parity, data type, trigger).

This sample supports EC1 encoder/SSI modules. The application is organized into four hierarchical menus: a main menu that provides access to the Common, Counter, and SSI configuration sub-menus. Each menu command maps directly to one or more naibrd_ENC_*() API calls that you can lift into your own code.

For the SSK 1.x version, see ENC SSI BasicOps (SSK 1.x).

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with an EC1 encoder module installed.

  • 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 enc_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_ENC_BasicOps.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, you select a channel and a main menu lets you access each configuration area.

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

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_ENC_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 module variant installed.

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

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_ENC_BasicOps(cardIndex, module, moduleID);
               }
            }
         }
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}

Note: This sample uses the legacy __VXWORKS__ guard; most SSK 2.x samples use NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS.

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

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

Program Structure

Entry Point

On VxWorks the entry point is ENC_BasicOps(); on all other platforms it is main(). The preprocessor guard __VXWORKS__ selects between them. After board connection and module selection, the application calls Run_ENC_BasicOps() which validates the module and enters the main command menu via ENC_CommandMenu().

Application Parameters

The Run_ENC_BasicOps() function populates an naiapp_AppParameters_t struct that is passed to every command handler:

naiapp_AppParameters_t  enc_params;
p_naiapp_AppParameters_t enc_basicops_params = &enc_params;
enc_basicops_params->cardIndex = cardIndex;
enc_basicops_params->module = module;
enc_basicops_params->modId = ModuleID;
enc_basicops_params->maxChannels = naibrd_ENC_GetChannelCount(ModuleID);
  • cardIndex — identifies which board in a multi-board system.

  • module — the slot number where the encoder module is installed.

  • modId — the module identifier returned by naibrd_GetModuleName().

  • maxChannels — total channel count, retrieved by calling naibrd_ENC_GetChannelCount().

Command Loop

ENC_CommandMenu() prompts the user for a channel number, displays the general configuration for that channel, and presents the main menu. Each sub-menu has its own command table, display function, and loop.

Command Description

IT

Configure the interval timer (preload, clock divide, enable/disable).

Glo

Configure global register settings (multi-channel read, interval timer trigger).

Com

Open the Common configuration sub-menu.

Cntr

Open the Counter configuration sub-menu.

SSI

Open the SSI configuration sub-menu.

STAT

Display channel status information.

Interval Timer Configuration

The CommandMenu_ConfigureIntervalTimer() function configures the interval timer.

naibrd_ENC_SetIntervalTimerPreload(cardIndex, module, (int16_t)preload);
naibrd_ENC_SetIntervalTimerClkDivide(cardIndex, module, clkDiv);
naibrd_ENC_SetIntervalTimerEnable(cardIndex, module, NAI_TRUE);
  • naibrd_ENC_SetIntervalTimerPreload() — sets the timer preload value (0-65535).

  • naibrd_ENC_SetIntervalTimerClkDivide() — sets the clock divide (25, 12.5, 6.25, or 3.125 MHz).

  • naibrd_ENC_SetIntervalTimerEnable() — enables or disables the interval timer.

Global Register Configuration

naibrd_ENC_SetMultiChanRdEnable(cardIndex, module, channel, NAI_TRUE);
naibrd_ENC_SetMultiChanCntrPreloadEnable(cardIndex, module, channelBitmask);
naibrd_ENC_SetIntvlTimerTrigEnable(cardIndex, module, NAI_TRUE);
naibrd_ENC_TriggerMultiChanRd(cardIndex, module);
  • naibrd_ENC_SetMultiChanRdEnable() — enables multi-channel read for a channel.

  • naibrd_ENC_SetMultiChanCntrPreloadEnable() — sets channels for counter preload.

  • naibrd_ENC_SetIntvlTimerTrigEnable() — enables interval timer as MCR trigger.

  • naibrd_ENC_TriggerMultiChanRd() — manually triggers a multi-channel read.

Common Configuration Sub-Menu

Command Description

Input

Set input configuration (RS-422 or TTL) and termination.

Mode

Set encoder mode (SSI, Counter, or Disabled).

A / B / C

Set debounce time for port A, B, or C (Index).

En

Enable or disable debounce for each port.

naibrd_ENC_SetInputMode(cardIndex, module, channel, NAIBRD_ENC_INPUT_RS422);
naibrd_ENC_SetInputTermination(cardIndex, module, channel, NAIBRD_ENC_DIFF_TERMINATED);
naibrd_ENC_SetControlMode(cardIndex, module, channel, NAIBRD_ENC_MODE_COUNTER);
naibrd_ENC_SetDebounceTime(cardIndex, module, channel, NAIBRD_ENC_PORT_A, 0.5);
naibrd_ENC_SetDebounceEnable(cardIndex, module, channel, NAIBRD_ENC_PORT_A, NAI_TRUE);
  • naibrd_ENC_SetInputMode() — sets the input mode (RS-422, TTL).

  • naibrd_ENC_SetInputTermination() — sets the input termination.

  • naibrd_ENC_SetControlMode() — sets the encoder operating mode.

  • naibrd_ENC_SetDebounceTime() — sets debounce time for a port.

  • naibrd_ENC_SetDebounceEnable() — enables or disables debounce.

Counter Configuration Sub-Menu

Command Description

Pre

Set counter preload value.

IC

Configure index control (Ignore, Load, Latch, Gate, Reset on Index).

S

Configure special control mode (Normal, Divide-by-N, Single Cycle).

IN

Configure input mode (None, Up, Down, Direction, Up/Down, Quad 1x/2x/4x).

Clk

Set clock divide value (62.5, 31.25, 12.5, 6.25 MHz).

Pol

Configure polarity for ports A, B, and Index.

Cmp

Set counter compare value and enable/disable compare.

Cmd

Set counter command (Reset, Load preload, Latch counters).

STAT

Display counter status (Borrow, Carry, Match, Sign, Direction, Active).

naibrd_ENC_SetCNTR_PreLoad(cardIndex, module, channel, preloadValue);
naibrd_ENC_SetCNTR_IndexControl(cardIndex, module, channel, NAIBRD_ENC_CNTR_ICM_LOAD_I);
naibrd_ENC_SetCNTR_SpecialControl(cardIndex, module, channel, NAIBRD_ENC_CNTR_SCM_NORMAL);
naibrd_ENC_SetCNTR_InputMode(cardIndex, module, channel, NAIBRD_ENC_CNTR_CIM_QUAD4X);
naibrd_ENC_SetCNTR_ClkDivide(cardIndex, module, channel, NAIBRD_ENC_CNTR_CLK_DIV_62_5_MHz);
naibrd_ENC_SetCNTR_Polarity(cardIndex, module, channel, NAIBRD_ENC_PORT_A, NAIBRD_ENC_CNTR_POLARITY_SET);
naibrd_ENC_SetCNTR_CompareEnable(cardIndex, module, channel, NAI_TRUE);
naibrd_ENC_SetCNTR_CompareCount(cardIndex, module, channel, compareValue);
naibrd_ENC_SetCNTR_ControlCommand(cardIndex, module, channel, NAIBRD_ENC_CNTR_CTRL_RESET);
  • naibrd_ENC_SetCNTR_PreLoad() — sets the counter preload value.

  • naibrd_ENC_SetCNTR_IndexControl() — configures index control behavior.

  • naibrd_ENC_SetCNTR_SpecialControl() — configures special control modes.

  • naibrd_ENC_SetCNTR_InputMode() — sets the counter input mode.

  • naibrd_ENC_SetCNTR_ClkDivide() — sets the counter clock divide.

  • naibrd_ENC_SetCNTR_Polarity() — sets counter polarity for a port.

  • naibrd_ENC_SetCNTR_CompareEnable() — enables or disables counter compare.

  • naibrd_ENC_SetCNTR_CompareCount() — sets the counter compare value.

  • naibrd_ENC_SetCNTR_ControlCommand() — writes a command to the counter control register.

  • naibrd_ENC_GetEventMappedStatus() — reads counter status bits.

SSI Configuration Sub-Menu

Command Description

Mode

Set SSI operating mode (Interface Controller or Listener).

Cnfg

Set SSI clock configuration (clock period and dwell time).

Bits

Set the number of SSI data bits (1-31).

Par

Set SSI parity type (Even or Odd).

PC

Enable or disable parity checking.

ZB

Enable or disable zero bit.

Err

Configure watchdog and error break settings.

Data

Configure SSI data type (Binary or Gray code, EC1 only).

Trig

Trigger an SSI data transfer.

STAT

Display SSI status.

naibrd_ENC_SetControlMode(cardIndex, module, channel, NAIBRD_ENC_MODE_SSI);
naibrd_ENC_SetSSI_Mode(cardIndex, module, channel, NAIBRD_ENC_SSI_CONTROLLER);
naibrd_ENC_SetSSI_ClockRate_uS(cardIndex, module, channel, clockRate);
naibrd_ENC_SetSSI_DwellCount_ClkCycles(cardIndex, module, channel, dwellTime);
naibrd_ENC_SetSSI_NumDataBits(cardIndex, module, channel, dataBits);
naibrd_ENC_SetSSI_Parity(cardIndex, module, channel, NAIBRD_ENC_SSI_PARITY_EVEN);
naibrd_ENC_SetSSI_ParityEnable(cardIndex, module, channel, NAI_TRUE);
naibrd_ENC_SetSSI_ZeroBitEnable(cardIndex, module, channel, NAI_TRUE);
naibrd_ENC_SetSSI_WatchDogEnable(cardIndex, module, channel, NAI_TRUE);
naibrd_ENC_SetSSI_ErrorBreakEnable(cardIndex, module, channel, NAI_TRUE);
naibrd_ENC_SetSSI_DataType(cardIndex, module, channel, NAIBRD_ENC_SSI_DATA_GRAY);

/* Trigger an SSI data transfer */
naibrd_ENC_SSI_TriggerData(cardIndex, module, channel);
  • naibrd_ENC_SetSSI_Mode() — sets the SSI operating mode.

  • naibrd_ENC_SetSSI_ClockRate_uS() — sets the SSI clock period in microseconds.

  • naibrd_ENC_SetSSI_DwellCount_ClkCycles() — sets the dwell count in clock cycles.

  • naibrd_ENC_SetSSI_NumDataBits() — sets the number of SSI data bits.

  • naibrd_ENC_SetSSI_Parity() — sets the parity type.

  • naibrd_ENC_SetSSI_ParityEnable() — enables or disables parity checking.

  • naibrd_ENC_SetSSI_ZeroBitEnable() — enables or disables the zero bit.

  • naibrd_ENC_SetSSI_WatchDogEnable() — enables or disables the SSI watchdog timer.

  • naibrd_ENC_SetSSI_ErrorBreakEnable() — enables or disables error break.

  • naibrd_ENC_SetSSI_DataType() — sets the SSI data type (Binary or Gray code).

  • naibrd_ENC_SSI_TriggerData() — triggers an SSI clock transaction to refresh data.

Channel Status Display

The STAT command on the main menu displays the BIT (Open/Short) status for the selected channel, with both realtime and latched values.

nai_status_bit_t chanStatusReal, chanStatusLatched;

naibrd_ENC_GetChannelMappedStatus(cardIndex, module, channel,
   NAIBRD_ENC_STATUS_BIT_REALTIME, &chanStatusReal);
naibrd_ENC_GetChannelMappedStatus(cardIndex, module, channel,
   NAIBRD_ENC_STATUS_BIT_LATCHED, &chanStatusLatched);

/* Clear latched status */
naibrd_ENC_ClearChannelMappedStatus(cardIndex, module, channel,
   NAIBRD_ENC_STATUS_BIT_LATCHED);
  • naibrd_ENC_GetChannelMappedStatus() — reads a channel-mapped status bit.

  • naibrd_ENC_ClearChannelMappedStatus() — clears a latched channel-mapped status bit.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

Module not recognized as ENC

The selected module slot does not contain an encoder module.

Verify the module type in the slot. See the EC1 Manual.

Counter value does not change

The encoder is not connected, or the input configuration does not match the encoder type.

Check wiring and set the correct input configuration (single-ended vs. differential).

SSI data reads zero

SSI mode is not configured, or clock settings do not match the encoder.

Configure the SSI mode, clock, and data bits to match your encoder specification.

SSI Trig command has no effect

The channel may not be in SSI mode.

Ensure the channel is set to SSI mode using the Mode command in the Common sub-menu.

Debounce has no effect

Debounce is not enabled.

Use the En command in the Common sub-menu to enable debounce.

Interval timer not working

The interval timer may not be enabled, or the preload value is zero.

Enable the interval timer and set a nonzero preload value.

Parity error on SSI read

The parity setting does not match the encoder.

Verify the parity type matches your encoder. Disable parity checking if the encoder does not support it.

Counter overflow

The counter reached its maximum value without a preload reset.

Configure the index control or preload to handle counter rollover.

Watchdog error on SSI

The SSI watchdog timer expired without receiving data.

Check the encoder connection. Disable the watchdog if using manual triggering.

Full Source

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

Full Source — enc_basic_ops.c (SSK 2.x)
/* 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"

/* naibrd include files */
#include "nai_libs/naibrd/include/nai.h"
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_enc.h"

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

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

/* Function prototypes */
int32_t Run_ENC_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID);
#if defined (__VXWORKS__)
int32_t ENC_BasicOps(void);
#endif

static nai_status_t ENC_CommandMenu(int32_t paramCount, int32_t* p_params);

static nai_status_t CommandMenu_ConfigureIntervalTimer(int32_t paramCount, int32_t* p_params);
static nai_status_t CommandMenu_ConfigureGlobalReg(int32_t paramCount, int32_t* p_params);
static nai_status_t CommandMenu_CommonConfigMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t CommandMenu_CntrConfigMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t CommandMenu_SSIConfigMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_ENC_ChanStatus(int32_t paramCount, int32_t* p_params);

static void Display_ENC_GeneralCfg(int32_t cardIndex, int32_t module, int32_t chan);
static void Display_ENC_CommonCfg(int32_t cardIndex, int32_t module, int32_t chan);
static void Display_ENC_CntrCfg(int32_t cardIndex, int32_t module, int32_t chan);
static void Display_ENC_SSICfg(int32_t cardIndex, int32_t module, int32_t chan);

static nai_status_t CommonMenu_SetInputConfig(int32_t paramCount, int32_t* p_params);
static nai_status_t CommonMenu_SetEncoderMode(int32_t paramCount, int32_t* p_params);
static nai_status_t CommonMenu_SetDebounceA(int32_t paramCount, int32_t* p_params);
static nai_status_t CommonMenu_SetDebounceB(int32_t paramCount, int32_t* p_params);
static nai_status_t CommonMenu_SetDebounceC(int32_t paramCount, int32_t* p_params);
static nai_status_t CommonMenu_SetDebounceEn(int32_t paramCount, int32_t* p_params);

static nai_status_t CounterMenu_SetPreload(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetIndxCtrl(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetSpecialCtrl(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetCtrlInputMode(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetClkDiv(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetPolarity(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetCntrCmp(int32_t paramCount, int32_t* p_params);
static nai_status_t CounterMenu_SetCommandReg(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_ENC_CntrStatus(int32_t paramCount, int32_t* p_params);

static nai_status_t SSIMenu_SetMode(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetClockConfig(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetDataBits(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetParity(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetParityEn(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetZeroBitEn(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetWD_EB(int32_t paramCount, int32_t* p_params);
static nai_status_t SSIMenu_SetDataType(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_ENC_SSIStatus(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_ENC_CHANNEL = 1;
/* MODID used for all functions */
uint32_t moduleID = 0;

/****** Command Table *******/
enum enc_basicops_commands
{
   ENC_BASICOP_CMD_CONFIG_INTERVAL_TIMER,
   ENC_BASICOP_CMD_CONFIG_GLOBAL_REG,
   ENC_BAISCOP_CMD_COMMON_CONFIG_MENU,
   ENC_BAISCOP_CMD_CNTR_CONFIG_MENU,
   ENC_BASICOP_CMD_SSI_CONFIG_MENU,
   ENC_BASICOP_CMD_VIEW_CHAN_STATUS,
   ENC_BASICOP_CMD_COUNT
};

/****** Command Functions *******/
naiapp_cmdtbl_params_t ENC_BasicOpMenuCmds[] =
{
   {"IT",    "Configure Interval Timer",            ENC_BASICOP_CMD_CONFIG_INTERVAL_TIMER,   CommandMenu_ConfigureIntervalTimer},
   {"Glo",   "Configure Global Register(s)",        ENC_BASICOP_CMD_CONFIG_GLOBAL_REG,       CommandMenu_ConfigureGlobalReg},
   {"Com",   "Set Channel's Common Configuration",  ENC_BAISCOP_CMD_COMMON_CONFIG_MENU,      CommandMenu_CommonConfigMenu},
   {"Cntr",  "Set Channel's Cntr Configuration",    ENC_BAISCOP_CMD_CNTR_CONFIG_MENU,        CommandMenu_CntrConfigMenu},
   {"SSI",   "Set Channel's SSI Configuration",     ENC_BASICOP_CMD_SSI_CONFIG_MENU,         CommandMenu_SSIConfigMenu},
   {"STAT",  "Display Chan Status",                 ENC_BASICOP_CMD_VIEW_CHAN_STATUS,        Display_ENC_ChanStatus}
};
/****** General Command Table *******/
enum enc_common_basicops_commands
{
   ENC_COMMON_BASICOP_CMD_INPUT_CONFIG,
   ENC_COMMON_BASICOP_CMD_ENC_MODE,
   ENC_COMMON_BASICOP_CMD_DEBOUNCE_A,
   ENC_COMMON_BASICOP_CMD_DEBOUNCE_B,
   ENC_COMMON_BASICOP_CMD_DEBOUNCE_C,
   ENC_COMMON_BASICOP_CMD_DEBOUNCE_En,
   ENC_COMMON_BASICOP_CMD_COUNT
};

/****** General Command Functions *******/
naiapp_cmdtbl_params_t ENC_Common_BasicOpMenuCmds[] =
{
   {"Input",    "Set Input Config",          ENC_COMMON_BASICOP_CMD_INPUT_CONFIG,       CommonMenu_SetInputConfig},
   {"Mode",     "Set Encoder Mode",          ENC_COMMON_BASICOP_CMD_ENC_MODE,           CommonMenu_SetEncoderMode},
   {"A",        "Set Debounce for A",        ENC_COMMON_BASICOP_CMD_DEBOUNCE_A,         CommonMenu_SetDebounceA},
   {"B",        "Set Debounce for B",        ENC_COMMON_BASICOP_CMD_DEBOUNCE_B,         CommonMenu_SetDebounceB},
   {"C",        "Set Debounce for C",        ENC_COMMON_BASICOP_CMD_DEBOUNCE_C,         CommonMenu_SetDebounceC},
   {"En",       "Set Debounce Enable",       ENC_COMMON_BASICOP_CMD_DEBOUNCE_En,        CommonMenu_SetDebounceEn},
};

/****** Counter Command Table *******/
enum enc_cntr_basicops_commands
{
   ENC_CNTR_BAISCOP_CMD_PRELOAD,
   ENC_CNTR_BASICOP_CMD_INDX_CTRL,
   ENC_CNTR_BASICOP_CMD_SPECIAL_CTRL,
   ENC_CNTR_BASICOP_CMD_INPUT,
   ENC_CNTR_BASICOP_CMD_CLK_DIV,
   ENC_CNTR_BASICOP_CMD_POLARITY,
   ENC_CNTR_BASICOP_CMD_COUNTER_COMPARE,
   ENC_CNTR_BASICOP_CMD_COMMAND,
   ENC_CNTR_BASICOP_CMD_STATUS,
   ENC_CNTR_BASICOP_CMD_COUNT
};

/****** Counter Command Functions *******/
naiapp_cmdtbl_params_t ENC_CNTR_BasicOpMenuCmds[] =
{
   {"Pre",   "Configure Counter Preload",  ENC_CNTR_BAISCOP_CMD_PRELOAD,         CounterMenu_SetPreload},
   {"IC",    "Configure Index Control",    ENC_CNTR_BASICOP_CMD_INDX_CTRL,       CounterMenu_SetIndxCtrl},
   {"S",     "Configure Special Control",  ENC_CNTR_BASICOP_CMD_SPECIAL_CTRL,    CounterMenu_SetSpecialCtrl},
   {"IN",    "Configure Input",            ENC_CNTR_BASICOP_CMD_INPUT,           CounterMenu_SetCtrlInputMode},
   {"Clk",   "Configure Clock Divide",     ENC_CNTR_BASICOP_CMD_CLK_DIV,         CounterMenu_SetClkDiv},
   {"Pol",   "Configure Polarity",         ENC_CNTR_BASICOP_CMD_POLARITY,        CounterMenu_SetPolarity},
   {"Cmp",   "Configure Counter Compare",  ENC_CNTR_BASICOP_CMD_COUNTER_COMPARE, CounterMenu_SetCntrCmp},
   {"Cmd",   "Set Counter Command",        ENC_CNTR_BASICOP_CMD_COMMAND,         CounterMenu_SetCommandReg},
   {"STAT",  "Display Counter Status",     ENC_CNTR_BASICOP_CMD_STATUS,          Display_ENC_CntrStatus}
};

/****** SSI Command Table *******/
enum enc_ssi_basicops_commands
{
   ENC_SSI_BASICOP_CMD_SETMODE,
   ENC_SSI_BASICOP_CMD_CLOCK_CONFIG,
   ENC_SSI_BASICOP_CMD_DATABITS,
   ENC_SSI_BASICOP_CMD_PARITY,
   ENC_SSI_BASICOP_CMD_PARITY_EN,
   ENC_SSI_BASICOP_CMD_ZEROBIT_EN,
   ENC_SSI_BASICOP_CMD_WD_ERRORBREAK,
   ENC_SSI_BASICOP_CMD_DATA_TYPE,
   ENC_SSI_BASICOP_CMD_TRIGGER_DATA,
   ENC_SSI_BASICOP_CMD_STATUS,
   ENC_SSI_BASICOP_CMD_COUNT
};

/****** SSI Command Fucntions *******/
naiapp_cmdtbl_params_t ENC_SSI_BasicOpMenuCmds[] =
{
   {"Mode",   "Set SSI Mode",                      ENC_SSI_BASICOP_CMD_SETMODE,          SSIMenu_SetMode},
   {"Cnfg",   "Set SSI Clock Config",              ENC_SSI_BASICOP_CMD_CLOCK_CONFIG,     SSIMenu_SetClockConfig},
   {"Bits",   "Set SSI DataBits",                  ENC_SSI_BASICOP_CMD_DATABITS,         SSIMenu_SetDataBits},
   {"Par",    "Set SSI Parity",                    ENC_SSI_BASICOP_CMD_PARITY,           SSIMenu_SetParity},
   {"PC",     "Enable/Disable ParityCheck",        ENC_SSI_BASICOP_CMD_PARITY_EN,        SSIMenu_SetParityEn},
   {"ZB",     "Enable/Disable ZeroBit",            ENC_SSI_BASICOP_CMD_ZEROBIT_EN,       SSIMenu_SetZeroBitEn},
   {"Err",    "Config WatchDog and Error Break",   ENC_SSI_BASICOP_CMD_WD_ERRORBREAK,    SSIMenu_SetWD_EB},
   {"Data",   "Config SSI Data Type (EC1 Only)",   ENC_SSI_BASICOP_CMD_DATA_TYPE,        SSIMenu_SetDataType},
   {"Trig",   "Trigger SSI Transfer",              ENC_SSI_BASICOP_CMD_TRIGGER_DATA,     NULL},
   {"STAT",   "Display SSI Status",                ENC_SSI_BASICOP_CMD_STATUS,           Display_ENC_SSIStatus}
};

/**************************************************************************************************************/
/** \defgroup ENCBasicOps

\brief This sample application demonstrates how to configure and use the basic features of an Encoder Module..

This sample application illustrates how to perform basic operations with the encoder module such as:
configuration setup, controlling the drive outputs, and reading data using the `naibrd` library. It is intended
to help users understand how to [goal of the sample app].

The main steps might include actions such as:
- Querying the user for the card index and module number
- Configuring the module for a specific mode or operation
- Receiving encoder data in either Counter or SSI mode.
- Displaying status and results

The features are broken up into 4 separate menus:
- Main Menu: Allows the user to access specific features of the encoder (ENC Common features, Counter, SSI)
- Common Menu: Allows the user to access features that apply to all ENC modes
- Counter Menu: Allows the user to access the Counter features of the ENC module
- SSI Menu: Allows the user to access the SSI features of the ENC module
*/
/**************************************************************************************************************/

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

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_ENC_BasicOps(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart application:\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;
}

int32_t Run_ENC_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
   int32_t maxChannel = naibrd_ENC_GetChannelCount(ModuleID);
   naiapp_AppParameters_t  enc_params;
   p_naiapp_AppParameters_t enc_basicops_params = &enc_params;
   enc_basicops_params->cardIndex = cardIndex;
   enc_basicops_params->module = module;
   enc_basicops_params->modId = ModuleID;
   enc_basicops_params->maxChannels = maxChannel;

   if (maxChannel == 0)
   {
      naiif_printf(" *** Module selection not recognized as ENC module. ***\r\n\r\n");
   }
   else
   {
      ENC_CommandMenu(APP_PARAM_COUNT, (int32_t*)enc_basicops_params);
   }
   return cardIndex;
}

static nai_status_t ENC_CommandMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t defaultchan = DEF_ENC_CHANNEL;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   int32_t MaxChannel = p_enc_params->maxChannels;

   while (bContinue)
   {
      naiif_printf("\r\nChannel selection \r\r\n");
      naiif_printf("================= \r\r\n");
      defaultchan = DEF_ENC_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      p_enc_params->channel = chan;

      while (bContinue)
      {
         Display_ENC_GeneralCfg(cardIndex, module, chan);
         naiapp_utils_LoadParamMenuCommands(ENC_BASICOP_CMD_COUNT, ENC_BasicOpMenuCmds);
         naiapp_display_ParamMenuCommands((int8_t*)"ENC Basic Operation Menu");
         naiif_printf("\r\nType ENC 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 ENC_BASICOP_CMD_CONFIG_INTERVAL_TIMER:
                     case ENC_BASICOP_CMD_CONFIG_GLOBAL_REG:
                     case ENC_BAISCOP_CMD_CNTR_CONFIG_MENU:
                     case ENC_BASICOP_CMD_VIEW_CHAN_STATUS:
                        ENC_BasicOpMenuCmds[cmd].func(paramCount, (int32_t*)p_enc_params);
                     break;
                     case ENC_BAISCOP_CMD_COMMON_CONFIG_MENU:
                     case ENC_BASICOP_CMD_SSI_CONFIG_MENU:
                        ENC_BasicOpMenuCmds[cmd].func(paramCount, (int32_t*)p_enc_params);
                     break;
                     default:
                        naiif_printf("Invalid command entered\r\n");
                     break;
                  }
               }
               else
                  naiif_printf("Invalid command entered\r\n");
            }
         }
         else
            bContinue = NAI_FALSE;
      }
   }
   return NAI_SUCCESS;
}

static nai_status_t CommandMenu_ConfigureIntervalTimer(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateEnable = NAI_FALSE, bUpdateClkDiv = NAI_FALSE, bUpdatePreload = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   naibrd_enc_intvl_clk_t clkDiv = NAIBRD_ENC_INTVL_CLK_25_MHz;
   uint32_t preload = 0u;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the interval timer preload value. */
   naiif_printf("\r\nEnter the desired preload value for interval timer (0-65,535), 'X'=Skip: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if (toupper(inputBuffer[0]) != 'X')
            {
               naiapp_query_UnsignedNumberFromResponse(&preload, inputBuffer, inputResponseCnt);
               bUpdatePreload = NAI_TRUE;
            }
         }
      }

   /* Set the clock divide for interval timer mode. */
   naiif_printf("\r\nChoose the desired Clock Div: ");
   naiif_printf("('1'=25 Mhz, '2'=12.5 Mhz, '3'=6.25 Mhz, '4'=3.125 Mhz, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case '1':
                  clkDiv = NAIBRD_ENC_INTVL_CLK_25_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case '2':
                  clkDiv = NAIBRD_ENC_INTVL_CLK_12_5_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case '3':
                  clkDiv = NAIBRD_ENC_INTVL_CLK_6_25_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case '4':
                  clkDiv = NAIBRD_ENC_INTVL_CLK_3_125_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid termination entry\r\n");
               break;
            }
         }
      }

   /* Disable/Enable Interval Timer Mode */
   naiif_printf("\r\nWould you like to Enable or Disable the interval timer: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case 'E':
                  enable = NAI_TRUE;
                  bUpdateEnable = NAI_TRUE;
               break;
               case 'D':
                  enable = NAI_FALSE;
                  bUpdateEnable = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid input mode entry\r\n");
               break;
            }
         }
      }

   if (!bQuit)
   {
      if (bUpdateEnable)
      {
         check_status(naibrd_ENC_SetIntervalTimerEnable(cardIndex, module, enable));
      }
      if (bUpdateClkDiv)
      {
         check_status(naibrd_ENC_SetIntervalTimerClkDivide(cardIndex, module, clkDiv));
      }
      if (bUpdatePreload)
      {
         check_status(naibrd_ENC_SetIntervalTimerPreload(cardIndex, module, (int16_t)preload));
      }
   }

   return NAI_SUCCESS;

}

static nai_status_t CommandMenu_ConfigureGlobalReg(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t maxChan = p_enc_params->maxChannels;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMCR_En = NAI_FALSE, bUpdateMC_Preload = NAI_FALSE, bUpdateMCRTR = NAI_FALSE, bUpdateITGR = NAI_FALSE;
   naibrd_enc_multi_chan_t MultiChanPreloadChannels = 0;
   bool_t MCREn = NAI_FALSE, ITGREn = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   int32_t i = 0;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the channels to preload counters for. */
   naiif_printf("\r\nEnter bitmapped value of channels to preload counters: ");
   naiif_printf("(LSB is channel one, MSB is channel 4 (0101 would correlate to channels 1 and 3), 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            if (toupper(inputBuffer[0]) != 'X')
            {
               naiapp_query_UnsignedNumberFromResponse(&MultiChanPreloadChannels, inputBuffer, inputResponseCnt);
               bUpdateMC_Preload = NAI_TRUE;
            }
         }
      }

   for (i = 1; i <= maxChan; i++)
   {
      /* Set the enable for multi channel read of channel. */
      naiif_printf("\r\nWould you like to enable/disable the multichan read for channel %d?", i);
      naiif_printf("'E' = enable, 'D' = disable, 'X'=Skip: ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            bUpdateMCR_En = NAI_FALSE;
            switch (toupper(inputBuffer[0]))
            {
               case 'E':
                  MCREn = NAI_TRUE;
                  bUpdateMCR_En = NAI_TRUE;
               break;
               case 'D':
                  MCREn = NAI_FALSE;
                  bUpdateMCR_En = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid input mode entry\r\n");
               break;
            }
         }
      }
      if (bUpdateMCR_En)
      {
         check_status(naibrd_ENC_SetMultiChanRdEnable(cardIndex, module, i, MCREn));
      }
   }

   /* Interval Timer for trigger to preload */
   naiif_printf("\r\nWould you like to Enable or Disable the interval timer as the trigger for MCR: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case 'E':
                  ITGREn = NAI_TRUE;
                  bUpdateITGR = NAI_TRUE;
               break;
               case 'D':
                  ITGREn = NAI_FALSE;
                  bUpdateITGR = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid input mode entry\r\n");
               break;
            }
         }
      }

   /* Trigger MCR */
   naiif_printf("\r\nWould you like to trigger multi channel read?: ");
   naiif_printf("('E'=trigger, 'D'=don't trigger): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case 'E':
                  bUpdateMCRTR = NAI_TRUE;
               break;
               case 'D':
               break;
               default:
                  naiif_printf("ERROR: Invalid input mode entry\r\n");
               break;
            }
         }
      }

   if (!bQuit)
   {
      if (bUpdateMC_Preload)
      {
         check_status(naibrd_ENC_SetMultiChanCntrPreloadEnable(cardIndex, module, MultiChanPreloadChannels));
      }
      if (bUpdateITGR)
      {
         check_status(naibrd_ENC_SetIntvlTimerTrigEnable(cardIndex, module, ITGREn));
      }
      if (bUpdateMCRTR)
      {
         check_status(naibrd_ENC_TriggerMultiChanRd(cardIndex, module));
      }
   }

   return NAI_SUCCESS;
}

static nai_status_t CommandMenu_CommonConfigMenu(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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;

   while (bContinue)
   {
      Display_ENC_CommonCfg(cardIndex, module, chan);

      naiapp_utils_LoadParamMenuCommands(ENC_COMMON_BASICOP_CMD_COUNT, ENC_Common_BasicOpMenuCmds);
      naiapp_display_ParamMenuCommands((int8_t *)"ENC Common Operation Menu");
      naiif_printf("\r\nType ENC 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 ENC_COMMON_BASICOP_CMD_INPUT_CONFIG:
                  case ENC_COMMON_BASICOP_CMD_ENC_MODE:
                  case ENC_COMMON_BASICOP_CMD_DEBOUNCE_A:
                  case ENC_COMMON_BASICOP_CMD_DEBOUNCE_B:
                  case ENC_COMMON_BASICOP_CMD_DEBOUNCE_C:
                  case ENC_COMMON_BASICOP_CMD_DEBOUNCE_En:
                     ENC_Common_BasicOpMenuCmds[cmd].func(paramCount, (int32_t*)p_enc_params);
                     break;
                  default:
                     naiif_printf("Invalid command entered\r\n");
                     break;
               }
            }
            else
               naiif_printf("Invalid command entered\r\n");
         }
      }
      else
         bContinue = NAI_FALSE;
   }
   return NAI_SUCCESS;
}

static nai_status_t CommonMenu_SetInputConfig(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMode = NAI_FALSE, bUpdateTerm = NAI_FALSE;
   naibrd_enc_input_mode_t inputMode = NAIBRD_ENC_INPUT_DIFFERENTIAL;
   naibrd_enc_term_t termination = NAIBRD_ENC_NOT_TERMINATED;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the input mode on channel. */
   naiif_printf("\r\nType the desired Input Mode: ");
   naiif_printf("('1'=RS-422, '2'=TTL, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case '1':
               inputMode = NAIBRD_ENC_INPUT_RS422;
               bUpdateMode = NAI_TRUE;
            break;
            case '2':
               inputMode = NAIBRD_ENC_INPUT_TTL;
               bUpdateMode = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid input mode entry\r\n");
            break;
         }
      }
   }

   /* Set the termination type on channel. */
   naiif_printf("\r\nType the desired Termination: ");
   naiif_printf("('D'=Term for Differential, 'N'=Term Disabled, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'N':
               termination = NAIBRD_ENC_NOT_TERMINATED;
               bUpdateTerm = NAI_TRUE;
            break;
            case 'D':
               termination = NAIBRD_ENC_DIFF_TERMINATED;
               bUpdateTerm = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid termination entry\r\n");
            break;
         }
      }
   }

   if (!bQuit)
   {
      if (bUpdateMode)
      {
         check_status(naibrd_ENC_SetInputMode(cardIndex, module, chan, inputMode));
      }
      if (bUpdateTerm)
      {
         check_status(naibrd_ENC_SetInputTermination(cardIndex, module, chan, termination));
      }
   }
   return NAI_SUCCESS;
}

static nai_status_t CommonMenu_SetEncoderMode(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMode = NAI_FALSE;
   naibrd_enc_mode_t mode = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the encoder mode on channel. */
   naiif_printf("\r\nEnter the desired Mode for the channel:  ");
   naiif_printf("('S'=SSI mode, 'C'=Counter mode, 'D'=Chan disabled,  'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'S':
               mode = NAIBRD_ENC_MODE_SSI;
               bUpdateMode = NAI_TRUE;
            break;
            case 'C':
               mode = NAIBRD_ENC_MODE_COUNTER;
               bUpdateMode = NAI_TRUE;
            break;
            case 'D':
               mode = NAIBRD_ENC_MODE_DISABLED;
               bUpdateMode = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid mode entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateMode)
      {
         check_status(naibrd_ENC_SetControlMode(cardIndex, module, chan, mode));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t CommonMenu_SetDebounceA(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateDebounce = NAI_FALSE;
   float64_t debounce = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the debounce value for A. */
   naiif_printf("\r\nType the desired debounce time for A (0-1.3107 ms), 'X' =Skip");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if (toupper(inputBuffer[0]) != 'X')
         {
            debounce = atof((const char*)inputBuffer);
            bUpdateDebounce = NAI_TRUE;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateDebounce)
      {
         check_status(naibrd_ENC_SetDebounceTime(cardIndex, module, chan, NAIBRD_ENC_PORT_A, debounce));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t CommonMenu_SetDebounceB(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateDebounce = NAI_FALSE;
   float64_t debounce = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the debounce value for A. */
   naiif_printf("\r\nType the desired debounce time for B (0-1.3107 ms), 'X' =Skip");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if (toupper(inputBuffer[0]) != 'X')
         {
            debounce = atof((const char*)inputBuffer);
            bUpdateDebounce = NAI_TRUE;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateDebounce)
      {
         check_status(naibrd_ENC_SetDebounceTime(cardIndex, module, chan, NAIBRD_ENC_PORT_B, debounce));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t CommonMenu_SetDebounceC(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateDebounce = NAI_FALSE;
   float64_t debounce = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the debounce value for A. */
   naiif_printf("\r\nType the desired debounce time for C (0-1.3107 ms), 'X' =Skip");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if (toupper(inputBuffer[0]) != 'X')
         {
            debounce = atof((const char*)inputBuffer);
            bUpdateDebounce = NAI_TRUE;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateDebounce)
      {
         check_status(naibrd_ENC_SetDebounceTime(cardIndex, module, chan, NAIBRD_ENC_PORT_Index, debounce));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t CommonMenu_SetDebounceEn(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateA = NAI_FALSE, bUpdateB = NAI_FALSE, bUpdateC = NAI_FALSE;
   bool_t enableA = NAI_FALSE, enableB = NAI_FALSE, enableC = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the debounce enable for A. */
   naiif_printf("\r\nType the desired input to enable/disable debounce for A: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enableA = NAI_TRUE;
               bUpdateA = NAI_TRUE;
            break;
            case 'D':
               enableA = NAI_FALSE;
               bUpdateA = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }

   /* Set the debounce enable for B. */
   naiif_printf("\r\nType the desired input to enable/disable debounce for B: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enableB = NAI_TRUE;
               bUpdateB = NAI_TRUE;
            break;
            case 'D':
               enableB = NAI_FALSE;
               bUpdateB = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }

   /* Set the debounce enable for C. */
   naiif_printf("\r\nType the desired input to enable/disable debounce for C: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enableC = NAI_TRUE;
               bUpdateC = NAI_TRUE;
            break;
            case 'D':
               enableC = NAI_FALSE;
               bUpdateC = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }

   if (!bQuit)
   {
      if (bUpdateA)
      {
         check_status(naibrd_ENC_SetDebounceEnable(cardIndex, module, chan, NAIBRD_ENC_PORT_A, enableA));
      }
      if (bUpdateB)
      {
         check_status(naibrd_ENC_SetDebounceEnable(cardIndex, module, chan, NAIBRD_ENC_PORT_B, enableB));
      }
      if (bUpdateC)
      {
         check_status(naibrd_ENC_SetDebounceEnable(cardIndex, module, chan, NAIBRD_ENC_PORT_Index, enableC));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t CommandMenu_CntrConfigMenu(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;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;

   while (bContinue)
   {
      Display_ENC_CntrCfg(cardIndex, module, chan);

      naiapp_utils_LoadParamMenuCommands(ENC_CNTR_BASICOP_CMD_COUNT, ENC_CNTR_BasicOpMenuCmds);
      naiapp_display_ParamMenuCommands((int8_t*)"ENC CNTR Basic Operation Menu");
      naiif_printf("\r\nType ENC CNTR 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 ENC_CNTR_BAISCOP_CMD_PRELOAD:
                  case ENC_CNTR_BASICOP_CMD_INDX_CTRL:
                  case ENC_CNTR_BASICOP_CMD_SPECIAL_CTRL:
                  case ENC_CNTR_BASICOP_CMD_INPUT:
                  case ENC_CNTR_BASICOP_CMD_CLK_DIV:
                  case ENC_CNTR_BASICOP_CMD_POLARITY:
                  case ENC_CNTR_BASICOP_CMD_COUNTER_COMPARE:
                  case ENC_CNTR_BASICOP_CMD_COMMAND:
                  case ENC_CNTR_BASICOP_CMD_STATUS:
                     ENC_CNTR_BasicOpMenuCmds[cmd].func(paramCount, (int32_t*)p_enc_params);
                  break;
                  default:
                     naiif_printf("Invalid command entered\r\n");
                  break;
               }
            }
            else
               naiif_printf("Invalid command entered\r\n");
         }
      }
      else
         bContinue = NAI_FALSE;
   }
   return NAI_SUCCESS;

}

static nai_status_t CounterMenu_SetPreload(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdatePreload = NAI_FALSE;
   uint32_t preload = 0u;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the counter preload value. */
   naiif_printf("\r\nEnter the desired preload value for the counter, 'X'=Skip: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if (toupper(inputBuffer[0]) != 'X')
         {
            naiapp_query_UnsignedNumberFromResponse(&preload, inputBuffer, inputResponseCnt);
            bUpdatePreload = NAI_TRUE;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdatePreload)
      {
         check_status(naibrd_ENC_SetCNTR_PreLoad(cardIndex, module, chan, preload));
      }
   }

   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetIndxCtrl(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMode = NAI_FALSE;
   naibrd_enc_cntr_icm_t mode = NAIBRD_ENC_CNTR_ICM_IGNORE_I;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
      /* Set the counter index control mode. */
      naiif_printf("\r\nChoose the desired Index Control Mode: ");
      naiif_printf("('1'=Ignore I, '2'=Load on I, '3'=Latch on I, '4'=Gate on I, '5'=Reset on I, 'X'=Skip): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case '1':
                  mode = NAIBRD_ENC_CNTR_ICM_IGNORE_I;
                  bUpdateMode = NAI_TRUE;
               break;
               case '2':
                  mode = NAIBRD_ENC_CNTR_ICM_LOAD_I;
                  bUpdateMode = NAI_TRUE;
               break;
               case '3':
                  mode = NAIBRD_ENC_CNTR_ICM_LATCH_I;
                  bUpdateMode = NAI_TRUE;
               break;
               case '4':
                  mode = NAIBRD_ENC_CNTR_ICM_GATE_I;
                  bUpdateMode = NAI_TRUE;
               break;
               case '5':
                  mode = NAIBRD_ENC_CNTR_ICM_RESET_I;
                  bUpdateMode = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid mode entry\r\n");
               break;
            }
         }
      }
      if (!bQuit)
      {
         if (bUpdateMode)
         {
            check_status(naibrd_ENC_SetCNTR_IndexControl(cardIndex, module, chan, mode));
         }
      }

   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetSpecialCtrl(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMode = NAI_FALSE;
   naibrd_enc_cntr_scm_t mode = NAIBRD_ENC_CNTR_SCM_NORMAL;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the counter special control mode. */
   naiif_printf("\r\nChoose the desired Special Control Mode: ");
   naiif_printf("('1'=Normal Operation, '2'=Divide by N, '3'=Single Cycle, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case '1':
               mode = NAIBRD_ENC_CNTR_SCM_NORMAL;
               bUpdateMode = NAI_TRUE;
            break;
            case '2':
               mode = NAIBRD_ENC_CNTR_SCM_DIVIDE_N;
               bUpdateMode = NAI_TRUE;
            break;
            case '3':
               mode = NAIBRD_ENC_CNTR_SCM_SNGLE_CYC;
               bUpdateMode = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid mode entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateMode)
      {
         check_status(naibrd_ENC_SetCNTR_SpecialControl(cardIndex, module, chan, mode));
      }
   }

   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetCtrlInputMode(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMode = NAI_FALSE;
   naibrd_enc_cntr_cim_t mode = NAIBRD_ENC_CNTR_CIM_NONE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the counter index control mode. */
   naiif_printf("\r\nChoose the desired Control Input Mode: ");
   naiif_printf("('1'=None, '2'=Count up, '3'=Count down, '4'=Direction count, '5'=Up/down count, '6'=Quad 1x, '7'=Quad 2x, '8'=Quad 4x, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case '1':
               mode = NAIBRD_ENC_CNTR_CIM_NONE;
               bUpdateMode = NAI_TRUE;
            break;
            case '2':
               mode = NAIBRD_ENC_CNTR_CIM_UP;
               bUpdateMode = NAI_TRUE;
            break;
            case '3':
               mode = NAIBRD_ENC_CNTR_CIM_DOWN;
               bUpdateMode = NAI_TRUE;
            break;
            case '4':
               mode = NAIBRD_ENC_CNTR_CIM_DIR_CNT;
               bUpdateMode = NAI_TRUE;
            break;
            case '5':
               mode = NAIBRD_ENC_CNTR_CIM_UP_DOWN_CNT;
               bUpdateMode = NAI_TRUE;
            break;
            case '6':
               mode = NAIBRD_ENC_CNTR_CIM_QUAD1X;
               bUpdateMode = NAI_TRUE;
            break;
            case '7':
               mode = NAIBRD_ENC_CNTR_CIM_QUAD2X;
               bUpdateMode = NAI_TRUE;
            break;
            case '8':
               mode = NAIBRD_ENC_CNTR_CIM_QUAD4X;
               bUpdateMode = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid mode entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateMode)
      {
         check_status(naibrd_ENC_SetCNTR_InputMode(cardIndex, module, chan, mode));
      }
   }

   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetClkDiv(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateClkDiv = NAI_FALSE;
   naibrd_enc_cntr_clk_div_t clkDiv = NAIBRD_ENC_CNTR_CLK_DIV_62_5_MHz;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
/* Set the clock divide for counter mode. */
      naiif_printf("\r\nChoose the desired counter Clock Div: ");
      naiif_printf("('1'=62.5 Mhz, '2'=31.25 Mhz, '3'=12.5 Mhz, '4'=6.25 Mhz, 'X'=Skip): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case '1':
                  clkDiv = NAIBRD_ENC_CNTR_CLK_DIV_62_5_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case '2':
                  clkDiv = NAIBRD_ENC_CNTR_CLK_DIV_31_25_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case '3':
                  clkDiv = NAIBRD_ENC_CNTR_CLK_DIV_12_5_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case '4':
                  clkDiv = NAIBRD_ENC_CNTR_CLK_DIV_6_25_MHz;
                  bUpdateClkDiv = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid clk div entry\r\n");
               break;
            }
         }
      }

      if (!bQuit)
      {
         if (bUpdateClkDiv)
         {
            check_status(naibrd_ENC_SetCNTR_ClkDivide(cardIndex, module, chan, clkDiv));
         }
      }

   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetPolarity(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateA = NAI_FALSE, bUpdateB = NAI_FALSE, bUpdateC = NAI_FALSE;
   naibrd_enc_cntr_polarity_t enableA = NAI_FALSE, enableB = NAI_FALSE, enableC = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the polarity enable for A. */
   naiif_printf("\r\nType the desired input to enable/disable polarity for A: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enableA = NAIBRD_ENC_CNTR_POLARITY_SET;
               bUpdateA = NAI_TRUE;
            break;
            case 'D':
               enableA = NAIBRD_ENC_CNTR_POLARITY_UNSET;
               bUpdateA = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }

   /* Set the polarity enable for B. */
   naiif_printf("\r\nType the desired input to enable/disable polarity for B: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enableB = NAIBRD_ENC_CNTR_POLARITY_SET;
               bUpdateB = NAI_TRUE;
            break;
            case 'D':
               enableB = NAIBRD_ENC_CNTR_POLARITY_UNSET;
               bUpdateB = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }

   /* Set the polarity enable for C. */
   naiif_printf("\r\nType the desired input to enable/disable polarity for C: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enableC = NAIBRD_ENC_CNTR_POLARITY_SET;
               bUpdateC = NAI_TRUE;
            break;
            case 'D':
               enableC = NAIBRD_ENC_CNTR_POLARITY_UNSET;
               bUpdateC = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }

   if (!bQuit)
   {
      if (bUpdateA)
      {
         check_status(naibrd_ENC_SetCNTR_Polarity(cardIndex, module, chan, NAIBRD_ENC_PORT_A, enableA));
      }
      if (bUpdateB)
      {
         check_status(naibrd_ENC_SetCNTR_Polarity(cardIndex, module, chan, NAIBRD_ENC_PORT_B, enableB));
      }
      if (bUpdateC)
      {
         check_status(naibrd_ENC_SetCNTR_Polarity(cardIndex, module, chan, NAIBRD_ENC_PORT_Index, enableC));
      }
   }
   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetCntrCmp(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateCompareEn = NAI_FALSE, bUpdateCompareValue = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   int32_t compareVal = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Disable/Enable Counter Compare */
   naiif_printf("\r\nWould you like to Enable or Disable the counter compare: ");
   naiif_printf("('E'=Enable, 'D'=Disable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enable = NAI_TRUE;
               bUpdateCompareEn = NAI_TRUE;
            break;
            case 'D':
               enable = NAI_FALSE;
               bUpdateCompareEn = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid input mode entry\r\n");
            break;
         }
      }
   }

   /* Set the counter compare value. */
   naiif_printf("\r\nEnter the desired counter compare value, 'X'=Skip: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if (toupper(inputBuffer[0]) != 'X')
         {
            compareVal = atoi((const char*)inputBuffer);
            bUpdateCompareValue = NAI_TRUE;
         }
      }
   }

   if (!bQuit)
   {
      if (bUpdateCompareEn)
      {
         check_status(naibrd_ENC_SetCNTR_CompareEnable(cardIndex, module, chan, enable));
      }
      if (bUpdateCompareValue)
      {
         check_status(naibrd_ENC_SetCNTR_CompareCount(cardIndex, module, chan, compareVal));
      }
   }

   return NAI_SUCCESS;
}

static nai_status_t CounterMenu_SetCommandReg(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateCommand = NAI_FALSE;
   naibrd_enc_cntr_ctrl_t command = 0u;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the counter command. */
      naiif_printf("\r\nChoose the desired counter command: ");
      naiif_printf("('1'=Reset Counter, '2'=Load Counter with preload value, '3'=Latch Counters 'X'=Skip): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            switch (toupper(inputBuffer[0]))
            {
               case '1':
                  command = NAIBRD_ENC_CNTR_CTRL_RESET;
                  bUpdateCommand = NAI_TRUE;
               break;
               case '2':
                  command = NAIBRD_ENC_CNTR_CTRL_LOAD;
                  bUpdateCommand = NAI_TRUE;
               break;
               case '3':
                  command = NAIBRD_ENC_CNTR_CTRL_LATCH;
                  bUpdateCommand = NAI_TRUE;
               break;
               case 'X':
               break;
               default:
                  naiif_printf("ERROR: Invalid termination entry\r\n");
               break;
            }
         }
      }
      if (!bQuit)
      {
         if (bUpdateCommand)
         {
            check_status(naibrd_ENC_SetCNTR_ControlCommand(cardIndex, module, chan, command));
         }
      }

   return NAI_SUCCESS;
}

static nai_status_t Display_ENC_CntrStatus(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   nai_status_bit_t status;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Available status:
         NAIBRD_ENC_CNTR_STATUS_BORROW
         NAIBRD_ENC_CNTR_STATUS_CARRY
         NAIBRD_ENC_CNTR_STATUS_MATCH
         NAIBRD_ENC_CNTR_STATUS_SIGN
         NAIBRD_ENC_CNTR_STATUS_CNTR_DIR
         NAIBRD_ENC_CNTR_STATUS_CNTR_ACTIVE
   */
   naiif_printf("\r\n");
   naiif_printf(" ------------------- Status ------------------\r\n");
   naiif_printf("  Borrow   Carry   Match   SGN   DIR   Active   \r\n");
   naiif_printf(" -------- ------- ------- ----- ----- --------\r\n");

   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_CNTR_BORROW_REALTIME, &status));
   naiif_printf("  %3i   ", status);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_CNTR_CARRY_REALTIME, &status));
   naiif_printf("   %3i   ", status);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_CNTR_MATCH_REALTIME, &status));
   naiif_printf("  %3i  ", status);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_CNTR_SIGN_REALTIME, &status));
   naiif_printf("  %3i  ", status);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_CNTR_DIR_REALTIME, &status));
   naiif_printf(" %3i  ", status);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_CNTR_ACTIVE_REALTIME, &status));
   naiif_printf("   %3i  ", status);
   naiif_printf("\r\n\r\n");

   return NAI_ERROR_UNKNOWN;
}

static nai_status_t CommandMenu_SSIConfigMenu(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   nai_status_t status = (nai_status_t)0;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;

   while (bContinue)
   {
      Display_ENC_SSICfg(cardIndex, module, chan);

      naiapp_utils_LoadParamMenuCommands(ENC_SSI_BASICOP_CMD_COUNT, ENC_SSI_BasicOpMenuCmds);
      naiapp_display_ParamMenuCommands((int8_t*)"ENC SSI Basic Operation Menu");
      naiif_printf("\r\nType ENC SSI 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 ENC_SSI_BASICOP_CMD_SETMODE:
                  case ENC_SSI_BASICOP_CMD_CLOCK_CONFIG:
                  case ENC_SSI_BASICOP_CMD_DATABITS:
                  case ENC_SSI_BASICOP_CMD_PARITY:
                  case ENC_SSI_BASICOP_CMD_PARITY_EN:
                  case ENC_SSI_BASICOP_CMD_ZEROBIT_EN:
                  case ENC_SSI_BASICOP_CMD_WD_ERRORBREAK:
                  case ENC_SSI_BASICOP_CMD_STATUS:
                     ENC_SSI_BasicOpMenuCmds[cmd].func(paramCount, (int32_t*)p_enc_params);
                  break;
                  case ENC_SSI_BASICOP_CMD_DATA_TYPE:
                     ENC_SSI_BasicOpMenuCmds[cmd].func(paramCount, (int32_t*)p_enc_params);
                  break;
                  case ENC_SSI_BASICOP_CMD_TRIGGER_DATA:
                     status = check_status(naibrd_ENC_SSI_TriggerData(cardIndex, module, chan));
                     if (status == NAI_SUCCESS)
                     {
                        naiif_printf("Triggered SSI clock, SSI data refreshed. \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;
   }
   return NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetMode(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateMode = NAI_FALSE;
   naibrd_enc_ssi_mode_t mode = NAIBRD_ENC_SSI_CONTROLLER;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the SSI mode (Interface controller or Listener) on channel. */
   naiif_printf("\r\nType the desired SSI mode");
   naiif_printf("('C'=SSI Interface Controller, 'L'=SSI Listener): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'C':
               mode = NAIBRD_ENC_SSI_CONTROLLER;
               bUpdateMode = NAI_TRUE;
            break;
            case 'L':
               mode = NAIBRD_ENC_SSI_LISTENER;
               bUpdateMode = NAI_TRUE;
            break;
            default:
               naiif_printf("ERROR: Invalid SSI mode Entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateMode)
      {
         check_status(naibrd_ENC_SetControlMode(cardIndex, module, chan, NAIBRD_ENC_MODE_SSI));
         check_status(naibrd_ENC_SetSSI_Mode(cardIndex, module, chan, mode));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetClockConfig(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdatePeriod = NAI_FALSE, bUpdateDwell = NAI_FALSE;
   uint32_t clockRate = 0, dwellTime = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the SSI clock period on channel. */
   naiif_printf("\r\nEnter the desired clock period (1-32)uS:  ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         clockRate = atoi((const char *)inputBuffer);
         bUpdatePeriod = NAI_TRUE;
      }
   }

   /* Set the SSI dwell time on channel. */
   naiif_printf("\r\nEnter the desired dwell time (1-31)clocks:  ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         dwellTime = atoi((const char*)inputBuffer);
         bUpdateDwell = NAI_TRUE;
      }
   }

   if (!bQuit)
   {
      if (bUpdatePeriod)
      {
         check_status(naibrd_ENC_SetSSI_ClockRate_uS(cardIndex, module, chan, clockRate));
      }
      if (bUpdateDwell)
      {
         check_status(naibrd_ENC_SetSSI_DwellCount_ClkCycles(cardIndex, module, chan, dwellTime));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetDataBits(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdatePeriod = NAI_FALSE;
   uint32_t dataBits = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the SSI data bits on channel. */
   naiif_printf("\r\nEnter the expected number of data bits (1-31):  ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         dataBits = atoi((const char *)inputBuffer);
         bUpdatePeriod = NAI_TRUE;
      }
   }
   if (!bQuit)
   {
      if (bUpdatePeriod)
      {
         check_status(naibrd_ENC_SetSSI_NumDataBits(cardIndex, module, chan, dataBits));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetParity(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateParity = NAI_FALSE;
   naibrd_enc_ssi_parity_t parity = NAIBRD_ENC_SSI_PARITY_EVEN;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the SSI parity on channel. */
   naiif_printf("\r\nType the desired SSI parity");
   naiif_printf("('E'=Even, 'O'=Odd): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               parity = NAIBRD_ENC_SSI_PARITY_EVEN;
               bUpdateParity = NAI_TRUE;
            break;
            case 'O':
               parity = NAIBRD_ENC_SSI_PARITY_ODD;;
               bUpdateParity = NAI_TRUE;
            break;
            default:
               naiif_printf("ERROR: Invalid SSI parity entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateParity)
      {
         check_status(naibrd_ENC_SetSSI_Parity(cardIndex, module, chan, parity));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetParityEn(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateParityEn = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the parity enable on channel. */
   naiif_printf("\r\nType the desired input to enable/disable parity checking");
   naiif_printf("('E'=Enable, 'D'=Disable): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enable = NAI_TRUE;
               bUpdateParityEn = NAI_TRUE;
            break;
            case 'D':
               enable = NAI_FALSE;
               bUpdateParityEn = NAI_TRUE;
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateParityEn)
      {
         check_status(naibrd_ENC_SetSSI_ParityEnable(cardIndex, module, chan, enable));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetZeroBitEn(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateZeroBitEn = NAI_FALSE;
   bool_t enable = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set enable/disable for zero bit on channel. */
   naiif_printf("\r\nType the desired input to enable/disable zero bit");
   naiif_printf("('E'=Enable, 'D'=Disable): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'E':
               enable = NAI_TRUE;
               bUpdateZeroBitEn = NAI_TRUE;
            break;
            case 'D':
               enable = NAI_FALSE;
               bUpdateZeroBitEn = NAI_TRUE;
            break;
            default:
               naiif_printf("ERROR: Invalid entry\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateZeroBitEn)
      {
         check_status(naibrd_ENC_SetSSI_ZeroBitEnable(cardIndex, module, chan, enable));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetWD_EB(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateWD = NAI_FALSE, bUpdateEB = NAI_FALSE;
   bool_t EnableWD = NAI_FALSE, EnableEB = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Enable/Disable Watch Dog Timer on channel. */
   naiif_printf("\r\nType the desired Watch Dog Configuration");
   naiif_printf("('D'=Disable WD Timer, 'E'=Enable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'D':
               bUpdateWD = NAI_TRUE;
               EnableWD = NAI_FALSE;
            break;
            case 'E':
               bUpdateWD = NAI_TRUE;
               EnableWD = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid input mode entry\r\n");
            break;
         }
      }
   }

   /* Enable/Disable Error Break on channel. */
   naiif_printf("\r\nType the desired Error Break Configuration");
   naiif_printf("('D'=Disable Break on Error, 'E'=Enable, 'X'=Skip): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'D':
               bUpdateEB = NAI_TRUE;
               EnableEB = NAI_FALSE;
            break;
            case 'E':
               bUpdateEB = NAI_TRUE;
               EnableEB = NAI_TRUE;
            break;
            case 'X':
            break;
            default:
               naiif_printf("ERROR: Invalid input mode entry\r\n");
            break;
         }
      }
   }

   if (!bQuit)
   {
      if (bUpdateWD)
      {
         check_status(naibrd_ENC_SetSSI_WatchDogEnable(cardIndex, module, chan, EnableWD));
      }
      if (bUpdateEB)
      {
         check_status(naibrd_ENC_SetSSI_ErrorBreakEnable(cardIndex, module, chan, EnableEB));
      }
   }
   return NAI_SUCCESS;
}

static nai_status_t SSIMenu_SetDataType(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdatedataType = NAI_FALSE;
   naibrd_enc_ssi_data_type_t dataType = NAIBRD_ENC_SSI_DATA_BINARY;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Set the SSI data type on channel. */
   naiif_printf("\r\nEnter the SSI data type:");
   naiif_printf("('B'=Binary, 'G'=Grey code): ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'B':
               dataType = NAIBRD_ENC_SSI_DATA_BINARY;
               bUpdatedataType = NAI_TRUE;
            break;
            case 'G':
               dataType = NAIBRD_ENC_SSI_DATA_GRAY;
               bUpdatedataType = NAI_TRUE;
            break;
            default:
               naiif_printf("ERROR: Invalid SSI data type entry\r\n");
            break;
         }
      }
   }

   if (!bQuit)
   {
      if (bUpdatedataType)
      {
         check_status(naibrd_ENC_SetSSI_DataType(cardIndex, module, chan, dataType));
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

static nai_status_t Display_ENC_SSIStatus(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   nai_status_bit_t SSIstatus;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Available status:
         NAIBRD_ENC_SSI_STATUS_NEWDATA
         NAIBRD_ENC_SSI_STATUS_OVERFLOW
         NAIBRD_ENC_SSI_STATUS_PARITY_ERROR
         NAIBRD_ENC_SSI_STATUS_BUSY
         NAIBRD_ENC_SSI_STATUS_WATCHDOG_ERROR
         NAIBRD_ENC_SSI_STATUS_EXTRA
         NAIBRD_ENC_GEN5_STATUS_SSI_ZB_ERR
   */
   naiif_printf("\r\n");

   naiif_printf(" ------------------------------------ Status ---------------------------------\r\n");
   naiif_printf("   NewData   Overflow    ZeroBit      Busy   ParityErr  WatchDogErr   Extra   \r\n");
   naiif_printf(" ---------- ---------- ---------- ---------- ---------- ----------- ----------\r\n");

   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_DATA_REALTIME, &SSIstatus));
   naiif_printf("   %3i    ", SSIstatus);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_OVFLW_REALTIME, &SSIstatus));
   naiif_printf("    %3i    ", SSIstatus);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_ZB_ERR_REALTIME, &SSIstatus));
   naiif_printf("    %3i    ", SSIstatus);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_BUSY_REALTIME, &SSIstatus));
   naiif_printf("    %3i    ", SSIstatus);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_PAR_ERR_REALTIME, &SSIstatus));
   naiif_printf("    %3i    ", SSIstatus);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_WD_ERR_REALTIME, &SSIstatus));
   naiif_printf("     %3i    ", SSIstatus);
   check_status(naibrd_ENC_GetEventMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_SSI_EX_CLK_ERR_REALTIME, &SSIstatus));
   naiif_printf("     %3i    ", SSIstatus);
   naiif_printf("\r\n\r\n");

   return NAI_ERROR_UNKNOWN;
}

static nai_status_t Display_ENC_ChanStatus(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_enc_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_enc_params->cardIndex;
   int32_t module = p_enc_params->module;
   int32_t chan = p_enc_params->channel;
   bool_t bQuit = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   nai_status_bit_t chanStatusLatched = NAI_STATUS_BIT_LO;
   nai_status_bit_t chanStatusReal = NAI_STATUS_BIT_LO;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   check_status(naibrd_ENC_GetChannelMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_BIT_REALTIME, &chanStatusReal));
   check_status(naibrd_ENC_GetChannelMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_BIT_LATCHED, &chanStatusLatched));

   naiif_printf("\r\n");
   naiif_printf("----------------- Channel %d Statuses -----------------\r\n", chan);
   naiif_printf("Status                   (Realtime/Latched)    \r\n\r\n");
   naiif_printf("BIT (Open/Short)         (    %d   /   %d   )\r\n", chanStatusReal, chanStatusLatched);

   naiif_printf("\r\n\r\n");
   naiif_printf("Do you wish to clear all latched statuses? (Y/N)");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
            case 'Y':
               check_status(naibrd_ENC_ClearChannelMappedStatus(cardIndex, module, chan, NAIBRD_ENC_STATUS_BIT_LATCHED));
            break;
            case 'N':
            break;
         default:
            naiif_printf("ERROR: Invalid input\r\n");
            break;
         }
      }
   }

   return NAI_ERROR_UNKNOWN;
}

static void Display_ENC_GeneralCfg(int32_t cardIndex, int32_t module, int32_t chan)
{
   bool_t intvlTimerEn = NAI_FALSE;
   bool_t MCRCh1_en = NAI_FALSE, MCRCh2_en = NAI_FALSE, MCRCh3_en = NAI_FALSE, MCRCh4_en = NAI_FALSE, intvlTimerAsTrigEn = NAI_FALSE;
   uint16_t intvlTimerPreload = 0u;
   nai_status_bit_t MCRStatus = (nai_status_bit_t)0u;
   naibrd_enc_intvl_clk_t intvlClk = 0;

   check_status(naibrd_ENC_GetIntervalTimerPreload(cardIndex, module, &intvlTimerPreload));
   check_status(naibrd_ENC_GetIntervalTimerClkDivide(cardIndex, module, &intvlClk));
   check_status(naibrd_ENC_GetIntervalTimerEnable(cardIndex, module, &intvlTimerEn));
   check_status(naibrd_ENC_GetMultiChanRdEnable(cardIndex, module, 1, &MCRCh1_en));
   check_status(naibrd_ENC_GetMultiChanRdEnable(cardIndex, module, 2, &MCRCh2_en));
   check_status(naibrd_ENC_GetMultiChanRdEnable(cardIndex, module, 3, &MCRCh3_en));
   check_status(naibrd_ENC_GetMultiChanRdEnable(cardIndex, module, 4, &MCRCh4_en));
   check_status(naibrd_ENC_GetIntvlTimerTrigEnable(cardIndex, module, &intvlTimerAsTrigEn));

   check_status(naibrd_ENC_GetMultiChanRdStatus(cardIndex, module, &MCRStatus));

   naiif_printf("\r\n === Configuration for all Channels ===\r\n\r\n");
   naiif_printf("Interval Timer Preload:             %u\r\n", intvlTimerPreload);
   naiif_printf("Interval Timer Enable:              %s\r\n", intvlTimerEn ? "Enabled" : "Disabled");
   naiif_printf("Interval Timer Clock Divide         ");
   switch (intvlClk)
   {
      case 0x0u:
         naiif_printf("25 Mhz\r\n");
      break;
      case 0x1u:
         naiif_printf("12.5 Mhz\r\n");
      break;
      case 0x2u:
         naiif_printf("6.25 Mhz\r\n");
      break;
      case 0x3u:
         naiif_printf("3.125 Mhz\r\n");
      break;
      default:
         naiif_printf("?? Mhz\r\n");
      break;
   }
   naiif_printf("MCR Enable Ch1:                     %s\r\n", MCRCh1_en ? "Enabled" : "Disabled");
   naiif_printf("MCR Enable Ch2:                     %s\r\n", MCRCh2_en ? "Enabled" : "Disabled");
   naiif_printf("MCR Enable Ch3:                     %s\r\n", MCRCh3_en ? "Enabled" : "Disabled");
   naiif_printf("MCR Enable Ch4:                     %s\r\n", MCRCh4_en ? "Enabled" : "Disabled");
   naiif_printf("Intvl Timer as trigger for MCR:     %s\r\n", intvlTimerAsTrigEn ? "Enabled" : "Disabled");
   naiif_printf("MCR Status:                         %u\r\n", MCRStatus);
}

static void Display_ENC_CommonCfg(int32_t cardIndex, int32_t module, int32_t chan)
{
   naibrd_enc_input_mode_t inputMode = 0;
   naibrd_enc_term_t term = 0;
   naibrd_enc_mode_t encMode = 0;
   float64_t debounceA = 0, debounceB = 0, debounceIndex = 0;
   bool_t debounceAEn = 0, debounceBEn = 0, debounceIndexEn = 0;

   check_status(naibrd_ENC_GetInputMode(cardIndex, module, chan, &inputMode));
   check_status(naibrd_ENC_GetInputTermination(cardIndex, module, chan, &term));

   check_status(naibrd_ENC_GetControlMode(cardIndex, module, chan, &encMode));
   check_status(naibrd_ENC_GetDebounceTime(cardIndex, module, chan, NAIBRD_ENC_PORT_A, &debounceA));
   check_status(naibrd_ENC_GetDebounceTime(cardIndex, module, chan, NAIBRD_ENC_PORT_B, &debounceB));
   check_status(naibrd_ENC_GetDebounceTime(cardIndex, module, chan, NAIBRD_ENC_PORT_Index, &debounceIndex));
   check_status(naibrd_ENC_GetDebounceEnable(cardIndex, module, chan, NAIBRD_ENC_PORT_A, &debounceAEn));
   check_status(naibrd_ENC_GetDebounceEnable(cardIndex, module, chan, NAIBRD_ENC_PORT_B , &debounceBEn));
   check_status(naibrd_ENC_GetDebounceEnable(cardIndex, module, chan, NAIBRD_ENC_PORT_Index , &debounceIndexEn));

   naiif_printf("\r\n === Channel %d Configuration ===\r\n\r\n", chan);
   naiif_printf("InputMode:                   ");
   switch (inputMode)
   {
      case 0x0u:
         naiif_printf("None\r\n");
      break;
      case 0x1u:
         naiif_printf("TTL\r\n");
      break;
      case 0x2u:
         naiif_printf("RS-422\r\n");
      break;
      case 0x10u:
         naiif_printf("Single Ended w/ Thresh\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("InputTermination Port:       ");
   switch (term)
   {
      case 0x0u:
         naiif_printf("None\r\n");
      break;
      case 0x1u:
         naiif_printf("Differential\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("Encoder Mode:                ");
   switch (encMode)
   {
      case 0x0u:
         naiif_printf("Disabled\r\n");
      break;
      case 0x1u:
         naiif_printf("SSI\r\n");
      break;
      case 0x2u:
         naiif_printf("Counter\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("Debounce Time PortA:         %.07f\r\n", debounceA);
   naiif_printf("Debounce Time PortB:         %.07f\r\n", debounceB);
   naiif_printf("Debounce Time PortIndx:      %.07f\r\n", debounceIndex);
   naiif_printf("Debounce Enable PortA:       %s\r\n", debounceAEn ? "Enabled" : "Disabled");
   naiif_printf("Debounce Enable PortB:       %s\r\n", debounceBEn ? "Enabled" : "Disabled");
   naiif_printf("Debounce Enable PortIndx:    %s\r\n", debounceIndexEn ? "Enabled" : "Disabled");
}

static void Display_ENC_CntrCfg(int32_t cardIndex, int32_t module, int32_t chan)
{
   uint32_t preLoad = 0;
   naibrd_enc_cntr_icm_t indexCtrl = 0;
   naibrd_enc_cntr_scm_t spclCtrl = 0;
   naibrd_enc_cntr_cim_t input = 0;
   naibrd_enc_cntr_clk_div_t clkDiv = 0;
   naibrd_enc_cntr_polarity_t polarityA = 0, polarityB = 0, polarityIndex = 0;
   bool_t enableCompare = 0;
   uint32_t coarseCount = 0;
   uint32_t fineCount = 0;
   uint32_t compareCount = 0;
   uint32_t speed = 0;
   naibrd_enc_cntr_direction_type_t direction = NAIBRD_ENC_CNTR_DIRECTION_DOWN;

   check_status(naibrd_ENC_GetCNTR_PreLoad(cardIndex, module, chan, &preLoad));
   check_status(naibrd_ENC_GetCNTR_IndexControl(cardIndex, module, chan,  &indexCtrl));
   check_status(naibrd_ENC_GetCNTR_SpecialControl(cardIndex, module, chan,  &spclCtrl));
   check_status(naibrd_ENC_GetCNTR_InputMode(cardIndex, module, chan,  &input));
   check_status(naibrd_ENC_GetCNTR_ClkDivide(cardIndex, module, chan, &clkDiv));
   check_status(naibrd_ENC_GetCNTR_Polarity(cardIndex, module, chan, NAIBRD_ENC_PORT_A, &polarityA));
   check_status(naibrd_ENC_GetCNTR_Polarity(cardIndex, module, chan, NAIBRD_ENC_PORT_B, &polarityB));
   check_status(naibrd_ENC_GetCNTR_Polarity(cardIndex, module, chan, NAIBRD_ENC_PORT_Index, &polarityIndex));
   check_status(naibrd_ENC_GetCNTR_CompareEnable(cardIndex, module, chan, &enableCompare));
   check_status(naibrd_ENC_GetCNTR_CompareCount(cardIndex, module, chan, &compareCount));
   check_status(naibrd_ENC_GetCNTR_Speed(cardIndex, module, chan, &direction, &speed));

   check_status(naibrd_ENC_GetCNTR_Count(cardIndex, module, chan, NAIBRD_ENC_COUNT_COARSE_REALTIME, &coarseCount));
   check_status(naibrd_ENC_GetCNTR_Count(cardIndex, module, chan, NAIBRD_ENC_COUNT_FINE_REALTIME, &fineCount));

   naiif_printf("\r\n === Channel %d Configuration ===\r\n\r\n", chan);
   naiif_printf("Counter Preload:                    %u\r\n", preLoad);
   naiif_printf("Counter Index Control:              ");
   switch (indexCtrl)
   {
      case 0x0u:
         naiif_printf("Ignore on I\r\n");
      break;
      case 0x1u:
         naiif_printf("Load on I\r\n");
      break;
      case 0x2u:
         naiif_printf("Latch on I\r\n");
      break;
      case 0x3u:
         naiif_printf("Gate on I\r\n");
      break;
      case 0x4u:
         naiif_printf("Reset on I\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("Counter Special Control:            ");
   switch (spclCtrl)
   {
      case 0x0u:
         naiif_printf("Normal\r\n");
      break;
      case 0x1u:
         naiif_printf("Divide N\r\n");
      break;
      case 0x2u:
         naiif_printf("Single Cycle\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("Counter Input Control:              ");
   switch (input)
   {
      case 0x0u:
         naiif_printf("None\r\n");
      break;
      case 0x1u:
         naiif_printf("Timer Up\r\n");
      break;
      case 0x2u:
         naiif_printf("Timer Down\r\n");
      break;
      case 0x3u:
         naiif_printf("Direction Count\r\n");
      break;
      case 0x4u:
         naiif_printf("Up-Down Count\r\n");
      break;
      case 0x5u:
         naiif_printf("Quad 1x\r\n");
      break;
      case 0x6u:
         naiif_printf("Quad 2x\r\n");
      break;
      case 0x7u:
         naiif_printf("Quad 4x\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("Counter Clock Divide:               ");
   switch (clkDiv)
   {
      case 0x0u:
         naiif_printf("62.5 Mhz\r\n");
      break;
      case 0x1u:
         naiif_printf("31.25 Mhz\r\n");
      break;
      case 0x2u:
         naiif_printf("12.5 Mhz\r\n");
      break;
      case 0x3u:
         naiif_printf("6.25 Mhz\r\n");
      break;
      default:
         naiif_printf("??\r\n");
      break;
   }
   naiif_printf("Counter Polarity PortA:             %s\r\n", polarityA ? "Set" : "Unset");
   naiif_printf("Counter Polarity PortB:             %s\r\n", polarityB ? "Set" : "Unset");
   naiif_printf("Counter Polarity PortIndx:          %s\r\n", polarityIndex ? "Set" : "Unset");

   naiif_printf("Counter Compare Enable:             %s\r\n", enableCompare ? "Enabled" : "Disabled");
   naiif_printf("Counter Compare Value:              %u\r\n", compareCount);
   naiif_printf("Counter Coarse Realtime Value:      %u\r\n", coarseCount);
   naiif_printf("Counter Fine Realtime Value:        %u\r\n", fineCount);
   naiif_printf("Counter Speed(uS) and Direction:    %u, %s\r\n", speed, (direction == NAIBRD_ENC_CNTR_DIRECTION_DOWN) ? "DOWN" : "UP");
   naiif_printf("\r\n\r\n");

}

static void Display_ENC_SSICfg(int32_t cardIndex, int32_t module, int32_t chan)
{
   naibrd_enc_ssi_mode_t ssiMode = 0;
   naibrd_enc_ssi_parity_t parity = 0;
   bool_t parityEn = 0;
   bool_t zeroBitEn = 0, ErrBreakEn = 0, WDEn = 0;
   uint32_t clockRate = 0, dwellCount = 0;
   uint32_t dataBits = 0;
   uint32_t ssiData = 0u;
   naibrd_enc_ssi_data_type_t dataType = 0;
   nai_status_bit_t rcvdPar = 0, rcvdZB = 0;

   check_status(naibrd_ENC_GetSSI_Mode(cardIndex, module, chan, &ssiMode));
   check_status(naibrd_ENC_GetSSI_ClockRate_uS(cardIndex, module, chan, &clockRate));
   check_status(naibrd_ENC_GetSSI_NumDataBits(cardIndex, module, chan, &dataBits));
   check_status(naibrd_ENC_GetSSI_Parity(cardIndex, module, chan, &parity));
   check_status(naibrd_ENC_GetSSI_ParityEnable(cardIndex, module, chan, &parityEn));
   check_status(naibrd_ENC_GetSSI_ErrorBreakEnable(cardIndex, module, chan, &ErrBreakEn));
   check_status(naibrd_ENC_GetSSI_WatchDogEnable(cardIndex, module, chan, &WDEn));
   check_status(naibrd_ENC_GetSSI_DwellCount_ClkCycles(cardIndex, module, chan, &dwellCount));
   check_status(naibrd_ENC_GetSSI_ZeroBitEnable(cardIndex, module, chan, &zeroBitEn));
   check_status(naibrd_ENC_GetSSI_DataType(cardIndex, module, chan, &dataType));

   naiif_printf("\r\n === Channel %d Configuration ===\r\n\r\n", chan);

   naiif_printf("SSI Mode:                    %s\r\n", ssiMode ? "Listener" : "Interface Controller");
   naiif_printf("ClockPeriod(uS):             %i\r\n", clockRate);
   naiif_printf("DataBits:                    %i\r\n", dataBits);
   naiif_printf("Parity:                      %s\r\n", parity ? "Odd" : "Even");
   naiif_printf("Parity Check:                %s\r\n", parityEn ? "Enabled" : "Disabled");
   naiif_printf("Error Break:                 %s\r\n", ErrBreakEn ? "Enabled" : "Disabled");
   naiif_printf("Watch Dog:                   %s\r\n", WDEn ? "Enabled" : "Disabled");
   naiif_printf("Dwell Count:                 %i\r\n", dwellCount);
   naiif_printf("ZeroBit:                     %s\r\n", zeroBitEn ? "Enabled" : "Disabled");
   naiif_printf("Data Type:                   %s\r\n", dataType ? "Gray Code" : "Binary");

   check_status(naibrd_ENC_GetSSI_Data(cardIndex, module, chan, &ssiData));
   check_status(naibrd_ENC_GetSSI_RcvdParity(cardIndex, module, chan, &rcvdPar));
   check_status(naibrd_ENC_GetSSI_RcvdZeroBit(cardIndex, module, chan, &rcvdZB));

   naiif_printf("\r\n");
   naiif_printf("-----------------Data------------------\r\n");
   naiif_printf("    SSI Rcvd Data:       0x%08x \r\n", ssiData);
   naiif_printf("    Rcvd Parity:         %i \r\n", rcvdPar);
   naiif_printf("    Rcvd ZeroBit:        %i \r\n", rcvdZB);
   naiif_printf("---------------------------------------\r\n");
}

Help Bot

X