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

nai rtd int

nai rtd int

Explanation

About the Sample C Application Code

Overview This sample application code is designed to work with North Atlantic Industries' (NAI) Sensor Synchronization Kit (SSK) to interact with their embedded function modules. Specifically, the sample focuses on configuring and handling Real-Time Data (RTD) module interrupts. Below is a brief rundown of the key components and functions in the code.

Included Headers and Libraries The application begins by including several common header files that are part of the NAI platform. These headers provide necessary definitions, function prototypes, and utilities to interact with the NAI hardware:

  • Common Sample Program headers:

  • 'naiapp_interrupt.h'

  • 'naiapp_interrupt_ether.h'

  • 'naiapp_boardaccess_query.h'

  • 'naiapp_boardaccess_access.h'

  • 'naiapp_boardaccess_display.h'

  • 'naiapp_boardaccess_utils.h'

  • RTD-specific headers:

  • 'nai_rtd_int.h'

  • 'nai_rtd_cfg.h'

  • Board-specific headers:

  • 'nai.h'

  • 'naibrd.h'

  • 'naibrd_ether.h'

  • 'functions/naibrd_rtd.h'

  • '../src/maps/nai_map_rtd.h'

Key Functions

'basic_ISR_RTD' This function serves as the Interrupt Service Routine (ISR) for handling interrupts from the RTD module. It sets a flag ('interruptOccurred') to TRUE, indicating that an interrupt has been detected. For vxWorks systems, it also retrieves and clears the interrupt vector.

'configureRTDToInterruptOnRx' This function sets up the RTD module to trigger an interrupt when any RTD channel’s open latched status is set to 1. It configures the necessary interrupt vectors, edges/levels, and steering settings for the RTD channels.

'enableRTDInterrupts' This function enables or disables interrupts for a range of RTD channels specified by 'minChannel' and 'maxChannel' in the input configuration. It updates the interrupt enable register based on the 'enable' parameter.

'checkForRTDInterrupt' This function is used interactively to check if an interrupt has occurred. It waits for user input to either query the status of the interrupt or quit the loop. Upon detecting an interrupt, it retrieves and displays the status of the RTD channels.

'GetRTDLatchStatusTriggerMode' This function prompts the user for the trigger mode (Edge Triggered or Level Triggered) for the RTD latched status register and updates the provided variable accordingly.

'DisplayMessage_RTDInterrupt' This function displays predefined messages based on the 'msgId' passed to it. The messages are generally informational and guide the user through the interrupt handling process.

'handleRTDInterrupt' This function processes the RTD interrupt by retrieving the open latched status of all channels that caused the interrupt and printing the status. It may also prompt the user to clear the interrupt, depending on the configuration.

'promptUserToClearInterrupt_RTD' This function prompts the user to acknowledge and clear the open status latched register after an interrupt has occurred. It waits for the user�s input before proceeding.

'printInterruptInformationToFile' This function prints the interrupt information, including the interrupt ID/vector and open latched status, to a specified file stream.

'printInterruptInformation_RTD' This function prints the interrupt information to the console. It also handles whether the information pertains to an Ethernet-based interrupt or a regular vector-based interrupt.

'ClearInterrupt_RTD' This function clears the open latched status register for the RTD channels. It may prompt the user based on the interrupt configuration settings.

Utility Functions - 'check_status': Likely a macro or utility function defined elsewhere in the codebase to handle and verify the status returned from NAI API calls.

Conclusion The provided sample code offers a comprehensive setup for configuring and handling RTD configuration and interrupts within an NAI system. It includes functions for setting up interrupts, enabling/disabling them, checking for an interrupt occurrence, and managing user interactions to handle interrupts efficiently.

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

/* Common RTD Sample Program include files */
#include "nai_rtd_int.h"
#include "nai_rtd_cfg.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "naibrd_ether.h"
#include "functions/naibrd_rtd.h"
#include "../src/maps/nai_map_rtd.h"

#include <stdlib.h>

/**************************************************************************************************************/
/**
<summary>
The routine is called to handle a interrupt. This function alerts checkForInterrupt that an interrupt has occurred.
In vxWorks you must clear the Interrupt on the board within the ISR.
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
void basic_ISR_RTD( uint32_t param )
#else
void basic_ISR_RTD( void *param, uint32_t vector )
#endif
{
   interruptOccurred = TRUE;

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

   #if defined (__VXWORKS__)
      interruptVectorOpen = nai_Onboard_GetInterruptVector();
      nai_Onboard_ClearInterrupt();
   #else
      interruptVectorOpen = vector;
   #endif
}

/**************************************************************************************************************/
/**
<summary>
This function configures an interrupt to occur when the open latched status of any of the RTD channels is
set to 1.
</summary>
*/
/**************************************************************************************************************/
void configureRTDToInterruptOnRx( InterruptConfig inputInterruptConfig, RtdConfig inputRTDConfig )
{
   int32_t channel;
   int32_t maxChan;
   int32_t cardIndex = inputRTDConfig.cardIndex;
   int32_t module = inputRTDConfig.module;
   int32_t vector = NAI_RTD_INTERRUPT_VECTOR;
   nai_rtd_interrupt_t interrupt_Level_Trigger = NAI_RTD_LEVEL_INTERRUPT;
   int32_t steering = inputInterruptConfig.steering;

   nai_rtd_status_type_t typeOpen = NAI_RTD_STATUS_OPEN_LATCHED;

   /* clear interruptConfigs of previous channels */
   check_status( naibrd_RTD_SetInterruptEnableRaw( cardIndex, module, typeOpen, 0 ) );
   check_status( naibrd_RTD_ClearStatusRaw( cardIndex, module, typeOpen, 0xFFFF ) );

   check_status( naibrd_RTD_SetInterruptVector( cardIndex, module, typeOpen, vector ) );
   maxChan = naibrd_RTD_GetChannelCount( inputRTDConfig.modid );
   for ( channel = 1; channel <= maxChan; channel++ )
   {
      check_status( naibrd_RTD_SetInterruptEdgeLevel( cardIndex, module, channel, typeOpen, interrupt_Level_Trigger ) );  /* Level triggered */
   }
   check_status( naibrd_RTD_SetInterruptSteering( cardIndex, module, typeOpen, steering ) );
}

/**************************************************************************************************************/
/**
<summary>
Enables the channels within the (minChannel, maxChannel) range to interrupt
if enable is true and disables them otherwise.
</summary>
*/
/**************************************************************************************************************/
void enableRTDInterrupts( RtdConfig inputRTDConfig, bool_t enable )
{
   int32_t channel;

   nai_rtd_status_type_t typeOpen = NAI_RTD_STATUS_OPEN_LATCHED;

   int32_t enableRegVal = 0;
   int32_t isEnabled = 0;
   for ( channel = inputRTDConfig.minChannel; channel <= inputRTDConfig.maxChannel; channel++ )
   {
      isEnabled = ( ( 1 << ( channel-1 ) ) & enableRegVal );
      if (enable)
         enableRegVal = ( 1 << ( channel-1 ) ) | enableRegVal;
      else if ( isEnabled )
         enableRegVal = ( 1 << ( channel-1 ) ) ^ enableRegVal;
   }
   check_status( naibrd_RTD_SetInterruptEnableRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, typeOpen, enableRegVal ) );
}

/**************************************************************************************************************/
/**
<summary>
Prompts user to check if an interrupt has occurred. MyIsr() should be installed if using this function.
</summary>
*/
/**************************************************************************************************************/
bool_t checkForRTDInterrupt( RtdConfig inputRTDConfig )
{
   bool_t bQuit;
   uint32_t statusOpen;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   statusOpen = 0;
   bQuit = FALSE;
   interruptOccurred = FALSE;

   while (!bQuit)
   {
      printf( "\nPress enter to check if interrupt Occurred (press Q to quit):" );
      bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
      if (!bQuit)
      {
         if (interruptOccurred)
         {
            check_status( naibrd_RTD_GetStatusRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, &statusOpen ) );
            printf( "\nOpen Vector = %#x \n", interruptVectorOpen );
            printf( "Open Status = %#x \n", statusOpen );

            interruptOccurred = FALSE;
         }
         else
         {
            printf( "\nNo Interrupt Occurred" );
         }
         printf( "\n\nWould you like to clear the status registers? (default:N):" );

         bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
         if ( inputBuffer[0] == 'y' || inputBuffer[0] =='Y' )
         {
            check_status( naibrd_RTD_ClearStatusRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, statusOpen ) );
         }
      }
   }
   return bQuit;
}

/**************************************************************************************************************/
/**
<summary>
GetRTDLatchStatusTriggerMode handles prompting the user for the trigger mode for the latched status register
(Edge Triggered or Level Triggered).
</summary>
*/
/**************************************************************************************************************/
bool_t GetRTDLatchStatusTriggerMode( int32_t* interrupt_Edge_Trigger )
{
   bool_t bQuit;
   uint32_t temp;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf( "\nEnter Latched Status Trigger Mode (Edge=0, Level=1) (Default=0): " );
   bQuit = naiapp_query_ForQuitResponse( sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt );
   if (!bQuit)
   {
      if ( inputResponseCnt > 0 )
      {
         temp = (int32_t)atol( (const char*)inputBuffer );

         if ( temp == 0 || temp == 1 )
         {
            *interrupt_Edge_Trigger = temp;
         }
         else
         {
            printf( "ERROR: Invalid Interrupt Trigger Mode.\n" );
         }
      }
      else
         *interrupt_Edge_Trigger = 0;
   }
   return( bQuit );
}

/**************************************************************************************************************/
/**
<summary>
DisplayMessage_RTDInterrupt handles displaying the messages associated with the msgId passed in.
</summary>
*/
/**************************************************************************************************************/
void DisplayMessage_RTDInterrupt( int32_t msgId )
{
   switch (msgId)
   {
      case (int32_t)MSG_BANNER_RTD_INT:
      {
         printf( "\n********************************************************************************" );
         printf( "\n******                        RTD INTERRUPT                               ******" );
         printf( "\nAn interrupt will occur when one of the interrupt conditions of the RTD module" );
         printf( "\nstatuses is met." );
         printf( "\n********************************************************************************" );
      }
      break;

      case (int32_t)MSG_USER_CLEAR_RTD_INT:
      {
         printf( "Press \"C\" to clear interrupts... " );
      }
      break;
   }
}

/**************************************************************************************************************/
/**
<summary>
This routine takes in the vector of the RTD open interrupt that has just occurred. And gets the open latched
status of all channels that interrupted, and prints it.
</summary>
*/
/**************************************************************************************************************/
void handleRTDInterrupt( uint32_t nVector )
{
   uint32_t statusOpen;

   printf( "\n\nInterrupt Occurred \n\n" );
   if ( inputInterruptConfig.bPromptForInterruptClear )
   {
      promptUserToClearInterrupt_RTD();
   }

   check_status( naibrd_RTD_GetStatusRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, &statusOpen ) );

   check_status( naibrd_RTD_ClearStatusRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, statusOpen ) );
   printInterruptInformationToFile( nVector, statusOpen, FALSE, fifoDataFile );
   printInterruptInformation_RTD( nVector, statusOpen, FALSE );
}

/**************************************************************************************************************/
/**
<summary>
This function prompts the user to clear the open status latched register upon open interrupt.
</summary>
*/
/**************************************************************************************************************/
void promptUserToClearInterrupt_RTD()
{
   /* Prompt the user to clear the interrupt received */
   SetUserRequestClearInt( FALSE );
   printf( "\n" );
   DisplayMessage_RTDInterrupt( MSG_USER_CLEAR_RTD_INT );

   /* Wait for the user to respond */
   while ( !GetUserRequestClearInt() )
   {
      nai_msDelay( 10 );
   }
}

/**************************************************************************************************************/
/**
<summary>
Function will print the RTD open latched status and idr id or vector to a file.
</summary>
*/
/**************************************************************************************************************/
void printInterruptInformationToFile( int32_t interruptID, uint32_t statusOpen, bool_t isEther, FILE* stream )
{
   fprintf( stream, "Interrupt Information\n" );
   fprintf( stream, "-----------------------------------\n" );
   if (isEther)
      fprintf( stream, "\nIDR ID = %#x \n", interruptID );
   else
      fprintf( stream, "\nVector = %#x \n", interruptID );
   fprintf( stream, "Open Status = %#x \n", statusOpen );
}

/**************************************************************************************************************/
/**
<summary>
Function will print the RTD open latched status and idr id or vector.
</summary>
*/
/**************************************************************************************************************/
void printInterruptInformation_RTD( int32_t interruptID, uint32_t statusOpen, bool_t isEther )
{
   printf( "Interrupt Information\n" );
   printf( "-----------------------------------\n" );
   if (isEther)
      printf( "\nIDR ID = %#x \n", interruptID );
   else
      printf( "\nVector = %#x \n", interruptID );
   printf( "Open Status = %#x \n", statusOpen );
}

void ClearInterrupt_RTD()
{
   uint32_t status;
   if (inputInterruptConfig.bPromptForInterruptClear)
   {
      promptUserToClearInterrupt_RTD();
   }
   naibrd_RTD_GetStatusRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, &status );
   naibrd_RTD_ClearStatusRaw( inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, status );
}

Help Bot

X