REF BasicOps
Edit this on GitLab
REF BasicOps Sample Application (SSK 2.x)
Overview
The REF BasicOps sample application demonstrates how to configure and control reference/excitation output modules using the NAI Software Support Kit (SSK 2.x). It covers the core REF operations you will need in your own application: setting output frequency and voltage, configuring current limits, enabling/disabling channel output power, managing floating-point mode, resetting channels, enabling channel status monitoring, running watchdog operations, checking power-on BIT, and managing module power reset.
This sample supports the AC1 module as well as LD6 modules that provide reference output functionality. For LD6 modules, a simplified menu is used with only frequency, voltage, current limit, and channel reset commands. For detailed module specifications, refer to the AC1 Manual.
For the SSK 1.x version, see REF BasicOps (SSK 1.x).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a REF module installed (AC1).
-
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 ref_basic_ops executable from your build output directory. On startup the application looks for a configuration file (default_RefBasicOps.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 displays measurement data for all channels and presents a command menu for configuring REF 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 REF. |
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_RefBasicOps.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 REF variant installed.
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t REF_RunBasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Select Card Index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
REFBasicMenu_Run(cardIndex, module, moduleID);
}
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
Note the SSK 2.x differences from SSK 1.x in this startup sequence:
-
The VxWorks preprocessor guard uses
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 REF_RunBasicOps():
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t REF_RunBasicOps(void)
#else
int32_t main(void)
#endif
Command Loop
After connecting to the board and selecting a module, the application calls REFBasicMenu_Run(). This function loads the appropriate command table based on the module ID (full menu for AC1, simplified menu for LD6), then enters a loop that displays measurement data for all channels, presents the command menu, and dispatches user selections. For commands that operate on individual channels, the user is first prompted to select a channel number.
The command table defines the following operations:
| Command | Description |
|---|---|
|
Set the output frequency for a selected channel. |
|
Set the output voltage for a selected channel. |
|
Set the current limit for a selected channel. |
|
Enable or disable the output power for a selected channel. |
|
Enable or disable hardware floating-point conversion mode (module-wide). |
|
Reset a selected channel (clears overcurrent and BIT status). |
|
Enable or disable channel status monitoring for a selected channel. |
|
Enter the watchdog submenu (not available on DEOS). |
|
Check power-on BIT completion status. |
|
Enter the module power reset submenu. |
Displaying Measurement Data
Before each command prompt, the application displays a measurement table showing all channels. The naiapp_REFBasicMenu_DisplayMeasurements() function reads:
check_status(naibrd_REF_GetData(cardIndex, module, channel, NAIBRD_REF_FREQUENCY, &frequencySet));
check_status(naibrd_REF_GetMeasuredData(cardIndex, module, channel, NAIBRD_REF_MEASURED_FREQUENCY, &frequencyOut));
check_status(naibrd_REF_GetData(cardIndex, module, channel, NAIBRD_REF_VOLTAGE, &voltageSet));
check_status(naibrd_REF_GetMeasuredData(cardIndex, module, channel, NAIBRD_REF_MEASURED_VOLTAGE, &voltageOut));
check_status(naibrd_REF_GetData(cardIndex, module, channel, NAIBRD_REF_CURRENT_LIMIT, ¤tLimit));
check_status(naibrd_REF_GetMeasuredData(cardIndex, module, channel, NAIBRD_REF_MEASURED_CURRENT, ¤tOut));
Key API calls:
-
naibrd_REF_GetData()— Reads configured (set) values for frequency, voltage, and current limit. -
naibrd_REF_GetMeasuredData()— Reads actual measured values (wrap-back) for frequency, voltage, and current. -
naibrd_REF_GetChannelEnable()— Reads the output power enable state. -
naibrd_REF_GetChanStatusEnable()— Reads whether channel status monitoring is enabled. -
naibrd_REF_GetChanMappedStatus()— Reads BIT status. -
naibrd_REF_GetEventMappedStatus()— Reads overcurrent status.
Setting Frequency, Voltage, and Current Limit
The configuration functions prompt the user for a value and call the corresponding API:
-
naibrd_REF_SetData(cardIndex, module, channel, NAIBRD_REF_FREQUENCY, freq)— Sets the output frequency. -
naibrd_REF_SetData(cardIndex, module, channel, NAIBRD_REF_VOLTAGE, volt)— Sets the output voltage. -
naibrd_REF_SetData(cardIndex, module, channel, NAIBRD_REF_CURRENT_LIMIT, currentLimit)— Sets the current limit.
Enabling Output Power and Floating-Point Mode
-
naibrd_REF_SetChannelEnable(cardIndex, module, channel, enable)— Enables (1) or disables (0) the output power for a channel. -
naibrd_SetFloatingPointModeEnable(cardIndex, module, enable)— Enables or disables hardware floating-point conversion mode for the entire module.
Channel Reset and Status
-
naibrd_REF_SetReset(cardIndex, module, channel, NAIBRD_REF_RESET_OVERCURRENT)— Resets the overcurrent condition for a channel. -
naibrd_REF_ClearEventMappedStatus(cardIndex, module, channel, NAIBRD_REF_STATUS_OVERCURRENT_LATCHED)— Clears the latched overcurrent status. -
naibrd_REF_ClearChanMappedStatus(cardIndex, module, channel, NAIBRD_REF_STATUS_BIT_LATCHED)— Clears the latched BIT status. -
naibrd_REF_SetChanStatusEnable(cardIndex, module, channel, enable)— Enables or disables channel status monitoring.
Watchdog Operations
The watchdog submenu (available on all platforms except DEOS) provides control over the module watchdog timer. The watchdog requires periodic strobing to prevent a fault condition. Commands include:
-
Set Quiet Time —
naibrd_REF_SetWatchdogQuietTime()sets the initial quiet period after watchdog activation. -
Set Window Time —
naibrd_REF_SetWatchdogWindowTime()sets the window within which the watchdog must be strobed. -
Display Settings — Shows current watchdog configuration.
-
Strobe — Starts a background thread that continuously strobes the watchdog.
-
Kill — Terminates the watchdog strobing thread.
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found |
Board not powered, cable disconnected, or wrong interface selected. |
Verify power, cables, and that the correct interface type is chosen in the board menu. |
Connection timeout |
Incorrect IP address, firewall blocking communication, or network misconfiguration. |
Confirm the board IP address. Disable or configure firewall rules. |
Invalid card or module index |
Indices are zero-based for cards and one-based for modules. |
Ensure the values you enter match your hardware setup. |
Output voltage reads as zero |
Channel output power is disabled. |
Use the |
Overcurrent status set |
The load exceeds the configured current limit. |
Reduce the load or increase the current limit. Use |
BIT status set |
Built-in test has detected a fault condition. |
Use |
Watchdog fault |
The watchdog strobe thread was killed or missed a strobe window. |
Restart the strobe thread using the |
LD6 module shows limited menu |
LD6 modules only support frequency, voltage, current limit, and channel reset. |
This is expected behavior. LD6 modules do not support output enable, floating-point mode, or watchdog. |
Floating-point mode not available |
The module firmware may not support hardware floating-point conversion. |
Verify firmware version. Floating-point mode is not available on LD6 modules. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
|
Note
|
This source file is large (approximately 1,200 lines) due to the extensive set of configuration commands, watchdog operations, and module power reset handling. |
Full Source — ref_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_ref.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 *SAMPLE_PGM_NAME = (const int8_t*)"REF Basic Operations";
static const int8_t *DEF_CONFIG_FILE = (const int8_t*)"default_RefBasicOps.txt";
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
static const int8_t *SAMPLE_WD_PGM_NAME = (const int8_t*)"REF Watchdog Operations";
#endif
/* Function prototypes */
static bool_t REFBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t naiapp_REFBasicMenu_DisplayMeasurements(int32_t cardIndex, int32_t module, int32_t maxChannels, uint32_t modId);
static nai_status_t naiapp_REFBasicMenu_SetFrequency(int32_t paramCount, int32_t* params);
static nai_status_t naiapp_REFBasicMenu_SetVoltage(int32_t paramCount, int32_t* params);
static nai_status_t naiapp_REFBasicMenu_SetCurrentLimit(int32_t paramCount, int32_t* params);
static nai_status_t naiapp_REFBasicMenu_SetOutputEnable(int32_t paramCount, int32_t* params);
static nai_status_t naiapp_REFBasicMenu_SetFloatingPointEnable(int32_t paramCount, int32_t* params);
static nai_status_t naiapp_REFBasicMenu_SetChannelReset(int32_t paramCount, int32_t* params);
static nai_status_t naiapp_REFBasicMenu_ChannelStatusEnable(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_CheckPowerOnBIT(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_ModulePowerResetMenu(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_REF_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t Handle_REF_SetModulePowerReset(int32_t paramCount, int32_t* p_params);
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
static nai_status_t Handle_REF_WatchDogQuietTime(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_WatchDogWindowTime(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_DisplayWatchdog(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_StrobeWatchdog(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_kill_WDStrobe_Thread(int32_t paramCount, int32_t* params);
static nai_status_t Handle_REF_WatchdogShowMenu(int32_t paramCount, int32_t* params);
static void naiapp_kill_WDStrobe_Thread();
#endif
enum ref_basicOpsMenu_commands
{
REF_BASICMENU_SET_FREQUENCY,
REF_BASICMENU_SET_VOLTAGE,
REF_BASICMENU_SET_CURRENT_LIMIT,
REF_BASICMENU_SET_OUTPUT_ENABLE,
REF_BASICMENU_SET_FLOATING_POINT_ENABLE,
REF_BASICMENU_SET_CHANNEL_RESET,
REF_BASICMENU_SET_CHANNEL_STATUS_ENABLE,
REF_BASICMENU_WD_MENU,
REF_BASICMENU_SET_PBIT,
REF_BASICMENU_MODULE_POWER_RESET_MENU,
REF_BASICMENU_CMD_COUNT
};
naiapp_cmdtbl_params_t REF_BasicOpMenuCmds[] =
{
{ "FREQ", "Set Frequency", REF_BASICMENU_SET_FREQUENCY, naiapp_REFBasicMenu_SetFrequency},
{ "VOLT", "Set Voltage", REF_BASICMENU_SET_VOLTAGE, naiapp_REFBasicMenu_SetVoltage},
{ "C_LIMIT","Set Current Limit", REF_BASICMENU_SET_CURRENT_LIMIT, naiapp_REFBasicMenu_SetCurrentLimit},
{ "POWR", "Set Output Power", REF_BASICMENU_SET_OUTPUT_ENABLE, naiapp_REFBasicMenu_SetOutputEnable},
{ "FP", "Set Floating Point", REF_BASICMENU_SET_FLOATING_POINT_ENABLE, naiapp_REFBasicMenu_SetFloatingPointEnable},
{ "RCHAN", "ResetChannel", REF_BASICMENU_SET_CHANNEL_RESET, naiapp_REFBasicMenu_SetChannelReset},
{"CHANSTAT", "Channel Status Enable/Disable", REF_BASICMENU_SET_CHANNEL_STATUS_ENABLE, naiapp_REFBasicMenu_ChannelStatusEnable},
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
{"WATCHDOG", "Show Watchdog Menu Options", REF_BASICMENU_WD_MENU, Handle_REF_WatchdogShowMenu},
#endif
{"PBIT", "Check Power-On BIT", REF_BASICMENU_SET_PBIT, Handle_REF_CheckPowerOnBIT},
{"PWRRESET","Show Module Power Reset Menu Options", REF_BASICMENU_MODULE_POWER_RESET_MENU, Handle_REF_ModulePowerResetMenu}
};
#define REF_LD6_BASICMENU_CMD_COUNT 3
naiapp_cmdtbl_params_t REF_LD6_BasicOpMenuCmds[] =
{
{ "FREQ", "Set Frequency", REF_BASICMENU_SET_FREQUENCY, naiapp_REFBasicMenu_SetFrequency},
{ "VOLT", "Set Voltage", REF_BASICMENU_SET_VOLTAGE, naiapp_REFBasicMenu_SetVoltage},
{ "C_LIMIT","Set Current Limit", REF_BASICMENU_SET_CURRENT_LIMIT, naiapp_REFBasicMenu_SetCurrentLimit},
{ "RCHAN", "ResetChannel", REF_BASICMENU_SET_CHANNEL_RESET, naiapp_REFBasicMenu_SetChannelReset},
};
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
enum ref_gen5_ref_watchdog_commands
{
REF_COMMON_CMD_WD_QUIETTIME,
REF_COMMON_CMD_WD_WINDOWTIME,
REF_COMMON_CMD_WD_DISPLAY,
REF_COMMON_CMD_WD_STROBE,
REF_COMMON_CMD_WD_KILL,
REF_COMMON_CMD_WD_BACK,
REF_COMMON_CMD_WD_COUNT
};
naiapp_cmdtbl_params_t REF_WatchdogOpMenuCmds[REF_COMMON_CMD_WD_COUNT] =
{
{"BACK", "Back to Main Menu", 0, NULL},
{"DISPLAY", "Display Watchdog Settings", REF_COMMON_CMD_WD_DISPLAY, Handle_REF_DisplayWatchdog},
{"TIME QUIET", "Set Watchdog Quiet Time", REF_COMMON_CMD_WD_QUIETTIME, Handle_REF_WatchDogQuietTime},
{"WINDOW", "Set Watchdog Window Time", REF_COMMON_CMD_WD_WINDOWTIME, Handle_REF_WatchDogWindowTime},
{"STROBE", "Start thread to continuously strobe watchdog", REF_COMMON_CMD_WD_STROBE, Handle_REF_StrobeWatchdog},
{"KILL", "Kill Watchdog strobing thread", REF_COMMON_CMD_WD_KILL, Handle_REF_kill_WDStrobe_Thread}
};
#endif
enum ref_module_power_reset_commands
{
REF_MODULE_POWER_RESET_CMD_BACK,
REF_MODULE_POWER_RESET_CMD_CLEAR_MODULE_POWER_RESET_STATUS,
REF_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET,
REF_MODULE_POWER_RESET_CMD_COUNT
};
naiapp_cmdtbl_params_t REF_ModulePowerResetMenuCmds[REF_MODULE_POWER_RESET_CMD_COUNT] =
{
{"BACK", "Back to Main Menu", REF_MODULE_POWER_RESET_CMD_BACK, NULL},
{"CLEAR", "Clear Module Power Reset Status", REF_MODULE_POWER_RESET_CMD_CLEAR_MODULE_POWER_RESET_STATUS, Handle_REF_ClearModulePowerResetStatus},
{"SET", "Set Module Power Reset Request", REF_MODULE_POWER_RESET_CMD_SET_MODULE_POWER_RESET, Handle_REF_SetModulePowerReset}
};
#if defined (WIN32)
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
/********************/
/* Global Variables */
/********************/
/* TX Thread */
#if defined (WIN32)
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
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
static bool_t terminateThread;
#endif
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t REF_RunBasicOps(void)
#else
int32_t main(void)
#endif
{
bool_t stop = NAI_FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Select Card Index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
REFBasicMenu_Run(cardIndex, module, moduleID);
}
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
static bool_t REFBasicMenu_Run(int32_t cardIndex, int32_t module, uint32_t modId)
{
bool_t bQuit = NAI_FALSE;
int32_t cmd = REF_BASICMENU_CMD_COUNT;
naiapp_AppParameters_t refParams;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
refParams.cardIndex = cardIndex;
refParams.module = module;
refParams.modId = modId;
refParams.maxChannels = naibrd_REF_GetChannelCount(modId);
if (NAIBRD_MODULE_ID_LD6 == modId)
{
naiapp_utils_LoadParamMenuCommands(REF_LD6_BASICMENU_CMD_COUNT, REF_LD6_BasicOpMenuCmds);
cmd = REF_LD6_BASICMENU_CMD_COUNT;
}
else
{
naiapp_utils_LoadParamMenuCommands(REF_BASICMENU_CMD_COUNT, REF_BasicOpMenuCmds);
}
do
{
naiapp_REFBasicMenu_DisplayMeasurements(cardIndex, module, refParams.maxChannels, modId);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_PGM_NAME);
naiif_printf("\r\n Type command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit && inputResponseCnt > 0)
{
naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
switch (cmd)
{
case REF_BASICMENU_SET_FLOATING_POINT_ENABLE:
REF_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)&refParams);
break;
case REF_BASICMENU_SET_FREQUENCY:
case REF_BASICMENU_SET_VOLTAGE:
case REF_BASICMENU_SET_CURRENT_LIMIT:
case REF_BASICMENU_SET_OUTPUT_ENABLE:
case REF_BASICMENU_SET_CHANNEL_RESET:
case REF_BASICMENU_SET_CHANNEL_STATUS_ENABLE:
naiapp_query_ChannelNumber(refParams.maxChannels, 1, &(refParams.channel));
REF_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)&refParams);
break;
case REF_BASICMENU_WD_MENU:
case REF_BASICMENU_SET_PBIT:
case REF_BASICMENU_MODULE_POWER_RESET_MENU:
REF_BasicOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)&refParams);
break;
default:
naiif_printf("Please enter a menu selection above\r\n");
break;
}
}
} while (!bQuit);
return NAI_TRUE;
}
static bool_t naiapp_REFBasicMenu_DisplayMeasurements(int32_t cardIndex, int32_t module, int32_t maxChannels, uint32_t modId)
{
int32_t channel;
float64_t frequencySet = 00000.000;
float64_t frequencyOut = 00000.000;
float64_t voltageSet = 000.000;
float64_t voltageOut = 000.000;
float64_t currentLimit = 00.00;
float64_t currentOut = 00.00;
uint32_t powerControlOut = 0;
bool_t fpEnable = NAI_FALSE;
nai_status_bit_t overCurrentStatusBit = NAI_STATUS_BIT_LO;
nai_status_bit_t BITStatusBit = NAI_STATUS_BIT_LO;
bool_t chanStatusEnabled = NAI_TRUE;
naiif_printf("\r\n\r\n ======================================================================= \r\n");
naiif_printf("%7s%14s%20s%18s%12s%15s%5s%13s\r\n", "Chan", "Frequency", "Voltage", "Current", "Output", "ChannelStatus", "BIT",
"OverCurrent");
naiif_printf("%7s%14s%22s%18s\r\n", "", "set(wrap)", "set(wrap)", "limit(wrap)");
for (channel = 1; channel <= maxChannels; channel++)
{
check_status(naibrd_REF_GetData(cardIndex, module, channel, NAIBRD_REF_FREQUENCY, &frequencySet));
check_status(naibrd_REF_GetMeasuredData(cardIndex, module, channel, NAIBRD_REF_MEASURED_FREQUENCY, &frequencyOut));
check_status(naibrd_REF_GetData(cardIndex, module, channel, NAIBRD_REF_VOLTAGE, &voltageSet));
check_status(naibrd_REF_GetMeasuredData(cardIndex, module, channel, NAIBRD_REF_MEASURED_VOLTAGE, &voltageOut));
check_status(naibrd_REF_GetData(cardIndex, module, channel, NAIBRD_REF_CURRENT_LIMIT, ¤tLimit));
check_status(naibrd_REF_GetMeasuredData(cardIndex, module, channel, NAIBRD_REF_MEASURED_CURRENT, ¤tOut));
naiif_printf("%4d %9.3f(%09.3f) %7.3f(%07.3f) %06.3f(%06.3f)", channel, frequencySet, frequencyOut, voltageSet, voltageOut,
currentLimit, currentOut);
if (NAIBRD_MODULE_ID_LD6 == modId)
{
naiif_printf("%6s", "N/A"); /* ChannelEnable */
naiif_printf("%15s", " N/A "); /* channelStatusEnabled */
naiif_printf("%8s", "N/A"); /* BITStatus */
naiif_printf("%8s", "N/A"); /* OverCurrentStatus */
}
else
{
check_status(naibrd_REF_GetChannelEnable(cardIndex, module, channel, &powerControlOut));
if (powerControlOut == NAI_TRUE)
naiif_printf("%5s", "ON ");
else
naiif_printf("%6s", "OFF");
check_status(naibrd_REF_GetChanStatusEnable(cardIndex, module, channel, &chanStatusEnabled));
if (chanStatusEnabled == NAI_FALSE)
naiif_printf("%16s", "DISABLED");
else
naiif_printf("%15s", "ENABLED");
check_status(naibrd_REF_GetChanMappedStatus(cardIndex, module, channel, NAIBRD_REF_STATUS_BIT_LATCHED, &BITStatusBit));
if (BITStatusBit == NAI_STATUS_BIT_HI)
naiif_printf("%8s", "SET");
else
naiif_printf("%9s", "CLEAR");
check_status(naibrd_REF_GetEventMappedStatus(cardIndex, module, channel, NAIBRD_REF_STATUS_OVERCURRENT_LATCHED, &overCurrentStatusBit));
if (overCurrentStatusBit == NAI_STATUS_BIT_HI)
naiif_printf("%8s", "SET");
else
naiif_printf("%9s", "CLEAR");
}
naiif_printf("\r\n");
}
if (NAIBRD_MODULE_ID_LD6 != modId)
{
check_status(naibrd_GetRunningInFloatingPointMode(cardIndex, module, &fpEnable));
naiif_printf("\r\n H/W Floating Point Mode: " );
naiif_printf(fpEnable == NAI_FALSE ? "Disabled\r\n" : "Enabled\r\n" );
}
return NAI_TRUE;
}
static nai_status_t naiapp_REFBasicMenu_SetFrequency(int32_t paramCount, int32_t* params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_refParams = NULL;
bool_t bQuit = NAI_FALSE;
float64_t freq = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (paramCount == APP_PARAM_COUNT)
{
p_refParams = (p_naiapp_AppParameters_t)params;
naiif_printf("Enter a frequency: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
sscanf((const char*)inputBuffer, "%lf", &freq);
check_status(naibrd_REF_SetData(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, NAIBRD_REF_FREQUENCY, freq));
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t naiapp_REFBasicMenu_SetVoltage(int32_t paramCount, int32_t* params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_refParams = NULL;
bool_t bQuit = NAI_FALSE;
float64_t volt = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (paramCount == APP_PARAM_COUNT)
{
p_refParams = (p_naiapp_AppParameters_t)params;
naiif_printf("Enter a voltage: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
sscanf((const char*)inputBuffer, "%lf", &volt);
check_status(naibrd_REF_SetData(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, NAIBRD_REF_VOLTAGE, volt));
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t naiapp_REFBasicMenu_SetCurrentLimit(int32_t paramCount, int32_t* params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_refParams = NULL;
bool_t bQuit = NAI_FALSE;
float64_t currentLimit = 0.0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (paramCount == APP_PARAM_COUNT)
{
p_refParams = (p_naiapp_AppParameters_t)params;
naiif_printf("Enter current limit: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
sscanf((const char*)inputBuffer, "%lf", ¤tLimit);
check_status(naibrd_REF_SetData(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, NAIBRD_REF_CURRENT_LIMIT, currentLimit));
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t naiapp_REFBasicMenu_SetOutputEnable(int32_t paramCount, int32_t* params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_refParams = NULL;
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (paramCount == APP_PARAM_COUNT)
{
p_refParams = (p_naiapp_AppParameters_t)params;
naiif_printf("Enter a Output Power (0 Off 1 On): ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputBuffer[0] == '0')
check_status(naibrd_REF_SetChannelEnable(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, 0));
else if (inputBuffer[0] == '1')
check_status(naibrd_REF_SetChannelEnable(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, 1));
}
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t naiapp_REFBasicMenu_SetFloatingPointEnable(int32_t paramCount, int32_t* params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_refParams = NULL;
bool_t bQuit = NAI_FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (paramCount == APP_PARAM_COUNT)
{
p_refParams = (p_naiapp_AppParameters_t)params;
naiif_printf("Enable H/W Floating Point Mode (Y = YES, any other key = NO)?");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')
status = check_status(naibrd_SetFloatingPointModeEnable(p_refParams->cardIndex, p_refParams->module, NAI_TRUE));
else
status = check_status(naibrd_SetFloatingPointModeEnable(p_refParams->cardIndex, p_refParams->module, NAI_FALSE));
}
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t naiapp_REFBasicMenu_SetChannelReset(int32_t paramCount, int32_t* params)
{
nai_status_t status = NAI_ERROR_UNKNOWN;
p_naiapp_AppParameters_t p_refParams = NULL;
if (paramCount == APP_PARAM_COUNT)
{
p_refParams = (p_naiapp_AppParameters_t)params;
check_status(naibrd_REF_SetReset(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, NAIBRD_REF_RESET_OVERCURRENT));
check_status(naibrd_REF_ClearEventMappedStatus(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, NAIBRD_REF_STATUS_OVERCURRENT_LATCHED));
check_status(naibrd_REF_ClearChanMappedStatus(p_refParams->cardIndex, p_refParams->module, p_refParams->channel, NAIBRD_REF_STATUS_BIT_LATCHED));
status = NAI_SUCCESS;
}
else
{
status = NAI_ERROR_INVALID_VALUE;
}
return status;
}
static nai_status_t naiapp_REFBasicMenu_ChannelStatusEnable(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t ref_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)
{
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_REF_SetChanStatusEnable(ref_params->cardIndex, ref_params->module, ref_params->channel,
((inputResponseCnt > 0) && (inputBuffer[0] == 'Y' || inputBuffer[0] == 'y')) ? NAI_TRUE : NAI_FALSE));
}
}
return status;
}
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
/**************************************************************************************************************/
/**
* <summary>
* This function displays the menu for watchdog commands
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_REF_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 ref_params = (p_naiapp_AppParameters_t)params;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
numMenuCmds = REF_COMMON_CMD_WD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, REF_WatchdogOpMenuCmds);
while (bContinue)
{
Handle_REF_DisplayWatchdog(paramCount, params);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_WD_PGM_NAME);
naiif_printf("\r\nType REF 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;
numMenuCmds = REF_BASICMENU_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, REF_BasicOpMenuCmds);
}
else
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
REF_WatchdogOpMenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)ref_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_REF_WatchDogQuietTime(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t ref_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_REF_SetWatchdogQuietTime(ref_params->cardIndex, ref_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_REF_WatchDogWindowTime(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t ref_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_REF_SetWatchdogWindow(ref_params->cardIndex, ref_params->module, windowTime * 1000));
}
}
}
return status;
}
/**************************************************************************************************************/
/**
* <summary>
* This function displays the Watchdog Operations data.
* </summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_REF_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 ref_params = (p_naiapp_AppParameters_t)params;
if (APP_PARAM_COUNT == paramCount)
{
naiif_printf("\r\n\r\nREF Watchdog Data:\r\n");
check_status(naibrd_REF_GetWatchdogQuietTime(ref_params->cardIndex, ref_params->module, &quietTime));
quietTime = quietTime / 1000;
naiif_printf("Quiet Time: %dmS\r\n", quietTime);
check_status(naibrd_REF_GetWatchdogWindow(ref_params->cardIndex, ref_params->module, &windowTime));
windowTime = windowTime / 1000;
naiif_printf("Window Time: %dmS\r\n", windowTime);
check_status(naibrd_REF_GetChanMappedStatus(ref_params->cardIndex, ref_params->module, 1, NAIBRD_REF_STATUS_WATCHDOG_TIMER_FAULT_LATCHED, &wdStatLatched));
check_status(naibrd_REF_GetChanMappedStatus(ref_params->cardIndex, ref_params->module, 1, NAIBRD_REF_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_REF_StrobeWatchdog(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t ref_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] = ref_params->cardIndex;
arg[1] = ref_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 (WIN32)
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 (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 (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);
}
#endif
}
/**************************************************************************************************************/
/**
* <summary>
* This function will continuously loop, strobing the watchdog every QuietTime + Window/2.
* </summary>
*/
/**************************************************************************************************************/
#if defined (WIN32)
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_REF_GetWatchdogQuietTime(cardIndex, module, &quietTime));
check_status(naibrd_REF_GetWatchdogWindow(cardIndex, module, &windowTime));
quietTime = quietTime / 1000;
windowTime = windowTime / 1000;
delayTime = quietTime + (windowTime / 2);
naibrd_REF_WatchdogStrobe(cardIndex, module);
do
{
naiif_msDelay(delayTime);
check_status(naibrd_REF_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_REF_kill_WDStrobe_Thread(int32_t paramCount, int32_t* params)
{
NAIBSP_UNREFERENCED_PARAMETER(paramCount);
NAIBSP_UNREFERENCED_PARAMETER(params);
naiapp_kill_WDStrobe_Thread();
return NAI_SUCCESS;
}
#endif
/*****************************************************************************/
/**
* <summary>
* Handle_REF_CheckPowerOnBIT() Checks to see if the power-on BIT test
* has been run on the module. If the PBIT test has run, it checks the result
* of the test and reports it back.
* </summary>
*/
/*****************************************************************************/
static nai_status_t Handle_REF_CheckPowerOnBIT(int32_t paramCount, int32_t* params)
{
p_naiapp_AppParameters_t da_params = (p_naiapp_AppParameters_t)params;
nai_status_t status = NAI_ERROR_UNKNOWN;
int32_t channelCount = 0, channel = 0;
bool_t pbitComplete;
nai_status_bit_t bitFailed;
if (APP_PARAM_COUNT == paramCount)
{
switch (da_params->modId)
{
case NAIBRD_MODULE_ID_AC1:
case NAIBRD_MODULE_ID_AC2:
case NAIBRD_MODULE_ID_AC3:
case NAIBRD_MODULE_ID_AC4:
{
channelCount = naibrd_REF_GetChannelCount(da_params->modId);
/* Check to see if PBIT ran for the module. */
naiif_printf("Checking if the Power-On BIT test has run...\r\n");
status = naibrd_REF_CheckPowerOnBITComplete(da_params->cardIndex, da_params->module, &pbitComplete);
naiif_printf("PBIT Complete: %s", (pbitComplete) ? "COMPLETED\r\n" : "NOT COMPLETED\r\n");
if (pbitComplete)
{
/* Read the BIT status */
naiif_printf("Checking the result of the Power-on BIT test...\r\n");
for (channel = 1; channel <= channelCount; channel++)
{
status = naibrd_REF_GetChanMappedStatus(da_params->cardIndex, da_params->module, channel, NAIBRD_REF_STATUS_BIT_LATCHED,
&bitFailed);
naiif_printf("Ch. %d: %s", channel, bitFailed ? "BIT FAILED\r\n" : "BIT Passed\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>
Configure_REF_ModulePowerResetMenu displays the menu for module power reset commands.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Handle_REF_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 = NAI_FALSE;
bool_t notDetectedStatus = NAI_FALSE;
bool_t notLinkInitStatus = NAI_FALSE;
bool_t notFWNotStatus = NAI_FALSE;
bool_t commErrorStatus = NAI_FALSE;
bool_t resetRequest = NAI_FALSE;
bool_t powerDownRequest = NAI_FALSE;
bool_t powerUpRequest = NAI_FALSE;
p_naiapp_AppParameters_t p_ref_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ref_params->cardIndex;
int32_t module = p_ref_params->module;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
numMenuCmds = REF_MODULE_POWER_RESET_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, REF_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_REF_GetModulePowerResetStatus(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_STATUS_POWERED_DOWN, &poweredDownStatus));
check_status(naibrd_REF_GetModulePowerResetStatus(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_STATUS_NOT_DETECTED, ¬DetectedStatus));
check_status(naibrd_REF_GetModulePowerResetStatus(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT, ¬LinkInitStatus));
check_status(naibrd_REF_GetModulePowerResetStatus(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_STATUS_FW_NOT_READY, ¬FWNotStatus));
check_status(naibrd_REF_GetModulePowerResetStatus(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_STATUS_COMM_ERROR, &commErrorStatus));
check_status(naibrd_REF_GetModulePowerReset(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_REQUEST_RESET, &resetRequest));
check_status(naibrd_REF_GetModulePowerReset(cardIndex, module, NAIBRD_REF_MODULE_POWER_RESET_REQUEST_POWER_DOWN, &powerDownRequest));
check_status(naibrd_REF_GetModulePowerReset(cardIndex, module, NAIBRD_REF_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 REF 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)
{
REF_ModulePowerResetMenuCmds[cmd].func(paramCount, p_params);
}
else
{
naiif_printf("\r\nInvalid command entered\r\n");
}
}
}
}
else
bContinue = NAI_FALSE;
}
numMenuCmds = REF_BASICMENU_CMD_COUNT;
naiapp_utils_LoadParamMenuCommands(numMenuCmds, REF_BasicOpMenuCmds);
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_REF_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_REF_ClearModulePowerResetStatus(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
naibrd_ref_module_power_reset_status_type_t statusTypeToClear = (naibrd_ref_module_power_reset_status_type_t)0u;
bool_t modulePowerResetStatusRead = 0u;
char statusTypeStr[14] = "";
p_naiapp_AppParameters_t p_ref_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ref_params->cardIndex;
int32_t module = p_ref_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_REF_MODULE_POWER_RESET_STATUS_POWERED_DOWN;
sprintf(statusTypeStr, "Powered Down");
break;
case '1':
statusTypeToClear = NAIBRD_REF_MODULE_POWER_RESET_STATUS_NOT_DETECTED;
sprintf(statusTypeStr, "Not Detected");
break;
case '2':
statusTypeToClear = NAIBRD_REF_MODULE_POWER_RESET_STATUS_NOT_LINK_INIT;
sprintf(statusTypeStr, "Not Link Init");
break;
case '3':
statusTypeToClear = NAIBRD_REF_MODULE_POWER_RESET_STATUS_FW_NOT_READY;
sprintf(statusTypeStr, "Not FW Not");
break;
case '4':
statusTypeToClear = NAIBRD_REF_MODULE_POWER_RESET_STATUS_COMM_ERROR;
sprintf(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_REF_GetModulePowerResetStatus(cardIndex, module, statusTypeToClear, &modulePowerResetStatusRead));
if (modulePowerResetStatusRead == 1u)
{
check_status(naibrd_REF_ClearModulePowerResetStatus(cardIndex, module, statusTypeToClear));
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_REF_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_REF_SetModulePowerReset(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = NAI_FALSE;
naibrd_ref_module_power_reset_type_t resetTypeToSet = (naibrd_ref_module_power_reset_type_t)0u;
char resetTypeStr[11] = "";
p_naiapp_AppParameters_t p_ref_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_ref_params->cardIndex;
int32_t module = p_ref_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_REF_MODULE_POWER_RESET_REQUEST_RESET;
sprintf(resetTypeStr, "Reset");
break;
case '1':
resetTypeToSet = NAIBRD_REF_MODULE_POWER_RESET_REQUEST_POWER_DOWN;
sprintf(resetTypeStr, "Power Down");
break;
case '2':
resetTypeToSet = NAIBRD_REF_MODULE_POWER_RESET_REQUEST_POWER_UP;
sprintf(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_REF_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)NAI_FALSE));
}
else if (inputBuffer[0] == '1')
{
check_status(naibrd_REF_SetModulePowerReset(cardIndex, module, resetTypeToSet, (bool_t)NAI_TRUE));
}
else
{
naiif_printf("\r\nInvalid selection entered\r\n");
}
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}