DIF BasicOps
Edit this on GitLab
DIF BasicOps Sample Application (SSK 1.x)
Overview
The DIF BasicOps sample application demonstrates how to configure and operate differential (DIF) I/O channels using the NAI Software Support Kit (SSK 1.x). It covers the core DIF operations you will need in your own application: setting I/O format (input or output mode), driving output states, configuring slew rate and input termination, setting debounce time, reading input levels, and monitoring channel status including BIT, overcurrent, and transition detection.
DIF modules provide isolated differential I/O channels. Unlike single-ended discrete I/O (which measures voltage on a single wire relative to a common ground), differential I/O uses balanced signal pairs. Each channel has two conductors that carry equal and opposite signals. The receiver measures the voltage difference between the two conductors rather than the voltage on either conductor individually. This balanced signaling provides strong common-mode noise rejection — electrical interference that couples equally into both conductors cancels out when the receiver takes the difference. The result is reliable digital I/O even in electrically noisy environments such as aircraft, vehicles, and industrial installations where long cable runs pick up interference from motors, power supplies, and radio transmitters.
This sample supports the following DIF module types: D8, DF1, DF2, and DF3. It also works with the CMH combination module, which includes DIF channels in its second function block. 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.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a DIF module installed (D8, DF1, DF2, DF3, or CMH).
-
SSK 1.x installed on your development host.
-
The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.
How to Run
Launch the DIF_BasicOps 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. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, you select a channel and then a command menu lets you exercise each DIF operation.
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. For details on board connection configuration, see the First Time Setup Guide. |
The main() function follows a standard SSK 1.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_GetModuleID()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 = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
Run_DIF_BasicOps(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR,
inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR,
inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On standard platforms the entry point is main(). On VxWorks the entry point is DIF_BasicOps() — the SSK 1.x build system selects the correct variant via a preprocessor guard:
#if defined (__VXWORKS__)
int32_t DIF_BasicOps(void)
#else
int32_t main(void)
#endif
The startup flow is the same in both cases:
-
Attempt to load the saved configuration file via
naiapp_RunBoardMenu(CONFIG_FILE). If the file does not yet exist, the interactive board menu is presented instead. -
Enter a loop that queries for card index and module slot.
-
Call
Run_DIF_BasicOps()to validate the module and enter the interactive command loop. -
On exit, close all open board connections with
naiapp_access_CloseAllOpenCards().
Module Detection
Run_DIF_BasicOps() validates that the selected module is a recognized DIF type by calling naibrd_DIF_GetChannelCount() with the module ID. If the function returns zero channels, the module is not a DIF module and the application prints an error. Otherwise, it proceeds to the channel configuration loop.
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)
{
printf(" *** Module selection not recognized as DIF module. ***\n\n");
}
else
{
Cfg_DIF_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
In your own application, call naibrd_DIF_GetChannelCount() after retrieving the module ID to confirm you have a DIF module and to determine the number of available channels.
Application Parameters
The Cfg_DIF_Channel() function populates an naiapp_AppParameters_t struct that is passed to every command handler. Your application will need to track these same values to identify which board, module, and channel you are targeting:
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;
dif_basicops_params->channel = chan;
-
cardIndex— identifies which board in a multi-board system. -
module— the slot number where the DIF module is installed. -
modId— the module identifier returned bynaibrd_GetModuleID(). API functions use this to apply module-specific behavior (for example, the D8 uses different I/O format constants than Gen5 modules). -
channel— the currently selected channel (defaults to 1).
Command Loop
Cfg_DIF_Channel() drives the interactive command loop. On each iteration it displays the current channel configuration, prints the command menu, and dispatches the user’s selection to the matching handler function:
The available commands are registered in the DIF_BasicOpMenuCmds[] table:
| Command | Description |
|---|---|
Format |
Set I/O format (input or output mode) |
Out |
Set output state (high or low) |
Slew |
Set slew rate (slow or fast) |
Term |
Set input termination (enabled or disabled) |
Debounce |
Set debounce time |
Stat |
Display channel status (BIT, overcurrent, transitions) |
Reset |
Reset overcurrent condition |
Clear |
Clear latched status registers |
The menu-driven structure is a convenience of the sample application. In your own application, you would call the same underlying naibrd_DIF_*() API functions directly — for example, calling naibrd_DIF_SetIOFormat() instead of navigating to the "Format" menu command.
I/O Configuration
This section covers the API calls used to configure DIF channel behavior: setting the I/O direction (input or output), driving output states, configuring slew rate, enabling input termination, and setting debounce time. These are the fundamental operations for controlling differential I/O channels.
Understanding Differential I/O
Each DIF channel operates on a balanced pair of conductors. When configured as an output, the module drives complementary voltage levels on the two conductors — one goes high while the other goes low, creating a differential voltage across the pair. When configured as an input, the module measures the voltage difference between the two conductors and compares it against internal thresholds to determine the logical state (high or low).
This differential signaling approach provides several hardware-level advantages:
-
Common-mode noise rejection — Electromagnetic interference that couples into the cable affects both conductors equally. Since the receiver measures only the difference, this common-mode noise cancels out.
-
Longer cable runs — The noise immunity of differential signaling allows reliable operation over longer distances than single-ended I/O.
-
Galvanic isolation — DIF modules provide electrical isolation between the I/O channels and the system, protecting both sides from ground loops and voltage transients.
The I/O format, slew rate, termination, and debounce settings let you tune each channel to match the characteristics of your specific wiring and signal environment. Consult your module’s manual for the electrical specifications of each setting.
Set I/O Format
To configure a channel as an input or output in your own application, call naibrd_DIF_SetIOFormat(). Each channel is independently configurable — you can have some channels reading inputs while others drive outputs on the same module.
The sample first retrieves the module ID via naibrd_GetModuleInfo() to determine which I/O format constants to use. The D8 (Gen3) module uses NAI_DIF_GEN3_IOFORMAT_OUTPUT for output mode, while Gen5 modules (DF1, DF2, DF3) use NAI_DIF_GEN5_IOFORMAT_OUTPUT. Input mode uses NAI_DIF_IOFORMAT_INPUT on all module types.
uint32_t ModuleID;
uint32_t ModuleVer, ModuleRev, ModInfo_Special;
uint32_t state;
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
/* Set channel to input mode */
state = NAI_DIF_IOFORMAT_INPUT;
naibrd_DIF_SetIOFormat(cardIndex, module, chan, state);
/* Set channel to output mode -- constant depends on module generation */
if (ModuleID == NAI_MODULE_ID_D8)
state = NAI_DIF_GEN3_IOFORMAT_OUTPUT;
else
state = NAI_DIF_GEN5_IOFORMAT_OUTPUT;
naibrd_DIF_SetIOFormat(cardIndex, module, chan, state);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the channel to configure. -
state— the I/O format:NAI_DIF_IOFORMAT_INPUT(0) for input,NAI_DIF_GEN3_IOFORMAT_OUTPUT(3) for Gen3 output, orNAI_DIF_GEN5_IOFORMAT_OUTPUT(1) for Gen5 output.
|
Note
|
Always check the module generation before setting output mode. Using the wrong output format constant will produce undefined behavior. The naibrd_GetModuleInfo() call returns the module ID, which you can compare against NAI_MODULE_ID_D8 to determine Gen3 versus Gen5.
|
Set Output State
To drive a channel high or low in your own application, call naibrd_DIF_SetOutputState(). This only takes effect on channels that have been configured as outputs via naibrd_DIF_SetIOFormat(). Calling it on a channel configured as an input has no effect on the physical output.
When you set a differential output high, the module drives a positive differential voltage across the balanced pair. When you set it low, the module drives a negative (or zero) differential voltage. The exact voltage levels depend on your module type — consult the module manual for specifications.
/* Drive the output high */
naibrd_DIF_SetOutputState(cardIndex, module, chan, NAI_DIF_STATE_HI);
/* Drive the output low */
naibrd_DIF_SetOutputState(cardIndex, module, chan, NAI_DIF_STATE_LO);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the channel to drive. -
The fourth parameter —
NAI_DIF_STATE_HI(1) for high output,NAI_DIF_STATE_LO(0) for low output.
Set Slew Rate
To control the output transition speed on a channel in your own application, call naibrd_DIF_SetSlewRate(). The slew rate determines how quickly the output voltage transitions between high and low states.
A slow slew rate reduces electromagnetic emissions and signal ringing at the expense of longer transition times. A fast slew rate provides sharper transitions, which is necessary for high-frequency switching but may cause signal integrity issues on long or poorly terminated cables. Choose the slew rate that matches your application’s speed requirements and EMI constraints.
/* Set slow slew rate for reduced EMI */
naibrd_DIF_SetSlewRate(cardIndex, module, chan, NAI_DIF_SLEWRATE_SLOW);
/* Set fast slew rate for high-speed switching */
naibrd_DIF_SetSlewRate(cardIndex, module, chan, NAI_DIF_SLEWRATE_FAST);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the channel to configure. -
The fourth parameter —
NAI_DIF_SLEWRATE_SLOW(0) orNAI_DIF_SLEWRATE_FAST(1).
|
Note
|
Slew rate applies to output channels. The setting is stored regardless of I/O format, so you can configure it before switching a channel to output mode. |
Set Input Termination
To enable or disable the internal termination resistor on a channel in your own application, call naibrd_DIF_SetInputTermination(). Input termination adds a resistor across the differential pair at the receiver end, which absorbs signal reflections and improves signal integrity on long cable runs.
Enable termination when your DIF channel is the last device on a cable run (the far end from the signal source). Disable termination when the channel is connected to a source that already has matched impedance, or when multiple receivers share a bus and only the last receiver should be terminated. Improper termination can cause signal reflections that lead to false transitions or unreliable readings.
/* Enable input termination */
naibrd_DIF_SetInputTermination(cardIndex, module, chan, NAI_DIF_INPUT_TERMINATED);
/* Disable input termination */
naibrd_DIF_SetInputTermination(cardIndex, module, chan, NAI_DIF_INPUT_NOT_TERMINATED);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the channel to configure. -
The fourth parameter —
NAI_DIF_INPUT_TERMINATED(1) to enable the termination resistor,NAI_DIF_INPUT_NOT_TERMINATED(0) to disable it.
|
Note
|
The termination resistor value is fixed in hardware and varies by module type. Consult your module’s manual for the termination impedance specification. |
Set Debounce Time
To configure the debounce time on a channel in your own application, call naibrd_DIF_SetDebounceTime(). Debounce filtering suppresses brief glitches on the input by requiring the signal to remain stable for the specified duration before the module registers a state change.
Set the debounce time long enough to reject noise and contact bounce from your signal source, but short enough that legitimate transitions are not delayed beyond your application’s timing requirements. A debounce time of zero disables the filter entirely, passing all transitions through immediately.
float64_t time = 1.0; /* debounce time in milliseconds */
naibrd_DIF_SetDebounceTime(cardIndex, module, chan, time);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the channel to configure. -
time— the debounce time in milliseconds. Consult your module’s manual for the supported range and resolution.
|
Note
|
On Gen3 modules (D8), debounce time is selected from a fixed set of discrete values. The API will round to the nearest supported value. Gen5 modules support finer resolution. Refer to your module’s manual for the exact set of available debounce settings. |
|
Important
|
Common Errors
|
Reading Channel Configuration and Input State
Each iteration of the command loop calls Display_DIF_ChannelCfg() to read and display the current channel configuration. This function demonstrates how to retrieve all the basic DIF channel parameters in your own application.
Reading Channel State
To read the current configuration and input state of a DIF channel, call the corresponding naibrd_DIF_Get*() functions. The sample reads I/O format, output state, input state, slew rate, termination, and debounce time in sequence:
uint32_t ioformat = 0;
nai_dif_state_t outputstate = 0;
nai_dif_state_t inputstate = 0;
nai_dif_slewRate_t slewRate = 0;
nai_dif_input_term_t termination = 0;
float64_t debounceTime = 0.0;
naibrd_DIF_GetIOFormat(cardIndex, module, chan, &ioformat);
naibrd_DIF_GetOutputState(cardIndex, module, chan, &outputstate);
naibrd_DIF_GetInputState(cardIndex, module, chan, &inputstate);
naibrd_DIF_GetSlewRate(cardIndex, module, chan, &slewRate);
naibrd_DIF_GetInputTermination(cardIndex, module, chan, &termination);
naibrd_DIF_GetDebounceTime(cardIndex, module, chan, &debounceTime);
-
naibrd_DIF_GetIOFormat()— returns the current I/O direction. Compare the result againstNAI_DIF_IOFORMAT_INPUT,NAI_DIF_GEN3_IOFORMAT_OUTPUT, orNAI_DIF_GEN5_IOFORMAT_OUTPUTdepending on module generation. -
naibrd_DIF_GetOutputState()— returns the current driven output level (NAI_DIF_STATE_HIorNAI_DIF_STATE_LO). This reflects the commanded state, not the physical line level. -
naibrd_DIF_GetInputState()— returns the current input level as read by the receiver. This is the logical state after debounce filtering and threshold comparison. A value of 1 indicates the differential voltage exceeds the high threshold; 0 indicates it is below the low threshold. -
naibrd_DIF_GetSlewRate()— returnsNAI_DIF_SLEWRATE_SLOWorNAI_DIF_SLEWRATE_FAST. -
naibrd_DIF_GetInputTermination()— returnsNAI_DIF_INPUT_TERMINATEDorNAI_DIF_INPUT_NOT_TERMINATED. -
naibrd_DIF_GetDebounceTime()— returns the configured debounce time in milliseconds.
The output state reading is only meaningful when the channel is configured as an output. When the channel is in input mode, the output state register may contain a stale value from a previous output configuration.
|
Important
|
Common Errors
|
Status and Diagnostics
This section covers the status monitoring and diagnostic features demonstrated by the sample: reading BIT status, overcurrent detection, transition detection, clearing latched status, and resetting overcurrent conditions. These capabilities let you detect hardware faults and monitor signal activity without polling input state in a tight loop.
Display Status
To read the status of a DIF channel in your own application, call naibrd_DIF_GetStatus() with the appropriate status type. The sample reads all available status types for the selected channel:
nai_status_bit_t statusread;
/* BIT status -- indicates built-in test pass/fail */
naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_BIT_LATCHED, &statusread);
/* Overcurrent status -- indicates excessive current draw */
naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_OVERCURRENT_LATCHED, &statusread);
/* Low-to-high transition -- input transitioned from low to high */
naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_LO_HI_TRANS_LATCHED, &statusread);
/* High-to-low transition -- input transitioned from high to low */
naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_HI_LO_TRANS_LATCHED, &statusread);
Each status type is available in both latched and real-time variants:
-
Latched — Once set, the status bit remains set until explicitly cleared. This ensures your application does not miss a transient event that occurred between status reads.
-
Real-time — Reflects the current instantaneous condition. The bit is set only while the condition is active and clears automatically when the condition resolves.
The available status types are:
| Status Type | Meaning |
|---|---|
|
Built-in test failure detected on the channel. A non-zero value indicates the channel’s self-test has detected a fault. This can indicate an open or shorted differential pair, or an internal circuit failure. |
|
Current BIT condition (Gen5 only). Reflects whether a BIT fault is active right now. |
|
Overcurrent condition detected. The channel drew more current than its rated limit, typically caused by a short circuit on the output or an overloaded external load. |
|
Current overcurrent condition (Gen5 only). Active only while the overcurrent condition persists. |
|
A low-to-high transition has occurred on the input since the last status clear. Useful for detecting rising edges without continuous polling. |
|
A low-to-high transition is currently in progress (Gen5 only). |
|
A high-to-low transition has occurred on the input since the last status clear. Useful for detecting falling edges. |
|
A high-to-low transition is currently in progress (Gen5 only). |
|
Note
|
Real-time status types are only available on Gen5 modules (DF1, DF2, DF3). On the D8 (Gen3), these calls return NAI_ERROR_NOT_SUPPORTED. The sample handles this gracefully by printing "N/A" when a real-time status read is not supported.
|
Clear Status
To clear latched status registers on a channel in your own application, call naibrd_DIF_ClearStatus() for each status type you want to reset. The sample clears all four latched status types in sequence:
naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_BIT_LATCHED);
naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_OVERCURRENT_LATCHED);
naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_LO_HI_TRANS_LATCHED);
naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_HI_LO_TRANS_LATCHED);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the channel whose status to clear. -
The fourth parameter — the latched status type to clear.
Clear latched status after you have read and processed it. If you do not clear latched status, it remains set indefinitely and you cannot distinguish new events from previously recorded ones. Only latched status types can be cleared — real-time status types reflect the current hardware condition and clear automatically.
Reset Overcurrent
To reset an overcurrent condition in your own application, call naibrd_DIF_ResetAll() to reset all channels on the module, or naibrd_DIF_Reset() to reset a specific channel. The sample demonstrates both approaches:
/* Reset overcurrent on all channels */
naibrd_DIF_ResetAll(cardIndex, module, NAI_DIF_RESET_OVERCURRENT);
/* Reset overcurrent on a specific channel (Gen5 only) */
naibrd_DIF_Reset(cardIndex, module, chan, (nai_dif_reset_type_t)NAI_DIF_RESET_OVERCURRENT);
-
cardIndex— identifies the board. -
module— the slot containing the DIF module. -
chan— the specific channel to reset (fornaibrd_DIF_Reset()only). -
NAI_DIF_RESET_OVERCURRENT— specifies that the overcurrent condition should be reset.
When an overcurrent condition occurs, the module may disable the affected output channel to protect the hardware. The overcurrent reset re-enables the output. If the overcurrent condition persists (for example, because the short circuit has not been removed), the module will immediately re-enter the overcurrent state.
|
Note
|
Per-channel overcurrent reset via naibrd_DIF_Reset() is available on Gen5 modules only. On Gen3 modules, use naibrd_DIF_ResetAll() to reset all channels simultaneously.
|
|
Important
|
Common Errors
|
Troubleshooting Reference
This table summarizes common errors and symptoms covered in the sections above. For detailed context on each entry, refer to the relevant section. Consult your module’s manual for hardware-specific diagnostic procedures.
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found or connection timeout |
Board not powered, incorrect or missing configuration file, network issue |
Verify hardware is powered and connected. If |
Module not detected as DIF |
No DIF module installed at the specified slot, incorrect module number entered |
Verify hardware configuration and module slot assignment. |
|
Feature not available for this module type (e.g., real-time status on Gen3) or FPGA revision too old |
Check your module type. Gen5 features are not available on the D8. Consult your module’s manual for supported features. |
Output state has no effect on physical line |
Channel is configured as input, wrong I/O format constant used for the module generation |
Call |
Input always reads 0 (low) |
No signal connected, cable wiring swapped, signal below threshold, termination misconfigured |
Verify cable connections and polarity. Check that the signal source provides sufficient differential voltage. Try enabling or disabling termination. |
Input reads opposite of expected |
Differential pair polarity reversed at the connector |
Swap the two conductors of the differential pair at the connector, or invert the reading in software. |
Overcurrent status triggered |
Short circuit on output, external load exceeds rated current, cable fault |
Remove the external fault. Reset the overcurrent condition with |
Spurious transition detections |
Electrical noise on the cable, insufficient debounce time, contact bounce from mechanical switches |
Increase the debounce time with |
Debounce time not matching requested value |
Requested value not supported by the module — the API rounds to the nearest valid setting |
Read back the configured value with |
BIT failure on a channel |
Open or shorted differential pair, internal circuit fault, connector issue |
Check cable and connector integrity. Consult your module’s manual for diagnostic procedures. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — DIF_BasicOps.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_dif.h"
#include "advanced/nai_ether_adv.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_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},
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DIF_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
operations with the discrete modules for configuration setup, controlling the drive outputs, and reading
the channels.
The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd DIF routines.
- ClearDeviceCfg
- QuerySystemCfg
- DisplayDeviceCfg
- GetBoardSNModCfg
- SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DIF_BasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
Run_DIF_BasicOps(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/**************************************************************************************************************/
/**
<summary>
Run_DIF_BasicOps prompts the user for the card, module and channel to use for the application and calls
Cfg_DIF_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
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)
{
printf(" *** Module selection not recognized as DIF module. ***\n\n");
}
else
{
Cfg_DIF_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
/**************************************************************************************************************/
/**
<summary>
Cfg_DIF_Channel handles calling the Display_DIF_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_DIF_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
nai_status_t status = NAI_SUCCESS;
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)
{
printf(" \r\n\r\n");
printf("Channel selection \r\n");
printf("================= \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");
printf("\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 = check_status(naibrd_DIF_ResetAll(cardIndex, module, NAI_DIF_RESET_OVERCURRENT)); /*This resets all channels*/
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_Reset(cardIndex, module, chan, (nai_dif_reset_type_t)NAI_DIF_RESET_OVERCURRENT)); /*This alternate function resets channel 1 only on Gen5 modules. */
if (status == NAI_SUCCESS)
{
printf("Overcurrent condition reset completed \n");
}
}
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
}
/**************************************************************************************************************/
/**
<summary>
Display_DIF_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DIF_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
uint32_t ioformat = 0;
nai_dif_state_t outputstate = 0;
nai_dif_state_t inputstate = 0;
nai_dif_slewRate_t slewRate = 0;
nai_dif_input_term_t termination = 0;
float64_t debounceTime = 0.0;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
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));
printf("\n === Channel %d ===\n\n", chan);
printf(" IOFormat Output Input Slew-Rate Termination Debounce(ms) \r\n");
printf(" --------- ------ ----- --------- ----------- ------------ \r\n");
if (ModuleID == NAI_MODULE_ID_D8)
{
/*For all Gen3 and prior modules, I/O output mode configuration control setting is different.*/
switch (ioformat)
{
case NAI_DIF_IOFORMAT_INPUT:
printf(" Input ");
break;
case NAI_DIF_GEN3_IOFORMAT_OUTPUT:
printf(" Output ");
break;
default:
printf(" Unknown ");
break;
}
}
else
{
switch (ioformat)
{
case NAI_DIF_IOFORMAT_INPUT:
printf(" Input ");
break;
case NAI_DIF_GEN5_IOFORMAT_OUTPUT:
printf(" Output ");
break;
default:
printf(" Unknown ");
break;
}
}
if (ioformat != NAI_DIF_IOFORMAT_INPUT)
{
switch (outputstate)
{
case NAI_DIF_STATE_LO:
printf(" Low ");
break;
case NAI_DIF_STATE_HI:
printf(" High");
break;
/* undefined value read back */
default:
printf(" UNK ");
break;
}
}
else
printf(" --- ");
printf(" %3i ", inputstate);
switch (slewRate)
{
case NAI_DIF_SLEWRATE_SLOW:
printf(" Slow ");
break;
case NAI_DIF_SLEWRATE_FAST:
printf(" Fast ");
break;
default:
printf(" Unknown ");
break;
}
switch (termination)
{
case NAI_DIF_INPUT_NOT_TERMINATED:
printf(" Unset ");
break;
case NAI_DIF_INPUT_TERMINATED:
printf(" Set ");
break;
default:
printf(" Unknown ");
break;
}
printf(" %3f ", debounceTime);
}
/**************************************************************************************************************/
/**
<summary>
Display_DIF_Status illustrate the methods to call in the naibrd library to retrieve the status states.
</summary>
*/
/**************************************************************************************************************/
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
/* Available statusread:
NAI_DIF_STATUS_BIT_LATCHED,
NAI_DIF_STATUS_BIT_REALTIME, (GEN5 only)
NAI_DIF_STATUS_OVERCURRENT_LATCHED,
NAI_DIF_STATUS_OVERCURRENT_REALTIME, (GEN5 only)
NAI_DIF_STATUS_LO_HI_TRANS_LATCHED,
NAI_DIF_STATUS_LO_HI_TRANS_REALTIME, (GEN5 only)
NAI_DIF_STATUS_HI_LO_TRANS_LATCHED,
NAI_DIF_STATUS_HI_LO_TRANS_REALTIME, (GEN5 only)
*/
printf("\n");
printf(" ------------------------- Status ----------------------------\n");
printf(" | BIT | OC | Lo-Hi Trans | Hi-Lo Trans |\n");
printf(" Latch RT Latch RT Latch RT Latch RT \n");
printf(" -------------- --------------- -------------- ---------------\n");
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_BIT_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_BIT_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_OVERCURRENT_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_OVERCURRENT_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_LO_HI_TRANS_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_LO_HI_TRANS_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_HI_LO_TRANS_LATCHED, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else
printf(" Err %3i", status);
status = check_status(naibrd_DIF_GetStatus(cardIndex, module, chan, NAI_DIF_STATUS_HI_LO_TRANS_REALTIME, &statusread));
if (status == NAI_SUCCESS)
printf(" %3i ", statusread);
else if (status == NAI_ERROR_NOT_SUPPORTED)
printf(" N/A "); /*not available*/
else
printf(" Err %3i", status);
printf("\n\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Clear_DIF_Status illustrate the methods to call in the naibrd library to clear the latched status states.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Clear_DIF_Status(int32_t paramCount, int32_t* p_params)
{
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
/* Available status:
NAI_DIF_STATUS_BIT_LATCHED,
NAI_DIF_STATUS_OVERCURRENT_LATCHED,
NAI_DIF_STATUS_LO_HI_TRANS_LATCHED,
NAI_DIF_STATUS_HI_LO_TRANS_LATCHED,
*/
/*Clear latched status - move this to separate operator option selection */
status = check_status(naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_BIT_LATCHED));
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_OVERCURRENT_LATCHED));
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_LO_HI_TRANS_LATCHED));
if (status == NAI_SUCCESS)
{
status = check_status(naibrd_DIF_ClearStatus(cardIndex, module, chan, NAI_DIF_STATUS_HI_LO_TRANS_LATCHED));
}
}
}
if (status == NAI_SUCCESS)
printf("Latched Status cleared \n\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_IOFormat handles the user request to configure the Input/Output configuration for the selected
channel and calls the method in the naibrd library to set the Input/Output mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_IOFormat(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateIOCfg = FALSE;
uint32_t state = 0;
int8_t iofmtreq;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
p_naiapp_AppParameters_t p_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
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
/* Set I/O format configuration for channel. Available configurations include:
NAI_DIF_IOFORMAT_INPUT
NAI_DIF_GEN3_IOFORMAT_OUTPUT
NAI_DIF_GEN5_IOFORMAT_OUTPUT
NAI_DIF_IOFORMAT_OUTPUT
*/
printf("Type the desired IO configuration ");
printf("(I=Input, Out=Output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
iofmtreq = (int8_t)toupper(inputBuffer[0]);
if (iofmtreq == 'I')
{
state = NAI_DIF_IOFORMAT_INPUT;
bUpdateIOCfg = TRUE;
}
else if (iofmtreq == 'O')
{
if (ModuleID == NAI_MODULE_ID_D8)
state = NAI_DIF_GEN3_IOFORMAT_OUTPUT;
else
state = NAI_DIF_GEN5_IOFORMAT_OUTPUT;
bUpdateIOCfg = TRUE;
}
else
{
printf("ERROR: Invalid selection\n");
}
}
if (!bQuit)
{
if (bUpdateIOCfg)
check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan, state));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_OutputState handles the user request to set the Output state for the selected
channel and calls the method in the naibrd library to set the Output state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_OutputState(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateOutput = FALSE;
nai_dif_state_t outputstate = 0;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
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
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
/* Set the output state (high or low) on output channels.
This is not applicable for channels configured as inputs.
*/
printf("\nEnter the desired output state ");
printf("(L=low output, H=high output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'L':
outputstate = 0;
bUpdateOutput = TRUE;
break;
case 'H':
outputstate= 1;
bUpdateOutput = TRUE;
break;
default:
printf("ERROR: Invalid Output State Format Entry\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateOutput)
check_status(naibrd_DIF_SetOutputState(cardIndex, module, chan, outputstate));
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_SlewRate handles the user request to configure the slew rate configuration for the selected
channel and calls the method in the naibrd library to set the slew rate mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_SlewRate(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateSRCfg = FALSE;
nai_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
/* Set Slew Rate configuration for channel. Available configurations include:
NAIBRD_DIF_SLEWRATE_SLOW
NAIBRD_DIF_SLEWRATE_FAST
*/
printf("Type the desired Slew Rate configuration ");
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 = NAI_DIF_SLEWRATE_SLOW;
bUpdateSRCfg = TRUE;
break;
case 'F':
state = NAI_DIF_SLEWRATE_FAST;
bUpdateSRCfg = TRUE;
break;
default:
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;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_Termination handles the user request to set the termination state for the selected
channel and calls the method in the naibrd library to set the termination state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_Termination(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateTerm = FALSE;
nai_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
/* Set Termination configuration for channel. Available configurations include:
NAIBRD_DIF_INPUT_NOT_TERMINATED
NAIBRD_DIF_INPUT_TERMINATED
*/
printf("\r\nEnter the desired termination state ");
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 = NAI_DIF_INPUT_TERMINATED;
bUpdateTerm = TRUE;
break;
case 'D':
termState = NAI_DIF_INPUT_NOT_TERMINATED;
bUpdateTerm = TRUE;
break;
default:
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;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_DebounceTime handles the user request to configure the debounce time for the selected
channel and calls the method in the naibrd library to set the debounce time.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_DebounceTime(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateDbTime = 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
/* Set I/O format configuration for channel. Available configurations include:
NAI_DIF_IOFORMAT_INPUT
NAI_DIF_GEN3_IOFORMAT_OUTPUT
NAI_DIF_GEN5_IOFORMAT_OUTPUT
NAI_DIF_IOFORMAT_OUTPUT
*/
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 = TRUE;
}
else
{
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;
}