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

DSW PatternGenerator

DSW PatternGenerator

Explanation

About the Sample Application Code

This sample application code is designed to interface with embedded function modules from North Atlantic Industries (NAI) using their Software Support Kit (SSK). Specifically, it demonstrates configuring and using a Pattern Generator mode on a Digital Switch (DSW) function module. The code is structured to guide users through interactions such as selecting cards and modules, configuring various parameters, and displaying current configurations.

Key Components

Header Files

  1. Standard C Libraries:

    • stdio.h, stdlib.h, string.h, time.h, ctype.h: Standard C libraries for input/output operations, memory management, string manipulation, time functions, and character utilities.

  2. NAI Specific Libraries:

    • naiapp_boardaccess_menu.h

    • naiapp_boardaccess_query.h

    • naiapp_boardaccess_access.h

    • naiapp_boardaccess_display.h

    • naiapp_boardaccess_utils.h

    • nai.h

    • naibrd.h

    • naibrd_dsw.h

    • nai_ether_adv.h

Constants and Macros

  • CONFIG_FILE: Default configuration file name.

  • DEF_DSW_CHANNEL: Default channel number.

  • MAX_DSW_PATTERN_GENERATOR_ENTRIES: Maximum entries in the pattern generator.

Enumerations

  • enum dsw_patterngen_commands: Lists various commands for configuring the pattern generator such as setting mode, start address, end address, period, burst count, loading data, enabling, pausing, resetting, and displaying information.

Data Structures

  • naiapp_cmdtbl_params_t: Represents the structure for menu commands in the application.

Function Prototypes

The code defines various function prototypes for configuration, loading patterns, and displaying configurations.

Main Function

The main function (int32_t main(void)) orchestrates the entire process. It initializes application menus, queries user input for card and module selection, and runs the DSW pattern generator if the module is valid. It also provides options to quit or restart.

Helper Functions

  1. Run_DSW_PatternGenerator: Handles running the DSW pattern generator by configuring the channel if valid.

  2. Cfg_DSW_PatternGen_Channel: Manages display and configuration commands for the DSW channel.

  3. Display_DSW_PatternGen_ChannelCfg: Displays the current DSW channel configuration.

  4. Configure_DSW_PatternGen_StartAddr: Configures the start address for the pattern generator.

  5. Configure_DSW_PatternGen_EndAddr: Configures the end address for the pattern generator.

  6. Configure_DSW_PatternGen_Period: Sets the period for the pattern generator.

  7. Configure_DSW_PatternGen_Burstcount: Sets the burst count for the pattern generator.

  8. Configure_DSW_PatternGen_Mode: Configures the mode (continuous or burst) for the pattern generator.

  9. Load_DSW_PatternGenArray: Loads the pattern data from a file into the pattern generator.

  10. Configure_DSW_ControlEnable: Enables or disables the pattern generator output.

  11. Configure_DSW_ControlPause: Pauses or resumes the pattern generator output.

  12. Display_DSW_PatternGen_Configuration: Displays the current pattern generator configuration.

Code Flow

  1. Initialization:

    • The program starts by initializing the board menu using naiapp_RunBoardMenu.

  2. User Interaction:

    • It queries the user to select a card and module and validates the module type.

  3. Running Pattern Generator:

    • The Run_DSW_PatternGenerator function configures the DSW channel if valid.

  4. Configuration Menu:

    • The Cfg_DSW_PatternGen_Channel manages a menu-driven interface to configure the DSW settings using commands like setting mode, start/end addresses, period, burst count, loading data, enabling/disabling, pausing/resuming, and resetting configurations.

  5. Display Configurations:

    • The Display_DSW_PatternGen_ChannelCfg and Display_DSW_PatternGen_Configuration functions show the current state and settings of the DSW channel and pattern generator.

  6. Configuration Commands:

    • Functions like Configure_DSW_PatternGen_StartAddr and others handle specific configurations and involve querying user inputs and making appropriate library calls to apply settings.

  7. Closing Application:

    • The program provides an option to quit (using 'Q') or restart and finally closes all open card interfaces before exiting.

This sample application serves as a comprehensive guide for users on configuring the DSW pattern generator using NAI’s SSK, illustrating effective use of API calls and user interactions.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>

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

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_dsw.h"
#include "advanced/nai_ether_adv.h"

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

/* Function prototypes */
void Run_DSW_PatternGenerator(int32_t cardIndex, int32_t module, int32_t ModuleID);
void Cfg_DSW_PatternGen_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel);
void Display_DSW_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID);
static nai_status_t Configure_DSW_PatternGen_StartAddr(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PatternGen_EndAddr(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PatternGen_Period(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PatternGen_Burstcount(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_PatternGen_Mode(int32_t paramCount, int32_t* p_params);
static nai_status_t Load_DSW_PatternGenArray(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_ControlEnable(int32_t paramCount, int32_t* p_params);
static nai_status_t Configure_DSW_ControlPause(int32_t paramCount, int32_t* p_params);
static nai_status_t Display_DSW_PatternGen_Configuration(int32_t paramCount, int32_t* p_params);

static const int32_t DEF_DSW_CHANNEL = 1;

#define MAX_DSW_PATTERN_GENERATOR_ENTRIES    4092

/****** Command Table *******/
enum dsw_patterngen_commands
{
   DSW_PATTERNGEN_CMD_MODE,
   DSW_PATTERNGEN_CMD_STARTADDR,
   DSW_PATTERNGEN_CMD_ENDADDR,
   DSW_PATTERNGEN_CMD_PERIOD,
   DSW_PATTERNGEN_CMD_BURSTCOUNT,
   DSW_PATTERNGEN_CMD_LOAD_DATA,
   DSW_PATTERNGEN_CMD_ENABLE,
   DSW_PATTERNGEN_CMD_PAUSE_DATA,
   DSW_PATTERNGEN_CMD_RESETMODE,
   DSW_PATTERNGEN_CMD_RESETALL,
   DSW_PATTERNGEN_CMD_SETALL,
   DSW_PATTERNGEN_CMD_DISP,
   DSW_PATTERNGEN_CMD_LAST
};

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

   {"Mode",			   "DSW Select Mode",                                DSW_PATTERNGEN_CMD_MODE,              Configure_DSW_PatternGen_Mode},
   {"StartAddr",     "DSW Set Start Address",                          DSW_PATTERNGEN_CMD_STARTADDR,         Configure_DSW_PatternGen_StartAddr},
   {"EndAddr",       "DSW Set End Address",                            DSW_PATTERNGEN_CMD_ENDADDR,           Configure_DSW_PatternGen_EndAddr},
   {"Period",        "DSW Pattern Generator Period",                   DSW_PATTERNGEN_CMD_PERIOD,            Configure_DSW_PatternGen_Period},
   {"Count",         "DSW Pattern Generator Burst count",              DSW_PATTERNGEN_CMD_BURSTCOUNT,        Configure_DSW_PatternGen_Burstcount},
   {"Load",          "DSW Load Pattern Generator Data",                DSW_PATTERNGEN_CMD_LOAD_DATA,         Load_DSW_PatternGenArray},
   {"CONtrol",       "DSW Enable or Disable Pattern Generator Output", DSW_PATTERNGEN_CMD_ENABLE,            Configure_DSW_ControlEnable},
   {"Pause/Play",    "DSW Pause or Resume Pattern Gen Output",         DSW_PATTERNGEN_CMD_PAUSE_DATA,        Configure_DSW_ControlPause},
   {"Reset",         "DSW Reset Chan Mode, Input",                     DSW_PATTERNGEN_CMD_RESETMODE,         NULL},
   {"RAll",          "DSW Reset All Channels, Input",                  DSW_PATTERNGEN_CMD_RESETALL,          NULL},
   {"SEtall",        "DSW Set All Channels to Pattern Gen",            DSW_PATTERNGEN_CMD_SETALL,            NULL},
   {"Display",       "DSW Display channel Pattern Generator Info",     DSW_PATTERNGEN_CMD_DISP,              Display_DSW_PatternGen_Configuration},
};

/**************************************************************************************************************/
/**
<summary>
The purpose of the DSW_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 DSW routines.
 - ClearDeviceCfg
 - QuerySystemCfg
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - SaveDeviceCfg
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t DSW_PatternGenerator(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   uint32_t moduleID = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

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

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != TRUE)
            {
               moduleID = naibrd_GetModuleID(cardIndex, module);
               if ((moduleID != 0))
               {
                  Run_DSW_PatternGenerator(cardIndex, module, moduleID);
               }
            }
         }

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

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

   return 0;
}
/**************************************************************************************************************/
/**
<summary>
Run_DSW_PatternGenerator prompts the user for the card, module and channel to use for the application and calls
Cfg_DSW_PatternGen_Channel if the card, module, channel is valid for as a DSW module.
</summary>
*/
/**************************************************************************************************************/
void Run_DSW_PatternGenerator(int32_t cardIndex, int32_t module, int32_t ModuleID)
{
   int32_t MaxChannel;

   MaxChannel = naibrd_DSW_GetChannelCount(ModuleID);

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

/**************************************************************************************************************/
/**
<summary>
Cfg_DSW_PatternGen_Channel handles calling the Display_DSW_PatternGen_ChannelCfg routine to display the DSW
channel configuration and calling the routines associated with the user's menu commands.
</summary>
*/
/**************************************************************************************************************/
void Cfg_DSW_PatternGen_Channel(int32_t cardIndex, int32_t module, uint32_t ModuleID, int32_t MaxChannel)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   bool_t bCmdFound = FALSE;
   int32_t defaultchan = 1;
   int32_t cmd;
   int32_t ch_loop;
   int32_t status = 0;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   naiapp_AppParameters_t  dsw_params;
   p_naiapp_AppParameters_t dsw_patgen_params = &dsw_params;
   dsw_patgen_params->cardIndex = cardIndex;
   dsw_patgen_params->module = module;
   dsw_patgen_params->modId = ModuleID;
   while (bContinue)
   {
      printf("    \r\n\r\n");
      printf("Channel selection \r\n");
      printf("================= \r\n");
      defaultchan = DEF_DSW_CHANNEL;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defaultchan, &dsw_patgen_params->channel);

      /* Configure the selected channel for Pattern Generator Mode */
      check_status(naibrd_DSW_SetOpMode(cardIndex, module, dsw_patgen_params->channel, NAI_DSW_MODE_OUTPUT_PATTERN_RAM));

      naiapp_utils_LoadParamMenuCommands(DSW_PATTERNGEN_CMD_LAST, DSW_PatternGen_MenuCmds);
      while (bContinue)
      {
         Display_DSW_PatternGen_ChannelCfg(cardIndex, module, dsw_patgen_params->channel, ModuleID);
         naiapp_display_ParamMenuCommands((int8_t *)"DSW Pattern Generator Operation Menu");
         printf("\nType DSW command or %c to quit : ", NAI_QUIT_CHAR);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt > 0)
            {
               bCmdFound = naiapp_utils_GetParamMenuCmdNum(inputResponseCnt, inputBuffer, &cmd);
               if (bCmdFound)
               {
                  switch (cmd)
                  {
                     case DSW_PATTERNGEN_CMD_LOAD_DATA:
                     case DSW_PATTERNGEN_CMD_PERIOD:
                     case DSW_PATTERNGEN_CMD_STARTADDR:
                     case DSW_PATTERNGEN_CMD_ENDADDR:
                     case DSW_PATTERNGEN_CMD_BURSTCOUNT:
                     case DSW_PATTERNGEN_CMD_MODE:
                     case DSW_PATTERNGEN_CMD_ENABLE:
                     case DSW_PATTERNGEN_CMD_PAUSE_DATA:
                     case DSW_PATTERNGEN_CMD_DISP:
                        DSW_PatternGen_MenuCmds[cmd].func(APP_PARAM_COUNT, (int32_t*)dsw_patgen_params);
                        break;
                     case DSW_PATTERNGEN_CMD_RESETMODE:
                     {
                        status |= check_status(naibrd_DSW_SetOpMode(cardIndex, module, dsw_patgen_params->channel, NAI_DSW_MODE_STD_INPUT_OUTPUT));
                        status |= check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_ENABLE, NAI_DSW_ENHANCE_OP_DISABLE));
                        status |= check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_BURST, NAI_DSW_ENHANCE_OP_DISABLE));
                        status |= check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_PAUSE, NAI_DSW_ENHANCE_OP_DISABLE));
                        if (status == NAI_SUCCESS)
                           printf("Reset completed \n");
                        else
                           printf("Error %2X on set \n", status);
                     }
                     break;
                     case DSW_PATTERNGEN_CMD_RESETALL:
                     {
                        for (ch_loop = 1; ch_loop <= 16; ch_loop++)
                        {
                           status |= check_status(naibrd_DSW_SetOpMode(cardIndex, module, dsw_patgen_params->channel, NAI_DSW_MODE_STD_INPUT_OUTPUT));
                           status |= check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_ENABLE, NAI_DSW_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_BURST, NAI_DSW_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_PAUSE, NAI_DSW_ENHANCE_OP_DISABLE));
                           status |= check_status(naibrd_DSW_Reset(cardIndex, module, ch_loop, NAI_DSW_RESET_TIMER_ONLY));
                        }
                        if (status == NAI_SUCCESS)
                           printf("Reset All completed \n");
                        else
                           printf("Error %2X on set \n", status);
                     }
                     break;
                     case DSW_PATTERNGEN_CMD_SETALL:
                     {
                        for (ch_loop = 1; ch_loop <= 16; ch_loop++)
                        {
                           status |= check_status(naibrd_DSW_SetOpMode(cardIndex, module, ch_loop, NAI_DSW_MODE_OUTPUT_PATTERN_RAM));
                        }
                        if (status == NAI_SUCCESS)
                           printf("Set on all channels completed \n");
                        else
                           printf("Error %2X on set \n", status);
                     }
                     break;
                     default:
                        printf("Invalid command entered\n");
                        break;
                  }
               }
               else
                  printf("Invalid command entered\n");
            }
         }
         else
            bContinue = FALSE;
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
Display_DSW_PatternGen_ChannelCfg illustrate the methods to call in the naibrd library to retrieve the configuration states
for basic operation.
</summary>
*/
/**************************************************************************************************************/
void Display_DSW_PatternGen_ChannelCfg(int32_t cardIndex, int32_t module, int32_t chan, uint32_t ModuleID)
{
   nai_dsw_state_t inputstate = 0;
   nai_dsw_state_t switchstate = 0;
   nai_dsw_enhanced_mode_t opmode = 0;
   nai_dsw_enable_t enablebit = 0;
   nai_dsw_enable_t burstbit = 0;
   nai_dsw_enable_t pausebit = 0;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);

   check_status(naibrd_DSW_GetSwitchState(cardIndex, module, chan, &switchstate));
   check_status(naibrd_DSW_GetInputState(cardIndex, module, chan, &inputstate));
   check_status(naibrd_DSW_GetOpMode(cardIndex, module, chan, &opmode));
   check_status(naibrd_DSW_GetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_ENABLE, &enablebit));
   check_status(naibrd_DSW_GetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_BURST, &burstbit));
   check_status(naibrd_DSW_GetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_PAUSE, &pausebit));

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

   /*read PWM configuration values here, Period, Pulsewidth, Continuous/Burst Mode, */
   {
      printf(" Switch    Input                                                              \n");
      printf(" State     State       Enhanced Mode Selection            Pattern Gen Mode      \n");
      printf("--------  -------    ---------------------------- ------------------------------\n");
   }

   switch (switchstate)
   {
      case NAI_DSW_STATE_LO:
         printf(" Open ");
         break;
      case NAI_DSW_STATE_HI:
         printf("Closed");
         break;
         /* undefined value read back */
      default:
         printf(" UNK  ");
         break;
   }
   printf("    %3i       ", inputstate);

   switch (opmode)
   {
      case NAI_DSW_MODE_STD_INPUT_OUTPUT:
         printf("  DSW MODE STD INPUT OUTPUT   ");
         break;
      case NAI_DSW_MODE_MEASURE_HIGH_TIME:
         printf("  DSW MODE MEASURE HIGH TIME   ");
         break;
      case NAI_DSW_MODE_MEASURE_LOW_TIME:
         printf("    DSW MODE MEASURE LOW TIME   ");
         break;
      case NAI_DSW_MODE_TIMESTAMP_RISING_EDGES:
         printf("    DSW MODE TIMESTAMP RISING EDGES   ");
         break;
      case NAI_DSW_MODE_TIMESTAMP_FALLING_EDGES:
         printf("    DSW MODE TIMESTAMP FALLING EDGES   ");
         break;
      case NAI_DSW_MODE_TIMESTAMP_ALL_EDGES:
         printf("    DSW MODE TIMESTAMP ALL EDGES   ");
         break;
      case NAI_DSW_MODE_COUNT_RISING_EDGES:
         printf("    DSW MODE COUNT RISING EDGES   ");
         break;
      case NAI_DSW_MODE_COUNT_FALLING_EDGES:
         printf("    DSW MODE COUNT FALLING EDGES   ");
         break;
      case NAI_DSW_MODE_COUNT_ALL_EDGES:
         printf("    DSW MODE COUNT ALL EDGES   ");
         break;
      case NAI_DSW_MODE_MEASURE_PERIOD_FROM_RISING_EDGE:
         printf("    DSW MODE MEASURE PERIOD FROM RISING EDGE   ");
         break;
      case NAI_DSW_MODE_MEASURE_FREQUENCY:
         printf("    DSW MODE Interval Counter   ");
         break;
      case NAI_DSW_MODE_OUTPUT_PWM_FOREVER:
         printf("    DSW MODE PWM Continuous  ");
         break;
      case NAI_DSW_MODE_OUTPUT_PWM_CYCLE_NUM_TIMES:
         printf("    DSW MODE PWM Burst   ");
         break;
      case NAI_DSW_MODE_OUTPUT_PATTERN_RAM:
         printf("    DSW MODE PATTERN RAM   ");
         break;
      default:
         printf("    Unknown    ");
         break;
   }
   switch (enablebit)
   {
      case NAI_DSW_STATE_LO:
         printf("  Disabled");
         break;
      case NAI_DSW_STATE_HI:
         printf("   Enabled");
         break;
         /* undefined value read back */
      default:
         printf("   UNK  ");
         break;
   }
   switch (burstbit)
   {
      case NAI_DSW_STATE_LO:
         printf(" Continuous Mode");
         break;
      case NAI_DSW_STATE_HI:
         printf(" Burst Mode");
         break;
         /* undefined value read back */
      default:
         printf(" UNK  ");
         break;
   }
   switch (pausebit)
   {
      case NAI_DSW_STATE_LO:
         break;
      case NAI_DSW_STATE_HI:
         printf(" PAUSED");
         break;
         /* undefined value read back */
      default:
         printf(" UNK  ");
         break;
   }
}

/**************************************************************************************************************/
/**
<summary>
Configure_DSW_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_DSW_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 = FALSE;
   uint32_t startAddr = 0;
   uint32_t min = 0;
   uint32_t max = 0;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired Start Address: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         startAddr = strtol(((const char *)inputBuffer), NULL, 16);
         switch (ModuleID)
         {
            case NAI_MODULE_ID_DT5:
               min = naibrd_DSW_GetValidPatternGenStart(ModuleID);
               max = naibrd_DSW_GetValidPatternGenEnd(ModuleID);
            default:
               break;
         }
         if (startAddr > max || startAddr < min)
            printf(" Entry out of range.  Range %08X to %08X \n", min, max);
         else
         {
            check_status(naibrd_DSW_SetPatternGenStartAddr(cardIndex, module, startAddr));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}

/**************************************************************************************************************/
/**
<summary>
Configure_DSW_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_DSW_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 = FALSE;
   uint32_t endAddr = 0;
   uint32_t min = 0;
   uint32_t max = 0;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired End Address: 0x");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         endAddr = strtol(((const char *)inputBuffer), NULL, 16);;
         switch (ModuleID)
         {
            case NAI_MODULE_ID_DT5:
               min = naibrd_DSW_GetValidPatternGenStart(ModuleID);
               max = naibrd_DSW_GetValidPatternGenEnd(ModuleID);
            default:
               break;
         }
         if (endAddr > max || endAddr < min)
            printf(" Entry out of range.  Range 0x%08X to 0x%08X \n", min, max);
         else
         {
            check_status(naibrd_DSW_SetPatternGenEndAddr(cardIndex, module, endAddr));
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_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_DSW_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 = FALSE;
   float64_t time = 0.0;
   float64_t lsb = 0;
   float64_t min = 1;
   float64_t max = -1;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired period in ms: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         time = atof((const char *)inputBuffer); /*entry in milliseconds*/
         lsb = naibrd_DSW_GetTimebaseLSB(ModuleID);
         switch (ModuleID)
         {
            case NAI_MODULE_ID_DT5:
               min = (float64_t)(0x2u * lsb);
               max = (float64_t)(0xFFFFFFFF * lsb);
            default:
               break;
         }
         if (time > max || time < min)
            printf(" Entry out of range.  Range %7.3f to %7.3f ms\n", min, max);
         else
         {
            check_status(naibrd_DSW_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_DSW_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 = FALSE;
   uint32_t burstcount;
   uint32_t ModuleID;
   uint32_t ModuleVer;
   uint32_t ModuleRev;
   uint32_t ModInfo_Special;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\nEnter the desired burst count: ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         naibrd_GetModuleInfo(cardIndex, module, &ModuleID, &ModuleVer, &ModuleRev, &ModInfo_Special);
         burstcount = atoi((const char *)inputBuffer);
         switch (ModuleID)
         {
            case NAI_MODULE_ID_DT5:
               if (burstcount < 1)
               {
                  burstcount = 1; /*minimum count is one*/
                  printf("Setting burstcount to minimum of 1.\n");
               }
               check_status(naibrd_DSW_SetPatternGen_BurstNum(cardIndex, module, burstcount));
               break;
            default:
               printf("Unsupported function for this module.\n");
               break;
         }
      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_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_DSW_PatternGen_Mode(int32_t paramCount, int32_t* p_params)
{
   p_naiapp_AppParameters_t dsw_params = (p_naiapp_AppParameters_t)p_params;
   int32_t cardIndex = dsw_params->cardIndex;
   int32_t module = dsw_params->module;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

#if defined (WIN32)
   UNREFERENCED_PARAMETER(paramCount);
#endif
   printf("\n == Pattern Gen Mode Selection == \n C  Continuous Pattern Gen mode \n Burst  Burst Pattern Gen mode  \n\n Type DSW command : ");
   bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
   if (!bQuit)
   {
      if (inputResponseCnt > 0)
      {
         if ((toupper(inputBuffer[0]) == 'C'))
         {
            naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_BURST, NAI_DSW_ENHANCE_OP_DISABLE);
         }
         else if ((toupper(inputBuffer[0]) == 'B'))
         {
            naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_BURST, NAI_DSW_ENHANCE_OP_ENABLE);
         }

      }
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Load_DSW_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_DSW_PatternGenArray(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 patternLoaded = FALSE;
   uint32_t dataPattern[MAX_DSW_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 addr[256];
   int8_t data[256];

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

   for (i = 0; i < MAX_DSW_PATTERN_GENERATOR_ENTRIES; i++)
      dataPattern[i] = 0;

   patternfile = fopen((const char *)filename, "r");
   if (patternfile != NULL)
   {
      while (fgets((char*)buffer, sizeof(buffer), patternfile))
      {
         if (entryCnt > MAX_DSW_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 addr entry */
            while ((buffer[i] != ',') && (i < len))
            {
               if (isdigit(buffer[i]) || isalpha(buffer[i]))
                  addr[j++] = buffer[i];
               i++;
            }
            addr[i] = '\0';
            /* Increment i to skip the comma */
            i++;
            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*)addr) > 0) && (strlen((const char*)data) > 0))
            {
               dataPattern[entryCnt] = naiapp_utils_HexStrToDecUInt32(data);
               entryCnt++;
            }
         }
      }
      if (entryCnt > 0)
      {
         /* Load the pattern into memory */
         check_status(naibrd_DSW_SetPatternGenBuf(cardIndex, module, entryCnt, &dataPattern[0]));
         patternLoaded = TRUE;
      }
      else
      {
         printf("ERROR: No pattern data has been loaded from Pattern file: %s\n", filename);
      }
      fclose(patternfile);
   }
   else
      printf("ERROR: Unable to open Pattern file: %s\n", filename);

   return (patternLoaded) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_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_DSW_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 = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_dsw_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).
   */
   printf("\n Type the desired Enable Bit Value, Enable or Disable \n ");
   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 = NAI_DSW_ENHANCE_OP_ENABLE;
               bUpdateOutput = TRUE;
               break;
            case 'D':
               enState = NAI_DSW_ENHANCE_OP_DISABLE;
               bUpdateOutput = TRUE;
               break;
            default:
               printf("ERROR: Invalid switch state selection\n");
               break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_ENABLE, enState));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Configure_DSW_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_DSW_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 = FALSE;
   bool_t bUpdateOutput = FALSE;
   nai_dsw_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).
   */
   printf("\n Type PAUSE or RESUME to Control Pattern Generator Output\n ");
   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 = NAI_DSW_ENHANCE_OP_ENABLE;
               bUpdateOutput = TRUE;
               break;
            case 'R':
               enState = NAI_DSW_ENHANCE_OP_DISABLE;
               bUpdateOutput = TRUE;
               break;
            default:
               printf("ERROR: Invalid switch state selection\n");
               break;
         }
      }
   }
   if (!bQuit)
   {
      if (bUpdateOutput)
         check_status(naibrd_DSW_SetPatternGenCtrl(cardIndex, module, NAI_DSW_PATTERN_RAM_CONTROL_PAUSE, enState));
   }
   return (bQuit) ? NAI_ERROR_UNKNOWN : NAI_SUCCESS;
}
/**************************************************************************************************************/
/**
<summary>
Display_DSW_PatternGen_Configuration illustrate the methods to call in the naibrd library to retrieve the PWM
configuration settings.
</summary>
*/
/**************************************************************************************************************/
static nai_status_t Display_DSW_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
   printf("\n");
   printf("  ----------PatternGen Configuration Settings-------------\n");
   printf("  Period (ms)      Burst Cnt      StartAddr     EndAddr  \n");
   printf("  -------------   -----------    -----------   ----------\n");

   check_status(naibrd_DSW_GetPatternGenPeriod(cardIndex, module, &period));
   printf(" %10.6f   ", period);

   check_status(naibrd_DSW_GetPatternGen_BurstNum(cardIndex, module, &burstnumber));
   printf("    0x%08X   ", burstnumber);

   check_status(naibrd_DSW_GetPatternGenStartAddr(cardIndex, module, &startaddr));
   printf("  0x%08X   ", startaddr);

   check_status(naibrd_DSW_GetPatternGenEndAddr(cardIndex, module, &endaddr));
   printf("  0x%08X   ", endaddr);

   printf("\n\n");
   return NAI_ERROR_UNKNOWN;
}

Help Bot

X