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

DT Pattern Gen

DT Pattern Gen Sample Application (SSK 2.x)

Overview

The DT Pattern Gen sample application demonstrates how to configure and output user-defined bit patterns on DT (Discrete) 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 on DT modules works by stepping the FPGA 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, enabling complex, repeatable digital waveforms without real-time host intervention.

Supported modules: DT4, and combination modules CM1, CM2, CM8.

For detailed register-level information, consult the DT1 Manual.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a supported DT module installed (DT4, CM1, CM2, or CM8).

  • 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) accessible to the application.

  • Appropriate output connections on the DT channel(s) under test.

How to Run

Launch the dt_pattern_gen executable from your build output directory. On startup the application looks for a configuration file (default_DT_PatternGenerator.txt). On the first run, this file will not exist — the application will present an interactive board menu. Once connected, select a channel, and the application presents a pattern generator operations menu.

Board Connection and Module Selection

Note

This startup sequence is common to all NAI sample applications. 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. The application explicitly checks for module IDs NAIBRD_MODULE_ID_DT4, NAIBRD_MODULE_ID_CM1, NAIBRD_MODULE_ID_CM2, or NAIBRD_MODULE_ID_CM8 before allowing pattern generation operations:

#ifdef NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS
int32_t DT_PatternGenerator(void)
#else
int32_t main(void)
#endif
{
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   bool_t stop = NAI_FALSE;
   uint32_t moduleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(),
            DEF_DT_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
            stop = naiapp_query_ModuleNumber(moduleCnt,
               DEF_DT_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module,
                  &moduleID));
               if ((moduleID != 0))
               {
                  if (moduleID == NAIBRD_MODULE_ID_DT4
                     || moduleID == NAIBRD_MODULE_ID_CM1
                     || moduleID == NAIBRD_MODULE_ID_CM2
                     || moduleID == NAIBRD_MODULE_ID_CM8)
                     Run_DT_PatternGenerator(cardIndex, module, moduleID);
                  else
                     naiif_printf("\r\nModule does have DT enhanced "
                        "functionality\r\n");
               }
            }
         }
      }
   }

   naiapp_access_CloseAllOpenCards();
   return 0;
}
Important

Common connection errors:

  • Module does not have DT enhanced functionality — only DT4, CM1, CM2, and CM8 support pattern generation.

  • Module not recognized as DT — naibrd_DT_GetChannelCount() returned zero.

Program Structure

Entry Point

On standard platforms the entry point is main(). On VxWorks the entry point is DT_PatternGenerator().

Command Loop

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

Pattern Generator Mode Selection

The sample supports two modes: continuous and burst.

Continuous Mode

check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan,
   NAIBRD_DT_MODE_OUTPUT_PATTERN_RAM));
check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DT_CTRL_PATTERN_BURST, NAIBRD_DT_DISABLE));

Burst Mode

check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan,
   NAIBRD_DT_MODE_OUTPUT_PATTERN_RAM));
check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DT_CTRL_PATTERN_BURST, NAIBRD_DT_ENABLE));

Address and Period Configuration

Start and End Address

check_status(naibrd_DT_SetPatternGenStartAddr(cardIndex, module,
   startAddr));
check_status(naibrd_DT_SetPatternGenEndAddr(cardIndex, module,
   endAddr));

Period

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

Burst Count

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

Loading Pattern Data

The Load_DT_PatternGenArray() function reads pattern data from TestRAMPattern.txt and writes it to the module’s pattern RAM:

check_status(naibrd_DT_SetPatternGenBuf(cardIndex, module,
   entryCnt, &dataPattern[0]));

The maximum number of pattern entries is 4092.

Controlling Pattern Output

Enable and Disable

/* Enable */
check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DT_CTRL_PATTERN_ENABLE, NAIBRD_DT_ENABLE));

/* Disable */
check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DT_CTRL_PATTERN_ENABLE, NAIBRD_DT_DISABLE));

Pause and Resume

/* Pause */
check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DT_CTRL_PATTERN_PAUSE, NAIBRD_DT_ENABLE));

/* Resume */
check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module,
   NAIBRD_DT_CTRL_PATTERN_PAUSE, NAIBRD_DT_DISABLE));

Displaying Configuration

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

check_status(naibrd_DT_GetPatternGenPeriod(cardIndex, module, &period));
check_status(naibrd_DT_GetPatternGen_BurstNum(cardIndex, module,
   &burstnumber));
check_status(naibrd_DT_GetPatternGenStartAddr(cardIndex, module,
   &startaddr));
check_status(naibrd_DT_GetPatternGenEndAddr(cardIndex, module,
   &endaddr));

Troubleshooting Reference

Symptom Possible Cause and Resolution

No output observed

Pattern generator is not enabled. Call naibrd_DT_SetPatternGenCtrl() with NAIBRD_DT_CTRL_PATTERN_ENABLE.

Pattern file not found

Ensure the pattern file is accessible from the application’s working directory.

Module not supported

Only DT4, CM1, CM2, and CM8 support pattern generation.

Output is static

Period may be invalid. Verify with naibrd_DT_GetPatternGenPeriod().

Burst mode runs forever

Burst control bit is not enabled. Set NAIBRD_DT_CTRL_PATTERN_BURST to NAIBRD_DT_ENABLE.

Pattern output paused

The pause bit may be set. Disable NAIBRD_DT_CTRL_PATTERN_PAUSE to resume.

Full Source

Full Source — dt_pattern_gen.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_dt.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 *DEF_CONFIG_FILE = (const int8_t *)"default_DT_PatternGenerator.txt";
#define MAX_DT_PATTERN_GENERATOR_ENTRIES    4092

#if defined (NAIBSP_CONFIG_SOFTWARE_OS_LINUX)
static const int8_t *PATTERN_GEN_FILENAME = (const int8_t *)"../../../../../../../../base/nai_sample_apps/naiapp_src/board_modules/dt/dt_pattern_gen/src/TestRAMPattern.txt";
#else
static const int8_t *PATTERN_GEN_FILENAME = (const int8_t *)"../../../../../../base/nai_sample_apps/naiapp_src/board_modules/dt/dt_pattern_gen/src/TestRAMPattern.txt";
#endif

/* Function prototypes */
static int32_t Run_DT_PatternGenerator(int32_t cardIndex, int32_t module, uint32_t modid);
static void Cfg_DT_PatternGen_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
static void Display_DT_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan);
static void Verify_DT_ParamCnt(int32_t paramCnt);
static nai_status_t Configure_DT_PatternGen_StartAddr(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PatternGen_EndAddr(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PatternGen_Period(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PatternGen_Burstcount(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_PatternGen_Mode(int32_t paramCnt, int32_t* p_params);
static nai_status_t Load_DT_PatternGenArray(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_ControlEnable(int32_t paramCnt, int32_t* p_params);
static nai_status_t Configure_DT_ControlPause(int32_t paramCnt, int32_t* p_params);
static nai_status_t Display_DT_PatternGen_Configuration(int32_t paramCnt, int32_t* p_params);

static const int32_t DEF_DT_CARD_INDEX = 0;
static const int32_t DEF_DT_MODULE = 1;
static const int32_t DEF_DT_CHANNEL = 1;
static const int32_t DEF_DT_KA_CHANNEL = 13;

#define MAX_DT_PATTERN_GENERATOR_ENTRIES    4092

/****** Command Table ******/
enum dt_patterngen_commands
{
   DT_PATTERNGEN_CMD_MODE,
   DT_PATTERNGEN_CMD_STARTADDR,
   DT_PATTERNGEN_CMD_ENDADDR,
   DT_PATTERNGEN_CMD_PERIOD,
   DT_PATTERNGEN_CMD_BURSTCOUNT,
   DT_PATTERNGEN_CMD_LOAD_DATA,
   DT_PATTERNGEN_CMD_ENABLE,
   DT_PATTERNGEN_CMD_PAUSE_DATA,
   DT_PATTERNGEN_CMD_RESETMODE,
   DT_PATTERNGEN_CMD_RESETALL,
   DT_PATTERNGEN_CMD_SETALL,
   DT_PATTERNGEN_CMD_DISP,
   DT_PATTERNGEN_CMD_COUNT
};

/****** Command Tables ******/
static naiapp_cmdtbl_params_t DT_PatternGen_MenuCmds[] = {

   {"Mode",            "DT Select Mode",                                DT_PATTERNGEN_CMD_MODE,              Configure_DT_PatternGen_Mode},
   {"StartAddr",     "DT Set Start Address",                          DT_PATTERNGEN_CMD_STARTADDR,         Configure_DT_PatternGen_StartAddr},
   {"EndAddr",       "DT Set End Address",                            DT_PATTERNGEN_CMD_ENDADDR,           Configure_DT_PatternGen_EndAddr},
   {"Period",        "DT Pattern Generator Period",                   DT_PATTERNGEN_CMD_PERIOD,            Configure_DT_PatternGen_Period},
   {"Count",         "DT Pattern Generator Burst count",              DT_PATTERNGEN_CMD_BURSTCOUNT,        Configure_DT_PatternGen_Burstcount},
   {"Load",          "DT Load Pattern Generator Data",                DT_PATTERNGEN_CMD_LOAD_DATA,         Load_DT_PatternGenArray},
   {"CONtrol",       "DT Enable or Disable Pattern Generator Output", DT_PATTERNGEN_CMD_ENABLE,            Configure_DT_ControlEnable},
   {"Pause/Play",    "DT Pause or Resume Pattern Gen Output",         DT_PATTERNGEN_CMD_PAUSE_DATA,        Configure_DT_ControlPause},
   {"Reset",         "DT Reset Chan Mode, Input",                     DT_PATTERNGEN_CMD_RESETMODE,         NULL},
   {"RAll",          "DT Reset All Channels, Input",                  DT_PATTERNGEN_CMD_RESETALL,          NULL},
   {"SEtall",        "DT Set All Channels to Pattern Gen",            DT_PATTERNGEN_CMD_SETALL,            NULL},
   {"Display",       "DT Display channel Pattern Generator Info",     DT_PATTERNGEN_CMD_DISP,              Display_DT_PatternGen_Configuration},
};
/**************************************************************************************************************/
/**
<summary>
The purpose of the DT_PatternGen is to illustrate the methods to call in the naibrd library to perform configuration
 setup for output in PWM operation mode.  Pulse period, pulse width, pulse polarity settings are configurable.

The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd DT routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#ifdef NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS
int32_t DT_PatternGenerator(void)
#else
int32_t main(void)
#endif
{
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   bool_t stop = NAI_FALSE;
   uint32_t moduleID;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
   {
      while (stop != NAI_TRUE)
      {
         /* Select Card Index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), DEF_DT_CARD_INDEX, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Select Module */
            stop = naiapp_query_ModuleNumber(moduleCnt, DEF_DT_MODULE, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  if (moduleID == NAIBRD_MODULE_ID_DT4 || moduleID == NAIBRD_MODULE_ID_CM1 || moduleID == NAIBRD_MODULE_ID_CM2 || moduleID == NAIBRD_MODULE_ID_CM8)
                     Run_DT_PatternGenerator(cardIndex, module, moduleID);
                  else naiif_printf("\r\nModule does have DT enhanced functionality\r\n");
                  naiif_printf("\r\nType Q to quit or Enter to continue:\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>
 * Verify_DT_ParamCnt verifies parameter count and displays error message if invalid.
 * </summary>
 */
 /**************************************************************************************************************/
static void Verify_DT_ParamCnt(int32_t paramCnt)
{
   if (paramCnt != APP_PARAM_COUNT)
   {
      naiif_printf(" *** Parameter count specified is incorrect!!! ***\r\n");
   }
}
/**************************************************************************************************************/
/**
<summary>
Run_DT_PatternGen prompts the user for the card, module and channel to use for the application and calls
Cfg_DT_PatternGen_Channel if the card, module, channel is valid for as a discrete module.
</summary>
*/
/**************************************************************************************************************/
static int32_t Run_DT_PatternGenerator(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = NAI_FALSE;
   int32_t maxchannel;

   if (!bQuit)
   {
      maxchannel = naibrd_DT_GetChannelCount(modid);
      if (maxchannel == 0)
      {
         naiif_printf(" *** Module selection not recognized as DT module. ***\r\n\r\n");
      }
      else
      {
         Cfg_DT_PatternGen_Channel(cardIndex, module, modid, maxchannel);
      }
   }
   return cardIndex;
}

/**************************************************************************************************************/
/**
<summary>
Cfg_DT_PatternGen_Channel handles calling the Display_DT_PWM_ChannelCfg routine to display the discrete channel configuration
and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
static void Cfg_DT_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 ch_loop;
   int32_t cmd;
   nai_status_t status = NAI_SUCCESS;
   naiapp_AppParameters_t  dtparams;
   p_naiapp_AppParameters_t dtParams = &dtparams;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      naiif_printf("\r\n\r\n");
      naiif_printf("Channel selection\r\n");
      naiif_printf("=================\r\n");
      if (ModuleID == NAIBRD_MODULE_ID_KA)
      {
         naiif_printf("\r\n For KA modules, only Channels 13-16 are configurable.");
         naiif_printf("\r\n Ch.01-12 are output only, Ch.17-28 are input only.\r\n");
         defaultchan = DEF_DT_KA_CHANNEL;
      }
      else
      {
         defaultchan = DEF_DT_CHANNEL;
      }
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &chan);
      dtParams->cardIndex = cardIndex;
      dtParams->module = module;
      dtParams->channel = chan;

      naiapp_utils_LoadParamMenuCommands(DT_PATTERNGEN_CMD_COUNT, DT_PatternGen_MenuCmds);
      while (bContinue)
      {
         Display_DT_PatternGen_ChannelCfg(cardIndex, module, chan);
         naiapp_display_ParamMenuCommands((int8_t *)"DT PatternGen Operation Menu");
         naiif_printf("\r\nType DT 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 DT_PATTERNGEN_CMD_MODE:
                     case DT_PATTERNGEN_CMD_STARTADDR:
                     case DT_PATTERNGEN_CMD_ENDADDR:
                     case DT_PATTERNGEN_CMD_PERIOD:
                     case DT_PATTERNGEN_CMD_BURSTCOUNT:
                     case DT_PATTERNGEN_CMD_LOAD_DATA:
                     case DT_PATTERNGEN_CMD_ENABLE:
                     case DT_PATTERNGEN_CMD_PAUSE_DATA:
                     case DT_PATTERNGEN_CMD_DISP:
                        DT_PatternGen_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dtParams);
                        break;
                     case DT_PATTERNGEN_CMD_RESETMODE:
                     {
                        status |= check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan, NAIBRD_DT_MODE_STD_INPUT_OUTPUT));
                        status |= check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_ENABLE, NAIBRD_DT_DISABLE));
                        status |= check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_BURST, NAIBRD_DT_DISABLE));
                        status |= check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_PAUSE, NAIBRD_DT_DISABLE));
                        if (status == NAI_SUCCESS)
                           naiif_printf("Reset completed \r\n");
                        else
                           naiif_printf("Error %2X on set \r\n", status);
                     }
                        break;
                     case DT_PATTERNGEN_CMD_RESETALL:
                     {
                        for (ch_loop = 1; ch_loop <= naibrd_DT_GetChannelCount(ModuleID); ch_loop++)
                        {
                           status |= check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan, NAIBRD_DT_MODE_STD_INPUT_OUTPUT));
                           status |= check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_ENABLE, NAIBRD_DT_DISABLE));
                           status |= check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_BURST, NAIBRD_DT_DISABLE));
                           status |= check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_PAUSE, NAIBRD_DT_DISABLE));
                           status |= check_status(naibrd_DT_Reset(cardIndex, module, ch_loop, NAIBRD_DT_RESET_TIMER));
                        }
                        if (status == NAI_SUCCESS)
                           naiif_printf("Reset All completed \r\n");
                        else
                           naiif_printf("Error %2X on set \r\n", status);
                     }
                     break;
                     case DT_PATTERNGEN_CMD_SETALL:
                     {
                        for (ch_loop = 1; ch_loop <= naibrd_DT_GetChannelCount(ModuleID); ch_loop++)
                        {
                           status |= check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, ch_loop, NAIBRD_DT_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_DT_PWM_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for PWM operation.
</summary>
*/
/**************************************************************************************************************/
static void Display_DT_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan)
{
   naibrd_dt_ioformat_t ioformat = 0;
   naibrd_dt_state_t outputstate = 0;
   naibrd_dt_state_t inputstate = 0;
   naibrd_dt_enhanced_mode_t opmode = 0;
   naibrd_dt_enable_type_t enablebit = 0;
   naibrd_dt_enable_type_t burstbit = 0;
   naibrd_dt_enable_type_t pausebit = 0;
   check_status(naibrd_DT_GetIOFormat(cardIndex, module, chan, &ioformat));
   check_status(naibrd_DT_GetOutputState(cardIndex, module, chan, &outputstate));
   check_status(naibrd_DT_GetInputState(cardIndex, module, chan, &inputstate));
   check_status(naibrd_DT_GetEnhancedMode(cardIndex, module, chan, &opmode));
   check_status(naibrd_DT_GetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_ENABLE, &enablebit));
   check_status(naibrd_DT_GetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_BURST, &burstbit));
   check_status(naibrd_DT_GetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_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            Pattern Gen Mode      \r\n");
      naiif_printf("---------  ------   ----------- -----------------------------    ---------------------------\r\n");
   }

   /*display configuration settings here- */
   switch (ioformat)
   {
      case NAIBRD_DT_IOFORMAT_INPUT:
         naiif_printf("  Input   ");
         break;
      case NAIBRD_DT_IOFORMAT_OUTPUT_LOW:
         naiif_printf(" Low Side "); /*may want add check for proper value depending on whether gen3 or gen5; for now, assume it correctly matches module*/
         break;
      case NAIBRD_DT_IOFORMAT_OUTPUT_HIGH:
         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;
      case NAIBRD_DT_IOFORMAT_OUTPUT_PUSHPULL:
         naiif_printf(" Push/Pull"); /*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_DT_STATE_LO:
      naiif_printf("  LOW Set ");
      break;
   case NAIBRD_DT_STATE_HI:
      naiif_printf(" HIGH Set ");
      break;
   default:
      naiif_printf(" Unknown  ");
      break;
   }

   switch (inputstate)
   {
   case NAIBRD_DT_STATE_LO:
      naiif_printf(" LOW Input  ");
      break;
   case NAIBRD_DT_STATE_HI:
      naiif_printf("HIGH Input  ");
      break;
   default:
      naiif_printf("Unknown     ");
      break;
   }

   switch (opmode)
   {
   case NAIBRD_DT_MODE_STD_INPUT_OUTPUT:
      naiif_printf("DT_MODE_ENHANCED_INPUT   ");
      break;
   case NAIBRD_DT_MODE_MEASURE_HIGH_TIME:
      naiif_printf("DT_MODE_MEASURE_HIGH_TIME   ");
      break;
   case NAIBRD_DT_MODE_MEASURE_LOW_TIME:
      naiif_printf("DT_MODE_MEASURE_LOW_TIME   ");
      break;
   case NAIBRD_DT_MODE_TIMESTAMP_RISING_EDGES:
      naiif_printf("DT_MODE_TIMESTAMP_RISING_EDGES   ");
      break;
   case NAIBRD_DT_MODE_TIMESTAMP_FALLING_EDGES:
      naiif_printf("DT_MODE_TIMESTAMP_FALLING_EDGES   ");
      break;
   case NAIBRD_DT_MODE_TIMESTAMP_ALL_EDGES:
      naiif_printf("DT_MODE_TIMESTAMP_ALL_EDGES   ");
      break;
   case NAIBRD_DT_MODE_COUNT_RISING_EDGES:
      naiif_printf("DT_MODE_COUNT_RISING_EDGES   ");
      break;
   case NAIBRD_DT_MODE_COUNT_FALLING_EDGES:
      naiif_printf("DT_MODE_COUNT_FALLING_EDGES   ");
      break;
   case NAIBRD_DT_MODE_COUNT_ALL_EDGES:
      naiif_printf("DT_MODE_COUNT_ALL_EDGES   ");
      break;
   case NAIBRD_DT_MODE_MEASURE_PERIOD_RISING_EDGE:
      naiif_printf("DT_MODE_MEASURE_PERIOD_FROM_RISING_EDGE   ");
      break;
   case NAIBRD_DT_MODE_MEASURE_FREQUENCY:
      naiif_printf("DT MODE Interval Counter   ");
      break;
   case NAIBRD_DT_MODE_OUTPUT_PWM_FOREVER:
      naiif_printf("DT MODE PWM Continuous  ");
      break;
   case NAIBRD_DT_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES:
      naiif_printf("DT MODE PWM Burst   ");
      break;
   case NAIBRD_DT_MODE_OUTPUT_PATTERN_RAM:
      naiif_printf("DT MODE PATTERN_RAM   ");
      break;
   default:
      naiif_printf("Unknown    ");
      break;
   }


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

/**************************************************************************************************************/
/**
<summary>
Configure_DT_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_DT_PatternGen_StartAddr(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   uint32_t startAddr = 0;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   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)
      {
         startAddr = strtol(((const char *)inputBuffer), NULL, 16);
         status = check_status(naibrd_DT_SetPatternGenStartAddr(cardIndex, module, startAddr));
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_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_DT_PatternGen_EndAddr(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   uint32_t endAddr = 0;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   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)
      {
         endAddr = strtol(((const char *)inputBuffer), NULL, 16);;
         status = check_status(naibrd_DT_SetPatternGenEndAddr(cardIndex, module, endAddr));
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_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>
*/
/**************************************************************************************************************/
static nai_status_t Configure_DT_PatternGen_Period(int32_t paramCnt, int32_t* p_params)
{
   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;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   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)
      {
         naibrd_GetModuleName(cardIndex, module, &ModuleID);

         time = atof((const char *)inputBuffer); /*entry in milliseconds*/
         lsb = naibrd_DT_GetTimebaseLSB(ModuleID);
         min = (float64_t)(0x2u * lsb);
         max = (float64_t)(0xFFFFFFFF * lsb);

         if (time > max || time < min)
            naiif_printf(" Entry out of range.  Range %7.3f to %7.3f ms\r\n", min, max);
         else
         {
            status = check_status(naibrd_DT_SetPatternGenPeriod(cardIndex, module, time));
         }
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<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_DT_PatternGen_Burstcount(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   uint32_t burstcount;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   naiif_printf("\r\nEnter the desired burst count: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         burstcount = atoi((const char *)inputBuffer);
         if (burstcount < 1)
         {
            burstcount = 1; /*minimum count is one*/
            naiif_printf("Setting burstcount to minimum of 1.\r\n");
         }
         status = check_status(naibrd_DT_SetPatternGen_BurstNum(cardIndex, module, burstcount));
      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_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_DT_PatternGen_Mode(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int32_t chan = dtParams->channel;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   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 DT 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_DT_SetEnhancedMode(cardIndex, module, chan , NAIBRD_DT_MODE_OUTPUT_PATTERN_RAM));
            status = check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_BURST, NAIBRD_DT_DISABLE));
         }
         else if ((toupper(inputBuffer[0]) == 'B'))
         {
            check_status(naibrd_DT_SetEnhancedMode(cardIndex, module, chan, NAIBRD_DT_MODE_OUTPUT_PATTERN_RAM));
           status = check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_BURST, NAIBRD_DT_ENABLE));
         }

      }
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Load_DT_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>
*/
/**************************************************************************************************************/
static nai_status_t Load_DT_PatternGenArray(int32_t paramCnt, int32_t* p_params)
{
   uint32_t dataPattern[MAX_DT_PATTERN_GENERATOR_ENTRIES];
   int32_t i, j, len;
   int32_t entryCnt = 0;
   FILE* patternfile = NULL;
   const int8_t* filename = PATTERN_GEN_FILENAME;
   int8_t data[256];
   int8_t buffer[256];
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   Verify_DT_ParamCnt(paramCnt);
   for (i = 0; i < MAX_DT_PATTERN_GENERATOR_ENTRIES; i++)
      dataPattern[i] = 0;

   patternfile = naiif_fopen((const char *)filename, "r");
   if (patternfile != NULL)
   {
      while (naiif_fgets_file((char*)buffer, sizeof(buffer), patternfile))
      {
         if (entryCnt > MAX_DT_PATTERN_GENERATOR_ENTRIES)
            break;
         else
         {
            /* Entries in the RAMPattern.txt are expected to be addr,data */
            len = (int32_t)strlen((const char*)buffer);
            i = 0;
            j = 0;
            /* read the data entry */
            while (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 */
         status = check_status(naibrd_DT_SetPatternGenBuf(cardIndex, module, entryCnt, &dataPattern[0]));
      }
      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 status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_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_DT_ControlEnable(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   naibrd_dt_enable_type_t enState = 0;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   /* 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_DT_ENABLE;
            bUpdateOutput = NAI_TRUE;
            break;
         case 'D':
            enState = NAIBRD_DT_DISABLE;
            bUpdateOutput = NAI_TRUE;
            break;
         default:
            naiif_printf("ERROR: Invalid switch state selection\r\n");
            break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         status = check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_ENABLE, enState));
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DT_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_DT_ControlPause(int32_t paramCnt, int32_t* p_params)
{
   bool_t bQuit = NAI_FALSE;
   bool_t bUpdateOutput = NAI_FALSE;
   naibrd_dt_enable_type_t enState = 0;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   Verify_DT_ParamCnt(paramCnt);

   /* 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_DT_ENABLE;
               bUpdateOutput = NAI_TRUE;
               break;
            case 'R':
               enState = NAIBRD_DT_DISABLE;
               bUpdateOutput = NAI_TRUE;
               break;
            default:
               naiif_printf("ERROR: Invalid switch state selection\r\n");
               break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         status = check_status(naibrd_DT_SetPatternGenCtrl(cardIndex, module, NAIBRD_DT_CTRL_PATTERN_PAUSE, enState));
   }
   return status;
}
/**************************************************************************************************************/
/**
<summary>
Display_DT_PatternGen_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DT_PatternGen_Configuration(int32_t paramCnt, int32_t* p_params)
{
   float64_t period;
   int32_t burstnumber;
   uint32_t startaddr;
   uint32_t endaddr;
   nai_status_t status = NAI_ERROR_NOT_SUPPORTED;
   p_naiapp_AppParameters_t dtParams = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dtParams->cardIndex;
   int32_t module = dtParams->module;
   Verify_DT_ParamCnt(paramCnt);

   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_DT_GetPatternGenPeriod(cardIndex, module, &period));
   naiif_printf(" %10.6f   ", period);

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

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

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

   naiif_printf("\r\n\r\n");
   return status;
}

Help Bot

X