Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

DIF Measure

DIF Measure

Explanation

About the Sample Application Code

This C code is designed to interface with North Atlantic Industries' (NAI) embedded function modules using their Software Support Kit (SSK). It specifically demonstrates how to configure and operate a Discrete Input FIFO (DIF) Enhanced FIFO mode using the naibrd library.

Includes The code begins by including necessary headers: - Standard C libraries: stdio.h, stdlib.h, string.h, time.h, ctype.h. - NAI-specific headers: - Common sample program headers (naiapp_boardaccess_menu.h, etc.). - naibrd library headers (nai.h, naibrd.h, etc.).

Constants and Prototypes - Constants: - CONFIG_FILE points to the configuration file "default_DIF_Measure.txt". - DEF_DIF_CHANNEL is a default channel identifier set to 2. - Function Prototypes: - Various functions for configuring operational parameters, running the application, displaying configuration, and handling user commands.

Enumerations and Command Tables Commands related to the DIF FIFO mode are enumerated to simplify references: - enum dif_fifo_commands lists command identifiers. - DIF_FIFO_MenuCmds provides a mapping between user commands and corresponding functions.

Main Function Depending on the system (VXWORKS or other platforms), the entry point is either DIF_FIFO or main function: - Main Work Flow: - naiapp_RunBoardMenu(CONFIG_FILE): Starts the board menu. - Queries user input for cardIndex and module. - Calls Run_DIF_FIFO with the selected cardIndex, module, and moduleID.

Core Functions 1. Run_DIF_FIFO: - Ensures the module is a valid DIF module. - Calls Cfg_DIF_FIFO_Channel to configure the channel if valid.

  1. Cfg_DIF_FIFO_Channel:

    • Prompts user to select a channel.

    • Enters a loop to continuously handle user commands using DIF_FIFO_MenuCmds.

  2. Display_DIF_ChannelCfg:

    • Displays current configuration and status of the selected DIF channel using naibrd library functions.

  3. Command Handling Functions:

    • Configure_DIF_FIFO_Mode: Sets FIFO operational mode.

    • Start_DIF_FIFO: Enables the FIFO mode.

    • Clear_DIF_FIFO: Clears old data from the FIFO.

    • Get_DIF_FIFO_Data: Reads data from the FIFO.

    • Configure_DIF_Counter_Interval: Configures gating intervals for measurements.

    • Get_DIF_FIFO_Count: Retrieves the current count value.

    • Get_DIF_FIFO_Status: Fetches the status of the FIFO.

Function Routines 1. Functions interact with NAI’s API (naibrd): - naibrd_GetModuleCount, naibrd_GetModuleID: Fetch module count and IDs. - naibrd_DIF_*: Set and get configurations and data for DIF modules.

  1. Error Handling:

    • The macro check_status ensures proper error checking and handling is performed after each API call.

User Interaction User interaction is achieved using menus to select options and queries for command input, which are processed iteratively within the main loop.

Summary The file is an application to serve as a practical guide for interacting with NAI’s DIF modules, specifically demonstrating configuration and operation of the FIFO mode. This includes reading and displaying status, setting operational modes, and handling user commands efficiently. The sample code ensures robustness through error checking and user prompts to provide a comprehensive overview for developers working with NAI’s embedded systems.

#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_dif.h"
#include "advanced/nai_ether_adv.h"

static const int8_t *CONFIG_FILE = (int8_t *)"default_DIF_Measure.txt";

/* Function prototypes */
void Run_DIF_FIFO(int32_t cardIndex, int32_t module, int32_t ModuleID);
void Cfg_DIF_FIFO_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);

static void Display_DIF_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
nai_status_t Configure_DIF_FIFO_Mode(int32_t paramCount, int32_t* p_params);
nai_status_t Start_DIF_FIFO(int32_t paramCount, int32_t* p_params);
nai_status_t Clear_DIF_FIFO(int32_t paramCount, int32_t* p_params);
nai_status_t Get_DIF_FIFO_Data(int32_t paramCount, int32_t* p_params);
nai_status_t Configure_DIF_Counter_Interval(int32_t paramCount, int32_t* p_params);
nai_status_t Get_DIF_FIFO_Status(int32_t paramCount, int32_t* p_params);
nai_status_t Get_DIF_FIFO_Count(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_DIF_CHANNEL       = 2;

/****** Command Table *******/
enum dif_fifo_commands
{
   DIF_FIFO_CMD_MODE,
   DIF_FIFO_CMD_GET_DATA,
   DIF_FIFO_CMD_FIFO_FREQ,
   DIF_FIFO_CMD_STATUS,
   DIF_FIFO_CMD_FIFO_START,
   DIF_FIFO_CMD_FIFO_STOP,
   DIF_FIFO_CMD_COUNT,
   DIF_FIFO_CMD_FIFO_CLEAR,
   DIF_FIFO_CMD_LAST

};
/****** Command Tables *******/
naiapp_cmdtbl_params_t DIF_FIFO_MenuCmds[] = {
   {"Mode",          "DIF Select FIFO Mode",       DIF_FIFO_CMD_MODE,            Configure_DIF_FIFO_Mode},
   {"Disp",          "DIF Display FIFO Data",      DIF_FIFO_CMD_GET_DATA,        Get_DIF_FIFO_Data},
   {"Intv",          "DIF Set Counter Interval",   DIF_FIFO_CMD_FIFO_FREQ,       Configure_DIF_Counter_Interval},
   {"Stat",          "DIF Display FIFO Status",    DIF_FIFO_CMD_STATUS,          Get_DIF_FIFO_Status},
   {"Go",            "DIF Start FIFO/Clear count", DIF_FIFO_CMD_FIFO_START,      Start_DIF_FIFO},
   {"STOP",          "DIF Stop Measurement",       DIF_FIFO_CMD_FIFO_STOP,       NULL},
   {"Count",         "DIF Display FIFO Count",     DIF_FIFO_CMD_COUNT,           Get_DIF_FIFO_Count},
   {"R",             "DIF Clear FIFO",             DIF_FIFO_CMD_FIFO_CLEAR,      Clear_DIF_FIFO}
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the DIF_FIFO is to illustrate the methods to call in the naibrd library to perform DIF enhanced
FIFO mode. This example code will configure DIF FIFO to desired mode, start, stop and display the DIF 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 DIF routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DIF_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_DIF_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_DIF_FIFO prompts the user for the card, module and channel to use for the application and calls
Cfg_DIF_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
void Run_DIF_FIFO(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
   int32_t MaxChannel;

   MaxChannel = naibrd_DIF_GetChannelCount(ModuleID);

   if (MaxChannel == 0)
   {
      printf(" *** Module selection not recognized as DIF module. ***\n\n");
   }
   else
   {
      Cfg_DIF_FIFO_Channel(cardIndex, module, ModuleID, MaxChannel);
   }
}

/**************************************************************************************************************/
/**
<summary>
Cfg_DIF_FIFO_Channel handles calling the Display_DIF_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
void Cfg_DIF_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;
   int32_t status;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   naiapp_AppParameters_t  dif_params;
   p_naiapp_AppParameters_t dif_measure_params = &dif_params;
   dif_measure_params->cardIndex = cardIndex;
   dif_measure_params->module = module;
   dif_measure_params->modId = ModuleID;

   while (bContinue)
   {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");
      defaultchan = DEF_DIF_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      dif_measure_params->channel = chan;

      naiapp_utils_LoadParamMenuCommands(DIF_FIFO_CMD_LAST, DIF_FIFO_MenuCmds);
      while (bContinue)
      {
         Display_DIF_ChannelCfg(cardIndex, module, chan, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"DIF Measurement Operations Menu");
         printf("\nType DIF command or %c to quit :\n > ", 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 DIF_FIFO_CMD_MODE:
                        case DIF_FIFO_CMD_FIFO_START:
                        case DIF_FIFO_CMD_FIFO_CLEAR:
                        case DIF_FIFO_CMD_GET_DATA:
                        case DIF_FIFO_CMD_FIFO_FREQ:
                        case DIF_FIFO_CMD_STATUS:
                        case DIF_FIFO_CMD_COUNT:
                              DIF_FIFO_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dif_measure_params);
                        break;
                        case DIF_FIFO_CMD_FIFO_STOP:
                           {
                              status = check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_DISABLE));
                              if (status == NAI_SUCCESS)
                                 printf("Measurement stopped, mode reset\n");
                           }
                           break;
                     default:
                                 printf("Invalid command entered\n");
                        break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
Display_DIF_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for measurement operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DIF_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   float64_t interval= 0.0;
   uint32_t numberOfElements = 0;
   nai_dif_fifo_status_t fifoStatus = 0;
   nai_dif_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_DIF_GetFIFOStatus( cardIndex, module, chan, &numberOfElements, &fifoStatus ));
   check_status(naibrd_DIF_GetOpMode(cardIndex, module, chan, &opmode));
   check_status(naibrd_DIF_GetTimebaseInterval( cardIndex, module, chan, &interval ));

   printf("\n === Channel %d ===\n\n", chan);

   /*read DIF FIFO configuration values here, Status, number of elements, interval, and mode */
   {
      printf("  Status          Count      Interval      Value     Enhanced Mode Selection\n");
      printf("-------------    -------   ---- mS -----   -------  ---------------------------\n");
   }

   /*display configuration settings here- */
   switch (fifoStatus)
   {
   case NAI_DIF_FIFO_STATUS_ALMOST_EMPTY:
      printf(" FIFO almost Empty ");
      break;
   case NAI_DIF_FIFO_STATUS_EMPTY:
      printf("  FIFO Empty  ");
      break;
   case NAI_DIF_FIFO_STATUS_FULL:
      printf("  FIFO Full   ");
      break;
   case NAI_DIF_FIFO_STATUS_ALMOST_FULL:
      printf(" FIFO Almost Full ");
      break;
   case NAI_DIF_FIFO_STATUS_BTWN_ALMOST_EMPTY_FULL:
      printf(" FIFO Btwn Empty and 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("%12.3f NA", interval);

   /* if opcode is 6,7,or 8 display the counter value */
   if( (opmode > 5) && (opmode < 9) )
   {
      check_status(naibrd_DIF_GetCountData( cardIndex, module, chan, &outcount ));
      printf("%7d         ", outcount);
   }
   else
      printf("%7d NA      ", outcount);

   switch (opmode)
   {
   case NAI_DIF_MODE_STD_INPUT_OUTPUT:
      printf("STD_INPUT_OUTPUT   ");
      break;
   case NAI_DIF_MODE_MEASURE_HIGH_TIME:
      printf("MEASURE_HIGH_TIME   ");
      break;
   case NAI_DIF_MODE_MEASURE_LOW_TIME:
      printf("MEASURE_LOW_TIME   ");
      break;
   case NAI_DIF_MODE_TIMESTAMP_RISING_EDGES:
      printf("TIMESTAMP_RISING_EDGES   ");
      break;
   case NAI_DIF_MODE_TIMESTAMP_FALLING_EDGES:
      printf("Record TIMESTAMP_FALLING_EDGES   ");
      break;
   case NAI_DIF_MODE_TIMESTAMP_ALL_EDGES:
      printf("Record TIMESTAMP_ALL_EDGES   ");
      break;
   case NAI_DIF_MODE_COUNT_RISING_EDGES:
      printf("MODE_COUNT_RISING_EDGES   ");
      break;
   case NAI_DIF_MODE_COUNT_FALLING_EDGES:
      printf("MODE_COUNT_FALLING_EDGES   ");
      break;
   case NAI_DIF_MODE_COUNT_ALL_EDGES:
      printf("MODE_COUNT_ALL_EDGES   ");
      break;
   case NAI_DIF_MODE_MEASURE_PERIOD_FROM_RISING_EDGE:
      printf("MEASURE_PERIOD_FROM_RISING_EDGE   ");
      break;
   case NAI_DIF_MODE_MEASURE_FREQUENCY:
      printf("Measure Interval Count ");
      break;
   case NAI_DIF_MODE_OUTPUT_PWM_FOREVER:
      printf("Continuous PWM Output");
      break;
   case NAI_DIF_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES:
      printf("Burst PWM Output");
      break;
   case NAI_DIF_MODE_OUTPUT_PATTERN_RAM:
      printf("NAI_DIF_MODE_OUTPUT_PATTERN_RAM   ");
      break;
   default:
      printf("Unknown    ");
      break;
   }
}

/**************************************************************************************************************/
/**
<summary>
Configure_DIF_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>
*/
/**************************************************************************************************************/
nai_status_t Configure_DIF_FIFO_Mode(int32_t paramCount, int32_t* p_params)
{
   bool_t bQuit = FALSE;
   uint32_t selection = 0;
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dif_params->cardIndex;
   int32_t module = p_dif_params->module;
   int32_t chan = p_dif_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");
   printf(" > ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   selection = atoi((const char *)inputBuffer);

   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
        /* Must be in enhanced mode to use DIF FIFO */
         if (selection == 1)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_MEASURE_HIGH_TIME));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 2)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_MEASURE_LOW_TIME));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 3)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_TIMESTAMP_RISING_EDGES));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 4)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_TIMESTAMP_FALLING_EDGES));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 5)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_TIMESTAMP_ALL_EDGES));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 6)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_COUNT_RISING_EDGES));
            /* clear old count value since we are changing modes */
            check_status(naibrd_DIF_ClearCountData(cardIndex, module, chan));
            /* now start the counter in the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 7)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_COUNT_FALLING_EDGES));
            /* clear old count value since we are changing modes */
            check_status(naibrd_DIF_ClearCountData(cardIndex, module, chan));
            /* now start the counter in the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 8)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_COUNT_ALL_EDGES));
            /* clear old count value since we are changing modes */
            check_status(naibrd_DIF_ClearCountData(cardIndex, module, chan));
            /* now start the counter in the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 9)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_MEASURE_PERIOD_FROM_RISING_EDGE));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else if (selection == 10)
         {
            check_status(naibrd_DIF_SetOpMode( cardIndex, module, chan, NAI_DIF_MODE_MEASURE_FREQUENCY));
            /* Set the interval */
            check_status(Configure_DIF_Counter_Interval(paramCount, p_params));
            /* clear old data from FIFO since we are changing modes */
            check_status(naibrd_DIF_ClearFIFO(cardIndex, module, chan));
            /* now start the FIFO */
            check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAI_DIF_ENHANCE_OP_ENABLE));
         }
         else
         {
          printf("Invalid mode %d\n", selection);
       }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Start_DIF_FIFO must be called in order to start the FIFO in a particular mode.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Start_DIF_FIFO(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   check_status(naibrd_DIF_SetEnhanceTriggerEnable(p_dif_params->cardIndex, p_dif_params->module, p_dif_params->channel, NAI_DIF_ENHANCE_OP_ENABLE));
   return NAI_ERROR_UNKNOWN;
}

/**************************************************************************************************************/
/**
<summary>
Clear_DIF_FIFO should be called before naibrd_DIF_StartMeasurement to clear out old data.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Clear_DIF_FIFO(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   check_status(naibrd_DIF_ClearFIFO( p_dif_params->cardIndex, p_dif_params->module, p_dif_params->channel ));
   return NAI_ERROR_UNKNOWN;
}

/**************************************************************************************************************/
/**
<summary>
Get_DIF_FIFO_Data reads back the data on the FIFO.
</summary>
*/
/**************************************************************************************************************/

nai_status_t Get_DIF_FIFO_Data(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dif_params->cardIndex;
   int32_t module = p_dif_params->module;
   int32_t chan = p_dif_params->channel;
   uint32_t count, numberOfElements, i, countRemaining, timeout;
   uint32_t outdata[512];
   bool_t bQuit = FALSE;
   nai_dif_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_DIF_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_DIF_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>
Configure_DIF_Counter_Interval will configure DIF module gating interval for measurement of counts within the user defined interval.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Configure_DIF_Counter_Interval(int32_t paramCount, int32_t* p_params)
{
   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;
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dif_params->cardIndex;
   int32_t module = p_dif_params->module;
   int32_t chan = p_dif_params->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   printf("\nEnter the desired interval in ms \n(Enter 1000 for direct frequency reading):\n > ");
   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_DIF_GetTimebaseLSB(ModuleID);
         switch (ModuleID)
         {
         case NAI_MODULE_ID_DF2:
            min =(float64_t)(0x2u * lsb);
            max =(float64_t)(0xFFFFFFFF * lsb);
         default:
               break;
         }
         if (interval > max || interval < min)
            printf(" Entry out of range.  Range %7.7f to %7.3f ms\n", min, max);
         else
         {
         check_status(naibrd_DIF_SetTimebaseInterval(cardIndex, module, chan, interval ));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Get_DIF_FIFO_Count will read back the value of the counter if the FIFO is configured for
* opmode 6,7, or 8.
</summary>
*/
/**************************************************************************************************************/
nai_status_t Get_DIF_FIFO_Count(int32_t paramCount, int32_t* p_params)
{
   uint32_t outcount;
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   check_status(naibrd_DIF_GetCountData(p_dif_params->cardIndex, p_dif_params->module, p_dif_params->channel, &outcount ));
   printf("Count is %d\n",outcount);
   return NAI_ERROR_UNKNOWN;
}

/**************************************************************************************************************/
/**
<summary>
Get_DIF_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_DIF_FIFO_Status(int32_t paramCount, int32_t* p_params)
{
   uint32_t numberOfElements;
   nai_dif_fifo_status_t fifoStatus;
   p_naiapp_AppParameters_t p_dif_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = p_dif_params->cardIndex;
   int32_t module = p_dif_params->module;
   int32_t chan = p_dif_params->channel;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   check_status(naibrd_DIF_GetFIFOStatus( cardIndex, module, chan, &numberOfElements, &fifoStatus ));
   switch (fifoStatus)
   {
   case NAI_DIF_FIFO_STATUS_ALMOST_EMPTY:
      printf(" FIFO almost Empty ");
      break;
   case NAI_DIF_FIFO_STATUS_EMPTY:
      printf("  FIFO Empty  ");
      break;
   case NAI_DIF_FIFO_STATUS_FULL:
      printf("  FIFO Full   ");
      break;
   case NAI_DIF_FIFO_STATUS_ALMOST_FULL:
      printf(" FIFO Almost Full ");
      break;
   case NAI_DIF_FIFO_STATUS_BTWN_ALMOST_EMPTY_FULL:
      printf(" FIFO Btwn Empty and Full ");
      break;
   default:
      printf("    Unknown   ");
      break;
   }
   return NAI_ERROR_UNKNOWN;
}

Help Bot

X