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 Pattern Generator

DIF Pattern Generator Sample Application (SSK 2.x)

Overview

The DIF Pattern Generator sample application demonstrates how to configure and output user-defined bit patterns on DIF (Differential Input Function) channels using the NAI Software Support Kit (SSK 2.x). It shows how to load pattern data from a file into the module’s pattern RAM, configure the playback period and address range, and control pattern generation output including continuous mode, burst mode, pause, and resume.

Pattern generation is fundamentally different from simple high/low output control. Instead of setting a single static output state, the FPGA on the DIF module steps through a block of RAM containing a sequence of bit patterns at a programmable rate. Each RAM entry defines the simultaneous output state of all channels on the module. This enables you to produce complex, repeatable digital waveforms — test patterns, stimulus sequences, or protocol-level bit streams — without real-time host intervention.

Supported modules: DF1, DF2, DF3.

For the SSK 1.x version, see DIF PatternGenerator (SSK 1.x). For detailed register-level information, consult the DF1 Manual.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a supported DIF module installed (DF1, DF2, or DF3).

  • SSK 2.x installed on your development host.

  • The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.

  • A pattern data file (TestRAMPattern.txt) in the working directory, containing hex-encoded pattern values (one per line).

  • Appropriate output connections or a load on the DIF channel(s) under test.

How to Run

Launch the dif_pattern_generator executable from your build output directory. On startup the application looks for a configuration file (default_DIF_PatternGenerator.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, select a channel, and the application presents a pattern generator operations menu where you configure the mode, addresses, period, load data, and enable or pause output.

Board Connection and Module Selection

Note

This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to DIF. For details on board connection configuration, see the SSK 2.x Software Development Guide.

The main() function follows a standard SSK 2.x startup flow:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_DIF_PatternGenerator.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleName() so downstream code can verify the module is a supported DIF type.

#if defined (__VXWORKS__)
int32_t DIF_PatternGenerator(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = NAI_FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(),
            DEF_DIF_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt,
               DEF_DIF_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module,
                  &moduleID));
               if ((moduleID != 0))
               {
                  Run_DIF_PatternGenerator(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart "
            "application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer),
            NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}

Note the SSK 2.x differences from SSK 1.x in this startup sequence:

  • The VxWorks preprocessor guard uses __VXWORKS__ in this particular source (some SSK 2.x samples use NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS).

  • The module identifier is retrieved with naibrd_GetModuleName() (SSK 1.x uses naibrd_GetModuleID()).

  • Boolean constants are NAI_TRUE / NAI_FALSE (SSK 1.x uses TRUE / FALSE).

  • Console output uses naiif_printf() from the platform abstraction layer (SSK 1.x uses printf() directly).

After retrieving the module ID, the application passes it to Run_DIF_PatternGenerator(), which validates that the module is a recognized DIF type by calling naibrd_DIF_GetChannelCount(). If the channel count is zero, the module is rejected:

void Run_DIF_PatternGenerator(int32_t cardIndex, int32_t module,
   int32_t ModuleID)
{
   int32_t MaxChannel;
   MaxChannel = naibrd_DIF_GetChannelCount(ModuleID);
   if (MaxChannel == 0)
   {
      naiif_printf(
         " *** Module selection not recognized as DIF module. ***\r\n\r\n");
   }
   else
   {
      Cfg_DIF_PatternGen_Channel(cardIndex, module, ModuleID, MaxChannel);
   }
}
Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — the card index is zero-based; the module number is one-based. Ensure the values you pass match your hardware setup.

  • Module not recognized as DIF — naibrd_DIF_GetChannelCount() returned zero. The slot does not contain a DF1, DF2, or DF3 module.

Program Structure

Entry Point

On standard platforms (Petalinux, DEOS) the entry point is main(). On VxWorks the entry point is DIF_PatternGenerator() — the SSK 2.x build system selects the correct variant via a preprocessor guard.

The startup flow is the same in both cases:

  1. Attempt to load the saved configuration file via naiapp_RunBoardMenu(CONFIG_FILE).

  2. Enter a loop that queries for card index and module slot.

  3. Validate the module with naibrd_DIF_GetChannelCount() and, if valid, enter Cfg_DIF_PatternGen_Channel() for the interactive session.

  4. On exit, close all open board connections with naiapp_access_CloseAllOpenCards().

Application Parameters

The Cfg_DIF_PatternGen_Channel() function populates an naiapp_AppParameters_t struct that is passed to every command handler:

naiapp_AppParameters_t  dif_params;
p_naiapp_AppParameters_t dif_patgen_params = &dif_params;
dif_patgen_params->cardIndex = cardIndex;
dif_patgen_params->module = module;
dif_patgen_params->modId = ModuleID;
dif_patgen_params->maxChannels = MaxChannel;
dif_patgen_params->channel = chan;

Command Loop

After selecting a channel, the application automatically sets the channel to Pattern RAM output mode and configures the I/O format for output:

check_status(naibrd_DIF_SetOpMode(cardIndex, module, chan,
   NAIBRD_DIF_MODE_OUTPUT_PATTERN_RAM));
check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan,
   NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));

It then enters a command loop, displaying the channel configuration and dispatching user commands:

Command Description

Mode

Select continuous or burst pattern generation mode

StartAddr

Set the start address in pattern RAM

EndAddr

Set the end address in pattern RAM

Period

Set the pattern generation period (ms)

Count

Set the burst count

Load

Load pattern data from file into RAM

CONtrol

Enable or disable pattern generator output

Pause/Play

Pause or resume pattern generation

Reset

Reset current channel to standard input mode

RAll

Reset all channels to standard input mode

SEtall

Set all channels to pattern generator mode

Display

Display current pattern generator configuration

Stat

Display channel status

Pattern Generator Mode Selection

The sample supports two pattern generation modes: continuous and burst.

Continuous Mode

In continuous mode, the pattern generator cycles through the pattern RAM addresses repeatedly until explicitly stopped. To configure continuous mode, set the enhanced mode to pattern RAM output and disable the burst control:

check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan,
   NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));
naibrd_DIF_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, NAIBRD_DIF_ENHANCE_OP_DISABLE);

Burst Mode

In burst mode, the pattern generator cycles through the pattern for a specified number of iterations (the burst count) and then stops. Enable the burst control bit:

check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan,
   NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));
naibrd_DIF_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, NAIBRD_DIF_ENHANCE_OP_ENABLE);

Address and Period Configuration

Start and End Address

The pattern generator steps through a range of RAM addresses. To set the active range, call naibrd_DIF_SetPatternGenStartAddr() and naibrd_DIF_SetPatternGenEndAddr():

check_status(naibrd_DIF_SetPatternGenStartAddr(cardIndex, module,
   startAddr));
check_status(naibrd_DIF_SetPatternGenEndAddr(cardIndex, module,
   endAddr));

The valid address range is module-specific. The sample validates the addresses using naibrd_DIF_GetValidPatternGenStart() and naibrd_DIF_GetValidPatternGenEnd().

Period

The period controls how fast the pattern generator steps through the RAM. The value is specified in milliseconds:

check_status(naibrd_DIF_SetPatternGenPeriod(cardIndex, module, time));

The valid range depends on the module’s timebase LSB, retrieved with naibrd_DIF_GetTimebaseLSB().

Burst Count

The burst count specifies how many times the pattern repeats in burst mode:

check_status(naibrd_DIF_SetPatternGen_BurstNum(cardIndex, module,
   burstcount));

The minimum burst count is 1.

Loading Pattern Data

The Load_DIF_PatternGenArray() function reads pattern data from a text file (TestRAMPattern.txt) and writes it to the module’s pattern RAM. Each line in the file contains one hex-encoded 32-bit data value. The data is loaded into the module with a single bulk write:

check_status(naibrd_DIF_SetPatternGenBuf(cardIndex, module,
   entryCnt, &dataPattern[0]));
  • entryCnt — the number of entries loaded from the file (up to 4092 maximum).

  • dataPattern — array of 32-bit pattern values. Each bit position corresponds to a channel.

Important

Common Errors

  • Pattern file not found — the file TestRAMPattern.txt must be in the application’s working directory. The sample prints an error if the file cannot be opened.

  • No data in file — if the file is empty or contains no valid hex entries, no data is loaded and the sample displays an error.

  • Pattern RAM is channel-independent — the pattern data array covers all channels on the module simultaneously. Each bit in a pattern word corresponds to one channel’s output state.

Controlling Pattern Output

Enable and Disable

To start pattern generation, enable the pattern generator control:

check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE, NAIBRD_DIF_ENHANCE_OP_ENABLE));

To stop pattern generation:

check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE, NAIBRD_DIF_ENHANCE_OP_DISABLE));

Pause and Resume

To temporarily suspend pattern output without disabling it:

/* Pause */
check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE, NAIBRD_DIF_ENHANCE_OP_ENABLE));

/* Resume */
check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE, NAIBRD_DIF_ENHANCE_OP_DISABLE));

Displaying Configuration and Status

Pattern Generator Configuration

The Display_DIF_PatternGen_Configuration() function reads back and displays the current period, burst count, start address, and end address:

check_status(naibrd_DIF_GetPatternGenPeriod(cardIndex, module, &period));
check_status(naibrd_DIF_GetPatternGen_BurstNum(cardIndex, module,
   &burstnumber));
check_status(naibrd_DIF_GetPatternGenStartAddr(cardIndex, module,
   &startaddr));
check_status(naibrd_DIF_GetPatternGenEndAddr(cardIndex, module,
   &endaddr));

Channel Status

The Display_DIF_Status() function reads latched status flags for the selected channel:

check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_DIF_STATUS_BIT_LATCHED, &status));
check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED, &status));
check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_DIF_STATUS_LO_HI_TRANS_LATCHED, &status));
check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan,
   NAIBRD_DIF_STATUS_HI_LO_TRANS_LATCHED, &status));

Troubleshooting Reference

Symptom Possible Cause and Resolution

No output observed

Pattern generator is not enabled. Call naibrd_DIF_SetPatternGenCtrl() with NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE set to NAIBRD_DIF_ENHANCE_OP_ENABLE.

Pattern file not found

Ensure TestRAMPattern.txt is in the application’s working directory.

Output is static (not cycling)

Period may be set to zero or an invalid value. Verify with naibrd_DIF_GetPatternGenPeriod().

Module not recognized

naibrd_DIF_GetChannelCount() returned zero. Verify the module type in the selected slot.

Address range error

Start or end address is outside the valid range for the module. Use naibrd_DIF_GetValidPatternGenStart() and naibrd_DIF_GetValidPatternGenEnd() to check.

Burst mode runs forever

Burst control bit is not enabled. Call naibrd_DIF_SetPatternGenCtrl() with NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST set to NAIBRD_DIF_ENHANCE_OP_ENABLE.

Pattern output paused unexpectedly

The pause bit may be set. Call naibrd_DIF_SetPatternGenCtrl() with NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE set to NAIBRD_DIF_ENHANCE_OP_DISABLE to resume.

Overcurrent status

The output channel may be shorted or the load exceeds the module’s drive capability. Check NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED.

Full Source

Full Source — dif_pattern_generator.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"

/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_dif.h"

/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"

/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"

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

/* Function prototypes */
void Run_DIF_PatternGenerator(int32_t cardIndex, int32_t module, int32_t ModuleID);
void Cfg_DIF_PatternGen_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
void Display_DIF_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Configure_DIF_PatternGen_StartAddr(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_PatternGen_EndAddr(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_PatternGen_Period(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_PatternGen_Burstcount(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_PatternGen_Mode(int32_t paramCount, int32_t* p_params);
static nai_status_t Load_DIF_PatternGenArray(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_ControlEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DIF_ControlPause(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_DIF_PatternGen_Configuration(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_DIF_Status(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_DIF_CARD_INDEX    = 0;
static const int32_t DEF_DIF_MODULE        = 1;
static const int32_t DEF_DIF_CHANNEL       = 1;
#define MAX_DIF_PATTERN_GENERATOR_ENTRIES    4092

/****** Command Table *******/
enum dif_patterngen_commands
{
   DIF_PATTERNGEN_CMD_MODE,
   DIF_PATTERNGEN_CMD_STARTADDR,
   DIF_PATTERNGEN_CMD_ENDADDR,
   DIF_PATTERNGEN_CMD_PERIOD,
   DIF_PATTERNGEN_CMD_BURSTCOUNT,
   DIF_PATTERNGEN_CMD_LOAD_DATA,
   DIF_PATTERNGEN_CMD_ENABLE,
   DIF_PATTERNGEN_CMD_PAUSE_DATA,
   DIF_PATTERNGEN_CMD_RESETMODE,
   DIF_PATTERNGEN_CMD_RESETALL,
   DIF_PATTERNGEN_CMD_SETALL,
   DIF_PATTERNGEN_CMD_DISP,
   DIF_PATTERNGEN_CMD_STATUS,
   DIF_PATTERNGEN_CMD_LAST
};

/****** Command Tables *******/
naiapp_cmdtbl_params_t DIF_PatternGen_MenuCmds[] = {

   {"Mode",          "DIF Select Pattern Mode",                        DIF_PATTERNGEN_CMD_MODE,              Configure_DIF_PatternGen_Mode},
   {"StartAddr",     "DIF Set Start Address",                          DIF_PATTERNGEN_CMD_STARTADDR,         Configure_DIF_PatternGen_StartAddr},
   {"EndAddr",       "DIF Set End Address",                            DIF_PATTERNGEN_CMD_ENDADDR,           Configure_DIF_PatternGen_EndAddr},
   {"Period",        "DIF Pattern Generator Period",                   DIF_PATTERNGEN_CMD_PERIOD,            Configure_DIF_PatternGen_Period},
   {"Count",         "DIF Pattern Generator Burst count",              DIF_PATTERNGEN_CMD_BURSTCOUNT,        Configure_DIF_PatternGen_Burstcount},
   {"Load",          "DIF Load Pattern Generator Data",                DIF_PATTERNGEN_CMD_LOAD_DATA,         Load_DIF_PatternGenArray},
   {"CONtrol",       "DIF Enable or Disable Pattern Generator Output", DIF_PATTERNGEN_CMD_ENABLE,            Configure_DIF_ControlEnable},
   {"Pause/Play",    "DIF Pause or Resume Pattern Gen Output",         DIF_PATTERNGEN_CMD_PAUSE_DATA,        Configure_DIF_ControlPause},
   {"Reset",         "DIF Reset Chan Mode, Input",                     DIF_PATTERNGEN_CMD_RESETMODE,         NULL},
   {"RAll",          "DIF Reset All Channels, Input",                  DIF_PATTERNGEN_CMD_RESETALL,          NULL},
   {"SEtall",        "DIF Set All Channels to Pattern Gen",            DIF_PATTERNGEN_CMD_SETALL,            NULL},
   {"Display",       "DIF Display channel Pattern Generator Info",     DIF_PATTERNGEN_CMD_DISP,              Display_DIF_PatternGen_Configuration},
   {"Stat",          "DIF Display Status",                             DIF_PATTERNGEN_CMD_STATUS,                   Display_DIF_Status},
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the DIF_PatternGenerator is to illustrate the methods to call in the naibrd library to perform configuration
 setup for output in Pattern Generator operation mode.  Pattern generator period setting is 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 DIF routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DIF_PatternGenerator(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = NAI_FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(CONFIG_FILE) == NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Query the user for the card index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DIF_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DIF_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_DIF_PatternGenerator(cardIndex, module, moduleID);
               }
            }
         }

         naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
         stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      }
   }

   naiif_printf("\r\nType the Enter key to exit the program: ");
   naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   naiapp_access_CloseAllOpenCards();

   return 0;
}

/**************************************************************************************************************/
/**
<summary>
Run_DIF_PatternGenerator prompts the user for the card, module and channel to use for the application and calls
Cfg_DIF_PatternGen_Channel if the card, module, channel is valid for as a TLL module.
</summary>
*/
/**************************************************************************************************************/
void Run_DIF_PatternGenerator(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
   int32_t MaxChannel;

   MaxChannel = naibrd_DIF_GetChannelCount(ModuleID);

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

/**************************************************************************************************************/
/**
<summary>
Cfg_DIF_PatternGen_Channel handles calling the Display_DIF_PatternGen_ChannelCfg routine to display the DIF
channel configuration and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
void Cfg_DIF_PatternGen_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bContinue = NAI_TRUE;
   bool_t bCmdFound = NAI_FALSE;
   int32_t chan, defaultchan = 1;
   int32_t cmd;
   int32_t ch_loop;
   int32_t status = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
   naiapp_AppParameters_t  dif_params;
   p_naiapp_AppParameters_t dif_patgen_params = &dif_params;
   dif_patgen_params->cardIndex = cardIndex;
   dif_patgen_params->module = module;
   dif_patgen_params->modId = ModuleID;
   dif_patgen_params->maxChannels = MaxChannel;
   while (bContinue)
   {
      naiif_printf("    \r\r\n\r\r\n");
      naiif_printf("Channel selection \r\r\n");
      naiif_printf("================= \r\r\n");
      defaultchan = DEF_DIF_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      dif_patgen_params->channel = chan;

      /* Configure the selected channel for Pattern Generator Mode and output mode */
      check_status(naibrd_DIF_SetOpMode(cardIndex, module, chan, NAIBRD_DIF_MODE_OUTPUT_PATTERN_RAM));
      check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan, NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));

      naiapp_utils_LoadParamMenuCommands(DIF_PATTERNGEN_CMD_LAST, DIF_PatternGen_MenuCmds);
      while (bContinue)
      {
         Display_DIF_PatternGen_ChannelCfg(cardIndex, module, chan, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"DIF Pattern Generator Operation Menu");
         naiif_printf("\r\nType DIF 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 DIF_PATTERNGEN_CMD_LOAD_DATA:
                   case DIF_PATTERNGEN_CMD_PERIOD:
                   case DIF_PATTERNGEN_CMD_STARTADDR:
                   case DIF_PATTERNGEN_CMD_ENDADDR:
                   case DIF_PATTERNGEN_CMD_BURSTCOUNT:
                   case DIF_PATTERNGEN_CMD_MODE:
                   case DIF_PATTERNGEN_CMD_ENABLE:
                   case DIF_PATTERNGEN_CMD_PAUSE_DATA:
                   case DIF_PATTERNGEN_CMD_DISP:
                   case DIF_PATTERNGEN_CMD_STATUS:
                     DIF_PatternGen_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dif_patgen_params);
                     break;
                  case DIF_PATTERNGEN_CMD_RESETMODE:
                     {
                        status |= check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, chan, NAIBRD_DIF_ENHANCE_OP_DISABLE));
                        status |= check_status(naibrd_DIF_SetOpMode(cardIndex, module, chan, NAIBRD_DIF_MODE_STD_INPUT_OUTPUT));
                        status |= check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE,NAIBRD_DIF_ENHANCE_OP_DISABLE));
                        status |= check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, NAIBRD_DIF_ENHANCE_OP_DISABLE));
                        status |= check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE, NAIBRD_DIF_ENHANCE_OP_DISABLE));

                        if (status == NAI_SUCCESS)
                           naiif_printf("Reset completed \r\n");
                        else
                           naiif_printf("Error %2X on set \r\n", status);
                     }
                     break;
                  case DIF_PATTERNGEN_CMD_RESETALL:
                     {
                        status = NAI_SUCCESS;
                        for (ch_loop=1; ch_loop<=MaxChannel; ch_loop++)
                        {
                           status |= check_status(naibrd_DIF_SetEnhanceTriggerEnable(cardIndex, module, ch_loop, NAIBRD_DIF_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DIF_SetOpMode(cardIndex, module, ch_loop, NAIBRD_DIF_MODE_STD_INPUT_OUTPUT));
                           status |= check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE, NAIBRD_DIF_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, NAIBRD_DIF_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE, NAIBRD_DIF_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DIF_Reset(cardIndex, module, ch_loop, NAIBRD_DIF_RESET_TIMER_ONLY));
                        }
                        if (status == NAI_SUCCESS)
                           naiif_printf("Reset All completed \r\n");
                        else
                           naiif_printf("Error %2X on set \r\n", status);
                     }
                     break;
                  case DIF_PATTERNGEN_CMD_SETALL:
                     {
                        status = NAI_SUCCESS;
                        for (ch_loop=1; ch_loop<=MaxChannel; ch_loop++)
                        {
                           status |= check_status(naibrd_DIF_SetOutputState(cardIndex, module, ch_loop, NAIBRD_DIF_STATE_LO));
                           status |= check_status(naibrd_DIF_SetIOFormat(cardIndex, module, ch_loop, NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));
                           status |= check_status(naibrd_DIF_SetOpMode(cardIndex, module, ch_loop, NAIBRD_DIF_MODE_OUTPUT_PATTERN_RAM));
                        }
                        if (status == NAI_SUCCESS)
                           naiif_printf("Set on all channels completed \r\n");
                        else
                           naiif_printf("Error %2X on set \r\n", status);
                     }
                     break;
                  default:
                     naiif_printf("Invalid command entered\r\n");
                     break;
                  }
               }
               else
                  naiif_printf("Invalid command entered\r\n");
            }
         }
         else
            bContinue = NAI_FALSE;
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
Display_DIF_PatternGen_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
void Display_DIF_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   uint32_t ioformat = 0;
   naibrd_dif_state_t outputstate = 0;
   naibrd_dif_state_t inputstate = 0;
   naibrd_dif_enhanced_mode_t opmode = (naibrd_dif_enhanced_mode_t)0;
   naibrd_dif_enable_t enablebit=0;
   naibrd_dif_enable_t burstbit=0;
   naibrd_dif_enable_t pausebit=0;

   check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));
   check_status(naibrd_DIF_GetIOFormat(cardIndex, module, chan, &ioformat));
   check_status(naibrd_DIF_GetOutputState(cardIndex, module, chan, &outputstate));
   check_status(naibrd_DIF_GetInputState(cardIndex, module, chan, &inputstate));
   check_status(naibrd_DIF_GetOpMode(cardIndex, module, chan, &opmode));

   check_status(naibrd_DIF_GetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE, &enablebit));
   check_status(naibrd_DIF_GetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, &burstbit));
   check_status(naibrd_DIF_GetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE, &pausebit));

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

   /*read PWM configuration values here, Period, Pulsewidth, Continuous/Burst Mode, */
   {
      naiif_printf("   I/O       Output    Input                             \r\n");
      naiif_printf("  Format     State     State    Enhanced Mode Selection  \r\n");
      naiif_printf(" --------   -------   -------  ------------------------- \r\n");
   }

   /*display configuration settings here- */
   switch (ioformat)
   {
   case NAIBRD_DIF_IOFORMAT_INPUT:
      naiif_printf("  Input   ");
      break;
   case NAIBRD_DIF_GEN3_IOFORMAT_OUTPUT:
   case NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT:
      naiif_printf(" High-side"); /*may want add check for proper value depending on whether gen3 or gen5; for now, assume it correctly matches module*/
      break;
   default:
      naiif_printf(" Unknown  ");
      break;
   }
   switch (outputstate)
   {
   case NAIBRD_DIF_STATE_LO:
      naiif_printf("  LOW     ");
      break;
   case NAIBRD_DIF_STATE_HI:
      naiif_printf("  HIGH    ");
      break;
   default:
      naiif_printf(" Unknown  ");
      break;
   }

   switch (inputstate)
   {
   case NAIBRD_DIF_STATE_LO:
      naiif_printf(" LOW Input  ");
      break;
   case NAIBRD_DIF_STATE_HI:
      naiif_printf("HIGH Input  ");
      break;
   default:
      naiif_printf("Unknown     ");
      break;
   }
   switch (opmode)
   {
   case NAIBRD_DIF_MODE_STD_INPUT_OUTPUT:
      naiif_printf("STD_INPUT_OUTPUT   \r\n");
      break;
   case NAIBRD_DIF_MODE_MEASURE_HIGH_TIME:
      naiif_printf("NAIBRD_DIF_MODE_MEASURE_HIGH_TIME   \r\n");
      break;
   case NAIBRD_DIF_MODE_MEASURE_LOW_TIME:
      naiif_printf("NAIBRD_DIF_MODE_MEASURE_LOW_TIME  \r\n ");
      break;
   case NAIBRD_DIF_MODE_TIMESTAMP_RISING_EDGES:
      naiif_printf("NAIBRD_DIF_MODE_TIMESTAMP_RISING_EDGES   \r\n");
      break;
   case NAIBRD_DIF_MODE_TIMESTAMP_FALLING_EDGES:
      naiif_printf("NAIBRD_DIF_MODE_TIMESTAMP_FALLING_EDGES   \r\n");
      break;
   case NAIBRD_DIF_MODE_TIMESTAMP_ALL_EDGES:
      naiif_printf("NAIBRD_DIF_MODE_TIMESTAMP_ALL_EDGES   \r\n");
      break;
   case NAIBRD_DIF_MODE_COUNT_RISING_EDGES:
      naiif_printf("NAIBRD_DIF_MODE_COUNT_RISING_EDGES   \r\n");
      break;
   case NAIBRD_DIF_MODE_COUNT_FALLING_EDGES:
      naiif_printf("NAIBRD_DIF_MODE_COUNT_FALLING_EDGES   \r\n");
      break;
   case NAIBRD_DIF_MODE_COUNT_ALL_EDGES:
      naiif_printf("NAIBRD_DIF_MODE_COUNT_ALL_EDGES  \r\n");
      break;
   case NAIBRD_DIF_MODE_MEASURE_PERIOD_FROM_RISING_EDGE:
      naiif_printf("NAIBRD_DIF_MODE_MEASURE_PERIOD_FROM_RISING_EDGE   \r\n");
      break;
   case NAIBRD_DIF_MODE_MEASURE_FREQUENCY:
      naiif_printf("NAIBRD_DIF_MODE_MEASURE_FREQUENCY   \r\n");
      break;
   case NAIBRD_DIF_MODE_OUTPUT_PWM_FOREVER:
      naiif_printf("NAIBRD_DIF_MODE_OUTPUT_PWM_FOREVER   \r\n");
      break;
   case NAIBRD_DIF_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES:
      naiif_printf("NAIBRD_DIF_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES   \r\n");
      break;
   case NAIBRD_DIF_MODE_OUTPUT_PATTERN_RAM:
      naiif_printf("NAIBRD_DIF_MODE_OUTPUT_PATTERN_RAM  \r\n");
      break;
   default:
      naiif_printf("Unknown    ");
      break;
   }

    naiif_printf("                     \r\n\r\n");
    naiif_printf("     Pattern Gen Mode   \r\n");
    naiif_printf(" --------------------------\r\n");

   switch (enablebit)
   {
      case NAIBRD_DIF_STATE_LO:
      naiif_printf("  Disabled");
      break;
      case NAIBRD_DIF_STATE_HI:
      naiif_printf("   Enabled");
      break;
      /* undefined value read back */
      default:
      naiif_printf("   UNK  ");
      break;
   }
   switch (burstbit)
   {
      case NAIBRD_DIF_STATE_LO:
      naiif_printf(" Continuous Mode");
      break;
      case NAIBRD_DIF_STATE_HI:
      naiif_printf(" Burst Mode");
      break;
      /* undefined value read back */
      default:
      naiif_printf(" UNK  ");
      break;
   }
   switch (pausebit)
   {
      case NAIBRD_DIF_STATE_LO:
      break;
      case NAIBRD_DIF_STATE_HI:
      naiif_printf(" PAUSED");
      break;
      /* undefined value read back */
      default:
      naiif_printf(" UNK  ");
      break;
   }

}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_PatternGen_StartAddr 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_DIF_PatternGen_StartAddr(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;
   bool_t bQuit = NAI_FALSE;
   uint32_t startAddr = 0;
   uint32_t min = 0;
   uint32_t max = 0;
   uint32_t ModuleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;


#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   naiif_printf("\r\nEnter the desired Start Address: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleName(cardIndex, module, &ModuleID);
         startAddr =  strtol(((const char *)inputBuffer),NULL,16);
        switch (ModuleID)
         {
         case NAIBRD_MODULE_ID_DF2:
            min = naibrd_DIF_GetValidPatternGenStart(ModuleID);
            max = naibrd_DIF_GetValidPatternGenEnd(ModuleID);
            break;
         default:
            break;
         }
         if (startAddr > max || startAddr < min)
            naiif_printf(" Entry out of range.  Range %08X to %08X \r\n", min, max);
         else
         {
            check_status(naibrd_DIF_SetPatternGenStartAddr(cardIndex,module,startAddr));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_PatternGen_EndAddr 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_DIF_PatternGen_EndAddr(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;
   bool_t bQuit = NAI_FALSE;
   uint32_t endAddr = 0;
   uint32_t min = 0;
   uint32_t max = 0;
   uint32_t ModuleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   naiif_printf("\r\nEnter the desired End Address: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));
         endAddr = strtol(((const char *)inputBuffer),NULL,16);;
        switch (ModuleID)
         {
         case NAIBRD_MODULE_ID_DF2:
            min =naibrd_DIF_GetValidPatternGenStart(ModuleID);
            max =naibrd_DIF_GetValidPatternGenEnd(ModuleID);
            break;
         default:
            break;
         }
         if (endAddr > max || endAddr < min)
            naiif_printf(" Entry out of range.  Range 0x%08X to 0x%08X \r\n", min, max);
         else
         {
            check_status(naibrd_DIF_SetPatternGenEndAddr(cardIndex,module,endAddr));
       }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Configure_DIF_PatternGen_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>
*/
/**************************************************************************************************************/
nai_status_t Configure_DIF_PatternGen_Period(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;
   bool_t bQuit = NAI_FALSE;
   float64_t time = 0.0;
   float64_t lsb = 0;
   float64_t min = 1;
   float64_t max = -1;
   uint32_t ModuleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   naiif_printf("\r\nEnter the desired period in ms: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));
         time = atof((const char *)inputBuffer); /*entry in milliseconds*/
         lsb = naibrd_DIF_GetTimebaseLSB(ModuleID);
         switch (ModuleID)
         {
         case NAIBRD_MODULE_ID_DF2:
            min =(float64_t)(0x2u * lsb);
            max =(float64_t)(0xFFFFFFFF * lsb);
         break;
         default:
            break;
         }
         if (time > max || time < min)
            naiif_printf(" Entry out of range.  Range %7.3f to %7.3f ms\r\n", min, max);
         else
         {
            check_status(naibrd_DIF_SetPatternGenPeriod(cardIndex, module, 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_DIF_PatternGen_Burstcount(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;
   bool_t bQuit = NAI_FALSE;
   uint32_t burstcount;
   uint32_t ModuleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   naiif_printf("\r\nEnter the desired burst count: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         check_status(naibrd_GetModuleName(cardIndex, module, &ModuleID));
         burstcount = atoi((const char *)inputBuffer);
         switch (ModuleID)
         {
         case NAIBRD_MODULE_ID_DF2:
            if (burstcount < 1)
            {
               burstcount = 1; /*minimum count is one*/
               naiif_printf("Setting burstcount to minimum of 1.\r\n");
            }
            check_status(naibrd_DIF_SetPatternGen_BurstNum(cardIndex, module, burstcount));
            break;
         default:
            naiif_printf("Unsupported function for this module.\r\n");
            break;
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_PatternGen_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_DIF_PatternGen_Mode(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;
   bool_t bQuit = NAI_FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   naiif_printf("\r\n == Pattern Gen Mode Selection == \r\n C  Continuous Pattern Gen mode \r\n Burst  Burst Pattern Gen mode  \r\n\r\n Type DIF 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_DIF_SetIOFormat(cardIndex, module, chan, NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));
            naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, NAIBRD_DIF_ENHANCE_OP_DISABLE);

        }
         else if ((toupper(inputBuffer[0]) == 'B'))
         {
            check_status(naibrd_DIF_SetIOFormat(cardIndex, module, chan, NAIBRD_DIF_GEN5_IOFORMAT_OUTPUT));
           naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_BURST, NAIBRD_DIF_ENHANCE_OP_ENABLE);
         }

      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Load_DIF_PatternGenArray loads the pattern from a file and illustrate the methods to call in the naibrd library to
set the pattern data. Channel independent, array covers all channels
</summary>
*/
/**************************************************************************************************************/
nai_status_t Load_DIF_PatternGenArray(int32_t paramCount, int32_t* p_params)
{
#if !defined (NAIBSP_CONFIG_SOFTWARE_OS_DEOS)
   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;
   bool_t patternLoaded = NAI_FALSE;
   uint32_t dataPattern[MAX_DIF_PATTERN_GENERATOR_ENTRIES];
   int32_t i, j, len;
   int32_t entryCnt = 0;
   FILE* patternfile = NULL;
   int8_t* filename = (int8_t*)"TestRAMPattern.txt";
   int8_t buffer[256];
   int8_t data[256];
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   for (i = 0; i < MAX_DIF_PATTERN_GENERATOR_ENTRIES; i++)
      dataPattern[i] = 0;

   patternfile = naiif_fopen((const char *)filename,"r");
   if (patternfile != NULL)
   {
      while (fgets((char*)buffer,sizeof(buffer),patternfile))
      {
         if (entryCnt > MAX_DIF_PATTERN_GENERATOR_ENTRIES)
            break;
         else
         {
            /* Entries in the RAMPattern.txt are expected to be data only in hex format, each data value is on a new line */
            len = (int32_t)strlen((const char*)buffer);
            i = 0;
            j = 0;
            /* read the addr entry */
            while ((buffer[i] != '\r') && (buffer[i] != '\n') && (i < len))
            {
              if (isdigit(buffer[i]) || isalpha(buffer[i]))
                  data[j++] = buffer[i];
               i++;
            }
            data[j] = '\0';

            if (strlen((const char*)data) > 0)
            {
               dataPattern[entryCnt] = naiapp_utils_HexStrToDecUInt32(data);
               entryCnt++;
            }
         }
      }
      if (entryCnt > 0)
      {
         /* Load the pattern into memory */
         check_status(naibrd_DIF_SetPatternGenBuf(cardIndex, module, entryCnt, &dataPattern[0]));
         patternLoaded = NAI_TRUE;
      }
      else
      {
         naiif_printf("ERROR: No pattern data has been loaded from Pattern file: %s\r\n", filename);
      }
      naiif_fclose(patternfile);
   }
   else
      naiif_printf("ERROR: Unable to open Pattern file: %s\r\n", filename);

   return (patternLoaded) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
#else
   naiif_printf("Command not supported.\r\n");
   return NAI_ERROR_NOT_SUPPORTED;
#endif
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_ControlEnable handles the user request to change the switch state for the selected
channel and calls the method in the naibrd library to set the state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_ControlEnable(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;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   naibrd_dif_state_t enState = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the switch state (open or closed).
   */
   naiif_printf("\r\n Type the desired Enable Bit Value, Enable or Disable \r\n ");
   naiif_printf(" Enter Enable or Disable: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'E':
            enState = NAIBRD_DIF_ENHANCE_OP_ENABLE;
            bUpdateOutput = NAI_TRUE;
            break;
         case 'D':
            enState=  NAIBRD_DIF_ENHANCE_OP_DISABLE;
            bUpdateOutput = NAI_TRUE;
            break;
         default:
            naiif_printf("ERROR: Invalid switch state selection\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
       check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_ENABLE, enState));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DIF_ControlPause handles the user request to change the switch state for the selected
channel and calls the method in the naibrd library to set the state.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DIF_ControlPause(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;
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   naibrd_dif_state_t enState = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   /* Set the switch state (open or closed).
   */
   naiif_printf("\r\n Type PAUSE or RESUME to Control Pattern Generator Output\r\n ");
   naiif_printf(" Enter PAUSE or RESUME: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         switch (toupper(inputBuffer[0]))
         {
         case 'P':
            enState = NAIBRD_DIF_ENHANCE_OP_ENABLE;
            bUpdateOutput = NAI_TRUE;
            break;
         case 'R':
            enState=  NAIBRD_DIF_ENHANCE_OP_DISABLE;
            bUpdateOutput = NAI_TRUE;
            break;
         default:
            naiif_printf("ERROR: Invalid switch state selection\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
       check_status(naibrd_DIF_SetPatternGenCtrl(cardIndex,module, NAIBRD_DIF_PATTERN_RAM_CONTROL_PAUSE, enState));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Display_DIF_PatternGen_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DIF_PatternGen_Configuration(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;
   float64_t period;
   uint32_t burstnumber;
   uint32_t startaddr;
   uint32_t endaddr;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   naiif_printf("\r\n");
   naiif_printf("  ----------PatternGen Configuration Settings-------------\r\n");
   naiif_printf("  Period (ms)      Burst Cnt      StartAddr     EndAddr  \r\n");
   naiif_printf("  -------------   -----------    -----------   ----------\r\n");

   check_status(naibrd_DIF_GetPatternGenPeriod(cardIndex, module, &period));
   naiif_printf(" %10.6f   ", period);

   check_status(naibrd_DIF_GetPatternGen_BurstNum(cardIndex, module, &burstnumber));
   naiif_printf("    0x%08X   ", burstnumber);

   check_status(naibrd_DIF_GetPatternGenStartAddr(cardIndex, module, &startaddr));
   naiif_printf("  0x%08X   ", startaddr);

   check_status(naibrd_DIF_GetPatternGenEndAddr(cardIndex, module, &endaddr));
   naiif_printf("  0x%08X   ", endaddr);

   naiif_printf("\r\n\r\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_DIF_Status(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;
   nai_status_bit_t status;
#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif

   /* Available status:
         NAIBRD_DIF_STATUS_BIT_LATCHED,
         NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED,
         NAIBRD_DIF_STATUS_LO_HI_TRANS_LATCHED,
         NAIBRD_DIF_STATUS_HI_LO_TRANS_LATCHED,
   */
   naiif_printf("\r\n");
   naiif_printf("  ----------- Status -----------\r\n");
   naiif_printf("   BIT      OC    Lo-Hi   Hi-Lo  \r\n");
   naiif_printf(" ------- -------- ------ ------- \r\n");

   check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_BIT_LATCHED, &status));
   naiif_printf("  %3i   ", status);

   check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_OVERCURRENT_LATCHED, &status));
   naiif_printf("  %3i   ", status);

   check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_LO_HI_TRANS_LATCHED, &status));
   naiif_printf("  %3i   ", status);

   check_status(naibrd_DIF_GetChanMappedStatus(cardIndex, module, chan, NAIBRD_DIF_STATUS_HI_LO_TRANS_LATCHED, &status));
   naiif_printf("  %3i   ", status);

   naiif_printf("\r\n\r\n");

   return NAI_ERROR_UNKNOWN;
}

Help Bot

X