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 Interrupt Ethernet

DSW Interrupt Ethernet

Explanation

About the Code

Overview

The DSW_Interrupt_Ethernet program is designed to demonstrate how to handle interrupts when a single channel receives a message using the naibrd library. The primary objective is to illustrate the method calls necessary for performing the interrupt. Detailed information on the process is provided in the naibrd SSK Quick Guide (Interrupts) file.

File Structure

Included Libraries

The program includes several libraries essential for its functionality:

  • Standard Libraries:

  • stdio.h, stdlib.h, string.h, time.h for standard I/O operations, memory management, string manipulation, and timing functions.

  • Module Specific Sample Program Include Files:

  • nai_dsw_int.h, nai_dsw_cfg.h for Direct Switch (DSW) specific configurations and methods.

  • Common Sample Program Include Files:

  • Provides interfaces for board access, user queries, and interrupt management:

  • naiapp_interrupt.h

  • naiapp_interrupt_ether.h

  • Various naiapp_boardaccess_* headers.

  • NAI Board Library Files:

  • nai.h, naibrd.h for overall board interactions.

  • functions/naibrd_dsw.h and maps/nai_map_dsw.h for DSW-specific operations.

Static Variables

  • DEF_RX_RESPONSE_IPv4_ADDR: Defines the default IPv4 address (192.168.1.100).

  • COMMANDS: Array to hold the commands with length determined by MAX_ETHER_IDR_CMD_CNT * MAX_ETHER_BLOCK_REG_CNT.

  • CONFIG_FILE: Path to the default configuration file.

Structures for Configuration

  • DswConfig: Stores the configurations for the DSW module.

  • InterruptConfig: Holds the settings for handling interrupts.

Internal Function Prototypes

  • Run_DSW_Interrupt_Basic_Ethernet: A static function to execute the core logic for handling the DSW interrupt via Ethernet.

Main Routine

The main routine performs the following major tasks:

  1. Configuration Initialization:

    • Initialize DSW, Interrupt, and IDR configurations using appropriate functions like initializeDSWConfigurations.

  2. Configuration File Load and Menu:

    • Load the default configuration file using naiapp_RunBoardMenu.

  3. User Query Loop:

    • Continuously query the user for the card index and module number.

    • Determine if the module ID is valid and if yes, call Run_DSW_Interrupt_Basic_Ethernet.

  4. Quit or Restart:

    • Prompt the user to quit or restart the application and handle inputs accordingly.

  5. Exit Procedure:

    • Close all open cards and exit the program.

Run_DSW_Interrupt_Basic_Ethernet Function

This function encapsulates the following steps, corresponding to the guidelines provided in the naibrd SSK Quick Guide (Interrupts):

  1. Check Ethernet Support:

    • Verify if the module supports Generation 4 Ethernet commands.

  2. Query User Inputs:

    • Query the user for channel number, IDR configuration, and whether to process onboard or offboard interrupts.

  3. Setup IDR Configuration:

    • Configure IDR to handle Ethernet interrupts using setupIDRConfiguration_DSW.

    • Start IDR via naibrd_Ether_StartIDR.

  4. Configure Module for Interrupts:

    • Setup module to enable interrupts calling appropriate functions like configureDSWToInterrupt.

  5. Show Interrupt Handling:

    • The IDR server listens for interrupts, decodes, and displays results via runIDRServer.

  6. Clear Configurations:

    • Disable module interrupts and clear configurations using enableDSWInterrupts and naibrd_Ether_StopIDR.

The program provides a comprehensive demonstration of the workflow for configuring and handling DSW interrupts over Ethernet, facilitating learning and implementation of similar setups using the naibrd library.

/**************************************************************************************************************/
/**
<summary>

The DSW_Interrupt_Ethernet program demonstrates how to perform an interrupt when a single channel receives
a message. The purpose of this program is to demonstrate the method calls in the naibrd library for performing
the interrupt. More information on this process can be found in the naibrd SSK Quick Guide(Interrupts) file.

</summary>
*/
/**************************************************************************************************************/

/************************/
/* Include Declarations */
/************************/

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

/*Common Module Specific Sample Program include files*/
#include "nai_dsw_int.h"
#include "nai_dsw_cfg.h"

/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.h"
#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"
#include "nai_dsw_int_ether.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"

/* Module Specific NAI Board Library files */
#include "functions/naibrd_dsw.h"
#include "maps/nai_map_dsw.h"

static uint8_t DEF_RX_RESPONSE_IPv4_ADDR[] =   {192,168,1,100};
static uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT];

/*********************************************/
/*			Program Configurations			 */
/*********************************************/
DswConfig inputDSWConfig;
InterruptConfig inputInterruptConfig;

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_DSW_Interrupt_Ethernet.txt";

/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_DSW_Interrupt_Basic_Ethernet();

/**************************************************************************************************************/
/*****                                     Main Routine                                                   *****/
/**************************************************************************************************************/

/**************************************************************************************************************/
/**
<summary>

The main routine assists in gaining access to the board.

The following routines from the nai_sys_cfg.c file are
called to assist with accessing and configuring the board.

 - ConfigDevice
 - DisplayDeviceCfg
 - GetBoardSNModCfg
 - CheckModule

</summary>

*/
/*****************************************************************************/
#if defined (__VXWORKS__)
int32_t DSW_Interrupt_Basic_Ethernet(void)
#else
int32_t main(void)
#endif
{
   bool_t stop = FALSE;
   int32_t cardIndex;
   int32_t moduleCnt;
   int32_t module;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   initializeDSWConfigurations(0, 0, 0, 0, 0, 0);
   initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, NAIBRD_INT_STEERING_ON_BOARD_1, -1, 0);
   initializeIDRConfigurations(0, 0, DEF_RX_RESPONSE_PROTOCOL, DEF_RX_RESPONSE_PORT, DEF_RX_RESPONSE_IPv4_ADDR, DEF_RX_RESPONSE_IPv4_LENGTH, COMMANDS, 0, 0, DEF_ETHERNET_DSW_LOHI_IDR_ID);

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

            /* Query the user for the module number */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            inputDSWConfig.module = module;
            if (stop != TRUE)
            {
               inputDSWConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputDSWConfig.modid != 0))
               {
                  Run_DSW_Interrupt_Basic_Ethernet();
               }
            }
         }
         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>
This function is broken into the following major steps. These steps correspond with the steps provided
in the naibrd SSK Quick Guide(Interrupts) file.

2a. Ethernet Interrupt Handling - Setup IDR to handle interrupt

   API CALLS - naibrd_Ether_SetIDRConfig, naibrd_Ether_StartIDR,naibrd_Ether_ClearIDRConfig

3. Enable Module Interrupts- Configures module to interrupt when channel receives DSW message.

   API CALLS - naibrd_DSW_SetInterruptEdgeLevel, naibrd_DSW_SetIntVector, naibrd_DSW_SetInterruptSteering, naibrd_DSW_SetIntEnable

4. Not applicable to DSW module

5. Show Interrupt Handling - The IDR server will listen on the boards ports for IDRs indicating an interrupt.
   These results will be decoded and displayed to the user.

6. Re-arming Interrupts - Clear the status register to allow interrupts to occur again. This is done by writing to the status register.
   In this program, the write command is included in the IDR.

   API CALLS - nai_ether_BeginWriteMessage, nai_ether_WriteMessageData, nai_ether_FinishMessage

7. Clear Module Configurations

   API CALLS - naibrd_DSW_SetRxEnable, naibrd_DSW_ClearStatus

8. Clear Board Configurations

   API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_DSW_Interrupt_Basic_Ethernet()
{
   bool_t bQuit = FALSE;
   bool_t bGen4DSWIDRCommands;

   inputDSWConfig.maxChannel = naibrd_DSW_GetChannelCount(inputDSWConfig.modid);
   inputDSWConfig.minChannel = 1;

   /* check if DSW module supports GEN 4 Ethernet */
   bGen4DSWIDRCommands = SupportsGen4Ether(inputDSWConfig.cardIndex);
    if (!bGen4DSWIDRCommands)
   {
        printf("DSW Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
        bQuit = TRUE;
   }
   if (!bQuit)
   {
      bQuit = naiapp_query_ChannelNumber(inputDSWConfig.maxChannel,inputDSWConfig.minChannel,&inputDSWConfig.channel);
   }
   if (!bQuit)
   {
      bQuit = QueryIDRConfigInformation(&inputIDRConfig);

   }
   if (!bQuit)
   {
      bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
   }
   if (!bQuit)
   {
      bQuit = QueryUserForEtherIDRMsgDisplay(&bDisplayEtherUPR);
   }

   if (!bQuit)
   {

      /****2. Setup IDR to Handle Interrupt (also contains step 6) ****/
      if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
      {
         inputIDRConfig.cardIndex = inputDSWConfig.cardIndex;
         inputIDRConfig.boardInterface =  NAI_INTF_ONBOARD;
         inputInterruptConfig.steering = NAIBRD_INT_STEERING_ON_BOARD_1;
      }
      else /*OffBoard Interrupt*/
      {
         inputIDRConfig.cardIndex = 0;
         inputIDRConfig.boardInterface = NAI_INTF_PCI;

         inputInterruptConfig.steering =  NAIBRD_INT_STEERING_CPCI_APP;
      }

      setupIDRConfiguration_DSW(inputDSWConfig,&inputIDRConfig,bGen4DSWIDRCommands);
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,(uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
      check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,(uint16_t)DEF_ETHERNET_DSW_HILO_IDR_ID));

      /****3. configure module To Interrupt****/
      configureDSWToInterrupt(inputInterruptConfig,inputDSWConfig);
      enableDSWInterrupts(inputDSWConfig,TRUE);

      /****5. Show Interrupt Handling****/
      dswEtherIntFunc = HandleDSWEtherInterrupt;
      bQuit = runIDRServer(inputIDRConfig);

      /*****7. Clear Module Configurations*****/
      enableDSWInterrupts(inputDSWConfig,FALSE);

      /*****8. Clear Board Configurations *****/
      check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
      check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DSW_LOHI_IDR_ID));
   }

   return bQuit;
}

Help Bot

X