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

RTD Interrupt Basic

RTD Interrupt Basic

Explanation

RTD_Interrupt_Basic Application

Overview

This sample C application demonstrates how to handle RTD (Resistance Temperature Detector) Open interrupts via a PCI bus connection using North Atlantic Industries' (NAI) software and libraries. The primary purpose is to show the use of NAI’s naibrd library functions for performing interrupts. This file can be used with the provided SSK (Software Support Kit) and it details how to configure, enable, handle, and clear interrupts on an NAI board.

Code Breakdown

Header Inclusions

The application includes a variety of header files necessary for interaction with the NAI hardware and software libraries, as well as standard C libraries.

  • Standard C Libraries: Provides basic functionalities such as input/output operations, memory allocation, and string manipulation. c #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h>

  • NAI Specific Libraries: These are headers specific to the NAI framework and its API, needed for hardware interaction. c #include "nai_rtd_int.h" #include "nai_rtd_cfg.h" #include "functions/naibrd_rtd.h"

  • Common Sample Program Libraries: These headers include various utility and access functions necessary for board access and interrupt handling. c #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.h" #include "naibrd.h"

Constants

The NAI_RTD_MIN_CHANNEL constant defines the minimum channel index for RTD.

#define NAI_RTD_MIN_CHANNEL 1

The configuration file name is defined for use within the application:

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

Function Prototypes

Prototype for the internal function Run_RTD_Interrupt_Basic().

static bool_t Run_RTD_Interrupt_Basic();

Main Function

The main routine which serves as the entry point to the application, in either VxWorks or other operating systems.

#if defined (__VXWORKS__)
int32_t RTD_Interrupt_Basic(void)
#else
int32_t main(void)
#endif
{
  1. Initialization: Initializes structures for RTD and interrupt configurations. c initializeRTDConfigurations(0, 0, 0, 0, 0, 0); initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, 0, 0, 0);

  2. Configuration and Access Loop:

    • Uses the naiapp_RunBoardMenu to start board configuration.

    • If successful, enters a loop to continuously query user inputs for card and module indices and handles the interrupts.

  3. Querying User for Card and Module:

    • Queries user for the card index and sets it in the configuration.

    • Queries user for the module number and checks the module ID.

  4. Interrupt Handling:

    • Calls Run_RTD_Interrupt_Basic() which manages the details of interrupt setup, enabling, and clearing.

  5. Exit Handling:

    • Provides user an option to quit or restart the application.

    • Closes all open card sessions before exiting.

Run_RTD_Interrupt_Basic Function

Handles the core logic for RTD interrupt management.

  1. Interrupt and Module Configuration:

    • Queries the user for channel number and interrupt steering type.

    • Installs the ISR (Interrupt Service Routine) using naibrd_InstallISR.

    • Configures RTD module to enable interrupts.

  2. Interrupt Handling Loop:

    • Waits and checks for interrupts using checkForRTDInterrupt.

    • Clears the interrupt and status registers allowing new interrupts to be detected.

  3. Clearing Configurations:

    • Disables RTD interrupts to prevent further interrupt generation.

    • Uninstalls the ISR using naibrd_UninstallISR.

Final Note

This application serves as a good starting point for developers looking to implement interrupt handling with NAI’s embedded function modules. By understanding and using provided API calls, users can adapt the sample to suit specific requirements and expand on the basic functionality demonstrated here.

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

The RTD_Interrupt_Basic program demonstrates how to check for RTD Open interrupts via PCI Bus Connection
to the board. 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_rtd_int.h"
#include "nai_rtd_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"

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

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

#define NAI_RTD_MIN_CHANNEL 1

/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/

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

/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_RTD_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 RTD_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;

   initializeRTDConfigurations(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);
         inputRTDConfig.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);
            inputRTDConfig.module = module;
            if (stop != TRUE)
            {
               inputRTDConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputRTDConfig.modid != 0))
               {
                  Run_RTD_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 RTD open latched status of channel is set to 1.

   API CALLS - naibrd_RTD_SetInterruptEdgeLevel, naibrd_RTD_SetInterruptVector, naibrd_RTD_SetInterruptSteering,
   naibrd_RTD_SetInterruptEnableRaw, naibrd_RTD_ClearStatusRaw

4. Nothing needs to be done for the RTD 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_RTD_ClearStatusRaw

7. Clear Module Configurations

   API CALLS - naibrd_RTD_SetInterruptEnableRaw

8. Clear Board Configurations

   API CALLS - naibrd_UninstallISR

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

   /* Query user for channel */
   if (!bQuit)
   {
      inputRTDConfig.maxChannel = naibrd_RTD_GetChannelCount( inputRTDConfig.modid );
      inputRTDConfig.minChannel = NAI_RTD_MIN_CHANNEL;
      printf( "\nWhich channel would you like to Receive on? \n" );
      bQuit = naiapp_query_ChannelNumber( inputRTDConfig.maxChannel, inputRTDConfig.minChannel, &inputRTDConfig.channel );
   }
   /* Query user for location interrupt will be sent out to */
   if (!bQuit)
   {
      bQuit = GetIntSteeringTypeFromUser( &inputInterruptConfig.steering );
   }

   if (!bQuit)
   {
      /**** 2. Implement Bus Interrupt Handling ****/
      setIRQ( inputInterruptConfig.steering, &inputInterruptConfig.irq );
      naibrd_InstallISR( inputRTDConfig.cardIndex, inputInterruptConfig.irq, basic_ISR_RTD, NULL );

      /**** 3. configure Module to perform interrupts ****/
      configureRTDToInterruptOnRx( inputInterruptConfig, inputRTDConfig );
      enableRTDInterrupts( inputRTDConfig,TRUE );

      /**** 4. Configure Module to cause Interrupts ****/
      /* Nothing needs to be done for the RTD module */

      /**** 5. Show Interrupt Handling (check for interrupt/ISR activity and clear statuses: contains step 6) ****/
      bQuit = checkForRTDInterrupt( inputRTDConfig );

      /***** 7. Clear Module Configurations *****/
      enableRTDInterrupts( inputRTDConfig, FALSE );

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

Help Bot

X