DSW PWM
Edit this on GitLab
DSW PWM
Explanation
About the Sample Application Code
This sample application demonstrates how to interact with North Atlantic Industries' (NAI) embedded function modules, specifically focusing on configuring and operating Discrete Synchronous Waveform (DSW) Pulse Width Modulation (PWM) channels using the NAI board support libraries.
Overview of Primary Components
Header Files
-
Standard Libraries: The application includes several standard libraries for general operations:
-
stdio.h
: Input/Output functions. -
stdlib.h
: General utility functions. -
string.h
: String handling. -
time.h
: Time-related functions. -
ctype.h
: Character type functions.
-
-
NAI Libraries:
-
naiapp_boardaccess_menu.h
: Manages menu interactions. -
naiapp_boardaccess_query.h
: Handles user queries. -
naiapp_boardaccess_access.h
: Manages board access functions. -
naiapp_boardaccess_display.h
: Functions for displaying configurations. -
naiapp_boardaccess_utils.h
: Utility functions. -
nai.h
: Core NAI definitions. -
naibrd.h
: Board-specific definitions. -
naibrd_dsw.h
: Functions specific to DSW modules. -
nai_ether_adv.h
: Advanced Ethernet functions.
-
Configurations
-
Configuration File: A constant
CONFIG_FILE
points to the default configuration file"default_DSW_PWM.txt"
.
Functions
-
Setup Functions:
-
Run_DSW_PWM
: Orchestrates the overall DSW PWM operations. -
Cfg_DSW_PWM_Channel
: Configures a specific PWM channel. -
Display_DSW_PWM_ChannelCfg
: Displays the current configuration of a PWM channel.
-
-
Command Handling Functions:
-
Configure_DSW_PWM_Mode
: Configures PWM mode. -
Configure_DSW_PWM_Period
: Sets the PWM period. -
Configure_DSW_PWM_Pulsewidth
: Sets the PWM pulse width. -
Configure_DSW_PWM_Burstcount
: Sets the PWM burst count. -
Configure_DSW_PWM_Polarity
: Sets the PWM polarity. -
Display_DSW_PWM_Configuration
: Displays the entire configuration of a PWM channel. -
Display_DSW_Status
: Displays the status information of a PWM channel.
-
Enumerations and Constants
-
Commands Enumeration:
enum dsw_pwm_commands
contains command identifiers for various PWM operations. -
Command Descriptions:
naiapp_cmdtbl_params_t DSW_PWM_MenuCmds[]
is an array mapping commands to their descriptions and associated functions.
Main Function
The main
function initiates the application based on the operating system (VxWorks or other). It prompts users to select the card and module for further configuration with a loop that manages user queries and corresponding actions.
PWM Operational Functions
-
Run_DSW_PWM: Handles interaction with DSW PWM based on user input.
-
Cfg_DSW_PWM_Channel: Manages configuration display and menu commands for a PWM channel.
-
Display_DSW_PWM_ChannelCfg: Retrieves and displays the current settings of a PWM channel.
Command Execution Functions
Each command (e.g., mode configuration, period setting) has its respective function that interacts with the board to apply the user’s settings. For instance, Configure_DSW_PWM_Mode
allows users to set the mode of operation for the PWM channel.
Status Display Functions
Functions like Display_DSW_Status
illustrate how to retrieve and display various status flags for a PWM channel, providing detailed insights into the channel’s current state.
Program Execution Flow
-
Initial Setup:
-
The application starts with executing
naiapp_RunBoardMenu
to configure the board.
-
-
User Interaction:
-
Prompts the user to select a card and module for further configuration.
-
Based on module selection, it validates and calls
Run_DSW_PWM
.
-
-
Channel Configuration:
-
Run_DSW_PWM
andCfg_DSW_PWM_Channel
prompt the user to enter specific settings for the PWM channel.
-
-
Command Execution:
-
Users execute various commands (set mode, set period, etc.) through the defined command table and corresponding functions.
-
-
Status Monitoring:
-
Users can display the current configuration or status of a PWM channel using provided commands (e.g.,
Display_DSW_PWM_Configuration
,Display_DSW_Status
).
-
Error Handling
-
Error Feedback: The application leverages
check_status
macros to confirm the success of library calls, providing feedback to the user.
This concise explanation and walkthrough aim to help users understand the overall purpose and operational flow of the provided sample application code.
#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_dsw.h"
#include "advanced/nai_ether_adv.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_DSW_PWM.txt";
/* Function prototypes */
static void Run_DSW_PWM(int32_t cardIndex, int32_t module, int32_t ModuleID);
static void Cfg_DSW_PWM_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_DSW_PWM_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Configure_DSW_PWM_Mode(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PWM_Period(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PWM_Pulsewidth(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PWM_Burstcount(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PWM_Polarity(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_DSW_PWM_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params);
static const int32_t DEF_DSW_CHANNEL = 1;
/****** Command Table *******/
enum dsw_pwm_commands
{
DSW_PWM_CMD_MODE,
DSW_PWM_CMD_PERIOD,
DSW_PWM_CMD_PULSEWIDTH,
DSW_PWM_CMD_BURSTCOUNT,
DSW_PWM_CMD_POLARITY,
DSW_PWM_CMD_PWM_CFG,
DSW_PWM_CMD_PWM_START,
DSW_PWM_CMD_PWM_STOP,
DSW_PWM_CMD_PWM_DEMO,
DSW_PWM_CMD_PWM_INITIAL,
DSW_PWM_CMD_STATUS,
DSW_PWM_CMD_PWM_BURST,
DSW_PWM_CMD_PWM_CONT,
DSW_PWM_CMD_COUNT
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DSW_PWM_MenuCmds[] = {
{"Mode", " DSW Select PWM Mode", DSW_PWM_CMD_MODE, Configure_DSW_PWM_Mode},
{"Period", " DSW Set PWM Period", DSW_PWM_CMD_PERIOD, Configure_DSW_PWM_Period},
{"Width", " DSW Set PWM Pulsewidth", DSW_PWM_CMD_PULSEWIDTH, Configure_DSW_PWM_Pulsewidth},
{"Count", " DSW Set PWM Burst count", DSW_PWM_CMD_BURSTCOUNT, Configure_DSW_PWM_Burstcount},
{"POlarity", " DSW Set PWM Polarity", DSW_PWM_CMD_POLARITY, Configure_DSW_PWM_Polarity},
{"PM", " DSW Display PWM configuration settings", DSW_PWM_CMD_PWM_CFG, Display_DSW_PWM_Configuration},
{"Trigger", " DSW Start PWM output", DSW_PWM_CMD_PWM_START, NULL},
{"Halt", " DSW Stop PWM output", DSW_PWM_CMD_PWM_STOP, NULL},
{"Demo", " DSW Demo PWM Settings", DSW_PWM_CMD_PWM_DEMO, NULL},
{"Reset", " DSW Reset All Channels to Initial Settings",DSW_PWM_CMD_PWM_INITIAL, NULL},
{"Stat", " DSW Display Status", DSW_PWM_CMD_STATUS, Display_DSW_Status},
{"SETBurst", " DSW Set all channels to PWM Burst", DSW_PWM_CMD_PWM_BURST, NULL},
{"SETCont", " DSW Set all channels to PWM Continuous", DSW_PWM_CMD_PWM_CONT, NULL},
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DSW_PWM is to illustrate the methods to call in the naibrd library to perform configuration
setup for output in PWM operation mode. Pulse period, pulse width, pulse polarity settings are configurable.
The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd DSW routines.
- ClearDeviceCfg
- QuerySystemCfg
- DisplayDeviceCfg
- GetBoardSNModCfg
- SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DSW_PWM(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
Run_DSW_PWM(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
/**************************************************************************************************************/
/**
<summary>
Run_DSW_PWM prompts the user for the card, module and channel to use for the application and calls
Cfg_DSW_PWM_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
static void Run_DSW_PWM(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
int32_t MaxChannel;
MaxChannel = naibrd_DSW_GetChannelCount(ModuleID);
if (MaxChannel == 0)
{
printf(" *** Module selection not recognized as DSW module. ***\n\n");
}
else
{
Cfg_DSW_PWM_Channel(cardIndex, module, ModuleID, MaxChannel);
}
}
/**************************************************************************************************************/
/**
<summary>
Display_DSW_PWM_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for PWM operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DSW_PWM_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
nai_dsw_state_t inputstate = 0;
nai_dsw_state_t switchstate = 0;
nai_dsw_enhanced_mode_t opmode = 0;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
check_status(naibrd_DSW_GetSwitchState(cardIndex, module, chan, &switchstate));
check_status(naibrd_DSW_GetInputState(cardIndex, module, chan, &inputstate));
check_status(naibrd_DSW_GetOpMode(cardIndex, module, chan, &opmode));
printf("\n === Channel %d ===\n\n", chan);
/*read PWM configuration values here, Period, Pulsewidth, Continuous/Burst Mode, */
{
printf(" Switch Input \n");
printf(" State State Enhanced Mode Selection \n");
printf("-------- ------- ---------------------------- \n");
}
switch (switchstate)
{
case NAI_DSW_STATE_LO:
printf(" Open ");
break;
case NAI_DSW_STATE_HI:
printf("Closed");
break;
/* undefined value read back */
default:
printf(" UNK ");
break;
}
printf(" %3i ", inputstate);
switch (opmode)
{
case NAI_DSW_MODE_STD_INPUT_OUTPUT:
printf(" DSW MODE STD INPUT OUTPUT ");
break;
case NAI_DSW_MODE_MEASURE_HIGH_TIME:
printf(" DSW MODE MEASURE HIGH TIME ");
break;
case NAI_DSW_MODE_MEASURE_LOW_TIME:
printf(" DSW MODE MEASURE LOW TIME ");
break;
case NAI_DSW_MODE_TIMESTAMP_RISING_EDGES:
printf(" DSW MODE TIMESTAMP RISING EDGES ");
break;
case NAI_DSW_MODE_TIMESTAMP_FALLING_EDGES:
printf(" DSW MODE TIMESTAMP FALLING EDGES ");
break;
case NAI_DSW_MODE_TIMESTAMP_ALL_EDGES:
printf(" DSW MODE TIMESTAMP ALL EDGES ");
break;
case NAI_DSW_MODE_COUNT_RISING_EDGES:
printf(" DSW MODE COUNT RISING EDGES ");
break;
case NAI_DSW_MODE_COUNT_FALLING_EDGES:
printf(" DSW MODE COUNT FALLING EDGES ");
break;
case NAI_DSW_MODE_COUNT_ALL_EDGES:
printf(" DSW MODE COUNT ALL EDGES ");
break;
case NAI_DSW_MODE_MEASURE_PERIOD_FROM_RISING_EDGE:
printf(" DSW MODE MEASURE PERIOD FROM RISING EDGE ");
break;
case NAI_DSW_MODE_MEASURE_FREQUENCY:
printf(" DSW MODE Interval Counter ");
break;
case NAI_DSW_MODE_OUTPUT_PWM_FOREVER:
printf(" DSW MODE PWM Continuous ");
break;
case NAI_DSW_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES:
printf(" DSW MODE PWM Burst ");
break;
case NAI_DSW_MODE_OUTPUT_PATTERN_RAM:
printf(" DSW MODE PATTERN RAM ");
break;
default:
printf(" Unknown ");
break;
}
}
/**************************************************************************************************************/
/**
<summary>
Cfg_DSW_PWM_Channel handles calling the Display_DSW_PWM_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_DSW_PWM_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
nai_status_t status = (nai_status_t)0;
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t chan, defaultchan = 1;
int32_t cmd;
int32_t ch_loop;
float64_t time;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
naiapp_AppParameters_t dsw_params;
p_naiapp_AppParameters_t dsw_measure_params = &dsw_params;
dsw_measure_params->cardIndex = cardIndex;
dsw_measure_params->module = module;
dsw_measure_params->modId = ModuleID;
while (bContinue)
{
printf(" \r\n\r\n");
printf("Channel selection \r\n");
printf("================= \r\n");
defaultchan = DEF_DSW_CHANNEL;
bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
dsw_measure_params->channel = chan;
naiapp_utils_LoadParamMenuCommands(DSW_PWM_CMD_COUNT, DSW_PWM_MenuCmds);
while (bContinue)
{
Display_DSW_PWM_ChannelCfg(cardIndex, module, chan, ModuleID);
naiapp_display_ParamMenuCommands((int8_t *)"DSW PWM Menu");
printf("\nType DSW command or %c to return to module select menu: ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case DSW_PWM_CMD_MODE:
case DSW_PWM_CMD_PERIOD:
case DSW_PWM_CMD_PULSEWIDTH:
case DSW_PWM_CMD_BURSTCOUNT:
case DSW_PWM_CMD_POLARITY:
case DSW_PWM_CMD_PWM_CFG:
case DSW_PWM_CMD_STATUS:
DSW_PWM_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dsw_measure_params);
break;
case DSW_PWM_CMD_PWM_START:
check_status(naibrd_DSW_StartPWM(cardIndex, module, chan));
break;
case DSW_PWM_CMD_PWM_STOP:
check_status(naibrd_DSW_StopPWM(cardIndex, module, chan));
break;
case DSW_PWM_CMD_PWM_DEMO:
{
if (!(ModuleID == NAI_MODULE_ID_DT5))
{
printf("PWM burst mode not supported for this module\n");
break;
}
printf("Set up all channels in incrementing period/pulsewidths and burstcounts? \n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= 16; ch_loop++)
{
time = ch_loop;
status |= check_status(naibrd_DSW_SetPWM_Period(cardIndex, module, ch_loop, time));
time /= 10.0;
status |= check_status(naibrd_DSW_SetPWM_Pulsewidth(cardIndex, module, ch_loop, time));
status |= check_status(naibrd_DSW_SetPWM_BurstNum(cardIndex, module, ch_loop, ch_loop));
}
if (status == NAI_SUCCESS)
printf("\n PWM channel configuration initialized for all channels. \n Set PWM Mode as needed. ");
else
printf("\n Configuration not completed successfully. \n");
}
}
}
}
break;
case DSW_PWM_CMD_PWM_INITIAL:
{
printf("Reset all channels to initial configuration? \n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= 16; ch_loop++)
{
status |= check_status(naibrd_DSW_SetPWM_Pulsewidth(cardIndex, module, ch_loop, 16E-1));
status |= check_status(naibrd_DSW_SetPWM_BurstNum(cardIndex, module, ch_loop, 0));
status |= check_status(naibrd_DSW_SetOpMode(cardIndex, module, ch_loop, NAI_DSW_MODE_STD_INPUT_OUTPUT));
status |= check_status(naibrd_DSW_SetDebounceTime(cardIndex, module, ch_loop, 0.0));
status |= check_status(naibrd_DSW_GetDebounceTime(cardIndex, module, ch_loop, &time));
if (time > 1E-10)
status++;
}
if (status == NAI_SUCCESS)
printf("\n PWM channel configuration initialized for all channels. \n");
else
printf("\n Initialization not completed successfully. \n");
}
}
}
}
break;
case DSW_PWM_CMD_PWM_BURST:
{
if (!(ModuleID == NAI_MODULE_ID_DT5))
{
printf("PWM burst mode not supported for this module\n");
break;
}
printf("Reset all channels to PWM burst mode? \n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= 16; ch_loop++)
{
status |= check_status(naibrd_DSW_SetOpMode(cardIndex, module, ch_loop, NAI_DSW_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES));
}
if (status == NAI_SUCCESS)
printf("\n PWM channel configuration set for PWM Burst mode for all channels. \n");
else
printf("\n Initialization not completed successfully. \n");
}
}
}
}
break;
case DSW_PWM_CMD_PWM_CONT:
{ if (!(ModuleID == NAI_MODULE_ID_DT5))
{
printf("PWM burst mode not supported for this module\n");
break;
}
printf("Reset all channels to PWM continuous mode? \n Enter Yes to confirm: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'Y'))
{
for (ch_loop = 1; ch_loop <= 16; ch_loop++)
{
status |= check_status(naibrd_DSW_SetOpMode(cardIndex, module, ch_loop, NAI_DSW_MODE_OUTPUT_PWM_FOREVER));
}
if (status == NAI_SUCCESS)
printf("\n PWM channel configuration set for PWM Burst mode for all channels. \n");
else
printf("\n Initialization not completed successfully. \n");
}
}
}
}
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_PWM_Mode handles the user request to select the PWM mode for the selected channel
and calls the method in the naibrd library to set the mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_PWM_Mode(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
bool_t bQuit = FALSE;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n == PWM Mode Selection == \n C Continuous PWM mode \n Burst PWM Burst mode \n None Basic input mode \n\n Type DSW command : ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'C'))
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_OUTPUT_PWM_FOREVER));
}
else if ((toupper(inputBuffer[0]) == 'B'))
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES));
}
else if ((toupper(inputBuffer[0]) == 'N'))
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_STD_INPUT_OUTPUT));
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_PWM_Period handles the user request to configure the time values for period on the selected
channel and calls the method in the naibrd library to set the period.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_PWM_Period(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
bool_t bQuit = FALSE;
float64_t time = 0.0;
float64_t lsb = 0;
float64_t min = 1;
float64_t max = -1;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nEnter the desired period in ms: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
time = atof((const char *)inputBuffer); /*entry in milliseconds*/
lsb = naibrd_DSW_GetTimebaseLSB(ModuleID);
switch (ModuleID)
{
case NAI_MODULE_ID_DT5:
min = (float64_t)(0x2u * lsb);
max = (float64_t)(0xFFFFFFFF * lsb);
default:
break;
}
if (time > max || time < min)
printf(" Entry out of range. Range %7.3f to %7.3f ms\n", min, max);
else
{
check_status(naibrd_DSW_SetPWM_Period(cardIndex, module, chan, time));
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_PWM_Pulsewidth handles the user request to configure the time values for pulsewidth on the selected
channel and calls the method in the naibrd library to set the width.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_PWM_Pulsewidth(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
bool_t bQuit = FALSE;
float64_t time = 0.0;
float64_t lsb = 0;
float64_t min = 1;
float64_t max = -1;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nEnter the desired pulsewidth in milliseconds: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
time = atof((const char *)inputBuffer);
lsb = naibrd_DSW_GetTimebaseLSB(ModuleID);
switch (ModuleID)
{
case NAI_MODULE_ID_DT5:
min = (float64_t)(0x1u * lsb);
max = (float64_t)(0xFFFFFFFE * lsb);
break;
default:
break;
}
if (time > max || time < min)
printf(" Entry out of range. Range %7.3f to %7.3f ms\n", min, max);
else
{
check_status(naibrd_DSW_SetPWM_Pulsewidth(cardIndex, module, chan, time));
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Handles the user request to set the burst count value for the number of pulses to be issued upon trigger in
PWM burst mode operation on the selected channel, calling the method in the naibrd library to set the burst number.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_PWM_Burstcount(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
bool_t bQuit = FALSE;
uint32_t burstcount;
uint32_t ModuleID;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\nEnter the desired burst count: ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
burstcount = atoi((const char *)inputBuffer);
switch (ModuleID)
{
case NAI_MODULE_ID_DT5:
if (burstcount < 1)
{
burstcount = 1; /*minimum count is one*/
printf("Setting burstcount to minimum of 1.\n");
}
check_status(naibrd_DSW_SetPWM_BurstNum(cardIndex, module, chan, burstcount));
break;
default:
printf("Unsupported function for this module.\n");
break;
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_PWM_Polarity handles the user request to select the PWM output polarity for the selected channel
and calls the method in the naibrd library for the setting.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_PWM_Polarity(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
bool_t bQuit = FALSE;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n == PWM Output Polarity Selection == \n Pos DSW PWM positive going pulse output \n Neg DSW PWM negative going pulse output \n\n Type DSW command : ");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if ((toupper(inputBuffer[0]) == 'P'))
check_status(naibrd_DSW_SetPWM_Polarity(cardIndex, module, chan, (nai_dsw_pwm_polarity_t)NAI_DSW_PWMPOLARITY_POS));
else if ((toupper(inputBuffer[0]) == 'N'))
check_status(naibrd_DSW_SetPWM_Polarity(cardIndex, module, chan, (nai_dsw_pwm_polarity_t)NAI_DSW_PWMPOLARITY_NEG));
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Display_DSW_PWM_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DSW_PWM_Configuration(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
nai_dsw_pwm_polarity_t polaritysetting;
float64_t period;
float64_t pulsewidth;
uint32_t burstnumber;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Available configuration settings:
PWM period", (Value read back in milliseconds)
PWM pulsewidth", (Value read back in milliseconds)
PWM burst count (Number of pulses issued upon trigger in burst mode)
PWM polarity", 0 = positive going pulsewidth, 1 = negative going
*/
printf("\n");
printf(" -------------PWM Configuration Settings----------------------------\n");
printf(" Period (ms) Pulsewidth (ms) Burst Cnt Polarity \n");
printf(" -------------- ---------------- ----------- ----------- \n");
check_status(naibrd_DSW_GetPWM_Period(cardIndex, module, chan, &period));
printf(" %10.6f ", period);
check_status(naibrd_DSW_GetPWM_Pulsewidth(cardIndex, module, chan, &pulsewidth));
printf(" %10.6f ", pulsewidth);
check_status(naibrd_DSW_GetPWM_BurstNum(cardIndex, module, chan, &burstnumber));
printf(" 0x%08X ", burstnumber);
check_status(naibrd_DSW_GetPWM_Polarity(cardIndex, module, chan, &polaritysetting));
if (polaritysetting == 0)
printf(" POS ");
else
printf(" NEG ");
printf("\n\n");
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Display_DSW_Status illustrate the methods to call in the naibrd library to retrieve the status states.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DSW_Status(int32_t paramCount, int32_t* p_params)
{
p_naiapp_AppParameters_t p_dsw_params = (p_naiapp_AppParameters_t)p_params;
int32_t cardIndex = p_dsw_params->cardIndex;
int32_t module = p_dsw_params->module;
int32_t chan = p_dsw_params->channel;
nai_status_bit_t status;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* Available status:
NAI_DSW_STATUS_BIT,
NAI_DSW_STATUS_OVERCURRENT,
NAI_DSW_STATUS_MAX_HI,
NAI_DSW_STATUS_MIN_LO,
NAI_DSW_STATUS_MID_RANGE,
NAI_DSW_STATUS_LO_HI_TRANS,
NAI_DSW_STATUS_HI_LO_TRANS,
*/
printf("\n");
printf(" ----------------- Status ----------------------------\n");
printf(" MinLo MidRng MaxHi Low-Hi Hi-Lo BIT OC\n");
printf(" ------- -------- ------ ------- -------- ------ ------\n");
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_MIN_LO_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_MID_RANGE_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_MAX_HI_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_LO_HI_TRANS_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_HI_LO_TRANS_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_BIT_LATCHED, &status));
printf(" %3i ", status);
check_status(naibrd_DSW_GetStatus(cardIndex, module, chan, NAI_DSW_STATUS_OVERCURRENT_LATCHED, &status));
printf(" %3i ", status);
printf("\n\n");
return NAI_ERROR_UNKNOWN;
}