DA BasicOps
Edit this on GitLab
DA BasicOps
Explanation
About the Code
This C application is designed to interact with North Atlantic Industries (NAI) embedded function modules using their Software Support Kit (SSK). The sample code is responsible for performing various data acquisition (DA) operations such as setting voltage ranges, checking statuses, and enabling/disabling features on the modules. Below is a concise walkthrough of the primary functions and data structures in the provided code:
Key Definitions and Libraries
First, let’s look at the essential headers and definitions:
-
Standard Libraries: These include standard C libraries like
stdio.h
,stdlib.h
,string.h
, and platform-specific threading libraries likepthread.h
. -
NAI-specific Headers: These are specific to the NAI support kit and include:
-
naiapp_boardaccess_menu.h
-
naiapp_boardaccess_query.h
-
naiapp_boardaccess_access.h
-
naiapp_boardaccess_display.h
-
naiapp_boardaccess_utils.h
-
Function and Board Include Files:
-
naibrd_gen5.h
,naibrd_da.h
, andnai_ether_adv.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#if defined (LINUX)
#include <pthread.h>
#endif
#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"
#include "boards/naibrd_gen5.h"
#include "functions/naibrd_da.h"
#include "advanced/nai_ether_adv.h"
Constants and Global Variables
The code defines several constants for voltage ranges, output triggers, signal modes, complete status, and default configuration files.
#define DEF_VOLTAGE 2.0
#define DEF_RANGE 10.0
#define DEF_OUTPUT_TRIGGER 0
#define DEF_SIGNAL_MODE 1
#define DEF_STATUS 0
#define DEF_WRAP_VOLTAGE 0.0
#define DEF_CURRENT 0.0
#define BACK_CHAR 'B'
static const int8_t *CONFIG_FILE = (const int8_t *)"default_DA_BasicOps.txt";
static const int8_t *SAMPLE_WD_PGM_NAME = (const int8_t*)"DA Watchdog Operations";
static bool_t terminateThread;
Function Prototypes
The code contains several static and external functions to manage different DA operations like setting data, clearing status, resetting outputs, enabling power supply, managing watchdog, etc.
static bool_t Run_DA_BasicOps( int32_t cardIndex, int32_t module, int32_t ModuleID );
// Other function prototypes...
Main Function
The main function initializes the application and runs the board menu according to the provided configuration file. It queries the user to select the card and module index, and then runs the Run_DA_BasicOps()
function for DA operations.
int32_t main(void)
{
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
// ...
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;
}
Running Basic DA Operations
The Run_DA_BasicOps()
function is responsible for executing basic DA operations by displaying option menus and calling corresponding handler functions based on user inputs.
static bool_t Run_DA_BasicOps(int32_t cardIndex, int32_t module, int32_t modId)
{
// Initialize parameters and query user for commands
// ...
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands( cmdCount, cmdtbl_params );
while (bContinue)
{
DA_DisplayOpData(cardIndex, module, da_basicops_params->maxChannels, modId);
naiapp_display_ParamMenuCommands( (int8_t *)"DA Standard Operations Menu" );
// Query user for command and execute corresponding function
// ...
}
}
return TRUE;
}
Command Tables
The commands for different DA operations are defined using enumerations and lookup tables.
enum da_gen3_standardop_commands { /* ... */ };
enum da_gen5_da1_da3_standardop_commands { /* ... */ };
enum da_watchdog_commands { /* ... */ };
naiapp_cmdtbl_params_t DA_Gen3_StandardOpMenuCmds[] = { /* ... */ };
naiapp_cmdtbl_params_t DA_Gen5_DA1_DA3_StandardOpMenuCmds[] = { /* ... */ };
naiapp_cmdtbl_params_t DA_WatchdogOpMenuCmds[DA_WD_CMD_COUNT] = { /* ... */ };
Handler Functions
Several handler functions such as Handle_DA_Data()
, Handle_DA_ClearStatus()
, Handle_DA_ResetToZero()
, and others manage specific DA operations based on the user input.
static nai_status_t Handle_DA_Data(int32_t paramCount, int32_t* p_params)
{
// Handle setting DA data based on user input
// ...
return NAI_SUCCESS;
}
static nai_status_t Handle_DA_ClearStatus(int32_t paramCount, int32_t* p_params)
{
// Handle clearing DA status based on user input
// ...
return NAI_SUCCESS;
}
Display Function
The DA_DisplayOpData()
function displays the current DA operation data for all channels.
static void DA_DisplayOpData( int32_t cardIndex, int32_t module, int32_t maxchan, uint32_t damodid )
{
// Display DA operation data for all channels
// ...
}
Conclusion
This sample code demonstrates how to set up and interact with NAI DA modules, providing a solid foundation for performing and managing various DA operations. The application structure includes querying user input for card and module selection, executing specific DA operations, and displaying the results effectively. The provided enumerations, command tables, and handler functions ensure the application is well-organized and easy to extend with additional DA functionalities.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#if defined (LINUX)
#include <pthread.h>
#endif
/* 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 "boards/naibrd_gen5.h"
#include "functions/naibrd_da.h"
#include "advanced/nai_ether_adv.h"
#define DEF_VOLTAGE 2.0
#define DEF_RANGE 10.0
#define DEF_OUTPUT_TRIGGER 0
#define DEF_SIGNAL_MODE 1
#define DEF_STATUS 0
#define DEF_WRAP_VOLTAGE 0.0
#define DEF_CURRENT 0.0
#define BACK_CHAR 'B'
static const int8_t *CONFIG_FILE = (const int8_t *)"default_DA_BasicOps.txt";
static const int8_t *SAMPLE_WD_PGM_NAME = (const int8_t*)"DA Watchdog Operations";
static bool_t terminateThread;
/* Function prototypes */
static bool_t Run_DA_BasicOps( int32_t cardIndex, int32_t module, int32_t ModuleID );
static nai_status_t Handle_DA_Data(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_ClearStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_ClearStatusAllChannels(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_ResetToZero(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_PowerSupplyEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_Range(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_Polarity(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_OpMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_OutputEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_BridgeMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_FloatingPointMode(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_FloatingPointOffset(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_FloatingPointScaleFactor(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_ChannelStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_SetD3TestEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_BITThresholds(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_WatchdogShowMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_WatchDogQuietTime(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_WatchDogWindowTime(int32_t paramCount, int32_t* p_params);
static bool_t Handle_DA_DisplayWatchdog(int32_t cardIndex, int32_t module, int32_t chan);
static nai_status_t Handle_DA_StrobeWatchdog(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DA_kill_WDStrobe_Thread(int32_t paramCount, int32_t* p_params);
static void naiapp_kill_WDStrobe_Thread();
#if defined (WIN32)
DWORD WINAPI WD_Strobe_ThreadEntryPoint(LPVOID param);
#elif defined (LINUX)
void* WD_Strobe_ThreadEntryPoint(void* arg);
#elif defined (__VXWORKS__)
static int WD_Strobe_ThreadEntryPoint(int32_t nParam);
#else
#error Unsupported OS
#endif
/* TX Thread */
#if defined (WIN32)
static HANDLE thread = NULL;
#elif defined (LINUX)
static pthread_t thread;
#elif defined (__VXWORKS__)
static int thread;
#else
#error Unsupported OS
#endif
static void DA_DisplayOpData( int32_t cardIndex, int32_t module, int32_t maxchan, uint32_t damodid );
static const int32_t DEF_DA_CHANNEL = 1;
static uint32_t generation; /* generation of the board/module */
/****** Command Tables *******/
enum da_gen3_standardop_commands
{
DA_GEN3_STANDARDOP_CMD_DATA,
DA_GEN3_STANDARDOP_CMD_RANGE,
DA_GEN3_STANDARDOP_CMD_POLARITY,
DA_GEN3_STANDARDOP_CMD_CLEAR_STATUS,
DA_GEN3_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS,
DA_GEN3_STANDARDOP_CMD_RESET_TO_ZERO,
DA_GEN3_STANDARDOP_CMD_COUNT
};
enum da_gen5_da1_da3_standardop_commands
{
DA_GEN5_DA1_DA3_STANDARDOP_CMD_DATA,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_RANGE,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_POLARITY,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_OPMODE,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_CLEAR_STATUS,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_RESET_TO_ZERO,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_POWER_SUPPLY_ENABLE,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_FLOATING_POINT_MODE,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_FLOATING_OFFSET,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_FLOATING_SCALE,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_CHANNEL_STATUS_ENABLE,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_PBIT,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_BIT_THRESHOLD,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_D3,
DA_GEN5_BASICOP_CMD_WATCHDOG_MENU,
DA_GEN5_DA1_DA3_STANDARDOP_CMD_COUNT
};
enum da_gen5_da2_standardop_commands
{
DA_GEN5_DA2_STANDARDOP_CMD_DATA,
DA_GEN5_DA2_STANDARDOP_CMD_RANGE,
DA_GEN5_DA2_STANDARDOP_CMD_POLARITY,
DA_GEN5_DA2_STANDARDOP_CMD_CLEAR_STATUS,
DA_GEN5_DA2_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS,
DA_GEN5_DA2_STANDARDOP_CMD_RESET_TO_ZERO,
DA_GEN5_DA2_STANDARDOP_CMD_OUTPUT_ENABLE,
DA_GEN5_DA2_STANDARDOP_CMD_FLOATING_POINT_MODE,
DA_GEN5_DA2_STANDARDOP_CMD_FLOATING_OFFSET,
DA_GEN5_DA2_STANDARDOP_CMD_FLOATING_SCALE,
DA_GEN5_DA2_STANDARDOP_CMD_CHANNEL_STATUS_ENABLE,
DA_GEN5_DA2_STANDARDOP_CMD_PBIT,
DA_GEN5_DA2_STANDARDOP_CMD_BIT_THRESHOLD,
DA_GEN5_DA2_STANDARDOP_CMD_D3,
DA_GEN5_DA2_BASICOP_CMD_WATCHDOG_MENU,
DA_GEN5_DA2_STANDARDOP_CMD_COUNT
};
enum da_gen5_da5_standardop_commands
{
DA_GEN5_DA5_STANDARDOP_CMD_DATA,
DA_GEN5_DA5_STANDARDOP_CMD_POWER_SUPPLY_ENABLE,
DA_GEN5_DA5_STANDARDOP_CMD_OUTPUT_ENABLE,
DA_GEN5_DA5_STANDARDOP_CMD_BRIDGE_ENABLE,
DA_GEN5_DA5_STANDARDOP_CMD_CLEAR_STATUS,
DA_GEN5_DA5_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS,
DA_GEN5_DA5_STANDARDOP_CMD_FLOATING_POINT_MODE,
DA_GEN5_DA5_STANDARDOP_CMD_FLOATING_OFFSET,
DA_GEN5_DA5_STANDARDOP_CMD_FLOATING_SCALE,
DA_GEN5_DA5_STANDARDOP_CMD_CHANNEL_STATUS_ENABLE,
DA_GEN5_DA5_STANDARDOP_CMD_PBIT,
DA_GEN5_DA5_STANDARDOP_CMD_BIT_THRESHOLD,
DA_GEN5_DA5_STANDARDOP_CMD_D3,
DA_GEN5_DA5_BASICOP_CMD_WATCHDOG_MENU,
DA_GEN5_DA5_STANDARDOP_CMD_COUNT
};
enum da_watchdog_commands
{
DA_WD_CMD_QUIETTIME,
DA_WD_CMD_WINDOWTIME,
DA_WD_CMD_STROBE,
DA_WD_CMD_KILL,
DA_WD_CMD_BACK,
DA_WD_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DA_Gen3_StandardOpMenuCmds[] =
{
{"DATA", "Set Voltage Data", DA_GEN3_STANDARDOP_CMD_DATA, Handle_DA_Data},
{"RANGE", "Set Voltage Range", DA_GEN3_STANDARDOP_CMD_RANGE, Handle_DA_Range},
{"POLARITY", "Set Range Polarity Mode", DA_GEN3_STANDARDOP_CMD_POLARITY, Handle_DA_Polarity},
{"CLEAR", "Clear DA Statuses", DA_GEN3_STANDARDOP_CMD_CLEAR_STATUS, Handle_DA_ClearStatus},
{"ALL CLEAR", "Clear DA Statuses All Channels", DA_GEN3_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS, Handle_DA_ClearStatusAllChannels},
{"SET", "Reset All Channel Outputs To Zero", DA_GEN3_STANDARDOP_CMD_RESET_TO_ZERO, Handle_DA_ResetToZero}
};
naiapp_cmdtbl_params_t DA_Gen5_DA1_DA3_StandardOpMenuCmds[] =
{
{"DATA", "Set Voltage/Current Data", DA_GEN5_DA1_DA3_STANDARDOP_CMD_DATA, Handle_DA_Data},
{"RANGE", "Set Voltage/Current Range", DA_GEN5_DA1_DA3_STANDARDOP_CMD_RANGE, Handle_DA_Range},
{"POLARITY", "Set Range Polarity Mode", DA_GEN5_DA1_DA3_STANDARDOP_CMD_POLARITY, Handle_DA_Polarity},
{"OPMODE", "Set Voltage/Current Op Mode", DA_GEN5_DA1_DA3_STANDARDOP_CMD_OPMODE, Handle_DA_OpMode},
{"CLEAR", "Clear DA Statuses", DA_GEN5_DA1_DA3_STANDARDOP_CMD_CLEAR_STATUS, Handle_DA_ClearStatus},
{"ALL CLEAR", "Clear DA Statuses All Channels", DA_GEN5_DA1_DA3_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS, Handle_DA_ClearStatusAllChannels},
{"SET", "Reset All Channel Outputs To Zero", DA_GEN5_DA1_DA3_STANDARDOP_CMD_RESET_TO_ZERO, Handle_DA_ResetToZero},
{"ENABLE", "Enable/Disable Power Supply", DA_GEN5_DA1_DA3_STANDARDOP_CMD_POWER_SUPPLY_ENABLE, Handle_DA_PowerSupplyEnable},
{"FLOAT", "Enable/Disable Floating-Point Mode", DA_GEN5_DA1_DA3_STANDARDOP_CMD_FLOATING_POINT_MODE, Handle_DA_FloatingPointMode},
{"OFFSET", "Set Hardware Floating-Point Conversion Mode Offset", DA_GEN5_DA1_DA3_STANDARDOP_CMD_FLOATING_OFFSET, Handle_DA_FloatingPointOffset},
{"SCALE", "Set Hardware Floating-Point Conversion Mode Scale Factor", DA_GEN5_DA1_DA3_STANDARDOP_CMD_FLOATING_SCALE, Handle_DA_FloatingPointScaleFactor},
{"CHANSTAT", "Channel Status Enable/Disable", DA_GEN5_DA1_DA3_STANDARDOP_CMD_CHANNEL_STATUS_ENABLE, Handle_DA_ChannelStatusEnable},
{"PBIT", "Check Power-On BIT", DA_GEN5_DA1_DA3_STANDARDOP_CMD_PBIT, Handle_DA_CheckPowerOnBIT},
{"THRESH", "Get/Set BIT Error Threshold", DA_GEN5_DA1_DA3_STANDARDOP_CMD_BIT_THRESHOLD, Handle_DA_BITThresholds},
{"D3", "Enable/Disable D3 Test", DA_GEN5_DA1_DA3_STANDARDOP_CMD_D3, Handle_DA_SetD3TestEnable},
{"WDT", "Show Watchdog Menu Options", DA_GEN5_BASICOP_CMD_WATCHDOG_MENU, Handle_DA_WatchdogShowMenu}
};
naiapp_cmdtbl_params_t DA_Gen5_DA2_StandardOpMenuCmds[] =
{
{"DATA", "Set Voltage Data", DA_GEN5_DA2_STANDARDOP_CMD_DATA, Handle_DA_Data},
{"RANGE", "Set Voltage Range", DA_GEN5_DA2_STANDARDOP_CMD_RANGE, Handle_DA_Range},
{"POLARITY", "Set Voltage Range Polarity Mode", DA_GEN5_DA2_STANDARDOP_CMD_POLARITY, Handle_DA_Polarity},
{"CLEAR", "Clear DA Statuses", DA_GEN5_DA2_STANDARDOP_CMD_CLEAR_STATUS, Handle_DA_ClearStatus},
{"ALL CLEAR", "Clear DA Statuses All Channels", DA_GEN5_DA2_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS, Handle_DA_ClearStatusAllChannels},
{"ZERO", "Reset All Channel Outputs To Zero", DA_GEN5_DA2_STANDARDOP_CMD_RESET_TO_ZERO, Handle_DA_ResetToZero},
{"OUTPUT_ENABLE","Enable/Disable Channel Output", DA_GEN5_DA2_STANDARDOP_CMD_OUTPUT_ENABLE, Handle_DA_OutputEnable},
{"FLOAT", "Enable/Disable Floating-Point Mode", DA_GEN5_DA2_STANDARDOP_CMD_FLOATING_POINT_MODE, Handle_DA_FloatingPointMode},
{"OFFSET", "Set Hardware Floating-Point Conversion Mode Offset", DA_GEN5_DA2_STANDARDOP_CMD_FLOATING_OFFSET, Handle_DA_FloatingPointOffset},
{"SCALE", "Set Hardware Floating-Point Conversion Mode Scale Factor", DA_GEN5_DA2_STANDARDOP_CMD_FLOATING_SCALE, Handle_DA_FloatingPointScaleFactor},
{"CHANSTAT", "Channel Status Enable/Disable", DA_GEN5_DA2_STANDARDOP_CMD_CHANNEL_STATUS_ENABLE, Handle_DA_ChannelStatusEnable},
{"PBIT", "Check Power-On BIT", DA_GEN5_DA2_STANDARDOP_CMD_PBIT, Handle_DA_CheckPowerOnBIT},
{"THRESH", "Get/Set BIT Error Threshold", DA_GEN5_DA2_STANDARDOP_CMD_BIT_THRESHOLD, Handle_DA_BITThresholds},
{"D3", "Enable/Disable D3 Test", DA_GEN5_DA2_STANDARDOP_CMD_D3, Handle_DA_SetD3TestEnable},
{"WDT", "Show Watchdog Menu Options", DA_GEN5_BASICOP_CMD_WATCHDOG_MENU, Handle_DA_WatchdogShowMenu}
};
naiapp_cmdtbl_params_t DA_Gen5_DA5_StandardOpMenuCmds[] =
{
{"DATA", "Set Voltage Data", DA_GEN5_DA5_STANDARDOP_CMD_DATA, Handle_DA_Data},
{"PS_ENABLE", "Enable/Disable Power Supply", DA_GEN5_DA5_STANDARDOP_CMD_POWER_SUPPLY_ENABLE, Handle_DA_PowerSupplyEnable},
{"OUTPUT_ENABLE","Enable/Disable Channel Output", DA_GEN5_DA5_STANDARDOP_CMD_OUTPUT_ENABLE, Handle_DA_OutputEnable},
{"BRIDGE_ENABLE","Enable/Disable Channel Bridge", DA_GEN5_DA5_STANDARDOP_CMD_BRIDGE_ENABLE, Handle_DA_BridgeMode},
{"CLEAR", "Clear DA Statuses", DA_GEN5_DA5_STANDARDOP_CMD_CLEAR_STATUS, Handle_DA_ClearStatus},
{"ALL CLEAR", "Clear DA Statuses All Channels", DA_GEN5_DA5_STANDARDOP_CMD_CLEAR_STATUS_ALL_CHANS, Handle_DA_ClearStatusAllChannels},
{"FLOAT", "Enable/Disable Floating-Point Mode", DA_GEN5_DA5_STANDARDOP_CMD_FLOATING_POINT_MODE, Handle_DA_FloatingPointMode},
{"OFFSET", "Set Hardware Floating-Point Conversion Mode Offset", DA_GEN5_DA5_STANDARDOP_CMD_FLOATING_OFFSET, Handle_DA_FloatingPointOffset},
{"SCALE", "Set Hardware Floating-Point Conversion Mode Scale Factor", DA_GEN5_DA5_STANDARDOP_CMD_FLOATING_SCALE, Handle_DA_FloatingPointScaleFactor},
{"CHANSTAT", "Channel Status Enable/Disable", DA_GEN5_DA5_STANDARDOP_CMD_CHANNEL_STATUS_ENABLE, Handle_DA_ChannelStatusEnable},
{"PBIT", "Check Power-On BIT", DA_GEN5_DA5_STANDARDOP_CMD_PBIT, Handle_DA_CheckPowerOnBIT},
{"THRESH", "Get/Set BIT Error Threshold", DA_GEN5_DA5_STANDARDOP_CMD_BIT_THRESHOLD, Handle_DA_BITThresholds},
{"D3", "Enable/Disable D3 Test", DA_GEN5_DA5_STANDARDOP_CMD_D3, Handle_DA_SetD3TestEnable},
{"WDT", "Show Watchdog Menu Options", DA_GEN5_BASICOP_CMD_WATCHDOG_MENU, Handle_DA_WatchdogShowMenu}
};
naiapp_cmdtbl_params_t DA_WatchdogOpMenuCmds[DA_WD_CMD_COUNT] =
{
{"BACK", "Back to Main Menu", DA_WD_CMD_BACK, NULL},
{"TIME QUIET", "Set Watchdog Quiet Time", DA_WD_CMD_QUIETTIME, Handle_DA_WatchDogQuietTime},
{"WINDOW", "Set Watchdog Window Time", DA_WD_CMD_WINDOWTIME, Handle_DA_WatchDogWindowTime},
{"STROBE", "Start thread to continuously strobe watchdog", DA_WD_CMD_STROBE, Handle_DA_StrobeWatchdog},
{"KILL", "Kill Watchdog strobing thread", DA_WD_CMD_KILL, Handle_DA_kill_WDStrobe_Thread}
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DA_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
operations with the DA 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 DA routines.
- ConfigDevice
- DisplayDeviceCfg
- GetBoardSNModCfg
- CheckModule
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DA_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_DA_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>
This function runs the basic operations DA program. It controls the top level menu of the DA_BasicOps
program and calls Handle_DA_Configuration or Handle_DA_StandardOps, depending on what the user specifies.
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_DA_BasicOps(int32_t cardIndex, int32_t module, int32_t modId)
{
naiapp_AppParameters_t da_params;
p_naiapp_AppParameters_t da_basicops_params = &da_params;
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t cmd;
naiapp_cmdtbl_params_t *cmdtbl_params = NULL;
int32_t cmdCount = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
da_basicops_params->cardIndex = cardIndex;
da_basicops_params->module = module;
da_basicops_params->modId = modId;
/* Get the Maximum DA Channels */
da_basicops_params->maxChannels = naibrd_DA_GetChannelCount( modId );
da_basicops_params->channel = DEF_DA_CHANNEL;
/* Get the generation of the board and module */
naibrd_GetBoardGen( cardIndex, &generation );
switch (modId)
{
case NAI_MODULE_ID_F1:
case NAI_MODULE_ID_F3:
case NAI_MODULE_ID_F5:
case NAI_MODULE_ID_J3:
case NAI_MODULE_ID_J5:
case NAI_MODULE_ID_J8:
cmdtbl_params = DA_Gen3_StandardOpMenuCmds;
cmdCount = DA_GEN3_STANDARDOP_CMD_COUNT;
break;
case NAI_MODULE_ID_DA1:
case NAI_MODULE_ID_DA3:
cmdtbl_params = DA_Gen5_DA1_DA3_StandardOpMenuCmds;
cmdCount = DA_GEN5_DA1_DA3_STANDARDOP_CMD_COUNT;
break;
case NAI_MODULE_ID_DA2:
cmdtbl_params = DA_Gen5_DA2_StandardOpMenuCmds;
cmdCount = DA_GEN5_DA2_STANDARDOP_CMD_COUNT;
break;
case NAI_MODULE_ID_DA5:
cmdtbl_params = DA_Gen5_DA5_StandardOpMenuCmds;
cmdCount = DA_GEN5_DA5_STANDARDOP_CMD_COUNT;
break;
default:
printf("Module ID: %u not supported!\n", modId);
break;
}
while (bContinue)
{
naiapp_utils_LoadParamMenuCommands( cmdCount, cmdtbl_params );
while (bContinue)
{
DA_DisplayOpData( cardIndex, module, da_basicops_params->maxChannels, modId );
naiapp_display_ParamMenuCommands( (int8_t *)"DA Standard Operations Menu" );
printf( "\nType DA command or %c to go back >", BACK_CHAR );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), BACK_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum( inputResponseCnt, inputBuffer, &cmd );
if (bCmdFound)
cmdtbl_params[cmd].func(APP_PARAM_COUNT, (int32_t*)da_basicops_params);
else
printf( "Invalid command entered\n" );
}
else
printf( "Invalid command entered\n" );
}
else
bContinue = FALSE;
}
}
return TRUE;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the contents of the data register of the channel specified by the user to the value
specified by the user. For Gen5 modules, the voltage or current will be set based on the current value in
the op mode register. Voltage will be set if the op mode is set to voltage mode, whereas current will be
set if the op mode is set to current mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_Data(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t modId = da_basicops_params->modId;
bool_t bQuit = FALSE;
float64_t data;
nai_da_data_type_t opmode;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
if ( (generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount) )
{
if (modId == NAI_MODULE_ID_DA2)
{
printf("Type Voltage value to set in V: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
data = atof((const char *)inputBuffer);
check_status(naibrd_DA_SetData(cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, data));
}
}
}
else
{
check_status( naibrd_DA_GetOpMode( cardIndex, module, da_basicops_params->channel, &opmode ) );
if ( opmode == NAI_DA_DATA_VOLTAGE )
{
printf( "Type Voltage value to set in V: " );
}
else if ( opmode == NAI_DA_DATA_CURRENT )
{
printf( "Type Current value to set in mA: " );
}
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
data = atof( (const char *)inputBuffer );
check_status( naibrd_DA_SetData( cardIndex, module, da_basicops_params->channel, opmode, data ) );
}
}
}
}
else
{
printf( "Type Voltage value to set in V: " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
data = atof( (const char *)inputBuffer );
check_status( naibrd_DA_SetData( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, data ) );
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function clears the status(es) of the channel specified by the user. Clearing the status of a channel
sets the latched status bit of the given status corresponding to the given channel to 0. Statuses that can
be cleared are BIT and Overcurrent statuses.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_ClearStatus(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t statnum;
uint32_t mask = 0x1u;
uint32_t shift = 0;
nai_da_status_type_t type;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t clearAllFlag = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
if (generation == NAI_XILINX_GEN5_ID)
{
printf( "Type Status type to be cleared ('0' = BIT, '1' = Overcurrent, '2' = Summary, '3' = All Statuses): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
statnum = atoi( (const char *)inputBuffer );
switch (statnum)
{
case 0:
type = NAI_DA_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_DA_STATUS_OVERCURRENT_LATCHED;
break;
case 2:
type = NAI_DA_STATUS_SUMMARY_LATCHED;
break;
case 3:
clearAllFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
break;
default:
errFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
if (!bQuit)
{
printf( "\nError! Invalid Status Type\n" );
}
break;
}
if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == FALSE ) )
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
check_status( naibrd_DA_ClearStatus( cardIndex, module, da_basicops_params->channel, type ) );
printf( "\nStatus Cleared!\n" );
}
}
else if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == TRUE ) )
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
check_status( naibrd_DA_ClearStatus( cardIndex, module, da_basicops_params->channel, NAI_DA_STATUS_BIT_LATCHED ) );
check_status( naibrd_DA_ClearStatus( cardIndex, module, da_basicops_params->channel, NAI_DA_STATUS_OVERCURRENT_LATCHED ) );
check_status( naibrd_DA_ClearStatus( cardIndex, module, da_basicops_params->channel, NAI_DA_STATUS_SUMMARY_LATCHED ) );
printf( "\nStatuses Cleared!\n" );
}
}
else
{
printf( "Type Status type to be cleared ('0' = BIT, '1' = Overcurrent, '2' = All Statuses): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
statnum = atoi( (const char *)inputBuffer );
switch (statnum)
{
case 0:
type = NAI_DA_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_DA_STATUS_OVERCURRENT_LATCHED;
break;
case 2:
clearAllFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
break;
default:
errFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
if (!bQuit)
{
printf( "\nError! Invalid Status Type\n" );
}
break;
}
if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == FALSE ) )
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
shift = da_basicops_params->channel-1;
if (!bQuit)
{
check_status( naibrd_DA_ClearStatusRaw( cardIndex, module, type, (mask << shift) ) );
printf( "\nStatus Cleared!\n" );
}
}
else if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == TRUE ) )
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
shift = da_basicops_params->channel-1;
if (!bQuit)
{
check_status( naibrd_DA_ClearStatusRaw( cardIndex, module, NAI_DA_STATUS_BIT_LATCHED, (mask << shift) ) );
check_status( naibrd_DA_ClearStatusRaw( cardIndex, module, NAI_DA_STATUS_OVERCURRENT_LATCHED, (mask << shift) ) );
printf( "\nStatuses Cleared!\n" );
}
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function clears the status(es) of all of the channels on the module. Clearing the status of a channel
sets the latched status bit of the given status corresponding to the given channel to 0. Statuses that can
be cleared are BIT and Overcurrent statuses.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_ClearStatusAllChannels(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
int32_t chan = da_basicops_params->channel;
uint32_t statnum;
uint32_t mask = 0x1u;
uint32_t shift = 0;
nai_da_status_type_t type;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t clearAllFlag = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
if (generation == NAI_XILINX_GEN5_ID)
{
printf( "Type Status type to be cleared ('0' = BIT, '1' = Overcurrent, '2' = Summary, '3' = All Statuses): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
statnum = atoi( (const char *)inputBuffer );
switch (statnum)
{
case 0:
type = NAI_DA_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_DA_STATUS_OVERCURRENT_LATCHED;
break;
case 2:
type = NAI_DA_STATUS_SUMMARY_LATCHED;
break;
case 3:
clearAllFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
break;
default:
errFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
if (!bQuit)
{
printf( "\nError! Invalid Status Type\n" );
}
break;
}
if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == FALSE ) )
{
for ( chan = 1; chan <= da_basicops_params->maxChannels; chan++ )
{
check_status( naibrd_DA_ClearStatus( cardIndex, module, chan, type ) );
}
if (type == NAI_DA_STATUS_OVERCURRENT_LATCHED)
{
check_status( naibrd_DA_ResetOverload( cardIndex, module ) );
}
printf( "\nStatuses Cleared!\n" );
}
else if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == TRUE ) )
{
for ( chan = 1; chan <= da_basicops_params->maxChannels; chan++ )
{
check_status( naibrd_DA_ClearStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_LATCHED ) );
check_status( naibrd_DA_ClearStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_LATCHED ) );
check_status( naibrd_DA_ClearStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_LATCHED ) );
}
check_status( naibrd_DA_ResetOverload( cardIndex, module ) );
printf( "\nStatuses Cleared!\n" );
}
}
else
{
printf( "Type Status type to be cleared ('0' = BIT, '1' = Overcurrent, '2' = All Statuses): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
statnum = atoi( (const char *)inputBuffer );
switch (statnum)
{
case 0:
type = NAI_DA_STATUS_BIT_LATCHED;
break;
case 1:
type = NAI_DA_STATUS_OVERCURRENT_LATCHED;
break;
case 2:
clearAllFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
break;
default:
errFlag = TRUE;
type = NAI_DA_STATUS_BIT_REALTIME; /* Set type equal to something arbitrary */
if (!bQuit)
{
printf( "\nError! Invalid Status Type\n" );
}
break;
}
if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == FALSE ) )
{
for ( chan = 1; chan <= da_basicops_params->maxChannels; chan++ )
{
shift = chan-1;
check_status( naibrd_DA_ClearStatusRaw( cardIndex, module, type, (mask << shift) ) );
}
printf( "\nStatuses Cleared!\n" );
}
else if ( ( !bQuit ) && ( inputResponseCnt > 0 ) && ( errFlag == FALSE ) && ( clearAllFlag == TRUE ) )
{
for ( chan = 1; chan <= da_basicops_params->maxChannels; chan++ )
{
shift = chan-1;
check_status( naibrd_DA_ClearStatusRaw( cardIndex, module, NAI_DA_STATUS_BIT_LATCHED, (mask << shift) ) );
check_status( naibrd_DA_ClearStatusRaw( cardIndex, module, NAI_DA_STATUS_OVERCURRENT_LATCHED, (mask << shift) ) );
}
printf( "\nStatuses Cleared!\n" );
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets all channel outputs on the module to zero.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_ResetToZero(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ((generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount))
{
printf( "This will set all channel outputs on the module to 0. Are you sure you want to do this? (Y or N)(default:Y): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( ( inputBuffer[0] == 'y' ) || ( inputBuffer[0] == 'Y' ) || ( inputResponseCnt == 0 ) )
{
check_status( naibrd_DA_ResetToZero( cardIndex, module ) );
printf( "\nAll Channel Outputs Have Been Reset To Zero\n" );
}
else if ( ( inputBuffer[0] == 'n' ) || ( inputBuffer[0] == 'N' ) )
{
/* If the user answers no to the prompt, do nothing */
}
else
{
printf( "\nError! Invalid user input!\n" );
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function enables/disables the module/channel power supply based on user input. Applies to Gen5 modules
only. DA1 has one power supply for the entire module, whereas DA3 has a power supply for each channel on the
module. The user can enable or disable the module power supply of a DA1 module or enable or disable any of the
power supplies of the channels of a DA3 module.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_PowerSupplyEnable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t modId = da_basicops_params->modId;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
nai_da_powersupply_ctrl_t enableVal;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ( (generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount) )
{
if ( modId == NAI_MODULE_ID_DA3 )
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf( "Type '0' to turn off/disable channel power supply or '1' to turn on/enable channel power supply. (default:1): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
enableVal = atoi( (const char *)inputBuffer );
switch (enableVal)
{
case NAI_DA_POWERSUPPLY_CTRL_DISABLE:
case NAI_DA_POWERSUPPLY_CTRL_ENABLE:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid user input!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_SetChannelPowerSupplyEnable( cardIndex, module, da_basicops_params->channel, enableVal ) );
if ( enableVal == NAI_DA_POWERSUPPLY_CTRL_DISABLE )
{
printf( "\nChannel %d Power Supply Disabled\n", da_basicops_params->channel );
}
else if ( enableVal == NAI_DA_POWERSUPPLY_CTRL_ENABLE )
{
printf( "\nChannel %d Power Supply Enabled\n", da_basicops_params->channel );
}
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_SetChannelPowerSupplyEnable( cardIndex, module, da_basicops_params->channel, NAI_DA_POWERSUPPLY_CTRL_ENABLE ) );
printf( "\nChannel %d Power Supply Enabled\n", da_basicops_params->channel );
}
}
}
}
else if ( (modId == NAI_MODULE_ID_DA1) || (modId == NAI_MODULE_ID_DA5) )
{
printf( "Type '0' to turn off/disable module power supply or '1' to turn on/enable module power supply. (default:1): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
enableVal = atoi( (const char *)inputBuffer );
switch (enableVal)
{
case NAI_DA_POWERSUPPLY_CTRL_DISABLE:
case NAI_DA_POWERSUPPLY_CTRL_ENABLE:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid user input!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_SetPowerSupplyEnable( cardIndex, module, enableVal ) );
if ( enableVal == NAI_DA_POWERSUPPLY_CTRL_DISABLE )
{
printf( "\nModule Power Supply Disabled\n" );
}
else if ( enableVal == NAI_DA_POWERSUPPLY_CTRL_ENABLE )
{
printf( "\nModule Power Supply Enabled\n" );
}
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_SetPowerSupplyEnable( cardIndex, module, NAI_DA_POWERSUPPLY_CTRL_ENABLE ) );
printf( "\nModule Power Supply Enabled\n" );
}
}
}
else
{
printf( "This feature is not supported by this module.\n" );
}
}
else
{
printf( "This feature is not supported by this module.\n" );
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the voltage/current range of the channel specified by the user to the range specified by
the user. For Gen5 modules, the voltage or current range will be set based on the current value in the op mode
register. Voltage range will be set if the op mode is set to voltage mode, whereas current range will be set
if the op mode is set to current mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_Range(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t modId = da_basicops_params->modId;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
nai_da_range_t range;
nai_da_range_t tempRange;
nai_da_range_mode_t mode;
nai_da_data_type_t opmode;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
if ( (generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount) )
{
if (modId == NAI_MODULE_ID_DA2)
{
printf( "Type Voltage Range to set ('2.5' for 2.5V, '5' for 5V, '10' for 10V)(default:2.5): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
range = atof( (const char *)inputBuffer );
if ( ( range != NAI_DA_GEN5_VOLT_RANGE_DA2_5V ) && ( range != NAI_DA_GEN5_VOLT_RANGE_DA2_2P5V ) && ( range != NAI_DA_GEN5_VOLT_RANGE_DA2_10V ) )
{
errFlag = TRUE;
printf( "\nError! Invalid range!\n" );
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, mode, range ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, mode, NAI_DA_GEN5_VOLT_RANGE_DA2_2P5V ) );
}
}
}
else
{
printf( "Would you like to set voltage range or current range? ('V' for voltage, 'C' for current)(default:V): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( ( inputBuffer[0] == 'V' ) || ( inputBuffer[0] == 'v' ) || ( inputResponseCnt == 0 ) )
{
opmode = NAI_DA_DATA_VOLTAGE;
}
else if ( ( inputBuffer[0] == 'C' ) || ( inputBuffer[0] == 'c' ) )
{
opmode = NAI_DA_DATA_CURRENT;
}
else
{
opmode = NAI_DA_DATA_ENUM_COUNT;
printf( "\nError! Invalid range type!\n" );
}
if ( modId == NAI_MODULE_ID_DA1 )
{
if ( opmode == NAI_DA_DATA_VOLTAGE )
{
printf( "Type Voltage Range to set ('1.25' for 1.25V, '2.5' for 2.5V, '5' for 5V, '10' for 10V)(default:1.25): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
range = atof( (const char *)inputBuffer );
if ( ( range != NAI_DA_GEN5_VOLT_RANGE_DA1_1P25V ) && ( range != NAI_DA_GEN5_VOLT_RANGE_DA1_2P5V )
&& ( range != NAI_DA_GEN5_VOLT_RANGE_DA1_5V ) && ( range != NAI_DA_GEN5_VOLT_RANGE_DA1_10V ) )
{
errFlag = TRUE;
printf( "\nError! Invalid range!\n" );
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, range ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, NAI_DA_GEN5_VOLT_RANGE_DA1_1P25V ) );
}
}
}
else if ( opmode == NAI_DA_DATA_CURRENT )
{
printf( "Type Current Range to set ('3.125' for 3.125mA, '6.25' for 6.25mA, '12.5' for 12.5mA, '25' for 25mA)(default:3.125): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
range = atof( (const char *)inputBuffer );
if ( ( range != NAI_DA_GEN5_CURRENT_RANGE_DA1_3P125mA ) && ( range != NAI_DA_GEN5_CURRENT_RANGE_DA1_6P25mA )
&& ( range != NAI_DA_GEN5_CURRENT_RANGE_DA1_12P5mA ) && ( range != NAI_DA_GEN5_CURRENT_RANGE_DA1_25mA ) )
{
errFlag = TRUE;
printf( "\nError! Invalid range!\n" );
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, range ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, NAI_DA_GEN5_CURRENT_RANGE_DA1_3P125mA ) );
}
}
}
}
else if ( modId == NAI_MODULE_ID_DA3 )
{
if ( opmode == NAI_DA_DATA_VOLTAGE )
{
printf( "Type Voltage Range to set ('10' for 10V, '20' for 20V, '40' for 40V)(default:10): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
range = atof( (const char *)inputBuffer );
if ( ( range != NAI_DA_GEN5_VOLT_RANGE_DA3_10V ) && ( range != NAI_DA_GEN5_VOLT_RANGE_DA3_20V ) && ( range != NAI_DA_GEN5_VOLT_RANGE_DA3_40V ) )
{
errFlag = TRUE;
printf( "\nError! Invalid range!\n" );
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, range ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, NAI_DA_GEN5_VOLT_RANGE_DA3_10V ) );
}
}
}
else if ( opmode == NAI_DA_DATA_CURRENT )
{
printf( "Type Current Range to set ('25' for 25mA, '50' for 50mA, '100' for 100mA)(default:25): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
range = atof( (const char *)inputBuffer );
if ( ( range != NAI_DA_GEN5_CURRENT_RANGE_DA3_25mA ) && ( range != NAI_DA_GEN5_CURRENT_RANGE_DA3_50mA ) && ( range != NAI_DA_GEN5_CURRENT_RANGE_DA3_100mA ) )
{
errFlag = TRUE;
printf( "\nError! Invalid range!\n" );
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, range ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, mode, NAI_DA_GEN5_CURRENT_RANGE_DA3_25mA ) );
}
}
}
}
}
}
}
else
{
printf( "Type Voltage Range to set ('5' for 5V, '10' for 10V, '15' for 15V, '20' for 20V, '25' for 25V)(default:5): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
range = atof( (const char *)inputBuffer );
if ( ( range != NAI_DA_GEN3_RANGE_F5_5V ) && ( range != NAI_DA_GEN3_RANGE_F5_10V ) && ( range != NAI_DA_GEN3_RANGE_F5_15V )
&& ( range != NAI_DA_GEN3_RANGE_F5_20V ) && ( range != NAI_DA_GEN3_RANGE_F5_25V ) )
{
errFlag = TRUE;
printf( "\nError! Invalid range!\n" );
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, mode, range ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &mode, &tempRange ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, mode, NAI_DA_GEN3_RANGE_F5_5V ) );
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the range polarity mode of the channel specified by the user to the mode specified by
the user. Note that this function does not modify the range or the op mode of any of the channels; it only
sets the range mode to unipolar or bipolar based on user input.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_Polarity(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t modId = da_basicops_params->modId;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
nai_da_range_mode_t polarity;
nai_da_range_t rangeRead;
nai_da_range_mode_t tempMode;
nai_da_data_type_t opmode = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ( (generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount) )
{
if (modId == NAI_MODULE_ID_DA2)
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf( "Type polarity mode to set ('0' for Unipolar, '1' for Bipolar)(default:1): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
polarity = atoi( (const char *)inputBuffer );
switch (polarity)
{
case NAI_DA_GEN5_RANGE_MODE_UNIPOLAR:
case NAI_DA_GEN5_RANGE_MODE_BIPOLAR:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid polarity mode!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &tempMode, &rangeRead ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, polarity, rangeRead ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &tempMode, &rangeRead ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, NAI_DA_GEN5_RANGE_MODE_BIPOLAR, rangeRead ) );
}
}
}
}
else
{
printf( "Would you like to set voltage range polarity mode or current range polarity mode? ('V' for voltage, 'C' for current)(default:V): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( ( inputBuffer[0] == 'V' ) || ( inputBuffer[0] == 'v' ) || ( inputResponseCnt == 0 ) )
{
opmode = NAI_DA_DATA_VOLTAGE;
}
else if ( ( inputBuffer[0] == 'C' ) || ( inputBuffer[0] == 'c' ) )
{
opmode = NAI_DA_DATA_CURRENT;
}
else
{
opmode = NAI_DA_DATA_ENUM_COUNT;
printf( "\nError! Invalid range polarity mode type!\n" );
}
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf( "Type polarity mode to set ('0' for Unipolar, '1' for Bipolar)(default:1): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
polarity = atoi( (const char *)inputBuffer );
switch (polarity)
{
case NAI_DA_GEN5_RANGE_MODE_UNIPOLAR:
case NAI_DA_GEN5_RANGE_MODE_BIPOLAR:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid polarity mode!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &tempMode, &rangeRead ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, polarity, rangeRead ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, opmode, &tempMode, &rangeRead ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, opmode, NAI_DA_GEN5_RANGE_MODE_BIPOLAR, rangeRead ) );
}
}
}
}
}
}
else
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf( "Type polarity mode to set ('4' for Unipolar, '0' for Bipolar)(default:0): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
polarity = atoi( (const char *)inputBuffer );
switch (polarity)
{
case NAI_DA_GEN3_RANGE_MODE_UNIPOLAR:
case NAI_DA_GEN3_RANGE_MODE_BIPOLAR:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid polarity mode!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &tempMode, &rangeRead ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, polarity, rangeRead ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_GetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, &tempMode, &rangeRead ) );
check_status( naibrd_DA_SetRange( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE, NAI_DA_GEN3_RANGE_MODE_BIPOLAR, rangeRead ) );
}
}
}
}
return NAI_SUCCESS;
}
static nai_status_t Handle_DA_BridgeMode(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ((generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount))
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf("Type Bridge Mode to set (0 for DISABLED, 1 for ENABLED)(default:DISABLED): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0 && inputBuffer[0] == '1')
check_status(naibrd_DA_SetFullBridgeMode(cardIndex, module, da_basicops_params->channel, TRUE));
else
check_status(naibrd_DA_SetFullBridgeMode(cardIndex, module, da_basicops_params->channel, FALSE));
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function enables/disables the floating-point hardware conversion mode of the channel specified by the user.
Applies to Gen5 modules only.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_FloatingPointMode(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
bool_t mode = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ((generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount))
{
printf("Type Floating-Point Mode to set (0 for DISABLED, 1 for ENABLED)(default:DISABLED): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
mode = (bool_t)atoi((const char *)inputBuffer);
switch (mode)
{
case TRUE:
case FALSE:
break;
default:
errFlag = TRUE;
printf("\nError! Invalid user input!\n");
break;
}
if (errFlag == FALSE)
{
check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, mode));
}
}
else if (inputResponseCnt == 0)
{
check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, mode));
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the floating-point hardware conversion mode offset of the channel specified by the user.
Applies to Gen5 modules only. Can only be set when module is in floating-point mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_FloatingPointOffset(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
bool_t bQuit = FALSE;
float64_t offset = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ((generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount))
{
bQuit = naiapp_query_ChannelNumber(da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel));
if (!bQuit)
{
printf("Type Floating-Point Offset value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
offset = atof((const char *)inputBuffer);
check_status(naibrd_DA_SetFloatingPointOffset(cardIndex, module, da_basicops_params->channel, offset));
}
else if (inputResponseCnt == 0)
{
printf("Invalid Offset Value.\n");
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the floating-point hardware conversion mode scale factor of the channel specified by the user.
Applies to Gen5 modules only. Can only be set when module is in floating-point mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_FloatingPointScaleFactor(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
bool_t bQuit = FALSE;
float64_t scaleFactor = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ((generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount))
{
bQuit = naiapp_query_ChannelNumber(da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel));
if (!bQuit)
{
printf("Type Floating-Point Scale Factor value to set: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
scaleFactor = atof((const char *)inputBuffer);
check_status(naibrd_DA_SetFloatingPointScaleFactor(cardIndex, module, da_basicops_params->channel, scaleFactor));
}
else if (inputResponseCnt == 0)
{
printf("Invalid Scale Factor Value.\n");
}
}
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
* <summary>
* This function Enables\Disables the reporting of the Channel Status. When enabled, the user will get status
* updates. When disabled, the statuses will not report and status-based interrupts will not assert.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_ChannelStatusEnable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
bQuit = naiapp_query_ChannelNumber(da_params->maxChannels, da_params->channel, &(da_params->channel));
if (!bQuit)
{
printf("Enable Channel Status (Y = YES, [any other key] = NO: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
status = check_status(naibrd_DA_SetChanStatusEnable(da_params->cardIndex, da_params->module, da_params->channel,
((inputResponseCnt > 0) && (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')) ? TRUE : FALSE));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* Handle_DA_CheckPowerOnBIT() Checks to see if the power-on BIT test
* has been run on the module. If the PBIT test has run, it checks the result
* of the test and reports it back.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_CheckPowerOnBIT(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_da_params = (p_naiapp_AppParameters_t)p_params;
int32_t channelCount = 0, channel = 0;
bool_t pbitComplete;
nai_status_bit_t bitFailed;
if (APP_PARAM_COUNT == paramCount)
{
channelCount = naibrd_DA_GetChannelCount(p_da_params->modId);
/* Check to see if PBIT ran for the module. */
printf("Checking if the Power-On BIT test has run...\n");
status = naibrd_DA_CheckPowerOnBITComplete(p_da_params->cardIndex, p_da_params->module, &pbitComplete);
printf("PBIT Complete: %s", (pbitComplete) ? "COMPLETED\n" : "NOT COMPLETED\n");
if (pbitComplete)
{
/* Read the BIT status */
printf("Checking the result of the Power-on BIT test...\n");
for (channel = 1; channel <= channelCount; channel++)
{
status = naibrd_DA_GetStatus(p_da_params->cardIndex, p_da_params->module, channel, NAI_DA_STATUS_BIT_LATCHED,
&bitFailed);
printf("Ch. %d: %s", channel, bitFailed ? "BIT FAILED\n" : "BIT Passed\n");
}
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* Handle_DA_BITThresholds() allows the user to set and get the BIT error thresholds.
* This is an advanced feature.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_BITThresholds(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_da_params = (p_naiapp_AppParameters_t)p_params;
bool_t bQuit = FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
uint32_t bitThreshold = 0u;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
printf("Set or Get BIT Error Threshold? ('S' = Set, 'G' = Get, 'C' = Clear BIT Counter): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (FALSE != bQuit)
{
if (inputBuffer[0] == 'S' || inputBuffer[0] == 's')
{
printf("\nType the desired BIT Error Threshold (Default = 5): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
printf("\n");
bitThreshold = atoi((const char*)inputBuffer);
status = naibrd_DA_SetModuleBITErrorThreshold(p_da_params->cardIndex, p_da_params->module, bitThreshold);
}
else if (inputBuffer[0] == 'G' || inputBuffer[0] == 'g')
{
status = naibrd_DA_GetModuleBITErrorThreshold(p_da_params->cardIndex, p_da_params->module, &bitThreshold);
printf("\nBIT Error threshold: %d", bitThreshold);
}
else if (inputBuffer[0] == 'C' || inputBuffer[0] == 'c')
{
int32_t ch;
int32_t channels = naibrd_DA_GetChannelCount(p_da_params->modId);
printf("\nClearing BIT counters on all channels.\n");
for (ch = 1; ch <= channels; ch++)
status = naibrd_DA_ClearModuleBITLogic(p_da_params->cardIndex, p_da_params->module, ch);
}
else
{
printf("\nSelection not recognized.\n");
}
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
/**************************************************************************************************************/
/**
<summary>
This function sets the op mode of the channel specified by the user to the mode specified by the user. Valid
op modes are voltage and current mode. Applies to Gen5 modules only.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_OpMode(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t modId = da_basicops_params->modId;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
nai_da_data_type_t mode;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
if ( (generation == NAI_XILINX_GEN5_ID) && (modId != NAI_MODULE_ID_DA2) )
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf( "Type Op Mode to set (0 for voltage mode, 1 for current mode)(default:0): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
mode = atoi( (const char *)inputBuffer );
switch (mode)
{
case NAI_DA_DATA_VOLTAGE:
case NAI_DA_DATA_CURRENT:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid user input!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_SetOpMode( cardIndex, module, da_basicops_params->channel, mode ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_SetOpMode( cardIndex, module, da_basicops_params->channel, NAI_DA_DATA_VOLTAGE ) );
}
}
}
}
else
{
printf( "This feature is not supported by this module.\n" );
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function enables/disables the output of the channel specified by the user. Applies to DA2 modules only.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DA_OutputEnable(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
uint32_t modId = da_basicops_params->modId;
bool_t bQuit = FALSE;
bool_t errFlag = FALSE;
nai_da_output_enable_t enable;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if ((generation == NAI_XILINX_GEN5_ID) && (APP_PARAM_COUNT == paramCount))
{
if ((modId == NAI_MODULE_ID_DA2) || (modId == NAI_MODULE_ID_DA5))
{
bQuit = naiapp_query_ChannelNumber( da_basicops_params->maxChannels, da_basicops_params->channel, &(da_basicops_params->channel) );
if (!bQuit)
{
printf( "Type '0' to turn off/disable channel output or '1' to turn on/enable channel output. (default:1): " );
bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
if (!bQuit)
{
if ( inputResponseCnt > 0 )
{
enable = atoi( (const char *)inputBuffer );
switch (enable)
{
case NAI_DA_ENABLE_OUTPUT:
case NAI_DA_DISABLE_OUTPUT:
break;
default:
errFlag = TRUE;
printf( "\nError! Invalid user input!\n" );
break;
}
if ( errFlag == FALSE )
{
check_status( naibrd_DA_SetOutputEnable( cardIndex, module, da_basicops_params->channel, enable ) );
}
}
else if ( inputResponseCnt == 0 )
{
check_status( naibrd_DA_SetOutputEnable( cardIndex, module, da_basicops_params->channel, NAI_DA_ENABLE_OUTPUT ) );
}
}
}
}
else
{
printf( "This feature is not supported by this module.\n" );
}
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
This function displays the DA Standard Operations data.
</summary>
*/
/**************************************************************************************************************/
static void DA_DisplayOpData( int32_t cardIndex, int32_t module, int32_t maxchan, uint32_t damodid )
{
int32_t chan;
float64_t data;
nai_da_range_t voltRange;
nai_da_range_mode_t voltPolarity;
nai_da_range_t currRange;
nai_da_range_mode_t currPolarity;
nai_da_output_enable_t outputEnable;
nai_status_bit_t bitStatLatched;
nai_status_bit_t overCurrentStatLatched;
nai_status_bit_t summaryStatusLatched;
nai_status_bit_t bitStatRealtime;
nai_status_bit_t overCurrentStatRealtime;
nai_status_bit_t summaryStatusRealtime;
float64_t wrapVolt;
float64_t measuredCurrent;
float64_t internalVoltage;
nai_da_data_type_t opmode;
nai_da_powersupply_ctrl_t psEnable;
bool_t floatModeEnabled = FALSE;
char* sVoltPolarity;
char* sCurrPolarity;
char* sPsEnable;
char* sOutputEnable;
float64_t fpOffset = 0.0;
float64_t fpScale = 0.0;
float64_t extPowerVPos = 0.0;
float64_t extPowerVNeg = 0.0;
bool_t bridgeEnable = FALSE;
char* sBridgeEnable;
printf( "\n\nDA Standard Operations Data:\n\n" );
if ( generation == NAI_XILINX_GEN5_ID )
{
if ( damodid == NAI_MODULE_ID_DA5 )
{
printf( " External External Wrap Wrap BIT Overcurrent Summary Floating Floating\n" );
printf( " Power Power Voltage Current Output Bridge Status Status Status Point Point \n" );
printf( "Ch Data (+) (-) (V) (mA) Enable Enable (L/R) (L/R) (L/R) Offset Scale \n" );
printf( "----------------------------------------------------------------------------------------------------------------------------------\n" );
for ( chan = 1; chan <= maxchan; chan++ )
{
check_status( naibrd_DA_GetData( cardIndex, module, chan, NAI_DA_DATA_VOLTAGE, &data ) );
check_status( naibrd_DA_GetExtPowerMeasurement( cardIndex, module, chan, NAI_DA_EXTPWR_MEAS_POSITIVE_VOLTAGE, &extPowerVPos ) );
check_status( naibrd_DA_GetExtPowerMeasurement( cardIndex, module, chan, NAI_DA_EXTPWR_MEAS_POSITIVE_VOLTAGE, &extPowerVNeg ) );
check_status( naibrd_DA_GetWrapVoltage( cardIndex, module, chan, &wrapVolt ) );
check_status( naibrd_DA_GetCurrentMeasurement( cardIndex, module, chan, &measuredCurrent ) );
check_status( naibrd_DA_GetOutputEnable( cardIndex, module, chan, &outputEnable ) );
switch ( outputEnable )
{
case NAI_DA_ENABLE_OUTPUT:
sOutputEnable = "ENABLED ";
break;
case NAI_DA_DISABLE_OUTPUT:
sOutputEnable = "DISABLED";
break;
default:
sOutputEnable = " ERROR ";
break;
}
check_status(naibrd_DA_GetFullBridgeMode(cardIndex, module, chan, &bridgeEnable));
switch ( bridgeEnable )
{
case NAI_DA_ENABLE_OUTPUT:
sBridgeEnable = "ENABLED ";
break;
case NAI_DA_DISABLE_OUTPUT:
sBridgeEnable = "DISABLED";
break;
default:
sBridgeEnable = " ERROR ";
break;
}
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_LATCHED, &bitStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_REALTIME, &bitStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_LATCHED, &overCurrentStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_REALTIME, &overCurrentStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_LATCHED, &summaryStatusLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_REALTIME, &summaryStatusRealtime ) );
check_status( naibrd_DA_GetFloatingPointOffset( cardIndex, module, chan, &fpOffset) );
check_status( naibrd_DA_GetFloatingPointScaleFactor( cardIndex, module, chan, &fpScale) );
printf( "%2d %7.3f %7.3f %7.3f %7.3f %7.3f %s %s (%1d/%1d) (%1d/%1d) (%1d/%1d) %7.3f %7.3f\n",
chan, data, extPowerVPos, extPowerVNeg, wrapVolt, measuredCurrent, sOutputEnable, sBridgeEnable, bitStatLatched, bitStatRealtime,
overCurrentStatLatched, overCurrentStatRealtime, summaryStatusLatched, summaryStatusRealtime, fpOffset, fpScale );
}
check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &floatModeEnabled));
if (floatModeEnabled)
{
printf("\nHardware Floating-Point Conversion Mode: ENABLED");
}
else
{
printf("\nHardware Floating-Point Conversion Mode: DISABLED");
}
check_status( naibrd_DA_GetPowerSupplyEnable( cardIndex, module, &psEnable ) );
switch ( psEnable )
{
case NAI_DA_POWERSUPPLY_CTRL_DISABLE:
sPsEnable = "Disabled";
break;
case NAI_DA_POWERSUPPLY_CTRL_ENABLE:
sPsEnable = "Enabled";
break;
default:
sPsEnable = "in an error state";
break;
}
printf( "\nModule power supply is %s.", sPsEnable );
}
else if ( (damodid == NAI_MODULE_ID_DA1) || (damodid == NAI_MODULE_ID_DA3) )
{
check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &floatModeEnabled));
if (damodid == NAI_MODULE_ID_DA3)
{
printf( " Voltage Current Wrap Wrap Power BIT Overcurrent Summary Floating Floating\n" );
printf( " Range Voltage Range Current Op Voltage Current Supply Status Status Status Point Point \n" );
printf( "Ch Data (V) Polarity (mA) Polarity Mode (V) (mA) State (L/R) (L/R) (L/R) Offset Scale \n" );
printf( "------------------------------------------------------------------------------------------------------------------------------------------------------\n" );
}
else
{
printf( " Voltage Current Wrap Wrap BIT Overcurrent Summary Floating Floating\n" );
printf( " Range Voltage Range Current Op Voltage Current Status Status Status Point Point \n" );
printf( "Ch Data (V) Polarity (mA) Polarity Mode (V) (mA) (L/R) (L/R) (L/R) Offset Scale \n" );
printf( "-------------------------------------------------------------------------------------------------------------------------------------------\n" );
}
for ( chan = 1; chan <= maxchan; chan++ )
{
check_status( naibrd_DA_GetOpMode( cardIndex, module, chan, &opmode ) );
check_status( naibrd_DA_GetData( cardIndex, module, chan, opmode, &data ) );
check_status( naibrd_DA_GetRange( cardIndex, module, chan, NAI_DA_DATA_VOLTAGE, &voltPolarity, &voltRange ) );
switch ( voltPolarity )
{
case NAI_DA_GEN5_RANGE_MODE_UNIPOLAR:
sVoltPolarity = "UNIPOLAR";
break;
case NAI_DA_GEN5_RANGE_MODE_BIPOLAR:
sVoltPolarity = "BIPOLAR ";
break;
default:
sVoltPolarity = " ERROR ";
break;
}
check_status( naibrd_DA_GetRange( cardIndex, module, chan, NAI_DA_DATA_CURRENT, &currPolarity, &currRange ) );
switch ( currPolarity )
{
case NAI_DA_GEN5_RANGE_MODE_UNIPOLAR:
sCurrPolarity = "UNIPOLAR";
break;
case NAI_DA_GEN5_RANGE_MODE_BIPOLAR:
sCurrPolarity = "BIPOLAR ";
break;
default:
sCurrPolarity = " ERROR ";
break;
}
check_status( naibrd_DA_GetWrapVoltage( cardIndex, module, chan, &wrapVolt ) );
check_status( naibrd_DA_GetCurrentMeasurement( cardIndex, module, chan, &measuredCurrent ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_LATCHED, &bitStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_REALTIME, &bitStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_LATCHED, &overCurrentStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_REALTIME, &overCurrentStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_LATCHED, &summaryStatusLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_REALTIME, &summaryStatusRealtime ) );
check_status( naibrd_DA_GetChannelPowerSupplyEnable( cardIndex, module, chan, &psEnable ) );
check_status( naibrd_DA_GetFloatingPointOffset( cardIndex, module, chan, &fpOffset) );
check_status( naibrd_DA_GetFloatingPointScaleFactor( cardIndex, module, chan, &fpScale) );
if (damodid == NAI_MODULE_ID_DA3)
{
switch ( psEnable )
{
case NAI_DA_POWERSUPPLY_CTRL_DISABLE:
sPsEnable = "DISABLED";
break;
case NAI_DA_POWERSUPPLY_CTRL_ENABLE:
sPsEnable = "ENABLED ";
break;
default:
sPsEnable = " ERROR ";
break;
}
}
else
{
sPsEnable = "\b\b\b";
}
if ( opmode == NAI_DA_DATA_CURRENT )
{
printf( "%2d %7.3f mA %7.3f %s %7.3f %s CURRENT %10.3f %9.3f %s (%1d/%1d) (%1d/%1d) (%1d/%1d) %7.3f %7.3f\n",
chan, data, voltRange, sVoltPolarity, currRange, sCurrPolarity, wrapVolt, measuredCurrent, sPsEnable, bitStatLatched,
bitStatRealtime, overCurrentStatLatched, overCurrentStatRealtime, summaryStatusLatched, summaryStatusRealtime,
fpOffset, fpScale);
}
else
{
printf( "%2d %7.3f V %7.3f %s %7.3f %s VOLTAGE %10.3f %9.3f %s (%1d/%1d) (%1d/%1d) (%1d/%1d) %7.3f %7.3f\n",
chan, data, voltRange, sVoltPolarity, currRange, sCurrPolarity, wrapVolt, measuredCurrent, sPsEnable, bitStatLatched,
bitStatRealtime, overCurrentStatLatched, overCurrentStatRealtime, summaryStatusLatched, summaryStatusRealtime,
fpOffset, fpScale);
}
}
if (damodid == NAI_MODULE_ID_DA1)
{
check_status( naibrd_DA_GetPowerSupplyEnable( cardIndex, module, &psEnable ) );
switch ( psEnable )
{
case NAI_DA_POWERSUPPLY_CTRL_DISABLE:
sPsEnable = "Disabled";
break;
case NAI_DA_POWERSUPPLY_CTRL_ENABLE:
sPsEnable = "Enabled";
break;
default:
sPsEnable = "in an error state";
break;
}
printf( "\nModule power supply is %s.", sPsEnable );
}
if (floatModeEnabled)
{
printf("\nHardware Floating-Point Conversion Mode: ENABLED\n");
}
else
{
printf("\nHardware Floating-Point Conversion Mode: DISABLED\n");
}
}
else if ( damodid == NAI_MODULE_ID_DA2 )
{
check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &floatModeEnabled));
printf( " Voltage Wrap Wrap Internal BIT Overcurrent Summary Floating Floating\n" );
printf( " Range Voltage Voltage Current Output Voltage Status Status Status Point Point \n" );
printf( "Ch Data (V) Polarity (V) (mA) Enable (V) (L/R) (L/R) (L/R) Offset Scale \n" );
printf( "----------------------------------------------------------------------------------------------------------------------------------\n" );
for ( chan = 1; chan <= maxchan; chan++ )
{
check_status( naibrd_DA_GetData( cardIndex, module, chan, NAI_DA_DATA_VOLTAGE, &data ) );
check_status( naibrd_DA_GetRange( cardIndex, module, chan, NAI_DA_DATA_VOLTAGE, &voltPolarity, &voltRange ) );
switch ( voltPolarity )
{
case NAI_DA_GEN5_RANGE_MODE_UNIPOLAR:
sVoltPolarity = "UNIPOLAR";
break;
case NAI_DA_GEN5_RANGE_MODE_BIPOLAR:
sVoltPolarity = "BIPOLAR ";
break;
default:
sVoltPolarity = " ERROR ";
break;
}
check_status( naibrd_DA_GetWrapVoltage( cardIndex, module, chan, &wrapVolt ) );
check_status( naibrd_DA_GetCurrentMeasurement( cardIndex, module, chan, &measuredCurrent ) );
check_status( naibrd_DA_GetOutputEnable( cardIndex, module, chan, &outputEnable ) );
switch ( outputEnable )
{
case NAI_DA_ENABLE_OUTPUT:
sOutputEnable = "ENABLED ";
break;
case NAI_DA_DISABLE_OUTPUT:
sOutputEnable = "DISABLED";
break;
default:
sOutputEnable = " ERROR ";
break;
}
check_status( naibrd_DA_GetInternalVoltage( cardIndex, module, chan, &internalVoltage ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_LATCHED, &bitStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_REALTIME, &bitStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_LATCHED, &overCurrentStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_REALTIME, &overCurrentStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_LATCHED, &summaryStatusLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_SUMMARY_REALTIME, &summaryStatusRealtime ) );
check_status( naibrd_DA_GetFloatingPointOffset( cardIndex, module, chan, &fpOffset) );
check_status( naibrd_DA_GetFloatingPointScaleFactor( cardIndex, module, chan, &fpScale) );
printf( "%2d %7.3f V %7.3f %s %7.3f %7.3f %s %7.3f (%1d/%1d) (%1d/%1d) (%1d/%1d) %7.3f %7.3f\n",
chan, data, voltRange, sVoltPolarity, wrapVolt, measuredCurrent, sOutputEnable, internalVoltage, bitStatLatched, bitStatRealtime,
overCurrentStatLatched, overCurrentStatRealtime, summaryStatusLatched, summaryStatusRealtime, fpOffset, fpScale );
}
if (floatModeEnabled)
{
printf("\nHardware Floating-Point Conversion Mode: ENABLED\n");
}
else
{
printf("\nHardware Floating-Point Conversion Mode: DISABLED\n");
}
}
}
else
{
printf( " Voltage Wrap Wrap BIT Overcurrent\n" );
printf( " Data Range Voltage Voltage Current Status Status \n" );
printf( "Ch (V) (V) Polarity (V) (mA) (L/R) (L/R) \n" );
printf( "-------------------------------------------------------------------\n" );
for ( chan = 1; chan <= maxchan; chan++ )
{
check_status( naibrd_DA_GetData( cardIndex, module, chan, NAI_DA_DATA_VOLTAGE, &data ) );
check_status( naibrd_DA_GetRange( cardIndex, module, chan, NAI_DA_DATA_VOLTAGE, &voltPolarity, &voltRange ) );
switch ( voltPolarity )
{
case NAI_DA_GEN3_RANGE_MODE_UNIPOLAR:
sVoltPolarity = "UNIPOLAR";
break;
case NAI_DA_GEN3_RANGE_MODE_BIPOLAR:
sVoltPolarity = "BIPOLAR ";
break;
default:
sVoltPolarity = " ERROR ";
break;
}
check_status( naibrd_DA_GetWrapVoltage( cardIndex, module, chan, &wrapVolt ) );
check_status( naibrd_DA_GetCurrentMeasurement( cardIndex, module, chan, &measuredCurrent ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_LATCHED, &bitStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_BIT_REALTIME, &bitStatRealtime ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_LATCHED, &overCurrentStatLatched ) );
check_status( naibrd_DA_GetStatus( cardIndex, module, chan, NAI_DA_STATUS_OVERCURRENT_REALTIME, &overCurrentStatRealtime ) );
printf( "%2d %7.3f %7.3f %s %7.3f %7.3f (%1d/%1d) (%1d/%1d)\n", chan, data, voltRange, sVoltPolarity, wrapVolt, measuredCurrent, bitStatLatched, bitStatRealtime, overCurrentStatLatched, overCurrentStatRealtime );
}
}
}
static nai_status_t Handle_DA_SetD3TestEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
p_naiapp_AppParameters_t da_basicops_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = da_basicops_params->cardIndex;
int32_t module = da_basicops_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Enable or Disable D3 Test (0 for disable, 1 for enable): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
switch (inputBuffer[0])
{
case '0':
check_status(naibrd_DA_SetModuleBITEnable(cardIndex, module, NAI_DA_D3_TEST, (bool_t)FALSE));
break;
case '1':
check_status(naibrd_DA_SetModuleBITEnable(cardIndex, module, NAI_DA_D3_TEST, (bool_t)TRUE));
break;
default:
printf("\nInvalid selection entered\n");
break;
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Handle_DA_WatchdogShowMenu(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
uint32_t ModuleID = 0u;
int32_t cmd = 0;
int32_t numMenuCmds = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t p_da_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_da_params->cardIndex;
int32_t module = p_da_params->module;
int32_t chan = p_da_params->channel;
ModuleID = naibrd_GetModuleID(cardIndex, module);
numMenuCmds = DA_WD_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DA_WatchdogOpMenuCmds);
while (bContinue)
{
Handle_DA_DisplayWatchdog(cardIndex, module, chan);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_WD_PGM_NAME);
printf("\nType DA Watchdog command or %c to quit : main > watchdog >", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((inputBuffer[0] == 'B') || (inputBuffer[0] == 'b'))
{
bContinue = FALSE;
}
else
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
DA_WatchdogOpMenuCmds[cmd].func(paramCount, p_params);
}
else
{
printf("\nInvalid command entered\n");
}
}
}
}
else
bContinue = FALSE;
}
switch (ModuleID)
{
case NAI_MODULE_ID_F1:
case NAI_MODULE_ID_F3:
case NAI_MODULE_ID_F5:
case NAI_MODULE_ID_J3:
case NAI_MODULE_ID_J5:
case NAI_MODULE_ID_J8:
naiapp_utils_LoadParamMenuCommands(DA_GEN3_STANDARDOP_CMD_COUNT, DA_Gen3_StandardOpMenuCmds);
break;
case NAI_MODULE_ID_DA1:
case NAI_MODULE_ID_DA3:
naiapp_utils_LoadParamMenuCommands(DA_GEN5_DA1_DA3_STANDARDOP_CMD_COUNT, DA_Gen5_DA1_DA3_StandardOpMenuCmds);
break;
case NAI_MODULE_ID_DA2:
naiapp_utils_LoadParamMenuCommands(DA_GEN5_DA2_STANDARDOP_CMD_COUNT, DA_Gen5_DA2_StandardOpMenuCmds);
break;
case NAI_MODULE_ID_DA5:
naiapp_utils_LoadParamMenuCommands(DA_GEN5_DA5_STANDARDOP_CMD_COUNT, DA_Gen5_DA5_StandardOpMenuCmds);
break;
default:
printf("Module ID: %u not supported!\n", ModuleID);
break;
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Handle_DA_WatchDogQuietTime(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t quietTime = 0u;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t p_da_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_da_params->cardIndex;
int32_t module = p_da_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\r\n*** To use this sample strobe it is recommended to set a quiet time > 500 ms **");
printf("\r\nEnter the desired Watchdog Quiet Time (ms): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (inputBuffer[0] == '-')
{
printf("\nInvalid value entered\n");
}
else
{
quietTime = atoi((const char *)inputBuffer);
if (quietTime == 0u)
{
if (inputBuffer[0] == '0')
{
check_status(naibrd_DA_SetWatchdogQuietTime(cardIndex, module, quietTime * 1000));
}
else
{
printf("\nInvalid value entered\n");
}
}
else
{
check_status(naibrd_DA_SetWatchdogQuietTime(cardIndex, module, quietTime * 1000));
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static nai_status_t Handle_DA_WatchDogWindowTime(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t windowTime = 0u;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t p_da_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_da_params->cardIndex;
int32_t module = p_da_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\r\n*** To use this sample strobe it is recommended to set a window time > 500 ms **");
printf("\r\nEnter the desired Watchdog Window Time (ms): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (inputBuffer[0] == '-')
{
printf("\nInvalid value entered\n");
}
else
{
windowTime = atoi((const char *)inputBuffer);
if (windowTime == 0u)
{
if (inputBuffer[0] == '0')
{
check_status(naibrd_DA_SetWatchdogWindow(cardIndex, module, windowTime * 1000));
}
else
{
printf("\nInvalid value entered\n");
}
}
else
{
check_status(naibrd_DA_SetWatchdogWindow(cardIndex, module, windowTime * 1000));
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static bool_t Handle_DA_DisplayWatchdog(int32_t cardIndex, int32_t module, int32_t chan)
{
nai_status_bit_t wdStatLatched = 0u;
nai_status_bit_t wdStatRT = 0u;
uint32_t windowTime = 0u;
uint32_t quietTime = 0u;
printf("\n\nDA Watchdog Data:\n");
check_status(naibrd_DA_GetWatchdogQuietTime(cardIndex, module, &quietTime));
quietTime = quietTime / 1000;
printf("Quiet Time: %d mS\n", quietTime);
check_status(naibrd_DA_GetWatchdogWindow(cardIndex, module, &windowTime));
windowTime = windowTime / 1000;
printf("Window Time: %d mS\n", windowTime);
check_status(naibrd_DA_GetStatus(cardIndex, module, chan, NAI_DA_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &wdStatLatched));
check_status(naibrd_DA_GetStatus(cardIndex, module, chan, NAI_DA_STATUS_WATCHDOG_TIMER_FAULT_REALTIME, &wdStatRT));
printf("WatchDog Status (R/L): (%1d/%1d)\n", wdStatRT, wdStatLatched);
printf("\n");
return 0u;
}
static nai_status_t Handle_DA_StrobeWatchdog(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int32_t* arg = (int32_t*)malloc(sizeof(int32_t) * 3);
int8_t inputBuffer[80];
int32_t inputResponseCnt;
p_naiapp_AppParameters_t p_da_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_da_params->cardIndex;
int32_t module = p_da_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\r\n**NOTE: When this thread/application exits, the module will shut off all outputs and will need to be power cycled in order to be operational **");
printf("\r\nEnter Y if you want to continue and N to go back: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((inputBuffer[0] == 'Y') || (inputBuffer[0] == 'y'))
{
printf("\r\nStrobing Watchdog every (QuietTime) + (Window)/2...");
printf("\r\nStarting thread...");
/* Spawn thread here */
arg[0] = cardIndex;
arg[1] = module;
#if defined (__VXWORKS__)
if (thread == 0)
#elif defined (LINUX)
if (thread == (pthread_t)NULL)
#else
if (thread == (int32_t*)NULL)
#endif
{
#if defined (WIN32)
LPDWORD threadID = 0;
thread = CreateThread(NULL, 0, WD_Strobe_ThreadEntryPoint, arg, 0, threadID);
#elif defined (LINUX)
pthread_create(&thread, NULL, WD_Strobe_ThreadEntryPoint, arg);
#elif defined (__VXWORKS__)
thread = taskSpawn("WD_Strobe_Thread", 100, 0, 10000, (FUNCPTR)WD_Strobe_ThreadEntryPoint, (int32_t)arg, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
#error Unsupported OS
#endif
if (thread != 0) {}
else
{
free(arg);
printf("\nFailed to Create Thread");
}
}
else
{
#if defined (WIN32)
LPDWORD threadID = 0;
#endif
/* kill previous thread and create new one. Report this to them. */
naiapp_kill_WDStrobe_Thread();
#if defined (WIN32)
thread = CreateThread(NULL, 0, WD_Strobe_ThreadEntryPoint, arg, 0, threadID);
#elif defined (LINUX)
pthread_create(&thread, NULL, WD_Strobe_ThreadEntryPoint, arg);
#elif defined (__VXWORKS__)
thread = taskSpawn("WD_Strobe_Thread", 100, 0, 10000, (FUNCPTR)WD_Strobe_ThreadEntryPoint, (int32_t)arg, 0, 0, 0, 0, 0, 0, 0, 0, 0);
#else
#error Unsupported OS
#endif
#if defined (__VXWORKS__)
if (thread != 0) {}
#elif defined (LINUX)
if (thread != (pthread_t)NULL) {}
#else
if (thread != (int32_t*)NULL) {}
#endif
else
{
free(arg);
printf("\nFailed to Create Thread");
}
}
}
else
{
printf("\r\nReturning to Menu...");
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
static void naiapp_kill_WDStrobe_Thread()
{
#if defined (__VXWORKS__)
if (thread != 0)
{
terminateThread = TRUE;
thread = 0;
}
#elif defined (LINUX)
if (thread != ((pthread_t)NULL))
{
terminateThread = TRUE;
thread = ((pthread_t)NULL);
}
#else
if (thread != ((int32_t*)NULL))
{
terminateThread = TRUE;
thread = ((int32_t*)NULL);
}
#endif
}
#if defined (WIN32)
DWORD WINAPI WD_Strobe_ThreadEntryPoint(LPVOID param)
#elif defined (LINUX)
void* WD_Strobe_ThreadEntryPoint(void* param)
#elif defined (__VXWORKS__)
static int WD_Strobe_ThreadEntryPoint(int32_t param)
#else
#error Unsupported OS
#endif
{
uint32_t windowTime = 0u;
uint32_t quietTime = 0u;
int32_t delayTime = 0;
int32_t* modInfo = (int32_t*)param;
int32_t cardIndex = modInfo[0];
int32_t module = modInfo[1];
terminateThread = FALSE;
free(modInfo);
check_status(naibrd_DA_GetWatchdogQuietTime(cardIndex, module, &quietTime));
check_status(naibrd_DA_GetWatchdogWindow(cardIndex, module, &windowTime));
quietTime = quietTime / 1000;
windowTime = windowTime / 1000;
delayTime = quietTime + (windowTime / 2);
check_status(naibrd_DA_WatchdogStrobe(cardIndex, module));
do
{
nai_msDelay(delayTime);
check_status(naibrd_DA_WatchdogStrobe(cardIndex, module));
} while (!terminateThread);
return NAI_SUCCESS;
}
static nai_status_t Handle_DA_kill_WDStrobe_Thread(int32_t paramCount, int32_t* p_params)
{
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
UNREFERENCED_PARAMETER(p_params);
#endif
naiapp_kill_WDStrobe_Thread();
return NAI_SUCCESS;
}