DT BasicOps
Edit this on GitLab
DT BasicOps Sample Application (SSK 2.x)
Overview
The DT BasicOps sample application demonstrates how to configure and control discrete I/O channels using the NAI Software Support Kit (SSK 2.x). It covers the core DT operations you will need in your own application: setting I/O format (input, low-side output, high-side output, or push-pull output), controlling output state, configuring voltage thresholds (min-low, lower, upper, max-high), setting debounce time, enabling floating-point mode, setting BIT error thresholds, managing channel status, reading status registers, resetting overcurrent conditions, running watchdog operations, and managing module power reset.
This sample supports the following DT module types: DT1 through DT5, as well as legacy modules K6, K9, KA, KB, and combination modules CM2, CM8, CMR. It includes special handling for KA modules, which have fixed I/O assignments (channels 1-12 are output-only, channels 13-16 are configurable, channels 17-28 are input-only).
For the SSK 1.x version, see DT BasicOps (SSK 1.x). For detailed module specifications, refer to the DT1 Manual.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a DT module installed (DT1-DT5).
-
SSK 2.x installed on your development host.
-
The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.
How to Run
Launch the dt_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_DT_BasicOps.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. Once connected, the application prompts for a channel number and presents a command menu for configuring DT operations.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to DT. |
The main() function follows a standard SSK 2.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_DT_BasicOps.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleName()so downstream code can adapt to the specific DT variant installed.
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t DT_BasicOps(void)
#else
int32_t main(void)
#endif
{
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
bool_t stop = NAI_FALSE;
uint32_t moduleID;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DT_CARD_INDEX, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DT_MODULE, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_DT_BasicOps(cardIndex, module, moduleID);
naiif_printf("\r\nType Q to quit or Enter to continue:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR,
inputBuffer, &inputResponseCnt);
}
}
}
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
Note the SSK 2.x differences from SSK 1.x in this startup sequence:
-
The VxWorks preprocessor guard uses
NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS(SSK 1.x uses__VXWORKS__). -
The module identifier is retrieved with
naibrd_GetModuleName()(SSK 1.x usesnaibrd_GetModuleID()). -
Boolean constants are
NAI_TRUE/NAI_FALSE(SSK 1.x usesTRUE/FALSE). -
Console output uses
naiif_printf()from the platform abstraction layer (SSK 1.x usesprintf()directly).
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
On standard platforms (Petalinux, Windows) the entry point is main(). On VxWorks the entry point is DT_BasicOps():
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t DT_BasicOps(void)
#else
int32_t main(void)
#endif
Command Loop
After connecting to the board and selecting a module, the application calls Run_DT_BasicOps(), which validates the module and delegates to Cfg_DT_Channel(). For KA modules, the default channel is set to 13 (the first configurable channel) with a note that channels 1-12 are output-only and 17-28 are input-only. The command loop prompts for a channel number, then displays the current channel configuration and presents the command menu.
The command table defines the following operations:
| Command | Description |
|---|---|
|
Set I/O format (Input, Low-side Output, High-side Output, or Push-pull Output). |
|
Set output state (High or Low). |
|
Set minimum low threshold voltage. |
|
Set lower threshold voltage. |
|
Set upper threshold voltage. |
|
Set maximum high threshold voltage. |
|
Set debounce time in milliseconds. |
|
Reset overcurrent condition for all channels. |
|
Display status registers (MinLo, MidRange, MaxHi, Low-Hi transition, Hi-Lo transition, BIT, overcurrent, summary, watchdog, inter-FPGA). |
|
Enable or disable hardware floating-point mode. |
|
Set BIT error threshold voltage. |
|
Enable or disable channel status monitoring. |
|
Check power-on BIT completion status. |
|
Clear module BIT logic. |
|
Enter the module power reset submenu. |
|
Enter the watchdog submenu (not available on DEOS). |
Displaying Channel Configuration
Before each command prompt, Display_DT_ChannelCfg() reads the I/O format, output/input state, threshold voltages (min-low, lower, upper, max-high), channel voltage, debounce time, VCC, and current (where applicable):
-
naibrd_DT_GetIOFormat()— Reads the I/O format. -
naibrd_DT_GetOutputState()/naibrd_DT_GetInputState()— Reads the output or input logic state. -
naibrd_DT_GetThreshold()— Reads threshold voltages. Types:NAIBRD_DT_THRESH_MIN_LO,NAIBRD_DT_THRESH_LOWER,NAIBRD_DT_THRESH_UPPER,NAIBRD_DT_THRESH_MAX_HI. -
naibrd_DT_GetVoltage()— Reads the channel voltage. -
naibrd_DT_GetDebounceTime()— Reads the debounce time. -
naibrd_DT_GetBankVccVoltage()— Reads VCC for the channel bank. -
naibrd_DT_GetCurrent()— Reads the channel current in milliamps.
Configuring I/O Format and Output State
-
naibrd_DT_SetIOFormat(cardIndex, module, channel, format)— Sets the I/O format. Options:NAIBRD_DT_IOFORMAT_INPUT,NAIBRD_DT_IOFORMAT_OUTPUT_LOW,NAIBRD_DT_IOFORMAT_OUTPUT_HIGH,NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL. -
naibrd_DT_SetOutputState(cardIndex, module, channel, state)— Sets the output state. UseNAIBRD_DT_STATE_LOorNAIBRD_DT_STATE_HI.
|
Note
|
Not all channels on all modules support all I/O formats. The application includes helper functions configurable_DT_IOFormat() and configurable_DT_Output() that check whether the selected channel supports I/O format changes and output state changes based on the module ID.
|
Setting Voltage Thresholds
The DT module supports four programmable voltage thresholds that define signal level boundaries:
-
naibrd_DT_SetThreshold(cardIndex, module, channel, NAIBRD_DT_THRESH_MIN_LO, voltage)— Sets the minimum low threshold. -
naibrd_DT_SetThreshold(cardIndex, module, channel, NAIBRD_DT_THRESH_LOWER, voltage)— Sets the lower threshold. -
naibrd_DT_SetThreshold(cardIndex, module, channel, NAIBRD_DT_THRESH_UPPER, voltage)— Sets the upper threshold. -
naibrd_DT_SetThreshold(cardIndex, module, channel, NAIBRD_DT_THRESH_MAX_HI, voltage)— Sets the maximum high threshold.
Reading and Clearing Status
The Display_DT_Status() function reads latched status registers including MinLo, MidRange, MaxHi, Low-Hi transition, Hi-Lo transition, BIT, overcurrent, summary, watchdog, and inter-FPGA fault. Each status is read with naibrd_DT_GetChanMappedStatus() and then cleared with naibrd_DT_ClearChanMappedStatus().
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
Module selection not recognized as DT module |
The selected slot does not contain a DT module. |
Verify that a DT1-DT5 module is installed in the selected slot. |
No board found |
Board not powered, cable disconnected, or wrong interface selected. |
Verify power, cables, and interface type. |
Output state has no effect |
Channel is configured as input, or I/O format not configurable for this channel. |
Set I/O format to output first. On KA modules, channels 17-28 are input-only. |
Threshold setting rejected |
Value outside supported range for the module. |
Consult the DT1 Manual for valid voltage ranges. |
Overcurrent status stuck |
Fault condition persists or has not been reset. |
Use |
VCC reads as zero |
No external VCC applied. |
Verify VCC source configuration and external power connections. |
KA module I/O format change fails |
Attempting to change I/O format on fixed channels (1-12 or 17-28). |
Only channels 13-16 are configurable on KA modules. |
Watchdog fault status set |
Strobe thread was killed or missed a window. |
Restart strobe thread via watchdog submenu. |
Current reading not available |
Module does not support current measurement (KB, KA, PD). |
Current measurement is only available on K6, K9, DT1, DT4, CM2, CM8, CMR, D1P, D4P, IF3 modules. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — dt_basic_ops.c (SSK 2.x)
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
#include <pthread.h>
#endif
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
#include <taskLib.h>
#endif
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"
/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_dt.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"
static const int8_t *DEF_CONFIG_FILE = (const int8_t *)"default_DT_BasicOps.txt";
/* Function prototypes */
static int32_t Run_DT_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid);
static void Verify_DT_ParamCnt(int32_t paramCnt);
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 paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_IOFormat(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_OutputState(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_MinLoThreshold(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_LowThreshold(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_UpperThreshold(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_MaxHiThreshold(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_Threshold(int32_t paramCnt, int32_t* p_params, naibrd_dt_thresh_type_t thresholdtype,
int8_t* thresholdtext);
static nai_status_t Configure_DT_Debounce(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_Floating(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_BITThresholds(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_ChannelStatusEnable(int32_t paramCount, int32_t* 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 Configure_DT_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DT_SetModulePowerReset(int32_t paramCount, int32_t* p_params);
/* DEOS does not support threading, hence you won't be able to pet the watchdog. */
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
static nai_status_t Handle_DT_WatchdogShowMenu(int32_t paramCount, int32_t* params);
static nai_status_t Handle_DT_WatchDogQuietTime(int32_t paramCount, int32_t* params);
static nai_status_t Handle_DT_WatchDogWindowTime(int32_t paramCount, int32_t* params);
static nai_status_t Handle_DT_DisplayWatchdog(int32_t paramCount, int32_t* params);
static nai_status_t Handle_DT_StrobeWatchdog(int32_t paramCount, int32_t* params);
static nai_status_t Handle_DT_kill_WDStrobe_Thread(int32_t paramCount, int32_t* params);
static void naiapp_kill_WDStrobe_Thread();
static bool_t terminateThread;
static const int8_t *SAMPLE_WD_PGM_NAME = (const int8_t*)"DT Watchdog Operations";
#endif
static const int32_t DEF_DT_CARD_INDEX = 0;
static const int32_t DEF_DT_MODULE = 1;
static const int32_t DEF_DT_CHANNEL = 1;
static const int32_t DEF_DT_KA_CHANNEL = 13;
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
DWORD WINAPI WD_Strobe_ThreadEntryPoint(LPVOID param);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
void* WD_Strobe_ThreadEntryPoint(void* arg);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static int WD_Strobe_ThreadEntryPoint(int32_t nParam);
#endif
/* TX Thread */
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
static HANDLE thread = NULL;
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static pthread_t thread;
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static TASK_ID thread;
#endif
/****** Command Table *******/
enum dt_basicops_commands
{
DT_BASICOP_CMD_IOFORMAT,
DT_BASICOP_CMD_OUTPUTSTATE,
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_DEBOUNCE,
DT_BASICOP_CMD_RESET_OC,
DT_BASICOP_CMD_STATUS,
DT_BASICOP_CMD_FLOAT,
DT_BASICOP_CMD_BIT_THRESHOLD,
DT_BASICOP_CMD_CHANNEL_STATUS_ENABLE,
DT_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE,
DT_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC,
DT_BASICOP_CMD_MODULE_POWER_RESET,
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
DT_BASICOP_CMD_WD_MENU,
#endif
DT_BASICOP_CMD_COUNT
};
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
enum dt_gen5_dt_watchdog_commands
{
DT_COMMON_CMD_WD_QUIETTIME,
DT_COMMON_CMD_WD_WINDOWTIME,
DT_COMMON_CMD_WD_DISPLAY,
DT_COMMON_CMD_WD_STROBE,
DT_COMMON_CMD_WD_KILL,
DT_COMMON_CMD_WD_BACK,
DT_COMMON_CMD_WD_COUNT
};
#endif
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 *******/
static 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},
{"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},
{"D", "DT Set Debounce Time", DT_BASICOP_CMD_DEBOUNCE, Configure_DT_Debounce},
{"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", DT_BASICOP_CMD_FLOAT, Configure_DT_Floating},
{"THRESH", "DT Set BIT Error Threshold", DT_BASICOP_CMD_BIT_THRESHOLD, Configure_DT_BITThresholds},
{"CHANSTAT", "DT Enable/Disable Channel Status", DT_BASICOP_CMD_CHANNEL_STATUS_ENABLE, Configure_DT_ChannelStatusEnable},
{"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},
{"RESET", "Show Module Power Reset Menu Options", DT_BASICOP_CMD_MODULE_POWER_RESET, Configure_DT_ModulePowerResetMenu},
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
{"WATCHDOG", "Show Watchdog Menu Options", DT_BASICOP_CMD_WD_MENU, Handle_DT_WatchdogShowMenu}
#endif
};
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
naiapp_cmdtbl_params_t DT_WatchdogOpMenuCmds[DT_COMMON_CMD_WD_COUNT] =
{
{"BACK", "Back to Main Menu", (int32_t)0, NULL},
{"DISPLAY", "Display Watchdog Settings", DT_COMMON_CMD_WD_DISPLAY, Handle_DT_DisplayWatchdog},
{"TIME QUIET", "Set Watchdog Quiet Time", DT_COMMON_CMD_WD_QUIETTIME, Handle_DT_WatchDogQuietTime},
{"WINDOW", "Set Watchdog Window Time", DT_COMMON_CMD_WD_WINDOWTIME, Handle_DT_WatchDogWindowTime},
{"STROBE", "Start thread to continuously strobe watchdog", DT_COMMON_CMD_WD_STROBE, Handle_DT_StrobeWatchdog},
{"KILL", "Kill Watchdog strobing thread", DT_COMMON_CMD_WD_KILL, Handle_DT_kill_WDStrobe_Thread}
};
#endif
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, Configure_DT_ClearModulePowerResetStatus},
{"SET", "Set Module Power Reset Request", DT_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET, Configure_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 (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t DT_BasicOps(void)
#else
int32_t main(void)
#endif
{
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
bool_t stop = NAI_FALSE;
uint32_t moduleID;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Select Card Index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DT_CARD_INDEX, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DT_MODULE, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_DT_BasicOps(cardIndex, module, moduleID);
naiif_printf("\r\nType Q to quit or Enter to continue:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
}
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/**************************************************************************************************************/
/**
* <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>
*/
/**************************************************************************************************************/
static int32_t Run_DT_BasicOps(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = NAI_FALSE;
int32_t maxchannel;
if (!bQuit)
{
maxchannel = naibrd_DT_GetChannelCount(modid);
if (maxchannel == 0)
{
naiif_printf(" *** Module selection not recognized as DT module. ***\r\n\r\n");
}
else
{
Cfg_DT_Channel(cardIndex, module, modid, maxchannel);
}
}
return cardIndex;
}
/**************************************************************************************************************/
/**
* <summary>
* Verify_DT_ParamCnt verifies parameter count and displays error message if invalid.
* </summary>
*/
/**************************************************************************************************************/
static void Verify_DT_ParamCnt(int32_t paramCnt)
{
if (paramCnt != APP_PARAM_COUNT)
{
naiif_printf(" *** Parameter count specified is incorrect!!! ***\r\n");
}
}
/**************************************************************************************************************/
/**
* <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 = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
bool_t bCmdFound = NAI_FALSE;
int32_t chan, defaultchan = 1;
int32_t cmd;
naiapp_AppParameters_t dtparams;
p_naiapp_AppParameters_t dtParams = &dtparams;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
while (bContinue)
{
naiif_printf("\r\n\r\n");
naiif_printf("Channel selection\r\n");
naiif_printf("=================\r\n");
if (ModuleID == NAIBRD_MODULE_ID_KA)
{
naiif_printf("\r\n For KA modules, only Channels 13-16 are configurable.");
naiif_printf("\r\n Ch.01-12 are output only, Ch.17-28 are input only.\r\n");
defaultchan = DEF_DT_KA_CHANNEL;
}
else
{
defaultchan = DEF_DT_CHANNEL;
}
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
dtParams->cardIndex = cardIndex;
dtParams->module = module;
dtParams->channel = chan;
dtParams->modId = ModuleID;
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");
naiif_printf("\r\nType DT command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case DT_BASICOP_CMD_IOFORMAT:
case DT_BASICOP_CMD_OUTPUTSTATE:
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_DEBOUNCE:
case DT_BASICOP_CMD_FLOAT:
case DT_BASICOP_CMD_BIT_THRESHOLD:
case DT_BASICOP_CMD_CHANNEL_STATUS_ENABLE:
case DT_BASICOP_CMD_CHECK_POWER_ON_BIT_COMPLETE:
case DT_BASICOP_CMD_CLEAR_MODULE_BIT_LOGIC:
case DT_BASICOP_CMD_MODULE_POWER_RESET:
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
case DT_BASICOP_CMD_WD_MENU:
#endif
DT_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dtParams);
break;
case DT_BASICOP_CMD_RESET_OC:
check_status(naibrd_DT_ResetAll(cardIndex, module, NAIBRD_DT_RESET_OVERCURRENT)); /* This resets all channels */
check_status(naibrd_DT_Reset(cardIndex, module, 1, NAIBRD_DT_RESET_OVERCURRENT)); /* This alternate function resets */
naiif_printf("Reset completed.\r\n\r\n");
break;
default:
naiif_printf("Invalid command entered\r\n");
break;
}
}
else
{
naiif_printf("Invalid command entered\r\n");
}
}
}
else
{
bContinue = NAI_FALSE;
}
}
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
naiapp_kill_WDStrobe_Thread();
#endif
}
}
/**************************************************************************************************************/
/**
* <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)
{
naibrd_dt_ioformat_t ioformat = NAIBRD_DT_IOFORMAT_INPUT;
naibrd_dt_state_t outputstate = NAIBRD_DT_STATE_LO;
naibrd_dt_state_t inputstate = NAIBRD_DT_STATE_LO;
float64_t minlo = 0.0, lower = 0.0, upper = 0.0, maxhi = 0.0, voltage = 0.0, vcc = 0.0, current = 0.0, debounceTime = 0.0;
int32_t MaxChannel;
uint32_t bank;
bool_t fpEnable = NAI_FALSE;
check_status(naibrd_DT_GetIOFormat(cardIndex, module, chan, &ioformat));
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, NAIBRD_DT_THRESH_MIN_LO, &minlo));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAIBRD_DT_THRESH_LOWER, &lower));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAIBRD_DT_THRESH_UPPER, &upper));
check_status(naibrd_DT_GetThreshold(cardIndex, module, chan, NAIBRD_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 != NAIBRD_MODULE_ID_KA)
{
/*read channel voltage and Vcc*/
check_status(naibrd_DT_GetVoltage(cardIndex, module, chan, &voltage));
check_status(naibrd_DT_GetDebounceTime(cardIndex, module, chan, &debounceTime));
}
if (ModuleID == NAIBRD_MODULE_ID_K6 || ModuleID == NAIBRD_MODULE_ID_K9 || ModuleID == NAIBRD_MODULE_ID_DT1 || ModuleID == NAIBRD_MODULE_ID_DT4 || ModuleID == NAIBRD_MODULE_ID_CM2
|| ModuleID == NAIBRD_MODULE_ID_CM8 || ModuleID == NAIBRD_MODULE_ID_CMR || ModuleID == NAIBRD_MODULE_ID_D1P || ModuleID == NAIBRD_MODULE_ID_D4P || ModuleID == NAIBRD_MODULE_ID_IF3)
{
check_status(naibrd_DT_GetBankVccVoltage(cardIndex, module, ((chan - 1) / (MaxChannel / bank) + 1), &vcc));
/*read current*/
check_status(naibrd_DT_GetCurrent(cardIndex, module, chan, ¤t));
}
else if (ModuleID == NAIBRD_MODULE_ID_D1I || ModuleID == NAIBRD_MODULE_ID_D4I || ModuleID == NAIBRD_MODULE_ID_CF1)
{
check_status(naibrd_DT_GetBankVccVoltage(cardIndex, module, ((chan - 1) / (MaxChannel / bank) + 1), &vcc));
}
naiif_printf("\r\n === Channel %d ===\r\n\r\n", chan);
/*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 == NAIBRD_MODULE_ID_KA || ModuleID == NAIBRD_MODULE_ID_KB)
{
naiif_printf(" IOFormat Output Input MinLow Lower Upper Max Hi\r\n");
naiif_printf(" --------- ------ ----- ------- ------- ------- --------\r\n");
}
else
{
naiif_printf(" IOFormat Output Input MinLow Lower Upper Max Hi Voltage Debounce\r\n");
naiif_printf(" --------- ------ ----- ------- ------- -------- -------- ------- -------\r\n");
}
switch (ioformat)
{
case NAIBRD_DT_IOFORMAT_INPUT:
naiif_printf(" Input ");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_LOW:
naiif_printf(" Low-side ");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_HIGH:
naiif_printf(" High-side");
break;
case NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL:
naiif_printf(" Push-pull");
break;
default:
naiif_printf(" Unknown ");
break;
}
if (ioformat != NAIBRD_DT_IOFORMAT_INPUT)
{
switch (outputstate)
{
case NAIBRD_DT_STATE_LO:
naiif_printf(" Low ");
break;
case NAIBRD_DT_STATE_HI:
naiif_printf(" High");
break;
/* undefined value read back */
default:
naiif_printf(" UNK ");
break;
}
}
else
{
naiif_printf(" --- ");
}
switch (inputstate)
{
{
case NAIBRD_DT_STATE_LO:
naiif_printf(" Low ");
break;
case NAIBRD_DT_STATE_HI:
naiif_printf(" High");
break;
/* undefined value read back */
default:
naiif_printf(" UNK ");
break;
}
}
naiif_printf("%+6.1f %+6.1f %+6.1f %+6.1f ", minlo, lower, upper, maxhi);
if (ModuleID != NAIBRD_MODULE_ID_KA)
{
naiif_printf("%+6.1f ", voltage);
}
if (ModuleID != NAIBRD_MODULE_ID_KA)
{
naiif_printf("%+6.1f ", debounceTime);
}
if (ModuleID == NAIBRD_MODULE_ID_K6 || ModuleID == NAIBRD_MODULE_ID_K9 || ModuleID == NAIBRD_MODULE_ID_DT1 || ModuleID == NAIBRD_MODULE_ID_CM2
|| ModuleID == NAIBRD_MODULE_ID_CM8 || ModuleID == NAIBRD_MODULE_ID_CMR || ModuleID == NAIBRD_MODULE_ID_DT4
|| ModuleID == NAIBRD_MODULE_ID_D1P || ModuleID == NAIBRD_MODULE_ID_D4P || ModuleID == NAIBRD_MODULE_ID_IF3)
{
naiif_printf("\r\n\r\n");
naiif_printf(" VCC Current (mA)\r\n");
naiif_printf(" ------ ------------\r\n");
naiif_printf("%+6.1f ", vcc);
naiif_printf("%+6.1f ", current); /*display in mA*/
}
else if (ModuleID == NAIBRD_MODULE_ID_D1I || ModuleID == NAIBRD_MODULE_ID_D4I || ModuleID == NAIBRD_MODULE_ID_CF1)
{
naiif_printf("\r\n\r\n");
naiif_printf(" VCC \r\n");
naiif_printf(" ------ \r\n");
naiif_printf("%+6.1f ", vcc);
}
check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &fpEnable));
naiif_printf("\r\nH/W Floating Point Mode: %s\r\n", (fpEnable == NAI_FALSE ? "DISABLED" : "ENABLED"));
}
/**************************************************************************************************************/
/**
* <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 paramCnt, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
nai_status_bit_t statusBit;
bool_t chanStatusEnabled = NAI_TRUE;
/* Available status:
* NAIBRD_DT_STATUS_BIT,
* NAIBRD_DT_STATUS_OVER_CURRENT,
* NAIBRD_DT_STATUS_MAX_HI,
* NAIBRD_DT_STATUS_MIN_LO,
* NAIBRD_DT_STATUS_MID_RANGE,
* NAIBRD_DT_STATUS_LO_HI_TRANS,
* NAIBRD_DT_STATUS_HI_LO_TRANS,
*/
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\n");
check_status(naibrd_DT_GetChanStatusEnable(cardIndex, module, chan, &chanStatusEnabled));
naiif_printf(" CHANNEL STATUS ENABLED: %s\r\n ", (chanStatusEnabled == NAI_FALSE) ? "NO- Below Statuses are always 0 " : "YES");
naiif_printf("------------------ Status ----------------------------\r\n");
naiif_printf(" MinLo MidRng MaxHi Low-Hi Hi-Lo BIT OC Summary Watchdog Inter-FPGA\r\n");
naiif_printf(" ------- -------- ------ ------- -------- ------ ------ ------- -------- ----------\r\n");
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_MIN_LO_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_MIN_LO_LATCHED));
}
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_MID_RANGE_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_MID_RANGE_LATCHED));
}
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_MAX_HI_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_MAX_HI_LATCHED));
}
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_LO_HI_TRANS_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_LO_HI_TRANS_LATCHED));
}
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_HI_LO_TRANS_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_HI_LO_TRANS_LATCHED));
}
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_BIT_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_BIT_LATCHED));
}
status = check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_OVERCURRENT_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_OVERCURRENT_LATCHED));
}
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_SUMMARY_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_SUMMARY_LATCHED));
}
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED));
}
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_INTER_FPGA_FAULT_LATCHED, &statusBit));
naiif_printf(" %3i ", statusBit);
if (status == NAI_SUCCESS)
{
check_status(naibrd_DT_ClearChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_INTER_FPGA_FAULT_LATCHED));
}
naiif_printf("\r\n\r\n");
return status;
}
/**************************************************************************************************************/
/**
* <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>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_IOFormat(int32_t paramCnt, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
naibrd_dt_ioformat_t ioformat = NAIBRD_DT_IOFORMAT_INPUT;
uint32_t ModuleID;
bool_t bQuit = NAI_FALSE;
bool_t bUpdateIOCfg = NAI_FALSE;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Set I/O format configuration for channel. Available configurations include:
* NAIBRD_DT_IOFORMAT_INPUT
* NAIBRD_DT_IOFORMAT_OUTPUT_LOW
* NAIBRD_DT_IOFORMAT_OUTPUT_HIGH
* NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL
*/
Verify_DT_ParamCnt(paramCnt);
check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));
if (configurable_DT_IOFormat(ModuleID, chan))
{
naiif_printf("Type the desired IO configuration ");
naiif_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)
{
switch (toupper(inputBuffer[0]))
{
case 'I':
naiif_printf("Setting to input\r\n");
ioformat = NAIBRD_DT_IOFORMAT_INPUT;
bUpdateIOCfg = NAI_TRUE;
break;
case 'L':
naiif_printf("Setting to output_low\r\n");
ioformat = NAIBRD_DT_IOFORMAT_OUTPUT_LOW;
bUpdateIOCfg = NAI_TRUE;
break;
case 'H':
naiif_printf("Setting to output_high\r\n");
ioformat = NAIBRD_DT_IOFORMAT_OUTPUT_HIGH;
bUpdateIOCfg = NAI_TRUE;
break;
case 'P':
naiif_printf("Setting to push-pull\r\n");
ioformat = NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL;
bUpdateIOCfg = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid Output State Format Entry\r\n");
bUpdateIOCfg = NAI_FALSE;
break;
}
if (bUpdateIOCfg)
{
status = check_status(naibrd_DT_SetIOFormat(cardIndex, module, chan, ioformat));
}
}
}
}
else
{
naiif_printf("IO configuration is not supported");
}
return status;
}
/**************************************************************************************************************/
/**
* <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 paramCnt, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
naibrd_dt_state_t outputstate = NAIBRD_DT_STATE_LO;
bool_t bQuit = NAI_FALSE;
bool_t bUpdateOutput = NAI_FALSE;
uint32_t ModuleID;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Set the output state (high or low) on output channels.
* This is not applicable for channels configured as inputs.
*/
Verify_DT_ParamCnt(paramCnt);
check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));
if (configurable_DT_Output(ModuleID, chan))
{
naiif_printf("\r\nType the desired output state ");
naiif_printf("(l=low output,h=high output): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
switch (toupper(inputBuffer[0]))
{
case 'L':
outputstate = NAIBRD_DT_STATE_LO;
bUpdateOutput = NAI_TRUE;
break;
case 'H':
outputstate = NAIBRD_DT_STATE_HI;
bUpdateOutput = NAI_TRUE;
break;
default:
naiif_printf("ERROR: Invalid Output State Format Entry\r\n");
bUpdateOutput = NAI_FALSE;
break;
}
}
if (bUpdateOutput)
{
check_status(naibrd_DT_SetOutputState(cardIndex, module, chan, outputstate));
}
}
}
else
{
naiif_printf("Output configuration is not supported");
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* Configure_DT_MinLoThreshold calls the Configure_DT_Threshold() routine for Min Low Threshold configuration.
* </summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DT_MinLoThreshold(int32_t paramCnt, int32_t* p_params)
{
return Configure_DT_Threshold(paramCnt, p_params, NAIBRD_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 paramCnt, int32_t* p_params)
{
return Configure_DT_Threshold(paramCnt, p_params, NAIBRD_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 paramCnt, int32_t* p_params)
{
return Configure_DT_Threshold(paramCnt, p_params, NAIBRD_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 paramCnt, int32_t* p_params)
{
return Configure_DT_Threshold(paramCnt, p_params, NAIBRD_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 paramCnt, int32_t* p_params, naibrd_dt_thresh_type_t thresholdtype, int8_t* thresholdtext)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
bool_t bQuit = NAI_FALSE;
float64_t threshold = 0.0;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\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);
status = check_status(naibrd_DT_SetThreshold(cardIndex, module, chan, thresholdtype, threshold));
}
}
return status;
}
/**************************************************************************************************************/
/**
* <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_Debounce(int32_t paramCnt, int32_t* p_params)
{
nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
bool_t bQuit = NAI_FALSE;
float64_t debounceTime = 0.0;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int32_t chan = dtParams->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("\r\nEnter the desired Debounce time (ms): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
debounceTime = atof((const char *)inputBuffer);
status = check_status(naibrd_DT_SetDebounceTime(cardIndex, module, chan, debounceTime));
}
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* Configure_DT_Floating handles the user request to set the floating point enable
* and calls the method in the naibrd library to set the floating point state.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_Floating(int32_t paramCnt, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = dtParams->cardIndex;
int32_t module = dtParams->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
naiif_printf("Select Floating-Point Mode to set ('0' for DISABLED, '1' for ENABLED): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputBuffer[0] == '0')
{
status = check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, 0x0));
}
else if (inputBuffer[0] == '1')
{
status = check_status(naibrd_SetFloatingPointModeEnable(cardIndex, module, 0x1));
}
naiif_printf("Returned status %s\r\n", naibrd_GetStatusString(status));
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* Configure_DT_BITThresholds() allows the user to set and get the BIT error thresholds.
* This is an advanced feature.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_BITThresholds(int32_t paramCnt, int32_t* p_params)
{
p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
nai_status_t status = NAI_ERROR_UNKNOWN;
uint32_t bitThreshold = 0u;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
Verify_DT_ParamCnt(paramCnt);
switch (dtParams->modId)
{
case NAIBRD_MODULE_ID_DT1:
case NAIBRD_MODULE_ID_DT4:
case NAIBRD_MODULE_ID_CM2:
case NAIBRD_MODULE_ID_CM8:
case NAIBRD_MODULE_ID_CMR:
case NAIBRD_MODULE_ID_IF3:
{
naiif_printf("Set or Get BIT Error Threshold? ('S' = Set, 'G' = Get, 'C' = Clear BIT Counter): ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (inputBuffer[0] == 'S')
{
naiif_printf("\r\nType the desired BIT Error Threshold (Default = 5): ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiif_printf("\r\n");
bitThreshold = atoi((const char*)inputBuffer);
status = naibrd_DT_SetModuleBITErrorThreshold(dtParams->cardIndex, dtParams->module, bitThreshold);
}
else if (inputBuffer[0] == 'G')
{
status = naibrd_DT_GetModuleBITErrorThreshold(dtParams->cardIndex, dtParams->module, &bitThreshold);
naiif_printf("\r\nBIT Error threshold: %d", bitThreshold);
}
else if (inputBuffer[0] == 'C')
{
int32_t ch;
int32_t channels = naibrd_DT_GetChannelCount(dtParams->modId);
naiif_printf("\r\nClearing BIT counters on all channels.\r\n");
for (ch = 1; ch <= channels; ch++)
status = naibrd_DT_ClearModuleBITLogic(dtParams->cardIndex, dtParams->module, ch);
}
else
{
naiif_printf("\r\nSelection not recognized.\r\n");
}
}
break;
default:
naiif_printf("\r\n\r\n*** This feature is not supported by this module.***\r\n");
status = NAI_ERROR_NOT_SUPPORTED;
break;
}
return status;
}
/**************************************************************************************************************/
/**
* <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 Configure_DT_ChannelStatusEnable(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t dt_params = (p_naiapp_AppParameters_t)params;
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
switch (dt_params->modId)
{
case NAIBRD_MODULE_ID_DT1:
case NAIBRD_MODULE_ID_DT4:
case NAIBRD_MODULE_ID_CM2:
case NAIBRD_MODULE_ID_CM8:
case NAIBRD_MODULE_ID_CMR:
case NAIBRD_MODULE_ID_IF3:
{
bQuit = naiapp_query_ChannelNumber(dt_params->maxChannels, dt_params->channel, &(dt_params->channel));
if (!bQuit)
{
naiif_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_DT_SetChanStatusEnable(dt_params->cardIndex, dt_params->module, dt_params->channel,
((inputResponseCnt > 0) && (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')) ? NAI_TRUE : NAI_FALSE));
}
}
}
break;
default:
naiif_printf("\r\n\r\n*** This feature is not supported by this module.***\r\n");
status = NAI_ERROR_NOT_SUPPORTED;
break;
}
}
Display_DT_Status(paramCount, params);
return status;
}
/**************************************************************************************************************/
/**
* <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 = NAI_TRUE;
if ((ModuleID == NAIBRD_MODULE_ID_KA) && ((chan < 13) || (chan > 16)))
configurable = NAI_FALSE;
else if (ModuleID == NAIBRD_MODULE_ID_D1I || ModuleID == NAIBRD_MODULE_ID_CF1)
{
configurable = NAI_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 = NAI_TRUE;
if ((ModuleID == NAIBRD_MODULE_ID_KA) && (chan > 16))
configurable = NAI_FALSE;
else if (ModuleID == NAIBRD_MODULE_ID_D1I || ModuleID == NAIBRD_MODULE_ID_CF1)
configurable = NAI_FALSE;
return configurable;
}
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
/**************************************************************************************************************/
/**
* <summary>
* This function displays the menu for watchdog commands
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_WatchdogShowMenu(int32_t paramCount, int32_t* params)
{
bool_t bQuit = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
bool_t bCmdFound = NAI_FALSE;
int32_t cmd = 0;
int32_t numMenuCmds = 0;
p_naiapp_AppParameters_t dt_params = (p_naiapp_AppParameters_t)params;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
numMenuCmds = DT_COMMON_CMD_WD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_WatchdogOpMenuCmds);
while (bContinue)
{
Handle_DT_DisplayWatchdog(paramCount, params);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_WD_PGM_NAME);
naiif_printf("\r\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 = NAI_FALSE;
bContinue = NAI_FALSE;
numMenuCmds = DT_BASICOP_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_BasicOpMenuCmds);
}
else
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
DT_WatchdogOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dt_params);
}
else
{
naiif_printf("Invalid command entered\r\n");
}
}
}
else
naiif_printf("Invalid command entered\r\n");
}
else
bContinue = NAI_FALSE;
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
* <summary>
* This function sets the watchdog quiet time for the module. The user is prompted for the value in ms.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_WatchDogQuietTime(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t dt_params = (p_naiapp_AppParameters_t)params;
bool_t bQuit = NAI_FALSE;
uint32_t quietTime = 0;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
naiif_printf("\r\n*** To use this sample strobe it is recommended to set a quiet time > 500 ms **");
naiif_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)
{
quietTime = atoi((const char *)inputBuffer);
status = check_status(naibrd_DT_SetWatchdogQuietTime(dt_params->cardIndex, dt_params->module, quietTime * 1000));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function sets the watchdog window time for the module. The user is prompted for the value in ms.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_WatchDogWindowTime(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t dt_params = (p_naiapp_AppParameters_t)params;
bool_t bQuit = NAI_FALSE;
uint32_t windowTime = 0;
nai_status_t status = NAI_ERROR_UNKNOWN;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
naiif_printf("\r\n*** To use this sample strobe it is recommended to set a window time > 500 ms **");
naiif_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)
{
windowTime = atoi((const char *)inputBuffer);
status = check_status(naibrd_DT_SetWatchdogWindow(dt_params->cardIndex, dt_params->module, windowTime * 1000));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function displays the DT Watchdog Operations data.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_DT_DisplayWatchdog(int32_t paramCount, int32_t* params)
{
nai_status_bit_t wdStatLatched = 0;
nai_status_bit_t wdStatRT = 0;
uint32_t windowTime = 0;
uint32_t quietTime = 0;
p_naiapp_AppParameters_t dt_params = (p_naiapp_AppParameters_t)params;
if (APP_PARAM_COUNT == paramCount)
{
naiif_printf("\r\n\r\nDT Watchdog Data:\r\n");
check_status(naibrd_DT_GetWatchdogQuietTime(dt_params->cardIndex, dt_params->module, &quietTime));
quietTime = quietTime / 1000;
naiif_printf("Quiet Time: %dmS\r\n", quietTime);
check_status(naibrd_DT_GetWatchdogWindow(dt_params->cardIndex, dt_params->module, &windowTime));
windowTime = windowTime / 1000;
naiif_printf("Window Time: %dmS\r\n", windowTime);
check_status(naibrd_DT_GetChanMappedStatus(dt_params->cardIndex, dt_params->module, 1, NAIBRD_DT_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &wdStatLatched));
check_status(naibrd_DT_GetChanMappedStatus(dt_params->cardIndex, dt_params->module, 1, NAIBRD_DT_STATUS_WATCHDOG_TIMER_FAULT_REALTIME, &wdStatRT));
naiif_printf("WatchDog Status (R/L): (%1d/%1d)\r\n", wdStatRT, wdStatLatched);
naiif_printf("\r\n");
}
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
* <summary>
* This function will start a thread to continuously Strobe the watchdog. The user is prompted for the value in ms.
* 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* params)
{
p_naiapp_AppParameters_t dt_params = (p_naiapp_AppParameters_t)params;
bool_t bQuit = NAI_FALSE;
nai_status_t status = NAI_ERROR_UNKNOWN;
int32_t* arg = (int32_t*)malloc(sizeof(int32_t) * 3);
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (APP_PARAM_COUNT == paramCount)
{
naiif_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 **");
naiif_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')
{
naiif_printf("\r\nStrobing Watchdog every (QuietTime) + (Window)/2...");
naiif_printf("\r\nStarting thread...");
/* Spawn thread here */
arg[0] = dt_params->cardIndex;
arg[1] = dt_params->module;
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
if (thread == 0)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
if (thread != (int32_t*)NULL)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
if (thread != (pthread_t)NULL)
#endif
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
LPDWORD threadID = 0;
thread = CreateThread(NULL, 0, WD_Strobe_ThreadEntryPoint, arg, 0, threadID);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
pthread_create(&thread, NULL, WD_Strobe_ThreadEntryPoint, arg);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_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);
naiif_printf("\r\nFailed to Create Thread");
}
}
else
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
LPDWORD threadID = 0;
#endif
/* kill previous thread and create new one. Report this to them. */
naiapp_kill_WDStrobe_Thread();
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
thread = CreateThread(NULL, 0, WD_Strobe_ThreadEntryPoint, arg, 0, threadID);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
pthread_create(&thread, NULL, WD_Strobe_ThreadEntryPoint, arg);
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_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 (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
if (thread != 0) {}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
if (thread != (int32_t*)NULL) {}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
if (thread != (pthread_t)NULL) {}
#endif
else
{
free(arg);
naiif_printf("\r\nFailed to Create Thread");
}
}
}
else
{
naiif_printf("\r\nReturning to Menu...");
}
}
}
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function 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 (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
if (thread != 0)
{
terminateThread = NAI_TRUE;
thread = 0;
}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
if (thread != ((int32_t*)NULL))
{
terminateThread = NAI_TRUE;
thread = ((int32_t*)NULL);
}
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
if (thread != (pthread_t)NULL)
{
terminateThread = NAI_TRUE;
thread = (pthread_t)NULL;
}
#else
#error Unspported OS
#endif
}
/**************************************************************************************************************/
/**
* <summary>
* This function will continuously loop, strobing the watchdog every QuietTime + Window/2.
* </summary>
*/
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
DWORD WINAPI WD_Strobe_ThreadEntryPoint(LPVOID param)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
void* WD_Strobe_ThreadEntryPoint(void* param)
#elif defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
static int WD_Strobe_ThreadEntryPoint(int32_t param)
#else
#error Unsupported OS
#endif
{
uint32_t windowTime = 0;
uint32_t quietTime = 0;
int32_t delayTime = 0;
int32_t* modInfo = (int32_t*)param;
int32_t cardIndex = modInfo[0];
int32_t module = modInfo[1];
terminateThread = NAI_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);
naibrd_DT_WatchdogStrobe(cardIndex, module);
do
{
naiif_msDelay(delayTime);
check_status(naibrd_DT_WatchdogStrobe(cardIndex, module));
} while (!terminateThread);
return NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
* <summary>
* This function 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* params)
{
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_WINDOWS)
NAIBSP_UNREFERENCED_PARAMETER(paramCount);
NAIBSP_UNREFERENCED_PARAMETER(params);
#endif
naiapp_kill_WDStrobe_Thread();
return NAI_SUCCESS;
}
#endif
/**************************************************************************************************************/
/**
<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 = NAI_FALSE;
int32_t channelCount = 0;
bool_t pBitComplete = NAI_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 modid = p_dt_params->modId;
int32_t chan = 0;
NAIBSP_UNREFERENCED_PARAMETER(paramCount);
if ((modid == NAIBRD_MODULE_ID_DT1) || (modid == NAIBRD_MODULE_ID_DT4) || (modid == NAIBRD_MODULE_ID_CM1) || (modid == NAIBRD_MODULE_ID_CM2) || modid == NAIBRD_MODULE_ID_CM8
|| modid == NAIBRD_MODULE_ID_CMR || modid == NAIBRD_MODULE_ID_IF3 )
{
channelCount = naibrd_DT_GetChannelCount(modid);
/* Check to see if PBIT ran for the module. */
naiif_printf("\r\nChecking if the Power-On BIT test has run...\r\n");
check_status(naibrd_DT_CheckPowerOnBITComplete(cardIndex, module, &pBitComplete));
switch (pBitComplete)
{
case 0u:
naiif_printf("\r\nPBIT Complete: NOT COMPLETED\r\n");
break;
case 1u:
naiif_printf("\r\nPBIT Complete: COMPLETED\r\n");
break;
default:
naiif_printf("\r\nPBIT Complete: UNKNOWN\r\n");
break;
}
if (pBitComplete)
{
/* Read the BIT status */
naiif_printf("\r\nChecking the result of the Power-on BIT test...\r\n");
for (chan = 1; chan <= channelCount; chan++)
{
check_status(naibrd_DT_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DT_STATUS_BIT_LATCHED, &bitStatus));
switch (bitStatus)
{
case (nai_status_bit_t)0u:
naiif_printf(strBitStatus, "BIT Passed");
break;
case (nai_status_bit_t)1u:
naiif_printf(strBitStatus, "BIT FAILED");
break;
default:
naiif_printf(strBitStatus, "Unknown");
break;
}
naiif_printf("Ch. %d: %s\r\n", chan, strBitStatus);
}
}
}
else
{
naiif_printf("\r\nModule does not support Power-On BIT!\r\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 = NAI_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;
int32_t chan = p_dt_params->channel;
uint32_t modid = p_dt_params->modId;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
NAIBSP_UNREFERENCED_PARAMETER(paramCount);
if ((modid == NAIBRD_MODULE_ID_DT1) || (modid == NAIBRD_MODULE_ID_DT4) || (modid == NAIBRD_MODULE_ID_CM1) || (modid == NAIBRD_MODULE_ID_CM2) || modid == NAIBRD_MODULE_ID_CM8
|| modid == NAIBRD_MODULE_ID_CMR || modid == NAIBRD_MODULE_ID_IF3 )
{
naiif_printf("\r\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
{
naiif_printf("\r\nModule does not support clearing of BIT logic!\r\n");
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handle_DT_ModulePowerResetMenu displays the menu for module power reset commands.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
bool_t bContinue = NAI_TRUE;
bool_t bCmdFound = NAI_FALSE;
int32_t cmd = 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;
numMenuCmds = DT_MODULE_POWER_RESET_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_ModulePowerResetMenuCmds);
while (bContinue)
{
naiif_printf("\r\n\r\n\r\n");
naiif_printf(" -----------------------------Status------------------------------ ----------Request----------\r\n");
naiif_printf(" Powered Down Not Detected Not Link Init Not FW Not Comm Error Reset Power Down Power Up\r\n");
naiif_printf(" ------------ ------------ ------------- ---------- ---------- ----- ---------- --------\r\n");
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_STATUS_POWERED_DOWN, &poweredDownStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_STATUS_NOT_DETECTED, ¬DetectedStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT, ¬LinkInitStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_STATUS_FW_NOT_READY, ¬FWNotStatus));
check_status(naibrd_DT_GetModulePowerResetStatus(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_STATUS_COMM_ERROR, &commErrorStatus));
check_status(naibrd_DT_GetModulePowerReset(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_REQUEST_RESET, &resetRequest));
check_status(naibrd_DT_GetModulePowerReset(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_REQUEST_POWER_DOWN, &powerDownRequest));
check_status(naibrd_DT_GetModulePowerReset(cardIndex, module, NAIBRD_DT_MODULE_POWER_RESET_REQUEST_POWER_UP, &powerUpRequest));
naiif_printf(" %1d %1d %1d %1d %1d %1d %1d %1d\r\n",
poweredDownStatus, notDetectedStatus, notLinkInitStatus, notFWNotStatus, commErrorStatus, resetRequest, powerDownRequest, powerUpRequest);
naiapp_display_ParamMenuCommands((int8_t*)"DT Power Reset Operation Menu");
naiif_printf("\r\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 = NAI_FALSE;
}
else
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
DT_ModulePowerResetMenuCmds[cmd].func(paramCount, p_params);
}
else
{
naiif_printf("\r\nInvalid command entered\r\n");
}
}
}
}
else
bContinue = NAI_FALSE;
}
numMenuCmds = DT_BASICOP_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, DT_BasicOpMenuCmds);
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 Configure_DT_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
naibrd_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;
NAIBSP_UNREFERENCED_PARAMETER(paramCount);
naiif_printf("\r\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 = NAIBRD_DT_MODULE_POWER_RESET_STATUS_POWERED_DOWN;
naiif_printf(statusTypeStr, "Powered Down");
break;
case '1':
statusTypeToClear = NAIBRD_DT_MODULE_POWER_RESET_STATUS_NOT_DETECTED;
naiif_printf(statusTypeStr, "Not Detected");
break;
case '2':
statusTypeToClear = NAIBRD_DT_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT;
naiif_printf(statusTypeStr, "Not Link Init");
break;
case '3':
statusTypeToClear = NAIBRD_DT_MODULE_POWER_RESET_STATUS_FW_NOT_READY;
naiif_printf(statusTypeStr, "Not FW Not");
break;
case '4':
statusTypeToClear = NAIBRD_DT_MODULE_POWER_RESET_STATUS_COMM_ERROR;
naiif_printf(statusTypeStr, "Comm Error");
break;
case 'q':
case 'Q':
bQuit = NAI_TRUE;
break;
default:
bQuit = NAI_TRUE;
naiif_printf("\r\nInvalid module power reset status type entered\r\n");
break;
}
if (!bQuit)
{
naiif_printf("\r\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 Configure_DT_SetModulePowerReset(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
naibrd_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;
NAIBSP_UNREFERENCED_PARAMETER(paramCount);
naiif_printf("\r\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 = NAIBRD_DT_MODULE_POWER_RESET_REQUEST_RESET;
naiif_printf(resetTypeStr, "Reset");
break;
case '1':
resetTypeToSet = NAIBRD_DT_MODULE_POWER_RESET_REQUEST_POWER_DOWN;
naiif_printf(resetTypeStr, "Power Down");
break;
case '2':
resetTypeToSet = NAIBRD_DT_MODULE_POWER_RESET_REQUEST_POWER_UP;
naiif_printf(resetTypeStr, "Power Up");
break;
case 'q':
case 'Q':
bQuit = NAI_TRUE;
break;
default:
bQuit = NAI_TRUE;
naiif_printf("\r\nInvalid module power reset request type entered\r\n");
break;
}
if (!bQuit)
{
naiif_printf("\r\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)NAI_FALSE));
}
else if (inputBuffer[0] == '1')
{
check_status(naibrd_DT_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)NAI_TRUE));
}
else
{
naiif_printf("\r\nInvalid selection entered\r\n");
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}