DSW Measure
Edit this on GitLab
DSW Measure
Explanation
About the Sample Application Code
This C application is developed by North Atlantic Industries (NAI) for interacting with their embedded function modules. The sample code demonstrates the methodology to set up, configure, and interact with a Discrete Input/Output module in FIFO (First In, First Out) mode. Below is a comprehensive walk-through of the code, its functions, and structure.
Header Files
The necessary library headers are included first, providing access to the NAI hardware interfaces and some standard C libraries:
-
stdio.h
,stdlib.h
,string.h
,time.h
,ctype.h
: Basic standard libraries for input/output, memory allocation, string manipulation, time functions, and character type checks. -
naiapp_boardaccess_menu.h
,naiapp_boardaccess_query.h
,naiapp_boardaccess_access.h
,naiapp_boardaccess_display.h
,naiapp_boardaccess_utils.h
: These headers provide functions for menu interactions, querying user inputs, board access, display routines, and utility functions for the application. -
nai.h
,naibrd.h
: NAI specific headers for board and device-level functions. -
naibrd_dsw.h
,nai_ether_adv.h
: Specific headers for the DSW (Discrete Switch) module functions and advanced Ethernet functionality.
Constants
-
CONFIG_FILE
: Defines the path to the configuration file used for default settings.
Function Prototypes
Several function prototypes are declared:
-
Run_DSW_FIFO()
,Cfg_DSW_FIFO_Channel()
,Display_DSW_ChannelCfg()
,Configure_DSW_Counter_Interval()
,Configure_DSW_FIFO_Mode()
,Get_DSW_FIFO_Data()
,Get_DSW_FIFO_Status()
,Configure_DSW_Debounce()
: These functions manage the configuration, display, and operations related to the DSW FIFO module.
Enumerations and Command Tables
Commands for interacting with the DSW FIFO module are enumerated and structured in command tables for menu-driven user interactions.
Application Main Function
The entry point of the application is dependent on the platform defined (VXWORKS
for VxWorks OS, otherwise a standard main()
):
-
Initializes variables and begins by running the board menu configuration.
-
Provides an interactive loop for querying card index, module number, and configuring the selected DSW FIFO operations.
Running DSW FIFO
-
Run_DSW_FIFO()
function queries for the card, module, and checks the validity to proceed with configuration. -
Cfg_DSW_FIFO_Channel()
manages the display and user menu commands to configure and interact with the DSW FIFO.
Configuration and Display Functions
-
Display_DSW_ChannelCfg()
retrieves and displays configuration states for the selected channel including status, mode, and FIFO data. -
Configure_DSW_FIFO_Mode()
allows users to set the FIFO mode for the DSW channel. -
Configure_DSW_Counter_Interval()
configures the counter interval for measuring counts at specific intervals. -
Get_DSW_FIFO_Data()
retrieves and presents the data stored in the FIFO buffer. -
Get_DSW_FIFO_Status()
checks and displays the status of the FIFO buffer. -
Configure_DSW_Debounce()
sets and displays the debounce time for the selected channel.
Error Handling and Utilities
-
Convenience macros and checks (
check_status()
) ensure proper handling of Module configuration and status retrieval. -
Utility functions from the included NAI libraries enable menu management, parameter loading, and command handling.
Summary
The provided code facilitates the configuration and interaction with NAI’s DSW modules in FIFO mode by:
-
Running a configuration menu and querying user inputs.
-
Allowing mode selection, data retrieval, interval configuration, and status display.
-
Ensuring proper setup and error handling through well-defined functions.
This example can be expanded or modified for specific operational needs and extended to interact with other functionality provided by NAI embedded function modules.
#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_FIFO.txt";
/* Function prototypes */
void Run_DSW_FIFO(int32_t cardIndex, int32_t module, int32_t ModuleID);
void Cfg_DSW_FIFO_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Configure_DSW_Counter_Interval(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_FIFO_Mode(int32_t paramCount, int32_t* p_params);
static nai_status_t Get_DSW_FIFO_Data(int32_t paramCount, int32_t* p_params);
static nai_status_t Get_DSW_FIFO_Status(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_Debounce(int32_t paramCount, int32_t* p_params);
static const int32_t DEF_DSW_CHANNEL = 2;
/****** Command Table *******/
enum dsw_fifo_commands
{
DSW_FIFO_CMD_MODE,
DSW_FIFO_CMD_GET_DATA,
DSW_FIFO_CMD_FIFO_FREQ,
DSW_FIFO_CMD_STATUS,
DSW_FIFO_CMD_FIFO_START,
DSW_FIFO_CMD_FIFO_STOP,
DSW_FIFO_CMD_COUNT,
DSW_FIFO_CMD_FIFO_CLEAR,
DSW_CMD_DEBOUNCE,
DSW_FIFO_CMD_LAST
};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DSW_FIFO_MenuCmds[] = {
{"Mode", "DSW Select FIFO Mode", DSW_FIFO_CMD_MODE, Configure_DSW_FIFO_Mode},
{"Disp", "DSW Display FIFO Data", DSW_FIFO_CMD_GET_DATA, Get_DSW_FIFO_Data},
{"Intv", "DSW Set Counter Interval", DSW_FIFO_CMD_FIFO_FREQ, Configure_DSW_Counter_Interval},
{"Stat", "DSW Display FIFO Status", DSW_FIFO_CMD_STATUS, Get_DSW_FIFO_Status},
{"Go", "DSW Start FIFO/Clear count", DSW_FIFO_CMD_FIFO_START, NULL},
{"STOP", "DSW Stop Measurement", DSW_FIFO_CMD_FIFO_STOP, NULL},
{"Count", "DSW Display FIFO Count", DSW_FIFO_CMD_COUNT, NULL},
{"R", "DSW Clear FIFO", DSW_FIFO_CMD_FIFO_CLEAR, NULL},
{"Debounce", "DSW Set debounce time", DSW_CMD_DEBOUNCE, Configure_DSW_Debounce}
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DSW_FIFO is to illustrate the methods to call in the naibrd library to perform DSW
FIFO mode. This example code will configure DSW FIFO to desired mode, start, stop and display the DSW FIFO
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_FIFO(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_FIFO(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_FIFO prompts the user for the card, module and channel to use for the application and calls
Cfg_DSW_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
void Run_DSW_FIFO(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_FIFO_Channel(cardIndex, module, ModuleID, MaxChannel);
}
}
/**************************************************************************************************************/
/**
<summary>
Cfg_DSW_FIFO_Channel handles calling the Display_DSW_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
void Cfg_DSW_FIFO_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
bool_t bQuit = FALSE;
bool_t bContinue = TRUE;
bool_t bCmdFound = FALSE;
int32_t chan, defaultchan = 1;
int32_t cmd;
uint32_t outcount; 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_FIFO_CMD_LAST, DSW_FIFO_MenuCmds);
while (bContinue)
{
Display_DSW_ChannelCfg(cardIndex, module, chan, ModuleID);
naiapp_display_ParamMenuCommands((int8_t *)"DSW Measurement Operations Menu");
printf("\nType DSW command or %c to quit : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
if (bCmdFound)
{
switch (cmd)
{
case DSW_FIFO_CMD_MODE:
case DSW_FIFO_CMD_GET_DATA:
case DSW_FIFO_CMD_FIFO_FREQ:
case DSW_FIFO_CMD_STATUS:
case DSW_CMD_DEBOUNCE:
DSW_FIFO_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dsw_measure_params);
break;
case DSW_FIFO_CMD_FIFO_START:
if (!(ModuleID == NAI_MODULE_ID_DT5))
{
printf("Not supported for this module\n");
break;
}
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
break;
case DSW_FIFO_CMD_FIFO_STOP:
if (!(ModuleID == NAI_MODULE_ID_DT5))
{
printf("Not supported for this module\n");
break;
}
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_DISABLE));
printf("Measurement stopped\n");
break;
case DSW_FIFO_CMD_COUNT:
check_status(naibrd_DSW_GetFIFOCount(cardIndex, module, chan, &outcount));
printf("Count is %d\n", outcount);
break;
case DSW_FIFO_CMD_FIFO_CLEAR:
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
printf("Cleared\n");
break;
default:
printf("Invalid command entered\n");
break;
}
}
else
printf("Invalid command entered\n");
}
}
else
bContinue = FALSE;
}
}
}
/**************************************************************************************************************/
/**
<summary>
Display_DSW_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for measurement operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DSW_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
float64_t interval = 0.0;
uint32_t numberOfElements = 0;
nai_dsw_fifo_status_t fifoStatus = 0;
nai_dsw_enhanced_mode_t opmode = 0;
uint32_t outcount = 0;
uint32_t ModuleVer;
uint32_t ModuleRev;
uint32_t ModInfo_Special;
naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
check_status(naibrd_DSW_GetFIFOStatus(cardIndex, module, chan, &numberOfElements, &fifoStatus));
check_status(naibrd_DSW_GetOpMode(cardIndex, module, chan, &opmode));
check_status(naibrd_DSW_GetTimebaseInterval(cardIndex, module, chan, &interval));
printf("\n === Channel %d ===\n\n", chan);
/*read DSW FIFO configuration values here, Status, number of elements, interval, and mode */
{
printf(" Status Count interval Value Mode Selection\n");
printf("--------- ------ ----------- ------- --------------------------------\n");
}
/*display configuration settings here- */
switch (fifoStatus)
{
case NAI_DSW_FIFO_STATUS_BTWN_ALMOST_EMPTY_FULL:
printf(" Data ");
break;
case NAI_DSW_FIFO_STATUS_EMPTY:
printf(" Empty ");
break;
case NAI_DSW_FIFO_STATUS_FULL:
printf(" Full ");
break;
case NAI_DSW_FIFO_STATUS_ALMOST_EMPTY:
printf(" Almost Empty ");
break;
case NAI_DSW_FIFO_STATUS_ALMOST_FULL:
printf(" Almost Full ");
break;
default:
printf("Unknown");
break;
}
/* display number of elements on FIFO */
printf(" %3d ", numberOfElements);
/* if opcode is 10 display the interval */
if (opmode == 10)
printf("%12.3f ", interval);
else
printf(" ");
/* if opcode is 6,7,or 8 display the counter value */
if ((opmode > 5) && (opmode < 9))
{
check_status(naibrd_DSW_GetCountData(cardIndex, module, chan, &outcount));
printf("%7d ", outcount);
}
else
printf(" ");
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>
Configure_DSW_FIFO_Mode handles the user request to select the FIFO mode for the selected channel
and calls the method in the naibrd library to set the mode.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_FIFO_Mode(int32_t paramCount, int32_t* p_params)
{
bool_t bQuit = FALSE;
uint32_t selection = 0;
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;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
printf("\n == FIFO Mode Selection == \n");
printf(" 1 Measure high time\n");
printf(" 2 Measure low time\n");
printf(" 3 Timestamp of all rising edges\n");
printf(" 4 Timestamp of all falling edges\n");
printf(" 5 Timestamp of all edges\n");
printf(" 6 Count total number of rising edges\n");
printf(" 7 Count total number of falling edges\n");
printf(" 8 Count total number of all edges\n");
printf(" 9 Measure period from rising edge\n");
printf("10 Measure Interval count / frequency\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
selection = atoi((const char *)inputBuffer);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
if (selection == 1)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_MEASURE_HIGH_TIME));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 2)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_MEASURE_LOW_TIME));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 3)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_TIMESTAMP_RISING_EDGES));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 4)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_TIMESTAMP_FALLING_EDGES));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 5)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_TIMESTAMP_ALL_EDGES));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 6)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_COUNT_RISING_EDGES));
/* clear old count value since we are changing modes */
check_status(naibrd_DSW_ClearCountData(cardIndex, module, chan));
/* now start the counter in the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 7)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_COUNT_FALLING_EDGES));
/* clear old count value since we are changing modes */
check_status(naibrd_DSW_ClearCountData(cardIndex, module, chan));
/* now start the counter in the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 8)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_COUNT_ALL_EDGES));
/* clear old count value since we are changing modes */
check_status(naibrd_DSW_ClearCountData(cardIndex, module, chan));
/* now start the counter in the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 9)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_MEASURE_PERIOD_FROM_RISING_EDGE));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else if (selection == 10)
{
check_status(naibrd_DSW_SetOpMode(cardIndex, module, chan, NAI_DSW_MODE_MEASURE_FREQUENCY));
/* Set the interval */
check_status(Configure_DSW_Counter_Interval(paramCount, p_params));
/* clear old data from FIFO since we are changing modes */
check_status(naibrd_DSW_ClearFIFO(cardIndex, module, chan));
/* now start the FIFO */
check_status(naibrd_DSW_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DSW_ENHANCE_OP_ENABLE));
}
else
{
printf("Invalid mode %d\n", selection);
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_Counter_Interval will configure DSW module gating interval for measurement of counts within the user
defined interval.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DSW_Counter_Interval(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 interval = 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 interval in ms (Enter 1000 for direct frequency reading): ");
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);
interval = 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 (interval > max || interval < min)
printf(" Entry out of range. Range %7.3f to %7.3f ms\n", min, max);
else
{
check_status(naibrd_DSW_SetTimebaseInterval(cardIndex, module, chan, interval));
}
}
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Get_DSW_FIFO_Data reads back the data on the FIFO.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Get_DSW_FIFO_Data(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;
uint32_t count, numberOfElements, i, countRemaining, timeout;
uint32_t outdata[512];
bool_t bQuit = FALSE;
nai_dsw_fifo_status_t outstatus;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
timeout = (0xFFFFFFFFu);
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
/* First check how many elements are on the FIFO */
check_status(naibrd_DSW_GetFIFOStatus(cardIndex, module, chan, &numberOfElements, &outstatus));
printf("\nThere is %d elements on FIFO, please enter number to display (Hit Enter for all)\n", numberOfElements);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
count = atoi((const char *)inputBuffer);
if (!bQuit)
{
if (inputResponseCnt > 0)
{
count = atoi((const char *)inputBuffer);
if (count > numberOfElements)
count = numberOfElements;
if (count < 0)
count = 0;
}
else
count = numberOfElements;
check_status(naibrd_DSW_ReadFIFORawEx(cardIndex, module, chan, count, timeout, outdata, &numberOfElements, &countRemaining));
for (i = 0; i < count; i++)
{
printf("FIFO element %d 0x%x\n", i, outdata[i]);
}
if (count > 0)
printf("\n%d items left in the FIFO\n", countRemaining);
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Get_DSW_FIFO_Status will read back the value of the counter if the FIFO is configured for
* opmode 6,7, or 8.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Get_DSW_FIFO_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;
uint32_t numberOfElements;
nai_dsw_fifo_status_t fifoStatus;
#if defined (WIN32)
UNREFERENCED_PARAMETER(paramCount);
#endif
check_status(naibrd_DSW_GetFIFOStatus(cardIndex, module, chan, &numberOfElements, &fifoStatus));
switch (fifoStatus)
{
case NAI_DSW_FIFO_STATUS_BTWN_ALMOST_EMPTY_FULL:
printf("NAI_DSW_FIFO_STATUS_BTWN_ALMOST_EMPTY_FULL\n");
break;
case NAI_DSW_FIFO_STATUS_EMPTY:
printf("NAI_DSW_FIFO_STATUS_EMPTY\n");
break;
case NAI_DSW_FIFO_STATUS_FULL:
printf("NAI_DSW_FIFO_STATUS_FULL\n");
break;
case NAI_DSW_FIFO_STATUS_ALMOST_EMPTY:
printf("NAI_DSW_FIFO_STATUS_ALMOST_EMPTY\n");
break;
case NAI_DSW_FIFO_STATUS_ALMOST_FULL:
printf("NAI_DSW_FIFO_STATUS_ALMOST_FULL\n");
break;
}
return NAI_ERROR_UNKNOWN;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_Debounce handles the user request to configure the values for debounce time on the selected
channel and calls the method in the naibrd library to set the debounce.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DSW_Debounce(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_t status = 0;
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 debounce time 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)(0x0u * lsb);
max = (float64_t)(0xFFFFFFFE * lsb);
break;
default:
break;
}
if (time > max || time < min)
printf(" Entry out of range. Range %12.6f to %12.6f ms\n", min, max);
else
{
check_status(naibrd_DSW_SetDebounceTime(cardIndex, module, chan, time));
}
}
status = check_status(naibrd_DSW_GetDebounceTime(cardIndex, module, chan, &time));
if (status == NAI_SUCCESS)
printf("Debounce set to %12.6f milliseconds\n", time);
}
return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}