PWM BasicOps
Edit this on GitLab
PWM BasicOps
Explanation
About PWM_BasicOps
Sample Application Code
Overview
The PWM_BasicOps
example is a sample application developed to illustrate how to interact with North Atlantic Industries (NAI) embedded function modules, specifically the PWM (Pulse Width Modulation) devices, using the NAI library (naibrd). It covers basic operations including configuration, control, and measurement for PWM devices such as 64PW2 and 68PW1.
File Inclusions The sample code includes several standard and NAI-specific headers:
-
Standard Library Headers:
-
<stdint.h>
,<stdio.h>
,<stdlib.h>
,<string.h>
,<time.h>
,<ctype.h>
-
These headers provide data types, input/output functions, memory management, string manipulation, timing functions, and character type functions.
-
NAI APP Library Headers:
-
naiapp_boardaccess_menu.h
-
naiapp_boardaccess_query.h
-
naiapp_boardaccess_access.h
-
naiapp_boardaccess_display.h
-
naiapp_boardaccess_utils.h
-
NAI Function-Specific Headers:
-
nai.h
-
naibrd.h
-
naibrd_pwm.h
-
nai_ether_adv.h
-
naibrd_gen5.h
Global Variables and Constants
- SAMPLE_PGM_NAME
: Stores the name of the sample program.
- CONFIG_FILE
: Stores the default configuration file name.
- g_op[80]
: A global buffer for user input.
- g_responseCnt
: Stores the count of user’s response characters.
- DEFAULT_CHANNEL
: Defines the default PWM channel.
- g_selectedDevice
: Stores the currently selected PWM device.
Enums
- nai_pwm_devices
: Defines the available PWM device types (DEVICE_NONE
, DEVICE_64PW2
, DEVICE_68PW1
).
Function Prototypes The application declares several prototypes, grouped by function type, covering PWM Channel Control, DAC Control, ADC Control, Measurements, Status, Module Configuration, Channel Configuration, Watchdog Configuration, General Controls, Serial Controls, and various private query routines.
Command Tables
Several enumerations and corresponding command tables (naiapp_cmdtbl_params_t
) define menu structures and the functions they invoke:
- Main Menu Commands: e.g., PWM_CMD_PWM_CONTROL
, PWM_CMD_DAC_CONTROL
.
- PWM Channel Control Commands: e.g., PWM_CMD_CHAN_CURRENT
, PWM_CMD_CHAN_VOLTAGE
.
- PWM ADC Control Commands: e.g., PWM_CMD_ADC_SOURCE
, PWM_CMD_ADC_ENABLE
.
- Module Configuration Commands: e.g., PWM_CMD_MODULE_CFG_DRIVE
, PWM_CMD_MODULE_CFG_SOURCE
.
- Channel Configuration Commands: e.g., PWM_CMD_CHAN_CFG_CURRENT_LIMIT
, PWM_CMD_CHAN_CFG_INPUT_SCALE
.
- PWM Watchdog Commands: e.g., PWM_CMD_WATCHDOG_TIMEOUT
, PWM_CMD_WATCHDOG_ENABLE
.
- PWM General Control Commands: e.g., PWM_CMD_BATTLEFIELD_OVERRIDE_ENABLE
, PWM_CMD_SOFT_RESET
.
- PWM Serial Control Commands: e.g., PWM_CMD_SERIAL_RX_CLOCK_EDGE
, PWM_CMD_SERIAL_WATCHDOG_TIMEOUT
.
Key Functions Main Function The main function serves as the entry point where the user can interact with the card and module, configure them, and perform various operations. It includes the process for querying card index, module number, and prompting the user to quit or restart the application.
PWM_BasicOps_run
This function handles the execution flow of the sample operations. It manages the command entry, calling appropriate functions based on user input.
PWM Channel Control Functions
- handlePWMChannelControls
- getPWMChannelControls
- setPWMChannelControls
- setCurrentCommand
- setVoltageCommand
- setDriveEnable
- resetDrive
These functions facilitate querying, getting, and setting PWM channel controls such as current and voltage commands, drive enable, and resetting the drive.
PWM DAC Control Functions
- handleDACControls
- getDACControls
These functions are responsible for handling Digital-to-Analog Converter (DAC) operations.
PWM ADC Control Functions
- handleADCControls
- getADCControls
- setADCEnable
- setADCSource
Analog-to-Digital Converter (ADC) operations are handled here.
PWM Measurement Functions
- handlePWMMeasurements
- getPWMMeasurements
These functions read and display PWM measurements such as current, voltage, and temperature.
PWM Status Functions
- handlePWMStatus
- getPWMStatus
These functions check and display the status of the PWM module.
PWM Module Configuration Functions
- handlePWMModuleCfg
- getPWMModuleCfg
- setDriveMode
- setSourceSelect
These functions manage and display module configurations such as Drive Mode and Source Select.
Channel Configuration Functions
- handlePWMChannelCfg
- getPWMChannelCfg
- setCurrentLimit
- setInputScale
- setGlobalGain
- setIntegralGain
- setProportionalGain
These functions manage the configuration parameters for individual PWM channels.
PWM Watchdog Functions
- handlePWMWatchdogCfg
- getPWMWatchdogCfg
- setPWMWatchdogTimeout
- setPWMWatchdogEnable
These functions manage the watchdog settings to ensure system safety.
PWM General Control Functions
- handlePWMGeneralControls
- getPWMGeneralControls
- setPWMSoftReset
- setPWMBattlefieldOverrideEnable
- setPWMPSOvertempOverrideEnable
These functions deal with general control settings including soft resets.
PWM Serial Control Functions
- handlePWMSerialControls
- getPWMSerialControls
- setPWMSerialRxClockEdge
- setPWMSerialWatchdogTimeout
- setPWMSerialWatchdogEnable
- setPWMSerialTestBits
- setPWMSerialTransmitEnable
- setPWMCRCErrorCountDisable
- setPWMDataFrameCountDisable
These functions manage settings and configurations for PWM serial control.
Private Query Routines
- queryPWMChannel
- queryFloat32Value
- queryInt32Value
- queryYesNoValue
- queryHex32Value
These private helper functions aid in querying and converting user inputs for various configurations.
Overall, the PWM_BasicOps
sample application serves as an extensive reference for interacting with NAI’s PWM embedded function modules, demonstrating various control and configuration capabilities.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_pwm.h"
#include "advanced/nai_ether_adv.h"
#include "boards/naibrd_gen5.h"
//#include "nai_sys_cfg.h"
//#include "nai_utils.h"
static const int8_t *SAMPLE_PGM_NAME = (const int8_t *)"PWM_BasicOps";
static const int8_t *CONFIG_FILE = (const int8_t *)"default_PWM_BasicOps.txt";
/* Global buffer and count for user input */
int8_t g_op[80];
int32_t g_responseCnt;
#define DEFAULT_CHANNEL 1
typedef enum nai_pwm_devices
{
DEVICE_NONE,
DEVICE_64PW2,
DEVICE_68PW1
}nai_pwm_devices_t;
/* Global variable for pwm device selected */
static nai_pwm_devices_t g_selectedDevice;
/*******************************/
/* Private Function Prototypes */
/*******************************/
static bool_t PWM_BasicOps_run(int32_t cardIndex, int32_t module, uint32_t modId);
/* PWM Channel Control Function Prototypes */
static nai_status_t handlePWMChannelControls(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMChannelControls(int32_t paramCount, int32_t* p_params);
static bool_t setPWMChannelControls(int32_t paramCount, int32_t* p_params);
static nai_status_t setCurrentCommand(int32_t paramCount, int32_t* p_params);
static nai_status_t setVoltageCommand(int32_t paramCount, int32_t* p_params);
static nai_status_t setDriveEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t resetDrive(int32_t paramCount, int32_t* p_params);
/* DAC Control Function Prototypes */
static nai_status_t handleDACControls(int32_t paramCount, int32_t* p_params);
static nai_status_t getDACControls(int32_t paramCount, int32_t* p_params);
/* ADC Control Function Prototypes */
static nai_status_t handleADCControls(int32_t paramCount, int32_t* p_params);
static nai_status_t getADCControls(int32_t paramCount, int32_t* p_params);
static bool_t setADCControls(int32_t paramCount, int32_t* p_params);
static nai_status_t setADCEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t setADCSource(int32_t paramCount, int32_t* p_params);
/* PWM Measurements Function Prototypes */
static nai_status_t handlePWMMeasurements(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMMeasurements(int32_t paramCount, int32_t* p_params);
/* PWM Status Function Prototypes */
static nai_status_t handlePWMStatus(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMStatus(int32_t paramCount, int32_t* p_params);
/* PWM Module Configuration Function Prototypes */
static nai_status_t handlePWMModuleCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMModuleCfg(int32_t paramCount, int32_t* p_params);
static bool_t setPWMModuleCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t setDriveMode(int32_t paramCount, int32_t* p_params);
static nai_status_t setSourceSelect(int32_t paramCount, int32_t* p_params);
/* Channel Configuration Function Prototypes */
static nai_status_t handlePWMChannelCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMChannelCfg(int32_t paramCount, int32_t* p_params);
static bool_t setPWMChannelCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t setCurrentLimit(int32_t paramCount, int32_t* p_params);
static nai_status_t setInputScale(int32_t paramCount, int32_t* p_params);
static nai_status_t setGlobalGain(int32_t paramCount, int32_t* p_params);
static nai_status_t setIntegralGain(int32_t paramCount, int32_t* p_params);
static nai_status_t setProportionalGain(int32_t paramCount, int32_t* p_params);
/* PWM VME/PCIe/Ethernet Watchdog Function Prototypes */
static nai_status_t handlePWMWatchdogCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMWatchdogCfg(int32_t paramCount, int32_t* p_params);
static bool_t setPWMWatchdogCfg(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMWatchdogTimeout(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMWatchdogEnable(int32_t paramCount, int32_t* p_params);
/* PWM General Control Function Prototypes */
static nai_status_t handlePWMGeneralControls(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMGeneralControls(int32_t paramCount, int32_t* p_params);
static bool_t setPWMGeneralControls(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMSoftReset(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMBattlefieldOverrideEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMPSOvertempOverrideEnable(int32_t paramCount, int32_t* p_params);
/* Serial Control Function Prototypes */
static nai_status_t handlePWMSerialControls(int32_t paramCount, int32_t* p_params);
static nai_status_t getPWMSerialControls(int32_t paramCount, int32_t* p_params);
static bool_t setPWMSerialControls(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMSerialRxClockEdge(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMSerialWatchdogTimeout(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMSerialWatchdogEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMSerialTestBits(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMSerialTransmitEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMCRCErrorCountDisable(int32_t paramCount, int32_t* p_params);
static nai_status_t setPWMDataFrameCountDisable(int32_t paramCount, int32_t* p_params);
/* Private Query Prototypes */
static int32_t queryPWMChannel(int8_t* p_queryText, int32_t maxChannel, int32_t defaultValue);
static bool_t queryFloat32Value(int8_t* p_queryText, float32_t* p_outFloat32);
static bool_t queryInt32Value(int8_t* p_queryText, int32_t* p_outInt32);
static bool_t queryYesNoValue(int8_t* p_queryText, bool_t* p_outresponseYes);
static bool_t queryHex32Value(int8_t* p_queryText, uint32_t* p_outHex32);
/*****************************/
/****** Command Tables *******/
/*****************************/
enum pwm_main_commands
{
PWM_CMD_PWM_CONTROL,
PWM_CMD_DAC_CONTROL,
PWM_CMD_ADC_CONTROL,
PWM_CMD_MEASUREMENT,
PWM_CMD_STATUS,
PWM_CMD_MODULE_CFG,
PWM_CMD_CHANNEL_CFG,
PWM_CMD_WATCHDOG,
PWM_CMD_GENERAL_CONTROL,
PWM_CMD_SERIAL,
PWM_CMD_MAIN_COUNT
};
/* Main Menu */
naiapp_cmdtbl_params_t PWM_MenuCmds[] = {
{"PCtl", " PWM Control", PWM_CMD_PWM_CONTROL, handlePWMChannelControls},
{"DCtl", " DAC Control", PWM_CMD_DAC_CONTROL, handleDACControls},
{"ACtl", " ADC Control", PWM_CMD_ADC_CONTROL, handleADCControls},
{"Meas", " PWM Measurements", PWM_CMD_MEASUREMENT, handlePWMMeasurements},
{"Stat", " Status", PWM_CMD_STATUS, handlePWMStatus},
{"MCfg", " Module Cfg", PWM_CMD_MODULE_CFG, handlePWMModuleCfg},
{"CCfg", " Channel Cfg", PWM_CMD_CHANNEL_CFG, handlePWMChannelCfg},
{"WD", " Watchdog", PWM_CMD_WATCHDOG, handlePWMWatchdogCfg},
{"GCtl", " General Control", PWM_CMD_GENERAL_CONTROL, handlePWMGeneralControls},
{"SCtl", " Serial Control", PWM_CMD_SERIAL, handlePWMSerialControls},
};
/* PWM Channel Control Menus */
enum pwm_channel_control_commands
{
PWM_CMD_CHAN_CURRENT,
PWM_CMD_CHAN_VOLTAGE,
PWM_CMD_CHAN_DRIVE_ENABLE,
PWM_CMD_CHAN_DRIVE_RESET,
PWM_CMD_CHAN_CONTROL_COUNT
};
naiapp_cmdtbl_params_t PWM_ChannelControlMenuCmds[] = {
{"C", " Current Command", PWM_CMD_CHAN_CURRENT, setCurrentCommand},
{"V", " Voltage Command", PWM_CMD_CHAN_VOLTAGE, setVoltageCommand},
{"D", " Drive Enable", PWM_CMD_CHAN_DRIVE_ENABLE, setDriveEnable},
{"R", " Reset Drive", PWM_CMD_CHAN_DRIVE_RESET, resetDrive},
};
/* PWM ADC Control Menus */
enum pwm_adc_control_commands
{
PWM_CMD_ADC_SOURCE,
PWM_CMD_ADC_ENABLE,
PWM_CMD_ADC_CONTROL_COUNT
};
naiapp_cmdtbl_params_t PWM_ADCControlMenuCmds[] = {
{"S", " ADC Source", PWM_CMD_ADC_SOURCE, setADCSource},
{"E", " ADC Enable", PWM_CMD_ADC_ENABLE, setADCEnable},
};
/* Module Configuration Menus */
enum pwm_module_cfg_commands
{
PWM_CMD_MODULE_CFG_DRIVE,
PWM_CMD_MODULE_CFG_SOURCE,
PWM_CMD_MODULE_CFG_COUNT
};
naiapp_cmdtbl_params_t PWM_ModuleCfgMenuCmds[] = {
{"D", " Drive Mode", PWM_CMD_MODULE_CFG_DRIVE, setDriveMode},
{"S", " Source", PWM_CMD_MODULE_CFG_SOURCE, setSourceSelect},
};
/* Channel Configuration Menus */
enum pwm_channel_cfg_commands
{
PWM_CMD_CHAN_CFG_CURRENT_LIMIT,
PWM_CMD_CHAN_CFG_INPUT_SCALE,
PWM_CMD_CHAN_CFG_GLOBAL_GAIN,
PWM_CMD_CHAN_CFG_INTEGRAL_GAIN,
PWM_CMD_CHAN_CFG_PROPORTIONAL_GAIN,
PWM_CMD_CHAN_CFG_COUNT
};
naiapp_cmdtbl_params_t PWM_ChannelCfgMenuCmds[] = {
{"C", " Current Limit", PWM_CMD_CHAN_CFG_CURRENT_LIMIT, setCurrentLimit},
{"S", " Input Scale", PWM_CMD_CHAN_CFG_INPUT_SCALE, setInputScale},
{"G", " Global Gain", PWM_CMD_CHAN_CFG_GLOBAL_GAIN, setGlobalGain},
{"I", " Integral Gain", PWM_CMD_CHAN_CFG_INTEGRAL_GAIN, setIntegralGain},
{"P", " Proportional Gain", PWM_CMD_CHAN_CFG_PROPORTIONAL_GAIN, setProportionalGain},
};
/* PWM Watchdog Menus */
enum pwm_watchdog_commands
{
PWM_CMD_WATCHDOG_TIMEOUT,
PWM_CMD_WATCHDOG_ENABLE,
PWM_CMD_WATCHDOG_COUNT
};
naiapp_cmdtbl_params_t PWM_WatchdogMenuCmds[] = {
{"T", " Watchdog Timeout", PWM_CMD_WATCHDOG_TIMEOUT, setPWMWatchdogTimeout},
{"E", " Watchdog Enable", PWM_CMD_WATCHDOG_ENABLE, setPWMWatchdogEnable},
};
/* PWM General Control Menus */
enum pwm_general_control_commands
{
PWM_CMD_BATTLEFIELD_OVERRIDE_ENABLE,
PWM_CMD_PS_OVERTEMP_OVERRIDE_ENABLE,
PWM_CMD_SOFT_RESET,
PWM_CMD_GENERAL_CONTROL_COUNT
};
naiapp_cmdtbl_params_t PWM_GeneralControlMenuCmds[] = {
{"B", " Battlefield Override Enable", PWM_CMD_BATTLEFIELD_OVERRIDE_ENABLE, setPWMBattlefieldOverrideEnable},
{"P", " PS Over-Temp Override Enable", PWM_CMD_PS_OVERTEMP_OVERRIDE_ENABLE, setPWMPSOvertempOverrideEnable},
{"R", " Soft Reset", PWM_CMD_SOFT_RESET, setPWMSoftReset},
};
/* PWM Serial Control Menus */
enum pwm_serial_control_commands
{
PWM_CMD_SERIAL_RX_CLOCK_EDGE,
PWM_CMD_SERIAL_WATCHDOG_TIMEOUT,
PWM_CMD_SERIAL_WATCHDOG_ENABLE,
PWM_CMD_SERIAL_TESTBITS,
PWM_CMD_SERIAL_TRANSMIT_ENABLE,
PWM_CMD_SERIAL_DISABLE_CRC_ERROR_COUNT,
PWM_CMD_SERIAL_DISABLE_DATA_FRAME_COUNT,
PWM_CMD_SERIAL_CONTROL_COUNT
};
naiapp_cmdtbl_params_t PWM_SerialControlMenuCmds[] = {
{"Clk", " Rx Clock Edge", PWM_CMD_SERIAL_RX_CLOCK_EDGE, setPWMSerialRxClockEdge},
{"WT", " Watchdog Timeout", PWM_CMD_SERIAL_WATCHDOG_TIMEOUT, setPWMSerialWatchdogTimeout},
{"WE", " Watchdog Enable", PWM_CMD_SERIAL_WATCHDOG_ENABLE, setPWMSerialWatchdogEnable},
{"TB", " Test Bits", PWM_CMD_SERIAL_TESTBITS, setPWMSerialTestBits},
{"TE", " Transmit Enable", PWM_CMD_SERIAL_TRANSMIT_ENABLE, setPWMSerialTransmitEnable},
{"CRC", " CRC Error Count Disable", PWM_CMD_SERIAL_DISABLE_CRC_ERROR_COUNT, setPWMCRCErrorCountDisable},
{"DF", " Data Frame Count Disable", PWM_CMD_SERIAL_DISABLE_DATA_FRAME_COUNT, setPWMDataFrameCountDisable},
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the PWM_BasicOps is to illustrate the methods to call in the naibrd library to perform basic
operations to the PWM Devices (64PW2 and 68PW1).
</summary>
*/
/**************************************************************************************************************/
#ifdef __VXWORKS__
int32_t PWM_BasicOps_Sample(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
PWM_BasicOps_run(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/* Private Function Prototypes */
static bool_t PWM_BasicOps_run(int32_t cardIndex, int32_t module, uint32_t modId)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
naiapp_AppParameters_t pwm_basicops_params;
p_naiapp_AppParameters_t pwm_basicOps_params = &pwm_basicops_params;
pwm_basicOps_params->cardIndex = cardIndex;
pwm_basicOps_params->module = module;
pwm_basicOps_params->channel = DEFAULT_CHANNEL;
pwm_basicOps_params->maxChannels = naibrd_PWM_GetChannelCount(modId);
pwm_basicOps_params->modId = modId;
pwm_basicOps_params->displayHex = FALSE;
do
{
naiapp_utils_LoadParamMenuCommands(PWM_CMD_MAIN_COUNT, PWM_MenuCmds);
naiapp_display_ParamMenuCommands((int8_t*)SAMPLE_PGM_NAME);
printf("\n\nPlease enter a command or 'q' to quit:");
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_PWM_CONTROL:
case PWM_CMD_DAC_CONTROL:
case PWM_CMD_ADC_CONTROL:
case PWM_CMD_MEASUREMENT:
case PWM_CMD_STATUS:
case PWM_CMD_CHANNEL_CFG:
case PWM_CMD_WATCHDOG:
case PWM_CMD_GENERAL_CONTROL:
case PWM_CMD_SERIAL:
PWM_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)pwm_basicOps_params);
break;
default:
break;
}
}
else
{
printf("Invalid command entered\n");
}
}
}
} while (!bQuit);
return bQuit;
}
/*********************************/
/* PWM Channel Control Functions */
/*********************************/
static nai_status_t handlePWMChannelControls(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMChannelControls(paramCount, p_params);
bQuit = setPWMChannelControls(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMChannelControls(int32_t paramCount, int32_t* p_params)
{
float32_t current_mA = 0.0;
float32_t voltage = 0.0;
bool_t driveEnabled = FALSE;
uint32_t hexValue = 0;
int32_t channel;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nPWM Controls:\n");
printf("==============\n");
printf("Chan Current Command (A) Voltage Command (V) Drive Enable \n");
printf("--------------------------------------------------------------------------\n");
for (channel = 1; channel <= pwm_basicOps_params->maxChannels; channel++)
{
printf(" %d ", channel);
/* Retrieve Current Command */
check_status(naibrd_PWM_GetCurrent(cardIndex, module, channel, ¤t_mA));
check_status(naibrd_PWM_GetChannelRaw(cardIndex, module, channel, NAI_PWM_CHAN_RAW_CURRENT_CMD, &hexValue));
printf(" %8.3f (0x%08X) ", current_mA/1000.0f, hexValue);
/* Retrieve Voltage Command */
check_status(naibrd_PWM_GetVoltage(cardIndex, module, channel, &voltage));
check_status(naibrd_PWM_GetChannelRaw(cardIndex, module, channel, NAI_PWM_CHAN_RAW_VOLTAGE_CMD, &hexValue));
printf(" %8.3f (0x%08X) ", voltage, hexValue);
/* Retrieve Drive Enable */
check_status(naibrd_PWM_GetDriveEnable(cardIndex, module, channel, &driveEnabled));
check_status(naibrd_PWM_GetChannelRaw(cardIndex, module, channel, NAI_PWM_CHAN_RAW_DRIVE_ENABLE, &hexValue));
if (driveEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf(" Disabled");
}
printf(" (0x%08X)", hexValue);
printf("\n");
}
return NAI_SUCCESS;
}
static bool_t setPWMChannelControls(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
int32_t channel;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
sprintf((char*)g_op, "\nPlease select the channel to update or Q to quit (default: 1): ");
channel = queryPWMChannel(g_op, pwm_basicOps_params->maxChannels, 1);
if (channel > 0)
{
naiapp_utils_LoadParamMenuCommands(PWM_CMD_CHAN_CONTROL_COUNT, PWM_ChannelControlMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"PWM Channel Control Menu");
printf("Type Channel Control command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_CHAN_CURRENT:
case PWM_CMD_CHAN_VOLTAGE:
case PWM_CMD_CHAN_DRIVE_ENABLE:
case PWM_CMD_CHAN_DRIVE_RESET:
PWM_ChannelControlMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
}
else
{
bQuit = TRUE;
}
return bQuit;
}
static nai_status_t setCurrentCommand(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t current;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Current Command in amps for Channel %d: ", channel);
bQuit = queryFloat32Value(g_op, ¤t);
if (!bQuit)
{
/* Note, the current API is units of mA */
status = check_status(naibrd_PWM_SetCurrent(cardIndex, module, channel, current * 1000.0f));
}
return status;
}
static nai_status_t setVoltageCommand(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t voltage;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Voltage Command in volts for Channel %d: ", channel);
bQuit = queryFloat32Value(g_op, &voltage);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetVoltage(cardIndex, module, channel, voltage));
}
//naibrd_ReadReg32(cardIndex, module, 0x10, &outvoltage);
//printf("\nsetVoltageCommand cardIdx:0x%x, module: 0x%x, outvoltage: 0x%x", cardIndex, module, outvoltage);
return status;
}
static nai_status_t setDriveEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the PWM Drive for Channel %d (Y or N)?: ", channel);
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetDriveEnable(cardIndex, module, channel, responseYes));
}
return status;
}
static nai_status_t resetDrive(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
return check_status(naibrd_PWM_ResetDrive(cardIndex, module, channel));
}
/*****************************/
/* PWM DAC Control Functions */
/*****************************/
static nai_status_t handleDACControls(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getDACControls(paramCount, p_params);
printf("Hit Enter to refresh data or type %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getDACControls(int32_t paramCount, int32_t* p_params)
{
float32_t dacOutput = 0;
uint32_t hexValue = 0;
int32_t dac;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nDAC Controls:\n");
printf("==============\n");
printf("DAC Output Value\n");
printf("------------------\n");
for (dac = 1; dac <= MAX_PWM_DAC_CHANNELS; dac++)
{
printf(" %d ", dac);
/* Retrieve DAC Output */
check_status(naibrd_PWM_GetDACOutput(cardIndex, module, dac, &dacOutput));
check_status(naibrd_PWM_GetDAChannelRaw(cardIndex, module, dac, NAI_PWM_CHAN_RAW_DA_OUTPUT, &hexValue));
printf("%8.3f (0x%08X)", dacOutput, hexValue);
printf("\n");
}
printf("\n");
return NAI_SUCCESS;
}
/*****************************/
/* PWM ADC Control Functions */
/*****************************/
static nai_status_t handleADCControls(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getADCControls(paramCount, p_params);
if (g_selectedDevice == DEVICE_64PW2)
{
bQuit = setADCControls(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
else
{
printf("Hit Enter to refresh data or type %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (bQuit)
{
bContinue = FALSE;
}
}
}
return NAI_SUCCESS;
}
static nai_status_t getADCControls(int32_t paramCount, int32_t* p_params)
{
float32_t voltage = 0;
nai_pwm_adc_source_t source;
bool_t adcEnabled;
uint32_t hexValue = 0;
int32_t adc;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nADC Controls:\n");
printf("==============\n");
printf("ADC Voltage Source Enabled \n");
printf("-----------------------------------------------------------------------\n");
for (adc = 1; adc <= MAX_PWM_ADC_CHANNELS; adc++)
{
printf(" %d ", adc);
/* Retrieve ADC Input */
check_status(naibrd_PWM_GetADCInput(cardIndex, module, adc, &voltage));
check_status(naibrd_PWM_GetADChannelRaw(cardIndex, module, adc, NAI_PWM_CHAN_RAW_AD_INPUT, &hexValue));
printf("%8.3f (0x%08X)", voltage, hexValue);
/* Retrieve ADC Source */
check_status(naibrd_PWM_GetADCSource(cardIndex, module, adc, &source));
switch (source)
{
case NAI_PWM_ADC_SOURCE_SERIAL:
printf(" Serial");
break;
case NAI_PWM_ADC_SOURCE_ETHERNET:
printf(" Ethernet");
break;
case NAI_PWM_ADC_SOURCE_PWM_CH1:
printf(" PWM Ch 1");
break;
case NAI_PWM_ADC_SOURCE_PWM_CH2:
printf(" PWM Ch 2");
break;
default:
printf(" Unknown");
break;
}
printf(" (0x%08X) ", source);
/* Retrieve AD Enable */
check_status(naibrd_PWM_GetADCEnable(cardIndex, module, adc, &adcEnabled));
check_status(naibrd_PWM_GetADChannelRaw(cardIndex, module, adc, NAI_PWM_CHAN_RAW_AD_ENABLE, &hexValue));
if (adcEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf("Disabled");
}
printf(" (0x%08X)", hexValue);
printf("\n");
}
return NAI_SUCCESS;
}
static bool_t setADCControls(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
int32_t adc;
sprintf((char*)g_op, "\nPlease select the ADC channel to update or Q to quit (default: 1): ");
adc = queryPWMChannel(g_op, MAX_PWM_ADC_CHANNELS, 1);
if (adc > 0)
{
naiapp_utils_LoadParamMenuCommands(PWM_CMD_ADC_CONTROL_COUNT, PWM_ADCControlMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"PWM ADC Control Menu");
printf("Type ADC Control command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_ADC_SOURCE:
case PWM_CMD_ADC_ENABLE:
PWM_ADCControlMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
}
else
{
bQuit = TRUE;
}
return bQuit;
}
static nai_status_t setADCEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the ADC Input for Channel %d (Y or N)?: ", channel);
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetADCEnable(cardIndex, module, channel, responseYes));
}
return status;
}
static nai_status_t setADCSource(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_SUCCESS;
bool_t bQuit = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Set Source:\n");
printf("S - Serial\n");
printf("E - Ethernet\n");
printf("1 - PWM Ch 1\n");
printf("2 - PWM Ch 2\n");
printf(">");
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
if ((toupper(g_op[0]) == 'S'))
{
status = check_status(naibrd_PWM_SetADCSource(cardIndex, module, channel, NAI_PWM_ADC_SOURCE_SERIAL));
}
else if ((toupper(g_op[0]) == 'E'))
{
status = check_status(naibrd_PWM_SetADCSource(cardIndex, module, channel, NAI_PWM_ADC_SOURCE_ETHERNET));
}
else if ((toupper(g_op[0]) == '1'))
{
status = check_status(naibrd_PWM_SetADCSource(cardIndex, module, channel, NAI_PWM_ADC_SOURCE_PWM_CH1));
}
else if ((toupper(g_op[0]) == '2'))
{
status = check_status(naibrd_PWM_SetADCSource(cardIndex, module, channel, NAI_PWM_ADC_SOURCE_PWM_CH2));
}
}
}
return status;
}
/*****************************/
/* PWM Measurement Functions */
/*****************************/
static nai_status_t handlePWMMeasurements(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMMeasurements(paramCount, p_params);
printf("Hit Enter to refresh data or type %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMMeasurements(int32_t paramCount, int32_t* p_params)
{
float32_t current1_mA = 0.0f, current2_mA = 0.0f, current3_mA = 0.0f;
float32_t voltage1 = 0.0f, voltage2 = 0.0f, voltage3 = 0.0f;
int32_t temperature = 0;
uint32_t hexValue = 0;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nPWM Measurements:\n");
printf("================\n");
if (NAI_MODULE_ID_PW1 == pwm_basicOps_params->modId)
{
printf("Chan Current (A) Voltage (V) Temperature(C)\n");
printf("---------------------------------------------------------------\n");
for (channel = 1; channel <= pwm_basicOps_params->maxChannels; channel++)
{
printf(" %d ", channel);
/* Retrieve Measured Current */
check_status(naibrd_PWM_GetMeasuredCurrent(cardIndex, module, channel, ¤t1_mA));
check_status(naibrd_PWM_GetChannelRaw(cardIndex, module, channel, NAI_PWM_CHAN_RAW_MEASURED_CURRENT, &hexValue));
printf("%8.3f (0x%08X)", current1_mA/1000.f, hexValue);
/* Retrieve Voltage */
check_status(naibrd_PWM_GetMeasuredVoltage(cardIndex, module, channel, &voltage1));
check_status(naibrd_PWM_GetChannelRaw(cardIndex, module, channel, NAI_PWM_CHAN_RAW_MEASURED_VOLTAGE, &hexValue));
printf("%8.3f (0x%08X)", voltage1, hexValue);
/* Retrieve Temperature */
check_status(naibrd_PWM_GetMeasuredTemperature(cardIndex, module, channel, &temperature));
printf(" %d", temperature);
printf("\n\n");
printf("PS Voltage (V) Temperature(C)\n");
printf("-------------------------------------------\n");
/* Retrieve Power Supply Voltage */
check_status(naibrd_PWM_GetMeasuredPSVoltage(cardIndex, module, &voltage1));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_PS_VOLTAGE, &hexValue));
printf(" %8.3f (0x%08X) ", voltage1, hexValue);
/* Retrieve Power Supply Temperature */
check_status(naibrd_PWM_GetMeasuredPSTemperature(cardIndex, module, &temperature));
printf(" %d", temperature);
}
}
else if (NAI_MODULE_ID_PW2 == pwm_basicOps_params->modId)
{
printf("Chan Current1(A) Current2(A) Current3(A) Voltage1 Voltage2 Voltage3 PSCurrent(A) PSVoltage\n");
printf("----------------------------------------------------------------------------------------------------\n");
for (channel = 1; channel <= pwm_basicOps_params->maxChannels; channel++)
{
printf(" %d ", channel);
/* Retrieve Measured Current */
check_status(naibrd_PWM_GetDriveMeasureCurrent(cardIndex, module, channel, 1, ¤t1_mA));
check_status(naibrd_PWM_GetDriveMeasureCurrent(cardIndex, module, channel, 2, ¤t2_mA));
check_status(naibrd_PWM_GetDriveMeasureCurrent(cardIndex, module, channel, 3, ¤t3_mA));
printf("%8.3f %8.3f %8.3f ", current1_mA/1000.0f, current2_mA/1000.0f, current3_mA/1000.0f);
/* Retrieve Voltage */
check_status(naibrd_PWM_GetDriveMeasureVoltage(cardIndex, module, channel, 1, &voltage1));
check_status(naibrd_PWM_GetDriveMeasureVoltage(cardIndex, module, channel, 2, &voltage2));
check_status(naibrd_PWM_GetDriveMeasureVoltage(cardIndex, module, channel, 3, &voltage3));
printf("%8.3f %8.3f %8.3f ", voltage1, voltage2, voltage3);
/* Retrieve Power Supply Voltage */
check_status(naibrd_PWM_GetPSVoltageMeasure(cardIndex, module, channel, &voltage1));
/* Retrieve Power Supply Current */
check_status(naibrd_PWM_GetPSCurrentMeasure(cardIndex, module, channel, ¤t1_mA));
printf("%8.3f %8.3f", current1_mA/1000.0f, voltage1);
printf("\n");
}
}
else
{
printf("Feature is not supported by this module.\n");
}
printf("\n\n");
return NAI_SUCCESS;
}
/************************/
/* PWM Status Functions */
/************************/
static nai_status_t handlePWMStatus(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMStatus(paramCount, p_params);
printf("Hit Enter to refresh data or type %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMStatus(int32_t paramCount, int32_t* p_params)
{
uint32_t hexValue = 0;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nPWM Status:\n");
printf("===========\n");
printf(" Status Board Ready \n");
printf("----------------------------------\n");
/* Retrieve PWM Status */
check_status(naibrd_PWM_GetStatus(cardIndex, module, &hexValue));
printf("0x%08X ", hexValue);
/* Retrieve Board Ready Status */
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_BOARD_READY, &hexValue));
if (naibrd_PWM_IsBoardReady(cardIndex, module) == NAI_SUCCESS)
{
printf(" READY");
}
else
{
printf("NOT READY");
}
printf(" (0x%08X)", hexValue);
printf("\n");
return NAI_SUCCESS;
}
/**************************************/
/* PWM Module Configuration Functions */
/**************************************/
static nai_status_t handlePWMModuleCfg(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMModuleCfg(paramCount, p_params);
bQuit = setPWMModuleCfg(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMModuleCfg(int32_t paramCount, int32_t* p_params)
{
nai_pwm_drive_mode_t mode;
nai_pwm_source_t source;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nPWM Module Configuration:\n");
printf("=========================\n");
printf(" Drive Mode Source \n");
printf("-----------------------------------------------\n");
/* Retrieve Drive Mode */
check_status(naibrd_PWM_GetDriveMode(cardIndex, module, &mode));
switch (mode)
{
case NAI_PWM_CURRENT_DRIVE:
printf("Current");
break;
case NAI_PWM_VOLTAGE_DRIVE:
printf("Voltage");
break;
default:
printf("Unknown");
break;
}
printf(" (0x%08X) ", mode);
/* Retrieve Source Select */
check_status(naibrd_PWM_GetSource(cardIndex, module, &source));
switch (source)
{
case NAI_PWM_SOURCE_SERIAL:
printf(" Serial");
break;
case NAI_PWM_SOURCE_OTHER:
printf(" Other");
break;
default:
printf("Unknown");
break;
}
printf(" (0x%08X) ", source);
return NAI_SUCCESS;
}
static bool_t setPWMModuleCfg(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
naiapp_utils_LoadParamMenuCommands(PWM_CMD_MODULE_CFG_COUNT, PWM_ModuleCfgMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"Board Configuration Menu");
printf("Type Module Configuration command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_MODULE_CFG_DRIVE:
case PWM_CMD_MODULE_CFG_SOURCE:
PWM_ModuleCfgMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
return bQuit;
}
static nai_status_t setDriveMode(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_SUCCESS;
bool_t bQuit = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Set Drive Mode:\n");
printf("C - Current\n");
printf("V - Voltage\n");
printf(">");
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
if ((toupper(g_op[0]) == 'C'))
{
status = check_status(naibrd_PWM_SetDriveMode(cardIndex, module, NAI_PWM_CURRENT_DRIVE));
}
else if ((toupper(g_op[0]) == 'V'))
{
status = check_status(naibrd_PWM_SetDriveMode(cardIndex, module, NAI_PWM_VOLTAGE_DRIVE));
}
}
}
return status;
}
static nai_status_t setSourceSelect(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_SUCCESS;
bool_t bQuit = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Set Source:\n");
printf("S - Serial\n");
printf("O - Other (VME, PCIe, Ethernet)\n");
printf(">");
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
if ((toupper(g_op[0]) == 'S'))
{
status = check_status(naibrd_PWM_SetSource(cardIndex, module, NAI_PWM_SOURCE_SERIAL));
}
else if ((toupper(g_op[0]) == 'O'))
{
status = check_status(naibrd_PWM_SetSource(cardIndex, module, NAI_PWM_SOURCE_OTHER));
}
}
}
return status;
}
/************************************/
/* Channel Configuration Functions */
/************************************/
static nai_status_t handlePWMChannelCfg(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMChannelCfg(paramCount, p_params);
bQuit = setPWMChannelCfg(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMChannelCfg(int32_t paramCount, int32_t* p_params)
{
float32_t currentLimit_mA = 0.0;
uint32_t hexValue = 0;
int32_t cfgValue = 0;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nChannel Configuration:\n");
printf("====================\n");
printf("Chan Current Limit Input Scale(Kc) Global Gain(Kg) Integral Gain(Ki) Prop Gain(Kp) \n");
printf("------------------------------------------------------------------------------------------------------------\n");
for (channel = 1; channel <= pwm_basicOps_params->maxChannels; channel++)
{
printf(" %d ", channel);
/* Retrieve Current Limit */
check_status(naibrd_PWM_GetCurrentLimit(cardIndex, module, channel, ¤tLimit_mA));
check_status(naibrd_PWM_GetChannelRaw(cardIndex, module, channel, NAI_PWM_CHAN_RAW_CURRENT_LIMIT, &hexValue));
printf("%8.3f (0x%08X)", currentLimit_mA/1000.0f, hexValue);
/* Retrieve Input Scale */
check_status(naibrd_PWM_GetInputScale(cardIndex, module, channel, &cfgValue));
printf(" %6d (0x%08X)", cfgValue, cfgValue);
/* Retrieve Global Gain */
check_status(naibrd_PWM_GetGlobalGain(cardIndex, module, channel, &cfgValue));
printf(" %6d (0x%08X)", cfgValue, cfgValue);
/* Retrieve Integral Gain */
check_status(naibrd_PWM_GetIntegralGain(cardIndex, module, channel, &cfgValue));
printf(" %6d (0x%08X)", cfgValue, cfgValue);
/* Retrieve Proportional Gain */
check_status(naibrd_PWM_GetProportionalGain(cardIndex, module, channel, &cfgValue));
printf(" %6d (0x%08X)", cfgValue, cfgValue);
printf("\n");
}
return NAI_SUCCESS;
}
static bool_t setPWMChannelCfg(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t channel = pwm_basicOps_params->channel;
sprintf((char*)g_op, "\nPlease select the channel to update or Q to quit (default: 1): ");
channel = queryPWMChannel(g_op, pwm_basicOps_params->maxChannels, 1);
if (channel > 0)
{
naiapp_utils_LoadParamMenuCommands(PWM_CMD_CHAN_CFG_COUNT, PWM_ChannelCfgMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"Channel Configuration Menu");
printf("Type Channel Configuration command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_CHAN_CFG_CURRENT_LIMIT:
case PWM_CMD_CHAN_CFG_INPUT_SCALE:
case PWM_CMD_CHAN_CFG_GLOBAL_GAIN:
case PWM_CMD_CHAN_CFG_INTEGRAL_GAIN:
case PWM_CMD_CHAN_CFG_PROPORTIONAL_GAIN:
PWM_ChannelCfgMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
}
else
{
bQuit = TRUE;
}
return bQuit;
}
static nai_status_t setCurrentLimit(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t currentLimit;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Current Limit in amps for Channel %d: ", channel);
bQuit = queryFloat32Value(g_op, ¤tLimit);
if (!bQuit)
{
/* Note, the current API is units of mA */
status = check_status(naibrd_PWM_SetCurrentLimit(cardIndex, module, channel, currentLimit * 1000.0f));
}
return status;
}
static nai_status_t setInputScale(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int32_t cfgValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Input Scale for Channel %d: ", channel);
bQuit = queryInt32Value(g_op, &cfgValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetInputScale(cardIndex, module, channel, cfgValue));
}
return status;
}
static nai_status_t setGlobalGain(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int32_t cfgValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Global Gain for Channel %d: ", channel);
bQuit = queryInt32Value(g_op, &cfgValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetGlobalGain(cardIndex, module, channel, cfgValue));
}
return status;
}
static nai_status_t setIntegralGain(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int32_t cfgValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Integral Gain for Channel %d: ", channel);
bQuit = queryInt32Value(g_op, &cfgValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetIntegralGain(cardIndex, module, channel, cfgValue));
}
return status;
}
static nai_status_t setProportionalGain(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
int32_t cfgValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
int32_t channel = pwm_basicOps_params->channel;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Proportional Gain for Channel %d: ", channel);
bQuit = queryInt32Value(g_op, &cfgValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetProportionalGain(cardIndex, module, channel, cfgValue));
}
return status;
}
/********************************************/
/* PWM VME/PCIe/Ethernet Watchdog Functions */
/********************************************/
static nai_status_t handlePWMWatchdogCfg(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMWatchdogCfg(paramCount, p_params);
bQuit = setPWMWatchdogCfg(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMWatchdogCfg(int32_t paramCount, int32_t* p_params)
{
float32_t watchdogTimeout = 0;
bool_t watchdogEnabled;
uint32_t hexValue = 0;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nWatchdog Configuration:\n");
printf("=======================\n");
printf(" Timeout Enabled \n");
printf("---------------------------------------\n");
/* Retrieve Watchdog Timeout */
check_status(naibrd_PWM_GetWatchdogTimeout(cardIndex, module, &watchdogTimeout));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_WATCHDOG_TIMEOUT, &hexValue));
printf("%7.2f (0x%08X)", watchdogTimeout, hexValue);
/* Retrieve Watchdog Enable State */
check_status(naibrd_PWM_GetWatchdogEnable(cardIndex, module, &watchdogEnabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_WATCHDOG_ENABLE, &hexValue));
if (watchdogEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf(" Disabled");
}
printf(" (0x%08X)", hexValue);
printf("\n");
return NAI_SUCCESS;
}
static bool_t setPWMWatchdogCfg(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
naiapp_utils_LoadParamMenuCommands(PWM_CMD_WATCHDOG_COUNT, PWM_WatchdogMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"PWM Watchdog Menu");
printf("Type Watchdog command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_WATCHDOG_TIMEOUT:
case PWM_CMD_WATCHDOG_ENABLE:
PWM_WatchdogMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
return bQuit;
}
static nai_status_t setPWMWatchdogTimeout(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t cfgValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Watchdog Timeout in milliseconds: ");
bQuit = queryFloat32Value(g_op, &cfgValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetWatchdogTimeout(cardIndex, module, cfgValue));
}
return status;
}
static nai_status_t setPWMWatchdogEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the Watchdog (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetWatchdogEnable(cardIndex, module, responseYes));
}
return status;
}
/*********************************/
/* PWM General Control Functions */
/*********************************/
static nai_status_t handlePWMGeneralControls(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMGeneralControls(paramCount, p_params);
bQuit = setPWMGeneralControls(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMGeneralControls(int32_t paramCount, int32_t* p_params)
{
bool_t battlefieldOverrideEnabled;
bool_t psOvertempOverrideEnabled;
uint32_t hexValue = 0;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nGeneral Controls:\n");
printf("=================\n");
printf("Battlefield Override PS Over-temp Override\n");
printf(" Enabled Enabled\n");
printf("----------------------------------------------\n");
/* Retrieve Battlefield Override Enable State */
check_status(naibrd_PWM_GetBattlefieldOverrideEnable(cardIndex, module, &battlefieldOverrideEnabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_BATTLEFIELD_OVERRIDE_ENABLE, &hexValue));
if (battlefieldOverrideEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf("Disabled");
}
printf(" (0x%08X) ", hexValue);
/* Retrieve PS Over-Temperature Override Enable State */
check_status(naibrd_PWM_GetPSOverTempOverrideEnable(cardIndex, module, &psOvertempOverrideEnabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_PS_OVERTEMP_DISABLE_OVERRIDE, &hexValue));
if (psOvertempOverrideEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf("Disabled");
}
printf(" (0x%08X)", hexValue);
printf("\n");
return NAI_SUCCESS;
}
static bool_t setPWMGeneralControls(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
do
{
naiapp_utils_LoadParamMenuCommands(PWM_CMD_GENERAL_CONTROL_COUNT, PWM_GeneralControlMenuCmds);
naiapp_display_ParamMenuCommands((int8_t*)"PWM General Control Menu");
printf("\n\nPlease enter a command or 'q' to quit:");
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_BATTLEFIELD_OVERRIDE_ENABLE:
case PWM_CMD_PS_OVERTEMP_OVERRIDE_ENABLE:
case PWM_CMD_SOFT_RESET:
PWM_GeneralControlMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
} while (!bQuit);
return bQuit;
}
static nai_status_t setPWMSoftReset(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Reset PWM (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
if (responseYes == TRUE)
{
check_status(naibrd_PWM_SoftReset(cardIndex, module));
}
}
return NAI_SUCCESS;
}
static nai_status_t setPWMBattlefieldOverrideEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the Battlefield Override (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
check_status(naibrd_PWM_SetBattlefieldOverrideEnable(cardIndex, module, responseYes));
}
return NAI_SUCCESS;
}
static nai_status_t setPWMPSOvertempOverrideEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the PS Over-Temperature Override (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
check_status(naibrd_PWM_SetPSOverTempOverrideEnable(cardIndex, module, responseYes));
}
return NAI_SUCCESS;
}
/****************************/
/* Serial Control Functions */
/****************************/
static nai_status_t handlePWMSerialControls(int32_t paramCount, int32_t* p_params)
{
bool_t bContinue = TRUE;
bool_t bQuit = FALSE;
while (bContinue)
{
getPWMSerialControls(paramCount, p_params);
bQuit = setPWMSerialControls(paramCount, p_params);
if (bQuit)
{
bContinue = FALSE;
}
}
return NAI_SUCCESS;
}
static nai_status_t getPWMSerialControls(int32_t paramCount, int32_t* p_params)
{
nai_pwm_clock_edge_t clockEdge;
float32_t watchdogTimeout;
bool_t bEnabled;
uint32_t testBits;
int32_t count;
bool_t bDisabled;
uint32_t hexValue = 0;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n\nSerial Controls:\n");
printf("====================\n");
printf("Serial Configuration\n");
printf("--------------------\n");
printf("Rx Clock Serial Watchdog Serial Watchdog Serial Test Serial Transmit\n");
printf(" Edge Timeout (ms) Enable Bits Enable\n");
printf("----------------------------------------------------------------------------------------------------\n");
/* Retrieve Rx Clock Edge */
check_status(naibrd_PWM_GetSerialRxClockEdge(cardIndex, module, &clockEdge));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_SERIAL_RX_CLOCK_EDGE, &hexValue));
switch (clockEdge)
{
case NAI_PWM_CLOCK_EDGE_RISING:
printf(" Rising");
break;
case NAI_PWM_CLOCK_EDGE_FALLING:
printf("Falling");
break;
default:
printf("Unknown");
break;
}
printf(" (0x%08X) ", hexValue);
/* Retrieve Serial Watchdog Timeout */
check_status(naibrd_PWM_GetSerialWatchdogTimeout(cardIndex, module, &watchdogTimeout));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_SERIAL_WATCHDOG_TIMEOUT, &hexValue));
printf("%7.2f (0x%08X)", watchdogTimeout, hexValue);
/* Retrieve Serial Watchdog Enable State */
check_status(naibrd_PWM_GetSerialWatchdogEnable(cardIndex, module, &bEnabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_SERIAL_WATCHDOG_ENABLE, &hexValue));
if (bEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf(" Disabled");
}
printf(" (0x%08X)", hexValue);
/* Retrieve Serial Test Bits */
check_status(naibrd_PWM_GetSerialTestBits(cardIndex, module, &testBits));
printf(" 0x%08X ", testBits);
/* Retrieve Serial Transmit Enable */
check_status(naibrd_PWM_GetSerialTransmitEnable(cardIndex, module, &bEnabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_SERIAL_TRANSMIT_ENABLE, &hexValue));
if (bEnabled == TRUE)
{
printf(" Enabled");
}
else
{
printf(" Disabled");
}
printf(" (0x%08X)", hexValue);
printf("\n\n");
printf("CRC Error/Data Frame\n");
printf("--------------------\n");
printf(" CRC Error Data Frame CRC Error Count Data Frame Count Data Frame\n");
printf(" Count Count Disable Disabled Status\n");
printf("----------------------------------------------------------------------------------\n");
/* Retrieve CRC Error Count */
check_status(naibrd_PWM_GetCRCErrorCount(cardIndex, module, &count));
printf(" %5d", count);
/* Retrieve Data Frame Count */
check_status(naibrd_PWM_GetDataFrameCount(cardIndex, module, &count));
printf(" %5d ", count);
/* Retrieve CRC Error Count Disable */
check_status(naibrd_PWM_GetCRCErrorCountDisable(cardIndex, module, &bDisabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_SERIAL_CRC_ERROR_COUNT_DISABLE, &hexValue));
if (bDisabled == FALSE)
{
printf(" Enabled");
}
else
{
printf(" Disabled");
}
printf(" (0x%08X)", hexValue);
/* Retrieve Data Frame Count Diable */
check_status(naibrd_PWM_GetDataFrameCountDisable(cardIndex, module, &bDisabled));
check_status(naibrd_PWM_GetRaw(cardIndex, module, NAI_PWM_RAW_SERIAL_DATA_FRAME_COUNT_DISABLE, &hexValue));
if (bDisabled == FALSE)
{
printf(" Enabled");
}
else
{
printf(" Disabled");
}
printf(" (0x%08X)", hexValue);
/* Retrieve Data Frame Status */
check_status(naibrd_PWM_GetDataFrameStatus(cardIndex, module, &hexValue));
printf(" 0x%08X", hexValue);
printf("\n");
return NAI_SUCCESS;
}
static bool_t setPWMSerialControls(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t bCmdFound = FALSE;
int32_t cmd;
naiapp_utils_LoadParamMenuCommands(PWM_CMD_SERIAL_CONTROL_COUNT, PWM_SerialControlMenuCmds);
naiapp_display_ParamMenuCommands((int8_t *)"PWM Serial Control Menu");
printf("Type Serial Control command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(g_responseCnt, g_op, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case PWM_CMD_SERIAL_RX_CLOCK_EDGE:
case PWM_CMD_SERIAL_WATCHDOG_TIMEOUT:
case PWM_CMD_SERIAL_WATCHDOG_ENABLE:
case PWM_CMD_SERIAL_TESTBITS:
case PWM_CMD_SERIAL_TRANSMIT_ENABLE:
case PWM_CMD_SERIAL_DISABLE_CRC_ERROR_COUNT:
case PWM_CMD_SERIAL_DISABLE_DATA_FRAME_COUNT:
PWM_SerialControlMenuCmds[cmd].func(paramCount, p_params);
break;
default:
break;
}
}
}
}
return bQuit;
}
static nai_status_t setPWMSerialRxClockEdge(int32_t paramCount, int32_t* p_params)
{
nai_status_t status = NAI_SUCCESS;
bool_t bQuit = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("Set Clock Edge:\n");
printf("R - Rising\n");
printf("F - Falling\n");
printf(">");
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
if ((toupper(g_op[0]) == 'R'))
{
status = check_status(naibrd_PWM_SetSerialRxClockEdge(cardIndex, module, NAI_PWM_CLOCK_EDGE_RISING));
}
else if ((toupper(g_op[0]) == 'F'))
{
status = check_status(naibrd_PWM_SetSerialRxClockEdge(cardIndex, module, NAI_PWM_CLOCK_EDGE_FALLING));
}
}
}
return status;
}
static nai_status_t setPWMSerialWatchdogTimeout(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
float32_t cfgValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Serial Watchdog Timeout in milliseconds: ");
bQuit = queryFloat32Value(g_op, &cfgValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetSerialWatchdogTimeout(cardIndex, module, cfgValue));
}
return status;
}
static nai_status_t setPWMSerialWatchdogEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the Serial Watchdog (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetSerialWatchdogEnable(cardIndex, module, responseYes));
}
return status;
}
static nai_status_t setPWMSerialTestBits(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t hexValue;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enter the Serial Test Value in Hex: ");
bQuit = queryHex32Value(g_op, &hexValue);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetSerialTestBits(cardIndex, module, hexValue));
}
return status;
}
static nai_status_t setPWMSerialTransmitEnable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Enable the Serial Transmit (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetSerialTransmitEnable(cardIndex, module, responseYes));
}
return status;
}
static nai_status_t setPWMCRCErrorCountDisable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Disable the CRC Error Count (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetCRCErrorCountDisable(cardIndex, module, responseYes));
}
return status;
}
static nai_status_t setPWMDataFrameCountDisable(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
bool_t responseYes = FALSE;
p_naiapp_AppParameters_t pwm_basicOps_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = pwm_basicOps_params->cardIndex;
int32_t module = pwm_basicOps_params->module;
nai_status_t status = NAI_SUCCESS;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
sprintf((char*)g_op, "Disable the Data Frame Count (Y or N)?: ");
bQuit = queryYesNoValue(g_op, &responseYes);
if (!bQuit)
{
status = check_status(naibrd_PWM_SetDataFrameCountDisable(cardIndex, module, responseYes));
}
return status;
}
/*********************************/
/* Private Query Routines */
/*********************************/
static int32_t queryPWMChannel(int8_t* p_queryText, int32_t maxChannel, int32_t defaultValue)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
int32_t channel = defaultValue;
if (maxChannel > 1)
{
while (bContinue)
{
printf("%s", p_queryText);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
channel = (int32_t)atol((const char*)g_op);
if ((channel > 0) && (channel <= maxChannel))
{
bContinue = FALSE;
}
else
{
printf("ERROR: Invalid channel entered\n");
}
}
else
{
channel = defaultValue;
bContinue = FALSE;
}
}
else
{
channel = 0;
bContinue = FALSE;
}
}
}
return channel;
}
static bool_t queryFloat32Value(int8_t* p_queryText, float32_t* p_outFloat32)
{
bool_t bQuit = FALSE;
printf("%s ", p_queryText);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
*p_outFloat32 = (float32_t)atof((const char*)g_op);
}
else
{
printf("Invalid value entered\n");
}
}
return bQuit;
}
static bool_t queryInt32Value(int8_t* p_queryText, int32_t* p_outInt32)
{
bool_t bQuit = FALSE;
printf("%s ", p_queryText);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
*p_outInt32 = (int32_t)atol((const char*)g_op);
}
else
{
printf("Invalid value entered\n");
}
}
return bQuit;
}
static bool_t queryYesNoValue(int8_t* p_queryText, bool_t* p_outresponseYes)
{
bool_t bQuit = FALSE;
printf("%s ", p_queryText);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
if (toupper(g_op[0]) == 'Y')
{
*p_outresponseYes = TRUE;
}
else if (toupper(g_op[0]) == 'N')
{
*p_outresponseYes = FALSE;
}
else
{
printf("Invalid value entered\n");
*p_outresponseYes = FALSE;
}
}
else
{
printf("Invalid value entered\n");
}
}
return bQuit;
}
static bool_t queryHex32Value(int8_t* p_queryText, uint32_t* p_outHex32)
{
bool_t bQuit = FALSE;
printf("%s ", p_queryText);
bQuit = naiapp_query_ForQuitResponse(sizeof(g_op), NAI_QUIT_CHAR, g_op, &g_responseCnt);
if (!bQuit)
{
if (g_responseCnt > 0)
{
*p_outHex32 = naiapp_utils_HexStrToDecUInt32(g_op);
}
else
{
printf("Invalid value entered\n");
}
}
return bQuit;
}----