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

TTL Interrupt Basic

TTL Interrupt Basic

Explanation

About TTL_Interrupt_Basic Program

Overview

The TTL_Interrupt_Basic program demonstrates how to perform an interrupt operation when a single channel receives a TTL message. The purpose of this program is to illustrate the method calls in the naibrd library for managing interrupts. For more detailed information on this process, please refer to the naibrd SSK Quick Guide (Interrupts).

Include Declarations

The program includes multiple header files which provide necessary definitions and declarations for the functionalities used: - Standard libraries: stdio.h, stdlib.h, string.h, and time.h. - Sample-specific and common module-specific include files: nai_ttl_int.h, nai_ttl_cfg.h. - Common sample program include files: - naiapp_interrupt.h - naiapp_interrupt_ether.h - naiapp_boardaccess_menu.h - naiapp_boardaccess_query.h - naiapp_boardaccess_access.h - naiapp_boardaccess_display.h - naiapp_boardaccess_utils.h - NAI board include files: nai.h, naibrd.h. - Module-specific NAI board library files: functions/naibrd_ttl.h.

Application Definitions

  • CONFIG_FILE: A configuration file named default_TTL_Interrupt_Basic.txt is declared as a constant and is used to initialize the program’s settings.

Internal Function Prototypes

  • Run_TTL_Interrupt_Basic(): This function handles the core logic for setting up and managing TTL interrupts.

Main Routine

The main routine initializes the application and assists in configuring and accessing the board. It follows these steps:

  1. Initialization: Configures TTL and interrupt settings using initializeTTLConfigurations and initializeInterruptConfigurations.

  2. Board Menu: Launches the board configuration menu using naiapp_RunBoardMenu.

  3. User Interaction: Queries the user for card index and module number using naiapp_query_CardIndex and naiapp_query_ModuleNumber. If the module ID is valid, it invokes Run_TTL_Interrupt_Basic to process interrupts.

  4. Exit Handling: Queries the user for exiting or restarting the application. The program terminates when the user chooses to quit, closing all open cards using naiapp_access_CloseAllOpenCards.

Run_TTL_Interrupt_Basic Function

This function is broken into the following major steps, corresponding with the steps provided in the naibrd SSK Quick Guide (Interrupts) file:

  1. Initialize: Determines the channel count using naibrd_TTL_GetChannelCount.

  2. Interrupt Steering: Queries the user for interrupt steering type using GetIntSteeringTypeFromUser.

  3. Bus Interrupt Handling:

    • Configures IRQ settings using setIRQ.

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

  4. Module Interrupt Configuration:

    • Configures the TTL module for handling interrupts using configureTTLToInterrupt.

    • Enables the TTL interrupts using enableTTLInterrupts.

  5. Interrupt Handling:

    • Checks if any interrupt has occurred using checkForTTLInterrupt.

    • Re-arms interrupts by clearing the status register using naibrd_TTL_ClearStatusRaw.

  6. Clear Configurations:

    • Disables TTL interrupts.

    • Uninstalls the ISR using naibrd_UninstallISR.

The function returns TRUE if the user chooses to quit during any of these steps.

Key Functions and API Calls

  • initializeTTLConfigurations: Sets initial configurations for TTL.

  • initializeInterruptConfigurations: Sets initial configurations for interrupts.

  • naiapp_RunBoardMenu: Runs the board configuration menu.

  • naiapp_query_CardIndex: Queries the card index from the user.

  • naiapp_query_ModuleNumber: Queries the module number from the user.

  • naibrd_GetModuleCount: Retrieves the number of modules.

  • naibrd_GetModuleID: Retrieves the module ID.

  • naiapp_query_ForQuitResponse: Queries the user for quitting or restarting the program.

  • time.h functions: Used for managing timing within the program.

  • naibrd_InstallISR: Installs the interrupt service routine.

  • naibrd_TTL_SetInterruptEdgeLevel: Configures the edge level for TTL interrupts.

  • naibrd_TTL_SetIntVector: Sets the interrupt vector.

  • naibrd_TTL_SetInterruptSteering: Configures the interrupt steering.

  • naibrd_TTL_SetIntEnable: Enables TTL interrupts.

  • naibrd_TTL_ClearStatusRaw: Clears the status register for re-arms.

  • naibrd_UninstallISR: Uninstalls the interrupt service routine.

This comprehensive walkthrough aims to aid in understanding the program’s functionality and the purpose of each section of the code. For further details, consult the naibrd SSK Quick Guide (Interrupts).

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

The TTL_Interrupt_Basic program demonstrates how to perform an interrupt when a single channel receives
a ttl 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_ttl_int.h"
#include "nai_ttl_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_ttl.h"

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

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

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

   initializeTTLConfigurations(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);
         inputTTLConfig.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);
            inputTTLConfig.module = module;
            if (stop != TRUE)
            {
               inputTTLConfig.modid = naibrd_GetModuleID(cardIndex, module);
               if ((inputTTLConfig.modid != 0))
               {
                  Run_TTL_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 TTL message.

   API CALLS - naibrd_TTL_SetInterruptEdgeLevel, naibrd_TTL_SetIntVector, naibrd_TTL_SetInterruptSteering, naibrd_TTL_SetIntEnable

4. Not applicable to this 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_TTL_ClearStatusRaw

7. Clear Module Configurations

8. Clear Board Configurations

   API CALLS - naibrd_UninstallISR

</summary>
*/
/**************************************************************************************************************/
static bool_t Run_TTL_Interrupt_Basic()
{
    bool_t bQuit = FALSE;
    int32_t maxChannel = naibrd_TTL_GetChannelCount(inputTTLConfig.modid);
    int32_t minChannel = 1;
    /*Query user for RX channel*/

   if(!bQuit)
   {

      bQuit = naiapp_query_ChannelNumber(maxChannel,minChannel,&inputTTLConfig.channel);
      inputTTLConfig.minChannel = inputTTLConfig.channel;
      inputTTLConfig.maxChannel = inputTTLConfig.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(inputTTLConfig.cardIndex,inputInterruptConfig.irq, basic_ISR_TTL,NULL);

      /****3. configure Module to perform interrupts****/
      configureTTLToInterrupt(inputInterruptConfig,inputTTLConfig);
      enableTTLInterrupts(inputTTLConfig,TRUE);

      /****5. Show  Interrupt Handling (contains step 6)****/
      bQuit = checkForTTLInterrupt(inputTTLConfig);

      /*****7. Clear Module Configurations*****/
      enableTTLInterrupts(inputTTLConfig,FALSE);

      /*****8. Clear Board Configurations *****/
      check_status(naibrd_UninstallISR(inputTTLConfig.cardIndex));
   }

   return bQuit;
}

Help Bot

X