DIF BasicOps
Edit this on GitLab
DIF BasicOps Sample Application (SSK 2.x)
Overview
The DIF BasicOps sample application demonstrates how to configure and control differential discrete I/O channels using the NAI Software Support Kit (SSK 2.x). It covers the core DIF operations you will need in your own application: setting I/O format (input or output), controlling output state, configuring slew rate and input termination, setting debounce time, reading channel status, and clearing latched status registers.
This sample supports the following DIF module types: DF1, DF2, and DF3. It also handles the legacy D8 module with appropriate Gen3-specific I/O format constants. It serves as a practical API reference — each menu command maps directly to one or more naibrd_DIF_*() API calls that you can lift into your own code.
For the SSK 1.x version, see DIF BasicOps (SSK 1.x). For detailed module specifications, refer to the DF1 Manual.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a DIF module installed (DF1, DF2, or DF3).
-
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 dif_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_DIF_BasicOps.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. Once connected, the application prompts for a channel number and presents a command menu for configuring DIF operations.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to DIF. |
The main() function follows a standard SSK 2.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_DIF_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. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleName()so downstream code can adapt to the specific DIF variant installed.
#if defined (__VXWORKS__)
int32_t DIF_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DIF_CARD_INDEX, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DIF_MODULE, &module);
if (stop != NAI_TRUE)
{
naibrd_GetModuleName(cardIndex, module, &moduleID);
if ((moduleID != 0))
{
Run_DIF_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;
}
Note the SSK 2.x differences from SSK 1.x in this startup sequence:
-
The VxWorks preprocessor guard uses
__VXWORKS__in this particular sample (most SSK 2.x samples useNAIBSP_CONFIG_SOFTWARE_OS_VXWORKS). -
The module identifier is retrieved with
naibrd_GetModuleName()(SSK 1.x usesnaibrd_GetModuleID()). -
Boolean constants are
NAI_TRUE/NAI_FALSE(SSK 1.x usesTRUE/FALSE). -
Console output uses
naiif_printf()from the platform abstraction layer (SSK 1.x usesprintf()directly).
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On standard platforms (Petalinux, Windows) the entry point is main(). On VxWorks the entry point is DIF_BasicOps():
#if defined (__VXWORKS__)
int32_t DIF_BasicOps(void)
#else
int32_t main(void)
#endif
Command Loop
After connecting to the board and selecting a module, the application calls Run_DIF_BasicOps(), which validates the module and delegates to Cfg_DIF_Channel(). The command loop prompts for a channel number, then displays the current channel configuration and presents the command menu. The user selects a command by typing its short name, and the corresponding handler function is called through a dispatch table.
The command table defines the following operations:
| Command | Description |
|---|---|
|
Set I/O format (Input or Output). |
|
Set output state (High or Low). |
|
Set slew rate (Slow or Fast). |
|
Set input termination (Enabled or Disabled). |
|
Set debounce time in milliseconds. |
|
Display status registers (BIT, overcurrent, transitions). |
|
Reset overcurrent condition for all channels. |
|
Clear all latched status registers. |
Displaying Channel Configuration
Before each command prompt, the application displays the current configuration for the selected channel. The Display_DIF_ChannelCfg() function reads and formats the channel settings:
static void Display_DIF_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
uint32_t ioformat = 0;
naibrd_dif_state_t outputstate = 0;
naibrd_dif_state_t inputstate = 0;
naibrd_dif_slewRate_t slewRate = 0;
naibrd_dif_input_term_t termination = 0;
float64_t debounceTime = 0.0;
check_status(naibrd_DIF_GetIOFormat(cardIndex, module, chan, &ioformat));
check_status(naibrd_DIF_GetOutputState(cardIndex, module, chan, &outputstate));
check_status(naibrd_DIF_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_DIF_GetSlewRate(cardIndex, module, chan, &slewRate));
check_status(naibrd_DIF_GetInputTermination(cardIndex, module, chan, &termination));
check_status(naibrd_DIF_GetDebounceTime(cardIndex, module, chan, &debounceTime));
/* ... display formatted values ... */
}
Key API calls:
-
naibrd_DIF_GetChannelCount(moduleID)— Returns the number of channels for the DIF module. -
naibrd_DIF_GetIOFormat()— Reads the I/O format (input or output). -
naibrd_DIF_GetOutputState()/naibrd_DIF_GetInputState()— Reads the output or input logic state. -
naibrd_DIF_GetSlewRate()— Reads the slew rate setting (slow or fast). -
naibrd_DIF_GetInputTermination()— Reads the termination state. -
naibrd_DIF_GetDebounceTime()— Reads the debounce time in milliseconds.
|
Note
|
The application handles D8 (Gen3) modules differently from Gen5 modules when interpreting the I/O format value. Gen3 modules use NAIBRD_DIF_GEN3_IOFORMAT_OUTPUT while Gen5 modules use NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT.
|
Configuring I/O Format
The Configure_DIF_IOFormat() function sets the I/O direction for the selected channel:
static nai_status_t Configure_DIF_IOFormat(int32_t paramCount, int32_t* p_params)
{
/* User enters: I=Input, O=Output */
if (iofmtreq == 'O')
{
if (p_dif_params->modId == NAIBRD_MODULE_ID_D8)
state = NAIBRD_DIF_GEN3_IOFORMAT_OUTPUT;
else
state = NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT;
}
check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan, state));
}
-
naibrd_DIF_SetIOFormat(cardIndex, module, channel, format)— Sets the I/O format. The output constant differs by generation: useNAIBRD_DIF_GEN3_IOFORMAT_OUTPUTfor D8 modules andNAIBRD_DIF_GEN5_IOFORMAT_OUTPUTfor DF1/DF2/DF3 modules.
Configuring Output State and Slew Rate
The Configure_DIF_OutputState() and Configure_DIF_SlewRate() functions control output behavior:
-
naibrd_DIF_SetOutputState(cardIndex, module, channel, state)— Sets the output state. UseNAIBRD_DIF_STATE_LOfor low andNAIBRD_DIF_STATE_HIfor high. This only applies when the channel is configured as an output. -
naibrd_DIF_SetSlewRate(cardIndex, module, channel, rate)— Sets the slew rate. UseNAIBRD_DIF_SLEWRATE_SLOWorNAIBRD_DIF_SLEWRATE_FAST.
Configuring Input Termination and Debounce
-
naibrd_DIF_SetInputTermination(cardIndex, module, channel, state)— Enables or disables input termination. UseNAIBRD_DIF_INPUT_TERMINATEDorNAIBRD_DIF_INPUT_NOT_TERMINATED. -
naibrd_DIF_SetDebounceTime(cardIndex, module, channel, timeMs)— Sets the debounce time in milliseconds as afloat64_tvalue.
Reading and Clearing Status
The Display_DIF_Status() function reads multiple status registers for the selected channel:
static nai_status_t Display_DIF_Status(int32_t paramCount, int32_t* p_params)
{
/* Read latched and real-time status for BIT, overcurrent, and transitions */
naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_BIT_LATCHED, &statusread);
naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED, &statusread);
naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_LO_HI_TRANS_LATCHED, &statusread);
naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_HI_LO_TRANS_LATCHED, &statusread);
/* Real-time variants (Gen5 only): _REALTIME suffix */
}
The Clear_DIF_Status() function clears all latched status registers:
-
naibrd_DIF_ClearChanMappedStatus(cardIndex, module, channel, statusType)— Clears a specific latched status register.
The overcurrent reset is handled inline in the command dispatch:
-
naibrd_DIF_ResetAll(cardIndex, module, NAIBRD_DIF_RESET_OVERCURRENT)— Resets overcurrent for all channels. -
naibrd_DIF_Reset(cardIndex, module, channel, NAIBRD_DIF_RESET_OVERCURRENT)— Resets overcurrent for a single channel (Gen5 only).
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
Module selection not recognized as DIF module |
The selected slot does not contain a DIF module, or the module ID is not recognized. |
Verify that a DF1, DF2, or DF3 module is installed in the selected slot. |
No board found |
Board not powered, cable disconnected, or wrong interface selected. |
Verify power, cables, and that the correct interface type is chosen in the board menu. |
Connection timeout |
Incorrect IP address, firewall blocking communication, or network misconfiguration. |
Confirm the board IP address. Disable or configure firewall rules. |
Output state has no effect |
The channel is configured as input, not output. |
Set the I/O format to output first using the |
Real-time status returns NAI_ERROR_NOT_SUPPORTED |
The module is Gen3 (D8) which does not support real-time status reads. |
This is expected behavior for Gen3 modules. Only latched status is available. |
Overcurrent status stuck |
The overcurrent condition has not been reset, or the fault condition persists. |
Use the |
Debounce time not taking effect |
The entered value may be outside the supported range for the module. |
Consult the DF1 Manual for valid debounce time ranges. |
I/O format uses wrong constant for output |
Using Gen3 constant on Gen5 module or vice versa. |
The application handles this automatically based on module ID. If writing custom code, check for |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — dif_basic_ops.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"
/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_dif.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_DIF_BasicOps.txt";
/* Function prototypes */
int32_t Run_DIF_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID);
static void Cfg_DIF_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_DIF_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Display_DIF_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Clear_DIF_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_IOFormat(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_OutputState(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_SlewRate(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_Termination(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_DebounceTime(int32_t paramCount, int32_t* p_params);
static const int32_t DEF_DIF_CARD_INDEX = 0;
static const int32_t DEF_DIF_MODULE = 1;
static const int32_t DEF_DIF_CHANNEL = 1;
/****** Command Table *******/
enum dt_basicops_commands
{
DIF_BASICOP_CMD_IOFORMAT,
DIF_BASICOP_CMD_OUTPUTSTATE,
DIF_BASICOP_CMD_SLEW_RATE,
DIF_BASICOP_CMD_TERMINATION,
DIF_BASICOP_CMD_DEBOUNCE,
DIF_BASICOP_CMD_STATUS,
DIF_BASICOP_CMD_ROC,
DIF_BASICOP_CMD_STATUS_CLEAR,
DIF_BASICOP_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DIF_BasicOpMenuCmds[] = {
{"Format", "DIF Set IO Format", DIF_BASICOP_CMD_IOFORMAT, Configure_DIF_IOFormat},
{"Out", "DIF Set Output State", DIF_BASICOP_CMD_OUTPUTSTATE, Configure_DIF_OutputState},
{"Slew", "DIF Set Slew Rate", DIF_BASICOP_CMD_SLEW_RATE, Configure_DIF_SlewRate},
{"Term", "DIF Set Termination", DIF_BASICOP_CMD_TERMINATION, Configure_DIF_Termination},
{"Debounce", "DIF Set Debounce Time", DIF_BASICOP_CMD_DEBOUNCE, Configure_DIF_DebounceTime},
{"Stat", "DIF Display Status", DIF_BASICOP_CMD_STATUS, Display_DIF_Status},
{"Reset", "DIF Reset Overcurrent", DIF_BASICOP_CMD_ROC, NULL},
{"Clear", "DIF Clear Status", DIF_BASICOP_CMD_STATUS_CLEAR, Clear_DIF_Status},
};
#if defined (__VXWORKS__)
int32_t DIF_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DIF_CARD_INDEX, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DIF_MODULE, &module);
if (stop != NAI_TRUE)
{
naibrd_GetModuleName(cardIndex, module, &moduleID);
if ((moduleID != 0))
{
Run_DIF_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_DIF_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
int32_t MaxChannel;
MaxChannel = naibrd_DIF_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
naiif_printf(" *** Module selection not recognized as DIF module. ***\r\n\r\n");
}
else
{
Cfg_DIF_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
static void Cfg_DIF_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
bool_t bCmdFound = NAI_FALSE;
nai_status_t status = 0;
int32_t chan, defaultchan = 1;
int32_t cmd;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_AppParameters_t dif_params;
p_naiapp_AppParameters_t dif_basicops_params = &dif_params;
dif_basicops_params->cardIndex = cardIndex;
dif_basicops_params->module = module;
dif_basicops_params->modId = ModuleID;
while (bContinue)
{
naiif_printf(" \r\r\n\r\r\n");
naiif_printf("Channel selection \r\r\n");
naiif_printf("================= \r\r\n");
defaultchan = DEF_DIF_CHANNEL;
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
dif_basicops_params->channel = chan;
naiapp_utils_LoadParamMenuCommands(DIF_BASICOP_CMD_COUNT, DIF_BasicOpMenuCmds);
while (bContinue)
{
Display_DIF_ChannelCfg(cardIndex, module, chan, ModuleID);
naiapp_display_ParamMenuCommands((int8_t *)"DIF Basic Operation Menu");
naiif_printf("\r\nType DIF 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 DIF_BASICOP_CMD_IOFORMAT:
case DIF_BASICOP_CMD_OUTPUTSTATE:
case DIF_BASICOP_CMD_SLEW_RATE:
case DIF_BASICOP_CMD_TERMINATION:
case DIF_BASICOP_CMD_DEBOUNCE:
case DIF_BASICOP_CMD_STATUS:
case DIF_BASICOP_CMD_STATUS_CLEAR:
DIF_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dif_basicops_params);
break;
case DIF_BASICOP_CMD_ROC:
status = NAI_SUCCESS;
status |= check_status(naibrd_DIF_ResetAll(cardIndex, module, NAIBRD_DIF_RESET_OVERCURRENT)); /*This resets all channels*/
status |= check_status(naibrd_DIF_Reset(cardIndex, module, chan, NAIBRD_DIF_RESET_OVERCURRENT)); /*This alternate function resets channel 1 only on Gen5 modules. */
if (status == NAI_SUCCESS)
naiif_printf("Overcurrent condition reset completed \r\n");
break;
default:
naiif_printf("Invalid command entered\r\n");
break;
}
}
else
naiif_printf("Invalid command entered\r\n");
}
}
else
bContinue = NAI_FALSE;
}
}
}
static void Display_DIF_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
uint32_t ioformat = 0;
naibrd_dif_state_t outputstate = 0;
naibrd_dif_state_t inputstate = 0;
naibrd_dif_slewRate_t slewRate = 0;
naibrd_dif_input_term_t termination = 0;
float64_t debounceTime = 0.0;
check_status(naibrd_DIF_GetIOFormat(cardIndex, module, chan, &ioformat));
check_status(naibrd_DIF_GetOutputState(cardIndex, module, chan, &outputstate));
check_status(naibrd_DIF_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_DIF_GetSlewRate(cardIndex, module, chan, &slewRate));
check_status(naibrd_DIF_GetInputTermination(cardIndex, module, chan, &termination));
check_status(naibrd_DIF_GetDebounceTime(cardIndex, module, chan, &debounceTime));
naiif_printf("\r\n === Channel %d ===\r\n\r\n", chan);
naiif_printf(" IOFormat Output Input Slew-Rate Termination Debounce(ms) \r\n");
naiif_printf(" --------- ------ ----- --------- ----------- ------------ \r\n");
if (ModuleID == NAIBRD_MODULE_ID_D8)
{
switch (ioformat)
{
case NAIBRD_DIF_IOFORMAT_INPUT:
naiif_printf(" Input ");
break;
case NAIBRD_DIF_GEN3_IOFORMAT_OUTPUT:
naiif_printf(" Output ");
break;
default:
naiif_printf(" Unknown ");
break;
}
}
else
{
switch (ioformat)
{
case NAIBRD_DIF_IOFORMAT_INPUT:
naiif_printf(" Input ");
break;
case NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT:
naiif_printf(" Output ");
break;
default:
naiif_printf(" Unknown ");
break;
}
}
if (ioformat != NAIBRD_DIF_IOFORMAT_INPUT)
{
switch (outputstate)
{
case NAIBRD_DIF_STATE_LO:
naiif_printf(" Low ");
break;
case NAIBRD_DIF_STATE_HI:
naiif_printf(" High");
break;
default:
naiif_printf(" UNK ");
break;
}
}
else
naiif_printf(" --- ");
naiif_printf(" %3i ", inputstate);
switch (slewRate)
{
case NAIBRD_DIF_SLEWRATE_SLOW:
naiif_printf(" Slow ");
break;
case NAIBRD_DIF_SLEWRATE_FAST:
naiif_printf(" Fast ");
break;
default:
naiif_printf(" Unknown ");
break;
}
switch (termination)
{
case NAIBRD_DIF_INPUT_NOT_TERMINATED:
naiif_printf(" Unset ");
break;
case NAIBRD_DIF_INPUT_TERMINATED:
naiif_printf(" Set ");
break;
default:
naiif_printf(" Unknown ");
break;
}
naiif_printf(" %3f ", debounceTime);
}
static nai_status_t Display_DIF_Status(int32_t paramCount, int32_t* p_params)
{
nai_status_bit_t statusread;
nai_status_t status = NAI_SUCCESS;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("\r\n");
naiif_printf(" ------------------------- Status ----------------------------\r\n");
naiif_printf(" | BIT | OC | Lo-Hi Trans | Hi-Lo Trans |\r\n");
naiif_printf(" Latch RT Latch RT Latch RT Latch RT \r\n");
naiif_printf(" -------------- --------------- -------------- ---------------\r\n");
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_BIT_LATCHED, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_BIT_REALTIME, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
naiif_printf(" N/A ");
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_OVERCURRENT_REALTIME, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
naiif_printf(" N/A ");
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_LO_HI_TRANS_LATCHED, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_LO_HI_TRANS_REALTIME, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
naiif_printf(" N/A ");
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_HI_LO_TRANS_LATCHED, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else
naiif_printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_HI_LO_TRANS_REALTIME, &statusread));
if (status == NAI_SUCCESS)
naiif_printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
naiif_printf(" N/A ");
else
naiif_printf(" Err %3i", status);
naiif_printf("\r\n\r\n");
return NAI_ERROR_UNKNOWN;
}
static nai_status_t Clear_DIF_Status(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
status = check_status(naibrd_DIF_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_BIT_LATCHED));
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED));
}
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_LO_HI_TRANS_LATCHED));
}
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_HI_LO_TRANS_LATCHED));
}
if (status == NAI_SUCCESS)
naiif_printf("Latched Status cleared \r\n\r\n");
return status;
}
static nai_status_t Configure_DIF_IOFormat(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateIOCfg = NAI_FALSE;
uint32_t state = 0;
int8_t iofmtreq;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("Type the desired IO configuration ");
naiif_printf("(I=Input, Out=Output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
iofmtreq = (int8_t)toupper(inputBuffer[0]);
if (iofmtreq == 'I')
{
state = NAIBRD_DIF_IOFORMAT_INPUT;
bUpdateIOCfg = NAI_TRUE;
}
else if (iofmtreq == 'O')
{
if (p_dif_params->modId == NAIBRD_MODULE_ID_D8)
state = NAIBRD_DIF_GEN3_IOFORMAT_OUTPUT;
else
state = NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT;
bUpdateIOCfg = NAI_TRUE;
}
else
{
naiif_printf("ERROR: Invalid selection\r\n");
}
}
if (!bQuit)
{
if (bUpdateIOCfg)
check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan, state));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Configure_DIF_OutputState(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateOutput = NAI_FALSE;
naibrd_dif_state_t outputstate = 0;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("\r\nEnter the desired output state ");
naiif_printf("(L=low output, H=high output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'L':
outputstate = 0;
bUpdateOutput = NAI_TRUE;
break;
case 'H':
outputstate= 1;
bUpdateOutput = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid Output State Format Entry\r\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateOutput)
check_status(naibrd_DIF_SetOutputState(cardIndex, module, chan, outputstate));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Configure_DIF_SlewRate(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateSRCfg = NAI_FALSE;
naibrd_dif_slewRate_t state = 0;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("Type the desired Slew Rate configuration ");
naiif_printf("(S=Slow, F=Fast): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'S':
state = NAIBRD_DIF_SLEWRATE_SLOW;
bUpdateSRCfg = NAI_TRUE;
break;
case 'F':
state = NAIBRD_DIF_SLEWRATE_FAST;
bUpdateSRCfg = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid Slew Rate selection\r\n");
break;
}
}
if (!bQuit)
{
if (bUpdateSRCfg)
check_status(naibrd_DIF_SetSlewRate(cardIndex, module, chan, state));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Configure_DIF_Termination(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateTerm = NAI_FALSE;
naibrd_dif_input_term_t termState = 0;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("\r\nEnter the desired termination state ");
naiif_printf("(E=Enable Termination, D=Disable Termination): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'E':
termState = NAIBRD_DIF_INPUT_TERMINATED;
bUpdateTerm = NAI_TRUE;
break;
case 'D':
termState = NAIBRD_DIF_INPUT_NOT_TERMINATED;
bUpdateTerm = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid Termination Entry\r\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateTerm)
check_status(naibrd_DIF_SetInputTermination(cardIndex, module, chan, termState));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Configure_DIF_DebounceTime(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bUpdateDbTime = NAI_FALSE;
float64_t time = 0;
p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dif_params->cardIndex;
int32_t module = p_dif_params->module;
int32_t chan = p_dif_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
naiif_printf("Type the desired debounce time in ms: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (strlen((const char*)inputBuffer) > 0)
{
time = atof((const char*)inputBuffer);
bUpdateDbTime = NAI_TRUE;
}
else
{
naiif_printf("ERROR: Invalid Debounce Time\r\n");
}
}
if (!bQuit)
{
if (bUpdateDbTime)
check_status(naibrd_DIF_SetDebounceTime(cardIndex, module, chan, time));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}