DT BasicOps
Edit this on GitLab
DT BasicOps
Explanation
About the Sample Application Code
This sample application code, written in C, interacts with North Atlantic Industries' (NAI) embedded function modules using the NAI System Software Kit (SSK). It showcases various functionalities to configure, control, and monitor discrete I/O modules. Below is an explanation of the code and its components.
File Inclusions and Definitions
-
Standard Library Headers:
-
#include <stdio.h>
: Standard I/O operations. -
#include <stdlib.h>
: Standard library functions like memory allocation, process control, etc. -
#include <string.h>
: String manipulation functions. -
#include <time.h>, <ctype.h>
: Time and character-handling functions. -
#if defined (LINUX)
: Conditional inclusion for threading on Linux systems.
-
-
NAI Application-Specific Headers:
These headers provide utility functions and structures for menu access, querying, displaying, and other utilities related to the NAI boards.c #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"
-
NAI Board Management Headers:
These headers include lower-level functions to interact with NAI boards and discrete I/O module functions.c #include "nai.h" #include "naibrd.h" #include "functions/naibrd_dt.h" #include "advanced/nai_ether_adv.h"
Constants and Prototypes
-
CONFIG_FILE: Path to the default configuration file used for module operations.
c static const int8_t *CONFIG_FILE = (const int8_t *)"default_DT_BasicOps.txt";
-
Function Prototypes: Prototypes and definitions of all the functions used in the program.
Enumerations and Structures
-
Enumerations for Command Table: These enums define command identifiers used in the application.
```c enum dt_basicops_commands { ... }; enum dt_watchdog_commands { ... }; enum dt_module_power_reset_commands { ... }; ```
-
Command Table Initialization: Structures for command mappings to their respective handler functions.
```c naiapp_cmdtbl_params_t DT_BasicOpMenuCmds[] = { ... }; naiapp_cmdtbl_params_t DT_WatchdogOpMenuCmds[DT_WD_CMD_COUNT] = { ... }; naiapp_cmdtbl_params_t DT_ModulePowerResetMenuCmds[DT_MODULE_POWER_RESET_CMD_COUNT] = { ... }; ```
Main Function
The main function initializes the application by querying the user for a card index and module number. It then enters a loop to display and execute commands for the selected module until the user quits.
#if defined (__VXWORKS__)
int32_t DT_BasicOps(void) { ... }
#else
int32_t main(void) { ... }
#endif
Function Breakdown
-
Run_DT_BasicOps: This function verifies the module and runs the basic operations if the module is valid.
c int32_t Run_DT_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID) { … }
-
Cfg_DT_Channel: Handles discrete channel configuration by displaying channel configurations and processing user commands.
c static void Cfg_DT_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel) { … }
-
Display_DT_ChannelCfg: Displays configuration and status of a selected channel.
c static void Display_DT_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID) { … }
-
Display_DT_Status: Retrieves and displays status information for a given channel.
c static nai_status_t Display_DT_Status(int32_t paramCount, int32_t* p_params) { … }
-
Configuration Handlers: Functions to configure various parameters such as IO format, output state, thresholds, status enables, etc.
c static nai_status_t Configure_DT_IOFormat(int32_t paramCount, int32_t* p_params) { … } static nai_status_t Configure_DT_OutputState(int32_t paramCount, int32_t* p_params) { … } …
-
Watchdog Handlers: Manage watchdog timer operations including quiet time and window time configuration, and triggering watchdog strobing.
c static nai_status_t Handle_DT_WatchdogShowMenu(int32_t paramCount, int32_t* p_params) { … } static nai_status_t Handle_DT_WatchDogQuietTime(int32_t paramCount, int32_t* p_params) { … } …
-
Module Power Reset Handlers: Manage module power reset operations such as setting/resetting power states and clearing statuses.
c static nai_status_t Handle_DT_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params) { … } static nai_status_t Handle_DT_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params) { … } …
Thread Management
For watchdog operations requiring a running thread to continuously strobe the watchdog, threads are managed using platform-specific implementations for Windows, Linux, and VXWorks.
#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
The application provides a comprehensive setup for interacting with NAI discrete modules, allowing for configuration, control, and status monitoring. The use of modular functions and platform-specific adjustments ensures compatibility across different operating systems.
#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 "nai.h"
#include "naibrd.h"
#include "functions/naibrd_dt.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (const int8_t *)"default_DT_BasicOps.txt";
/* Function prototypes */
int32_t Run_DT_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID);
static void Cfg_DT_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_DT_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Display_DT_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_IOFormat(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_OutputState(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_ChanStatusEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_FloatingPointEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_ClearAllStatuses(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_MinLoThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_LowThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_UpperThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_MaxHiThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_Threshold(int32_t cardIndex, int32_t module, int32_t chan, nai_dt_thresh_type_t thresholdtype, int8_t* thresholdtext);
static nai_status_t Configure_DT_BITErrorThreshold(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_CheckPBITComplete(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_ClearModuleBITLogic(int32_t paramCount, int32_t* p_params);
static bool_t configurable_DT_IOFormat(uint32_t ModuleID, int32_t chan);
static bool_t configurable_DT_Output(uint32_t ModuleID, int32_t chan);
static nai_status_t Handle_DT_WatchdogShowMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DT_WatchDogQuietTime(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DT_WatchDogWindowTime(int32_t paramCount, int32_t* p_params);
static bool_t Handle_DT_DisplayWatchdog(int32_t cardIndex, int32_t module, int32_t chan);
static nai_status_t Handle_DT_StrobeWatchdog(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DT_kill_WDStrobe_Thread(int32_t paramCount, int32_t* p_params);
static void naiapp_kill_WDStrobe_Thread();
static nai_status_t Handle_DT_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DT_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_DT_SetModulePowerReset(int32_t paramCount, int32_t* p_params);
static const int32_t DEF_DT_CHANNEL = 1;
static const int32_t DEF_DT_KA_CHANNEL = 13;
static const int8_t *SAMPLE_WD_PGM_NAME = (const int8_t*)"DT Watchdog Operations";
static const int8_t *SAMPLE_MODULE_POWER_RESET_PGM_NAME = (const int8_t*)"DT Module Power Reset Menu";
static bool_t terminateThread;
#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
/****** Command Table *******/
enum dt_basicops_commands
{
DT_BASICOP_CMD_IOFORMAT,
DT_BASICOP_CMD_OUTPUTSTATE,
DT_BASICOP_CMD_CLEAR_ALL_STATUSES,
DT_BASICOP_CMD_THRESHOLD_MIN_LO,
DT_BASICOP_CMD_THRESHOLD_LOWER,
DT_BASICOP_CMD_THRESHOLD_UPPER,
DT_BASICOP_CMD_THRESHOLD_MAX_HI,
DT_BASICOP_CMD_RESET_OC,
DT_BASICOP_CMD_STATUS,
DT_BASICOP_CMD_FLOATING_POINT_MODE_ENABLE,
DT_BASICOP_CMD_SET_BIT_ERROR_THRESHOLD,
DT_BASICOP_CMD_CHAN_STATUS_ENABLE,
DT_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE,
DT_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC,
DT_BASICOP_CMD_WATCHDOG_MENU,
DT_BASICOP_CMD_MODULE_POWER_RESET,
DT_BASICOP_CMD_COUNT
};
enum dt_watchdog_commands
{
DT_WD_CMD_QUIETTIME,
DT_WD_CMD_WINDOWTIME,
DT_WD_CMD_STROBE,
DT_WD_CMD_KILL,
DT_WD_CMD_BACK,
DT_WD_CMD_COUNT
};
enum dt_module_power_reset_commands
{
DT_MODULE_POWER_RESET_CMD_BACK,
DT_MODULE_POWER_RESET_CMD_CLEAR_MODULE_POWER_RESET_STATUS,
DT_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET,
DT_MODULE_POWER_RESET_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DT_BasicOpMenuCmds[] = {
{"IO", "DT Set IO Format", DT_BASICOP_CMD_IOFORMAT, Configure_DT_IOFormat},
{"OUT", "DT Set Output State", DT_BASICOP_CMD_OUTPUTSTATE, Configure_DT_OutputState},
{"Clear", "DT Clear All Latched Statuses", DT_BASICOP_CMD_CLEAR_ALL_STATUSES, Configure_DT_ClearAllStatuses},
{"ML", "DT Set Min Low Threshold", DT_BASICOP_CMD_THRESHOLD_MIN_LO, Configure_DT_MinLoThreshold},
{"L", "DT Set Lower Threshold", DT_BASICOP_CMD_THRESHOLD_LOWER, Configure_DT_LowThreshold},
{"U", "DT Set Upper Threshold", DT_BASICOP_CMD_THRESHOLD_UPPER, Configure_DT_UpperThreshold},
{"MH", "DT Set Max High Threshold", DT_BASICOP_CMD_THRESHOLD_MAX_HI, Configure_DT_MaxHiThreshold},
{"Over", "DT Reset Overcurrent", DT_BASICOP_CMD_RESET_OC, NULL},
{"STAT", "DT Display Status", DT_BASICOP_CMD_STATUS, Display_DT_Status},
{"Float", "DT Enable/Disable Floating-Point Mode", DT_BASICOP_CMD_FLOATING_POINT_MODE_ENABLE, Configure_DT_FloatingPointEnable},
{"Thres", "DT Set Module BIT Error Threshold", DT_BASICOP_CMD_SET_BIT_ERROR_THRESHOLD, Configure_DT_BITErrorThreshold},
{"Enable", "DT Enable/Disable Channel Status Reporting", DT_BASICOP_CMD_CHAN_STATUS_ENABLE, Configure_DT_ChanStatusEnable},
{"Power", "DT Check Power-On BIT Completed", DT_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE, Configure_DT_CheckPBITComplete},
{"BIT", "DT Clear Module BIT Logic", DT_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC, Configure_DT_ClearModuleBITLogic},
{"WDT", "Show Watchdog Menu Options", DT_BASICOP_CMD_WATCHDOG_MENU, Handle_DT_WatchdogShowMenu},
{"Reset", "Show Module Power Reset Menu Options", DT_BASICOP_CMD_MODULE_POWER_RESET, Handle_DT_ModulePowerResetMenu}
};
naiapp_cmdtbl_params_t DT_WatchdogOpMenuCmds[DT_WD_CMD_COUNT] =
{
{"BACK", "Back to Main Menu", DT_WD_CMD_BACK, NULL},
{"TIME QUIET", "Set Watchdog Quiet Time", DT_WD_CMD_QUIETTIME, Handle_DT_WatchDogQuietTime},
{"WINDOW", "Set Watchdog Window Time", DT_WD_CMD_WINDOWTIME, Handle_DT_WatchDogWindowTime},
{"STROBE", "Start thread to continuously strobe watchdog", DT_WD_CMD_STROBE, Handle_DT_StrobeWatchdog},
{"KILL", "Kill Watchdog strobing thread", DT_WD_CMD_KILL, Handle_DT_kill_WDStrobe_Thread}
};
naiapp_cmdtbl_params_t DT_ModulePowerResetMenuCmds[DT_MODULE_POWER_RESET_CMD_COUNT] =
{
{"BACK", "Back to Main Menu", DT_MODULE_POWER_RESET_CMD_BACK, NULL},
{"CLEAR", "Clear Module Power Reset Status", DT_MODULE_POWER_RESET_CMD_CLEAR_MODULE_POWER_RESET_STATUS, Handle_DT_ClearModulePowerResetStatus},
{"SET", "Set Module Power Reset Request", DT_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET, Handle_DT_SetModulePowerReset}
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DT_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
operations with the discrete modules for configuration setup, controlling the drive outputs, and reading
the channels.
The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd DT routines.
- ClearDeviceCfg
- QuerySystemCfg
- DisplayDeviceCfg
- GetBoardSNModCfg
- SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DT_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_DT_BasicOps(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/**************************************************************************************************************/
/**
<summary>
Run_DT_BasicOps prompts the user for the card, module and channel to use for the application and calls
Cfg_DT_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
int32_t Run_DT_BasicOps(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
int32_t MaxChannel;
MaxChannel = naibrd_DT_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
printf(" *** Module selection not recognized as DSW module. ***\n\n");
}
else
{
Cfg_DT_Channel(cardIndex, module, ModuleID, MaxChannel);
}
return cardIndex;
}
/**************************************************************************************************************/
/**
<summary>
Cfg_DT_Channel handles calling the Display_DT_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_DT_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t chan, defaultchan = 1;
nai_status_t status = (nai_status_t)0;
int32_t cmd;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_AppParameters_t dt_params;
p_naiapp_AppParameters_t dt_basicops_params = &dt_params;
dt_basicops_params->cardIndex = cardIndex;
dt_basicops_params->module = module;
dt_basicops_params->modId = ModuleID;
while (bContinue)
{
printf(" \r\n\r\n");
printf("Channel selection \r\n");
printf("================= \r\n");
if (ModuleID == NAI_MODULE_ID_KA)
{
printf("\n For KA modules, only Channels 13-16 are configurable.");
printf("\n Ch.01-12 are output only, Ch.17-28 are input only. \n");
defaultchan = DEF_DT_KA_CHANNEL;
}
else
defaultchan = DEF_DT_CHANNEL;
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
dt_basicops_params->channel = chan;
naiapp_utils_LoadParamMenuCommands(DT_BASICOP_CMD_COUNT, DT_BasicOpMenuCmds);
while (bContinue)
{
Display_DT_ChannelCfg(cardIndex, module, chan, ModuleID);
naiapp_display_ParamMenuCommands((int8_t *)"DT Basic Operation Menu");
printf("\nType DT command or %c to quit : main >", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case DT_BASICOP_CMD_IOFORMAT:
case DT_BASICOP_CMD_OUTPUTSTATE:
case DT_BASICOP_CMD_CLEAR_ALL_STATUSES:
case DT_BASICOP_CMD_THRESHOLD_MIN_LO:
case DT_BASICOP_CMD_THRESHOLD_LOWER:
case DT_BASICOP_CMD_THRESHOLD_UPPER:
case DT_BASICOP_CMD_THRESHOLD_MAX_HI:
case DT_BASICOP_CMD_STATUS:
case DT_BASICOP_CMD_FLOATING_POINT_MODE_ENABLE:
case DT_BASICOP_CMD_SET_BIT_ERROR_THRESHOLD:
case DT_BASICOP_CMD_CHAN_STATUS_ENABLE:
case DT_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE:
case DT_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC:
case DT_BASICOP_CMD_WATCHDOG_MENU:
case DT_BASICOP_CMD_MODULE_POWER_RESET:
DT_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dt_basicops_params);
break;
case DT_BASICOP_CMD_RESET_OC:
status = check_status(naibrd_DT_ResetAll(cardIndex, module, NAI_DT_RESET_OVERCURRENT)); /*This resets all channels*/
status = check_status(naibrd_DT_Reset(cardIndex, module, 1, NAI_DT_RESET_OVERCURRENT)); /*This alternate function resets channel 1 only on Gen5 modules. */
if (status == NAI_SUCCESS)
printf("Reset completed. \n\n");
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
}
/**************************************************************************************************************/
/**
<summary>
Display_DT_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DT_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
bool_t chanStatusEnabled = FALSE;
bool_t floatModeEnabled = FALSE;
bool_t pBITComplete = FALSE;
uint32_t bitErrThres = 0u;
uint32_t ioformat = 0;
nai_dt_state_t outputstate = 0;
nai_dt_state_t inputstate = 0;
float64_t minlo= 0.0, lower = 0.0, upper = 0.0, maxhi = 0.0, voltage = 0.0, vcc = 0.0, current = 0.0;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
int32_t MaxChannel;
uint32_t bank;
char strChanStatusEnabled[10] = "";
char strFloatModeEnabled[10] = "";
char strPBITComplete[14] = "";
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
if ((ModuleID == NAI_MODULE_ID_KA) && ((chan < 13) || (chan > 16)) )
{
if (chan < 13) /*KA Ch. 1-12 fixed as output channels*/
ioformat = NAI_DT_IOFORMAT_OUTPUT_LOW;
else /*KA Ch. 17-28 fixed as input channels*/
ioformat = NAI_DT_IOFORMAT_INPUT;
}
else
{
check_status(naibrd_DT_GetIOFormat(cardIndex, module, chan, &ioformat));
}
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
check_status(naibrd_DT_GetChanStatusEnable(cardIndex, module, chan, &chanStatusEnabled));
switch (chanStatusEnabled)
{
case (bool_t)TRUE:
sprintf(strChanStatusEnabled, "Enabled ");
break;
case (bool_t)FALSE:
sprintf(strChanStatusEnabled, "Disabled");
break;
default:
sprintf(strChanStatusEnabled, "Unknown ");
break;
}
check_status(naibrd_GetFloatingPointModeEnable(cardIndex, module, &floatModeEnabled));
switch (floatModeEnabled)
{
case (bool_t)TRUE:
sprintf(strFloatModeEnabled, "Enabled ");
break;
case (bool_t)FALSE:
sprintf(strFloatModeEnabled, "Disabled");
break;
default:
sprintf(strFloatModeEnabled, "Unknown ");
break;
}
check_status(naibrd_DT_CheckPowerOnBITComplete(cardIndex, module, &pBITComplete));
switch (pBITComplete)
{
case (bool_t)TRUE:
sprintf(strPBITComplete, "Completed ");
break;
case (bool_t)FALSE:
sprintf(strPBITComplete, "Not Completed");
break;
default:
sprintf(strPBITComplete, "Unknown ");
break;
}
check_status(naibrd_DT_GetModuleBITErrorThreshold(cardIndex, module, &bitErrThres));
}
check_status(naibrd_DT_GetOutputState(cardIndex, module, chan, &outputstate));
check_status(naibrd_DT_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAI_DT_THRESH_MIN_LO, &minlo));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAI_DT_THRESH_LOWER, &lower));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAI_DT_THRESH_UPPER, &upper));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAI_DT_THRESH_MAX_HI, &maxhi));
/* Get the number of VCC banks for the module */
bank = naibrd_DT_GetVCCBankCount(ModuleID);
MaxChannel = naibrd_DT_GetChannelCount(ModuleID);
if (ModuleID != NAI_MODULE_ID_KA)
{
/*read channel voltage and Vcc*/
check_status(naibrd_DT_GetVoltage(cardIndex, module, chan, &voltage));
}
if ((ModuleID == NAI_MODULE_ID_K6) || (ModuleID == NAI_MODULE_ID_K9) || (ModuleID == NAI_MODULE_ID_DT1) ||
(ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
check_status(naibrd_DT_GetBankVccVoltage(cardIndex, module, ((chan-1)/(MaxChannel/bank)+1), &vcc));
/*read current*/
check_status(naibrd_DT_GetCurrent(cardIndex, module, chan, ¤t));
}
printf("\n === Channel %d ===\n\n", chan);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf(" Floating-Point Mode (all channels): %s\n", strFloatModeEnabled);
printf(" Module Power-On BIT Completed (all channels): %s\n", strPBITComplete);
printf(" Module BIT Error Threshold (all channels): %u\n", bitErrThres);
printf(" Channel Status Enable: %s\n\n", strChanStatusEnabled);
}
/*Channel voltage readings available for the following modules : K6 V4 and up, K9, KB, PD+ (not on KA) */
/*Channel current readings not applicable for the following modules: KA, KB, PD */
/*Vcc readings not applicable for the following modules: KA, KB, PD */
if (ModuleID == NAI_MODULE_ID_KA || ModuleID == NAI_MODULE_ID_KB)
{
printf(" IOFormat Output Input MinLow Lower Upper Max Hi\n");
printf(" --------- ------ ----- ------- ------- ------- --------\n");
}
else if (((ModuleID == NAI_MODULE_ID_K6) && (ModuleVer >= 4)) || (ModuleID == NAI_MODULE_ID_K9) || (ModuleID == NAI_MODULE_ID_DT1) ||
(ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf(" IOFormat Output Input MinLow Lower Upper Max Hi Voltage \n");
printf(" --------- ------ ----- ------- ------- -------- -------- ------- \n");
}
switch (ioformat)
{
case NAI_DT_IOFORMAT_INPUT:
printf(" Input ");
break;
case NAI_DT_IOFORMAT_OUTPUT_LOW:
printf(" Low-side ");
break;
case NAI_DT_IOFORMAT_OUTPUT_HIGH:
printf(" High-side");
break;
case NAI_DT_IOFORMAT_OUTPUT_PUSHPULL:
printf(" Push-pull");
break;
default:
printf(" Unknown ");
break;
}
if (ioformat != NAI_DT_IOFORMAT_INPUT)
{
switch (outputstate)
{
case NAI_DT_STATE_LO:
printf(" Low ");
break;
case NAI_DT_STATE_HI:
printf(" High");
break;
/* undefined value read back */
default:
printf(" UNK ");
break;
}
}
else
printf(" --- ");
printf(" %3i ", inputstate);
printf("%+6.1f %+6.1f %+6.1f %+6.1f ", minlo, lower, upper, maxhi);
if (ModuleID != NAI_MODULE_ID_KA)
{
printf("%+6.1f ", voltage);
}
if (((ModuleID == NAI_MODULE_ID_K6) && (ModuleVer >= 4)) || (ModuleID == NAI_MODULE_ID_K9) || (ModuleID == NAI_MODULE_ID_DT1) ||
(ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf("\n\n");
printf("\n VCC Current (mA)\n");
printf("\n ------ ------------\n");
printf("%+6.1f ", vcc);
printf("%+6.1f ", current*1000); /*display in mA*/
}
}
/**************************************************************************************************************/
/**
<summary>
Display_DT_Status illustrate the methods to call in the naibrd library to retrieve the status states.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DT_Status(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
nai_status_bit_t status;
uint32_t ModuleID;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Available status:
NAI_DT_STATUS_BIT,
NAI_DT_STATUS_OVER_CURRENT,
NAI_DT_STATUS_MAX_HI,
NAI_DT_STATUS_MIN_LO,
NAI_DT_STATUS_MID_RANGE,
NAI_DT_STATUS_LO_HI_TRANS,
NAI_DT_STATUS_HI_LO_TRANS,
NAI_DT_STATUS_SUMMARY,
NAI_DT_STATUS_WATCHDOG_TIMER_FAULT,
NAI_DT_STATUS_CRC_FAULT
*/
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf("\n");
printf(" ----------------- Status ----------------------------------------------------------\n");
printf(" MinLo MidRng MaxHi Low-Hi Hi-Lo BIT OC Summary Watchdog Inter-FPGA\n");
printf(" ------- -------- ------ ------- -------- ------ ------ ------- -------- ----------\n");
}
else
{
printf("\n");
printf(" ----------------- Status ----------------------------\n");
printf(" MinLo MidRng MaxHi Low-Hi Hi-Lo BIT OC \n");
printf(" ------- -------- ------ ------- -------- ------ ------\n");
}
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_MIN_LO_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_MID_RANGE_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_MAX_HI_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_LO_HI_TRANS_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_HI_LO_TRANS_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_BIT_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_OVERCURRENT_LATCHED, &status));
printf(" %3i ", status);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_SUMMARY_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_CRC_FAULT_LATCHED, &status));
printf(" %3i ", status);
}
printf("\n\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_IOFormat handles the user request to configure the Input/Output configuration for the selected
channel and calls the method in the naibrd library to set the Input/Output mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_IOFormat(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bUpdateIOCfg = FALSE;
uint32_t state = 0;
int8_t iofmtreq;
uint32_t ModuleID;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int32_t chan = p_dt_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Set I/O format configuration for channel. Available configurations include:
NAI_DT_IOFORMAT_INPUT
NAI_DT_IOFORMAT_OUTPUT_LOW
NAI_DT_IOFORMAT_OUTPUT_HIGH
NAI_DT_IOFORMAT_OUTPUT_PUSHPULL
*/
ModuleID = naibrd_GetModuleID(cardIndex, module);
if (configurable_DT_IOFormat(ModuleID,chan))
{
printf("Type the desired IO configuration ");
if (ModuleID == NAI_MODULE_ID_KA || ModuleID == NAI_MODULE_ID_KB )
printf("(i=input,l=low side output): ");
else
printf("(i=input,l=low side output,h=high side output,p=push-pull output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
iofmtreq = (int8_t)toupper(inputBuffer[0]);
if (iofmtreq == 'I')
{
state = NAI_DT_IOFORMAT_INPUT;
bUpdateIOCfg = TRUE;
}
else if (iofmtreq == 'L')
{
state = NAI_DT_IOFORMAT_OUTPUT_LOW;
bUpdateIOCfg = TRUE;
}
else
{
if (ModuleID == NAI_MODULE_ID_KA || ModuleID == NAI_MODULE_ID_KB )
printf("ERROR: Invalid I/O Format Entry\n");
else if (iofmtreq == 'H')
{
state = NAI_DT_IOFORMAT_OUTPUT_HIGH;
bUpdateIOCfg = TRUE;
}
else if (iofmtreq == 'P')
{
state = NAI_DT_IOFORMAT_OUTPUT_PUSHPULL;
bUpdateIOCfg = TRUE;
}
else
printf("ERROR: Invalid I/O Format Entry\n");
}
}
if (!bQuit)
{
if (bUpdateIOCfg)
check_status(naibrd_DT_SetIOFormat(cardIndex, module, chan, state));
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_OutputState handles the user request to set the Output state for the selected
channel and calls the method in the naibrd library to set the Output state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_OutputState(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
bool_t bQuit = FALSE;
bool_t bUpdateOutput = FALSE;
nai_dt_state_t outputstate = 0;
uint32_t ModuleID;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Set the output state (high or low) on output channels.
This is not applicable for channels configured as inputs.
*/
ModuleID = naibrd_GetModuleID(cardIndex, module);
if (configurable_DT_Output(ModuleID, chan))
{
printf("\nType the desired output state ");
printf("(l=low output,h=high output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'L':
outputstate = 0;
bUpdateOutput = TRUE;
break;
case 'H':
outputstate= 1;
bUpdateOutput = TRUE;
break;
default:
printf("ERROR: Invalid Output State Format Entry\n");
break;
}
}
}
if (!bQuit)
{
if (bUpdateOutput)
check_status(naibrd_DT_SetOutputState(cardIndex, module, chan, outputstate));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_ChanStatusEnable handles the user request to set the channel status reporting
enabled/disabled state for the selected channel and calls the method in the naibrd library
to set the channel status reporting enabled/disabled state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_ChanStatusEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t chanStatusEnable = FALSE;
uint32_t ModuleID = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int32_t chan = p_dt_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf("\nSelect Channel Status Enabled/Disabled Setting to set: [0 (Disabled) or 1 (Enabled)]: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if ((inputBuffer[0] == '0') || (inputBuffer[0] == '1'))
{
if (inputBuffer[0] == '1')
{
chanStatusEnable = TRUE;
}
check_status(naibrd_DT_SetChanStatusEnable(cardIndex, module, chan, chanStatusEnable));
}
else
{
printf("\nInvalid Setting Entered\n");
}
}
}
else
{
printf("\nModule does not support Channel Status Enable!\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_FloatingPointEnable handles the user request to set the floating-point mode
enabled/disabled state for the module and calls the method in the naibrd library to set
the floating-point mode enabled/disabled state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_FloatingPointEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t floatModeEnable = FALSE;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nSelect Floating-Point Mode Enabled/Disabled Setting to set: [0 (Disabled) or 1 (Enabled)]: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if ((inputBuffer[0] == '0') || (inputBuffer[0] == '1'))
{
if (inputBuffer[0] == '1')
{
floatModeEnable = TRUE;
}
check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, floatModeEnable));
}
else
{
printf("\nInvalid Setting Entered\n");
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_ClearAllStatuses handles the user request to clear all latched statuses for the selected
channel and calls the method in the naibrd library to clear the latched statuses.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_ClearAllStatuses(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_status_bit_t status = 0u;
uint32_t ModuleID = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int32_t chan = p_dt_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
ModuleID = naibrd_GetModuleID(cardIndex, module);
printf("\nAre you sure you want to clear all Latched Statuses for channel %d? (Y for Yes or N for No): ", chan);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
{
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_BIT_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_BIT_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_OVERCURRENT_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_OVERCURRENT_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_MAX_HI_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_MAX_HI_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_MIN_LO_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_MIN_LO_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_MID_RANGE_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_MID_RANGE_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_LO_HI_TRANS_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_LO_HI_TRANS_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_HI_LO_TRANS_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_HI_LO_TRANS_LATCHED));
}
status = 0u;
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_CRC_FAULT_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_CRC_FAULT_LATCHED));
}
status = 0u;
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_SUMMARY_LATCHED, &status));
if (status == 1u)
{
check_status(naibrd_DT_ClearStatus(cardIndex, module, chan, NAI_DT_STATUS_SUMMARY_LATCHED));
}
}
Display_DT_Status(paramCount, p_params);
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_MinLoThreshold calls the Configure_DT_Threshold() routine for Min Low Threshold configuration.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_MinLoThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DT_Threshold(p_dsw_params->cardIndex, p_dsw_params->module, p_dsw_params->channel, NAI_DT_THRESH_MIN_LO, (int8_t *)"Min Low");
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_LowThreshold calls the Configure_DT_Threshold() routine for Lower Threshold configuration.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_LowThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DT_Threshold(p_dsw_params->cardIndex, p_dsw_params->module, p_dsw_params->channel, NAI_DT_THRESH_LOWER, (int8_t *)"Lower");
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_UpperThreshold calls the Configure_DT_Threshold() routine for Upper Threshold configuration.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_UpperThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DT_Threshold(p_dsw_params->cardIndex, p_dsw_params->module, p_dsw_params->channel, NAI_DT_THRESH_UPPER, (int8_t *)"Upper");
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_MaxHiThreshold calls the Configure_DT_Threshold() routine for Max High Threshold configuration.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_MaxHiThreshold(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return Configure_DT_Threshold(p_dsw_params->cardIndex, p_dsw_params->module, p_dsw_params->channel, NAI_DT_THRESH_MAX_HI, (int8_t *)"Max High");
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_Threshold handles the user request to configure the selected threshold configuration and
channel and calls the method in the naibrd library to set the threshold voltage.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_Threshold(int32_t cardIndex, int32_t module, int32_t chan, nai_dt_thresh_type_t thresholdtype, int8_t* thresholdtext)
{
bool_t bQuit = FALSE;
float64_t threshold= 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
printf("\nEnter the desired %s threshold voltage : ", thresholdtext);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
threshold = atof((const char *)inputBuffer);
check_status(naibrd_DT_SetThreshold(cardIndex, module, chan, thresholdtype, threshold));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_BITErrorThreshold handles the user request to set the BIT Error Threshold for
the module and calls the method in the naibrd library to set the BIT Error Threshold.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_BITErrorThreshold(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t ModuleID = 0u;
uint32_t bitErrThres = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf("\nEnter the desired BIT Error Threshold : ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (inputBuffer[0] == '-')
{
printf("\nInvalid value entered\n");
}
else
{
bitErrThres = (uint32_t)strtoul((const char*)inputBuffer, NULL, 10);
if (bitErrThres == 0u)
{
if (inputBuffer[0] == '0')
{
check_status(naibrd_DT_SetModuleBITErrorThreshold(cardIndex, module, bitErrThres));
}
else
{
printf("\nInvalid value entered\n");
}
}
else
{
check_status(naibrd_DT_SetModuleBITErrorThreshold(cardIndex, module, bitErrThres));
}
}
}
}
else
{
printf("\nModule does not support BIT Error Threshold!\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_CheckPBITComplete handles the user request to check the module power-on BIT completed state
and calls the method in the naibrd library to check the power-on BIT completed state. If the power-on BIT
completed state is set, meaning that power-on BIT has completed, the Latched BIT Status of each channel
is checked by calling the method in the naibrd library to read the BIT Status.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_CheckPBITComplete(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t ModuleID = 0u;
int32_t channelCount = 0;
bool_t pBitComplete = FALSE;
nai_status_bit_t bitStatus = 0u;
char strBitStatus[12] = "";
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int32_t chan = 0;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
channelCount = naibrd_DT_GetChannelCount(ModuleID);
/* Check to see if PBIT ran for the module. */
printf("\nChecking if the Power-On BIT test has run...\n");
check_status(naibrd_DT_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
switch (pBitComplete)
{
case 0u:
printf("\nPBIT Complete: NOT COMPLETED\n");
break;
case 1u:
printf("\nPBIT Complete: COMPLETED\n");
break;
default:
printf("\nPBIT Complete: UNKNOWN\n");
break;
}
if (pBitComplete)
{
/* Read the BIT status */
printf("\nChecking the result of the Power-on BIT test...\n");
for (chan = 1; chan <= channelCount; chan++)
{
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_BIT_LATCHED, &bitStatus));
switch (bitStatus)
{
case (nai_status_bit_t)0u:
sprintf(strBitStatus, "BIT Passed");
break;
case (nai_status_bit_t)1u:
sprintf(strBitStatus, "BIT FAILED");
break;
default:
sprintf(strBitStatus, "Unknown");
break;
}
printf("Ch. %d: %s\n", chan, strBitStatus);
}
}
}
else
{
printf("\nModule does not support Power-On BIT!\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_ClearModuleBITLogic handles the user request to clear the module BIT logic,
which resets the Continuous BIT internal circuitry and counter, and calls the method
in the naibrd library to clear the module BIT logic.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_ClearModuleBITLogic(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t ModuleID = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int32_t chan = p_dt_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
printf("\nAre you sure you want to reset the Continuous BIT internal circuitry and counter? (Y for Yes or N for No): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
{
check_status(naibrd_DT_ClearModuleBITLogic(cardIndex, module, chan));
}
}
else
{
printf("\nModule does not support clearing of BIT logic!\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
configurable_DT_IOFormat determines whether the channel selected for the given Discrete Module ID is capable
of being programmed for high side and push-pull output configurations.
</summary>
*/
/**************************************************************************************************************/
static bool_t configurable_DT_IOFormat(uint32_t ModuleID, int32_t chan)
{
bool_t configurable = TRUE;
if ((ModuleID == NAI_MODULE_ID_KA) && ((chan < 13) || (chan > 16)))
configurable = FALSE;
return configurable;
}
/**************************************************************************************************************/
/**
<summary>
configurable_DT_Output determines whether the channel selected for the given Discrete Module ID is capable
of being configured as an output channel.
</summary>
*/
/**************************************************************************************************************/
static bool_t configurable_DT_Output(uint32_t ModuleID, int32_t chan)
{
bool_t configurable = TRUE;
if ((ModuleID == NAI_MODULE_ID_KA) && (chan > 16))
configurable = FALSE;
return configurable;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_WatchdogShowMenu displays the menu for watchdog commands.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_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;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int32_t chan = p_dt_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
numMenuCmds = DT_WD_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_WatchdogOpMenuCmds);
while (bContinue)
{
Handle_DT_DisplayWatchdog(cardIndex, module, chan);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_WD_PGM_NAME);
printf("\nType DT 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)
{
DT_WatchdogOpMenuCmds[cmd].func(paramCount, p_params);
}
else
{
printf("\nInvalid command entered\n");
}
}
}
}
else
bContinue = FALSE;
}
numMenuCmds = DT_BASICOP_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_BasicOpMenuCmds);
}
else
{
printf("\nModule does not support Watchdog Timer!\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_WatchDogQuietTime handles the user request to set the watchdog quiet time for the module and calls
the method in the naibrd library to set the watchdog quiet time. The user is prompted for the value in ms.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_WatchDogQuietTime(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t quietTime = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#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_DT_SetWatchdogQuietTime(cardIndex, module, quietTime * 1000));
}
else
{
printf("\nInvalid value entered\n");
}
}
else
{
check_status(naibrd_DT_SetWatchdogQuietTime(cardIndex, module, quietTime * 1000));
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_WatchDogWindowTime handles the user request to set the watchdog window time for the module and calls
the method in the naibrd library to set the watchdog window time. The user is prompted for the value in ms.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_WatchDogWindowTime(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t windowTime = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#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_DT_SetWatchdogWindow(cardIndex, module, windowTime * 1000));
}
else
{
printf("\nInvalid value entered\n");
}
}
else
{
check_status(naibrd_DT_SetWatchdogWindow(cardIndex, module, windowTime * 1000));
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_DisplayWatchdog displays the DT Watchdog Operations data. The data is retrieved by calling the
methods in the naibrd library to retrieve the data.
</summary>
*/
/**************************************************************************************************************/
static bool_t Handle_DT_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\nDT Watchdog Data:\n");
check_status(naibrd_DT_GetWatchdogQuietTime(cardIndex, module, &quietTime));
quietTime = quietTime / 1000;
printf("Quiet Time: %d mS\n", quietTime);
check_status(naibrd_DT_GetWatchdogWindow(cardIndex, module, &windowTime));
windowTime = windowTime / 1000;
printf("Window Time: %d mS\n", windowTime);
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &wdStatLatched));
check_status(naibrd_DT_GetStatus(cardIndex, module, chan, NAI_DT_STATUS_WATCHDOG_TIMER_FAULT_REALTIME, &wdStatRT));
printf("WatchDog Status (R/L): (%1d/%1d)\n", wdStatRT, wdStatLatched);
printf("\n");
return 0u;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_StrobeWatchdog will start a thread to continuously Strobe the watchdog.
The Watchdog Strobe is done by calling the method in the naibrd library to strobe the watchdog.
NOTE: When this thread/application exits, the module will shut off all outputs and will need to
be power cycled in order to be operational.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_StrobeWatchdog(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int32_t* arg = (int32_t*)malloc(sizeof(int32_t) * 3);
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#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;
}
/**************************************************************************************************************/
/**
<summary>
naiapp_kill_WDStrobe_Thread will terminate the WD strobing thread. Module will shut off outputs
at this state and will need to be power cycled to be operational.
</summary>
*/
/**************************************************************************************************************/
static void naiapp_kill_WDStrobe_Thread()
{
#if defined (__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
}
/**************************************************************************************************************/
/**
<summary>
WD_Strobe_ThreadEntryPoint will continuously loop, strobing the watchdog every QuietTime + Window/2.
</summary>
*/
/**************************************************************************************************************/
#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_DT_GetWatchdogQuietTime(cardIndex, module, &quietTime));
check_status(naibrd_DT_GetWatchdogWindow(cardIndex, module, &windowTime));
quietTime = quietTime / 1000;
windowTime = windowTime / 1000;
delayTime = quietTime + (windowTime / 2);
check_status(naibrd_DT_WatchdogStrobe(cardIndex, module));
do
{
nai_msDelay(delayTime);
check_status(naibrd_DT_WatchdogStrobe(cardIndex, module));
} while (!terminateThread);
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_kill_WDStrobe_Thread will terminate the WD Strobing thread. Module will shut off outputs
at this state and will need to be power cycled to be operational.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_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;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_ModulePowerResetMenu displays the menu for module power reset commands.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_ModulePowerResetMenu(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;
bool_t poweredDownStatus = 0u;
bool_t notDetectedStatus = 0u;
bool_t notLinkInitStatus = 0u;
bool_t notFWNotStatus = 0u;
bool_t commErrorStatus = 0u;
bool_t resetRequest = 0u;
bool_t powerDownRequest = 0u;
bool_t powerUpRequest = 0u;
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
ModuleID = naibrd_GetModuleID(cardIndex, module);
if ((ModuleID == NAI_MODULE_ID_DT1) || (ModuleID == NAI_MODULE_ID_DT4) || (ModuleID == NAI_MODULE_ID_DTB) || (ModuleID == NAI_MODULE_ID_CM1))
{
numMenuCmds = DT_MODULE_POWER_RESET_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_ModulePowerResetMenuCmds);
while (bContinue)
{
printf("\n\n\n");
printf(" -----------------------------Status------------------------------ ----------Request----------\n");
printf(" Powered Down Not Detected Not Link Init Not FW Not Comm Error Reset Power Down Power Up\n");
printf(" ------------ ------------ ------------- ---------- ---------- ----- ---------- --------\n");
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAI_DT_MODULE_POWER_RESET_STATUS_POWERED_DOWN, &poweredDownStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAI_DT_MODULE_POWER_RESET_STATUS_NOT_DETECTED, ¬DetectedStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAI_DT_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT, ¬LinkInitStatus));
//check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAI_DT_MODULE_POWER_RESET_STATUS_NOT_FW_NOT, ¬FWNotStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAI_DT_MODULE_POWER_RESET_STATUS_COMM_ERROR, &commErrorStatus));
check_status(naibrd_DT_GetModulePowerReset(cardIndex, module, NAI_DT_MODULE_POWER_RESET_REQUEST_RESET, &resetRequest));
check_status(naibrd_DT_GetModulePowerReset(cardIndex, module, NAI_DT_MODULE_POWER_RESET_REQUEST_POWER_DOWN, &powerDownRequest));
check_status(naibrd_DT_GetModulePowerReset(cardIndex, module, NAI_DT_MODULE_POWER_RESET_REQUEST_POWER_UP, &powerUpRequest));
printf(" %1d %1d %1d %1d %1d %1d %1d %1d\n",
poweredDownStatus, notDetectedStatus, notLinkInitStatus, notFWNotStatus, commErrorStatus, resetRequest, powerDownRequest, powerUpRequest);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_MODULE_POWER_RESET_PGM_NAME);
printf("\nType DT Module Power Reset command or %c to quit : main > module power reset >", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((inputBuffer[0] == 'B') || (inputBuffer[0] == 'b'))
{
bContinue = FALSE;
}
else
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
DT_ModulePowerResetMenuCmds[cmd].func(paramCount, p_params);
}
else
{
printf("\nInvalid command entered\n");
}
}
}
}
else
bContinue = FALSE;
}
numMenuCmds = DT_BASICOP_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_BasicOpMenuCmds);
}
else
{
printf("\nModule does not support Module Power Reset!\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_ClearModulePowerResetStatus handles the user request to clear the module power reset status
and calls the method in the naibrd library to clear the module power reset status. The user is
prompted for the module power reset status type to clear.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_dt_module_power_reset_status_type_t statusTypeToClear = 0u;
bool_t modulePowerResetStatusRead = 0u;
char statusTypeStr[14] = "";
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nSelect Module Power Reset Status type to clear: (0 for Powered Down, 1 for Not Detected, 2 for Not Link Init, 3 for Not FW Not, 4 for Comm Error, q for quit): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
switch (inputBuffer[0])
{
case '0':
statusTypeToClear = NAI_DT_MODULE_POWER_RESET_STATUS_POWERED_DOWN;
sprintf(statusTypeStr, "Powered Down");
break;
case '1':
statusTypeToClear = NAI_DT_MODULE_POWER_RESET_STATUS_NOT_DETECTED;
sprintf(statusTypeStr, "Not Detected");
break;
case '2':
statusTypeToClear = NAI_DT_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT;
sprintf(statusTypeStr, "Not Link Init");
break;
/*case '3':
statusTypeToClear = NAI_DT_MODULE_POWER_RESET_STATUS_NOT_FW_NOT;
sprintf(statusTypeStr, "Not FW Not");
break;*/
case '4':
statusTypeToClear = NAI_DT_MODULE_POWER_RESET_STATUS_COMM_ERROR;
sprintf(statusTypeStr, "Comm Error");
break;
case 'q':
case 'Q':
bQuit = TRUE;
break;
default:
bQuit = TRUE;
printf("\nInvalid module power reset status type entered\n");
break;
}
if (!bQuit)
{
printf("\nAre you sure you want to clear the %s status? (Y for Yes or N for No): ", statusTypeStr);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0) && (toupper(inputBuffer[0]) == 'Y'))
{
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, statusTypeToClear, &modulePowerResetStatusRead));
if (modulePowerResetStatusRead == 1u)
{
check_status(naibrd_DT_ClearModulePowerResetStatus(cardIndex, module, statusTypeToClear));
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_SetModulePowerReset handles the user request to set the module power reset request
and calls the method in the naibrd library to set the module power reset request. The user is
prompted for the module power reset request type to set, and then the user is prompted to set
or reset the request bit.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_SetModulePowerReset(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
nai_dt_module_power_reset_type_t resetTypeToSet = 0u;
char resetTypeStr[11] = "";
p_naiapp_AppParameters_t p_dt_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dt_params->cardIndex;
int32_t module = p_dt_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nSelect Module Power Reset Request type to set: (0 for Reset, 1 for Power Down, 2 for Power Up, q for quit): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
switch (inputBuffer[0])
{
case '0':
resetTypeToSet = NAI_DT_MODULE_POWER_RESET_REQUEST_RESET;
sprintf(resetTypeStr, "Reset");
break;
case '1':
resetTypeToSet = NAI_DT_MODULE_POWER_RESET_REQUEST_POWER_DOWN;
sprintf(resetTypeStr, "Power Down");
break;
case '2':
resetTypeToSet = NAI_DT_MODULE_POWER_RESET_REQUEST_POWER_UP;
sprintf(resetTypeStr, "Power Up");
break;
case 'q':
case 'Q':
bQuit = TRUE;
break;
default:
bQuit = TRUE;
printf("\nInvalid module power reset request type entered\n");
break;
}
if (!bQuit)
{
printf("\nDo you want to set or reset the %s request? (1 to set, 0 to reset): ", resetTypeStr);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if ((!bQuit) && (inputResponseCnt > 0))
{
if (inputBuffer[0] == '0')
{
check_status(naibrd_DT_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)FALSE));
}
else if (inputBuffer[0] == '1')
{
check_status(naibrd_DT_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)TRUE));
}
else
{
printf("\nInvalid selection entered\n");
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}