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 Basic

DSW Interrupt Basic

Explanation

About DSW_Interrupt_Basic Sample Application

Overview

The DSW_Interrupt_Basic program demonstrates how to perform an interrupt when a single channel receives a message. This sample application leverages the NAI (North Atlantic Industries) boards and corresponding libraries to manage and handle interrupts in a Distributed Switch (DSW) module.

Structure and Key Components

Include Directives

The program begins by including the necessary headers for standard operations, NAI-specific configurations, and board interaction functionalities:

  • Standard Libraries: stdio.h, stdlib.h, string.h, time.h

  • NAI-specific libraries: nai_dsw_cfg.h, nai_dsw_int.h, nai.h, naibrd.h, naibrd_dsw.h

  • Common Sample Program libraries: naiapp_interrupt.h, naiapp_interrupt_ether.h, etc.

Configuration

The configuration file used by the application is specified via the CONFIG_FILE constant:

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

Main Function

The main function of the program is responsible for initializing the configurations, querying the card index and module number from the user, and running the interrupt logic.

Key Functions Used

  • initializeDSWConfigurations(): Initializes the DSW-specific configurations.

  • initializeInterruptConfigurations(): Sets up the initial state for handling interrupts.

  • naiapp_RunBoardMenu(): Manages the board menu driven from the configuration file.

  • naiapp_query_CardIndex(): Queries the user to select the card index.

  • naibrd_GetModuleCount(): Retrieves the number of modules available on the selected card.

  • naiapp_query_ModuleNumber(): Queries the user for the module number.

  • naibrd_GetModuleID(): Fetches the module ID for a particular card and module index.

  • naiapp_query_ForQuitResponse(): Allows the user to quit or restart the application.

Interrupt Handling

Interrupt handling logic is implemented in the Run_DSW_Interrupt_Basic() function.

Steps for Handling Interrupts

  1. Implement Bus Interrupt Handling:

    • The function installs an Interrupt Service Routine (ISR) using the naibrd_InstallISR() API call.

  2. Enable Module Interrupts:

    • Configures the module to interrupt when a channel receives a message using the following API calls:

    • naibrd_DSW_SetInterruptEdgeLevel()

    • naibrd_DSW_SetIntVector()

    • naibrd_DSW_SetInterruptSteering()

    • naibrd_DSW_SetIntEnable()

  3. Interrupt Handling:

    • The main loop checks if any interrupt has occurred and reports the status using checkForDSWInterrupt(). The status register is cleared to allow further interrupts.

    • naibrd_DSW_ClearStatusRaw() is used to clear the status register.

  4. Clear Module Configurations:

    • Disables the DSW interrupts using enableDSWInterrupts().

  5. Clear Board Configurations:

    • Uninstalls the ISR using naibrd_UninstallISR().

Definitions and Types

  • bool_t: A boolean type.

  • inputDSWConfig, inputInterruptConfig: Structures holding runtime configurations for DSW and interrupts.

  • basic_ISR_DSW: A function pointer to the basic interrupt service routine for DSW.

  • NAI_QUIT_CHAR: Character used to indicate quitting the application.

Conclusion

This sample program provides an essential guide for setting up and handling interrupts in NAI boards using the Distributed Switch (DSW) module. It methodically initializes configurations, installs ISRs, and handles incoming messages by enabling and disabling interrupts dynamically. The structure outlines the interaction with the naibrd library, making it easier for users to follow and implement their interrupt handling logic.

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

The DSW_Interrupt_Basic 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_cfg.h"
#include "nai_dsw_int.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"

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

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

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

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

/**************************************************************************************************************/
/*****                                     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(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, 0, 0, 0);

   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();
               }
            }
         }
         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.

2. Bus Interrupt Handling - Install ISR

   API CALLS - naibrd_InstallISR

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 - Check if any interrupt has occurred and report back the status and vector

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, we use an API call to do this.

   API CALLS - naibrd_DSW_ClearStatusRaw

7. Clear Module Configurations

8. Clear Board Configurations

   API CALLS - naibrd_UninstallISR

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_DSW_Interrupt_Basic()
{
   bool_t bQuit = FALSE;
   /* Query user for RX channel */
   inputDSWConfig.maxChannel = naibrd_DSW_GetChannelCount(inputDSWConfig.modid);
   inputDSWConfig.minChannel = 1;

   if(!bQuit)
   {
      bQuit = GetIntSteeringTypeFromUser(&inputInterruptConfig.steering);
   }
   if (!bQuit)
   {
      /**** 2. Implement Bus Interrupt Handling****/
      setIRQ(inputInterruptConfig.steering,&inputInterruptConfig.irq);
      naibrd_InstallISR(inputDSWConfig.cardIndex,inputInterruptConfig.irq, basic_ISR_DSW,NULL);

      /****3. configure Module to perform interrupts****/
      configureDSWToInterrupt(inputInterruptConfig,inputDSWConfig);
      enableDSWInterrupts(inputDSWConfig,TRUE);

      /****5. Show Interrupt Handling (contains step 6)****/
      bQuit = checkForDSWInterrupt(inputDSWConfig);

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

      /*****8. Clear Board Configurations *****/
      check_status(naibrd_UninstallISR(inputDSWConfig.cardIndex));
   }
   return bQuit;

}

Help Bot

X