RTD Interrupt
Edit this on GitLab
RTD Interrupt
Explanation
RTD_Interrupt Program Explanation
Overview
The RTD_Interrupt
program demonstrates how to handle RTD (Resistance Temperature Detector) open interrupts via a PCI Bus Connection to a board. This demonstration includes handling multiple interrupts, querying the user for edge trigger values, and prompting the user to clear an interrupt, along with support for offboard interrupts. The methods employed utilize the naibrd
library.
Include Declarations
The program begins by including necessary libraries and headers:
-
Standard libraries like
<stdio.h>
,<stdlib.h>
,<string.h>
, and<time.h>
. -
Module-specific include files such as:
-
nai_rtd_int.h
for RTD interrupt handling. -
nai_rtd_cfg.h
for RTD configurations. -
Common sample program include files from the common directory:
-
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
-
naibrd.h
for board-specific functionalities. -
naibrd_rtd.h
for module-specific RTD functionalities.
Application Name and Revision Declaration
A static constant for the config file: static const int8_t *CONFIG_FILE = (int8_t *)"default_RTD_Interrupt.txt";
Function Prototypes
One internal function is prototyped:
-
static bool_t Run_RTD_Interrupt();
Main Routine
Purpose
The main routine assists in gaining access to the board. It utilizes various routines for accessing and configuring the board.
Function
#if defined (__VXWORKS__)
int32_t RTD_Interrupt(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();
}
}
}
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;
}
Description
-
Initialization: The program initializes the RTD and interrupt configurations.
-
Main Loop:
-
Prompts user to select the card index and gets the module count.
-
Prompts user to select the module number.
-
If the module ID is valid (i.e.,
modid != 0
), it runs the interrupt handling.
-
-
User Prompts: After running the interrupt, the program prompts the user to either quit the application or restart it.
-
Exit: When the user decides to quit, the program closes all open cards and exits.
Run_RTD_Interrupt Function
Purpose
This function is responsible for handling the various steps involved in RTD interrupt processing, following the steps mentioned in the naibrd SSK Quick Guide(Interrupts)
file.
Function
static bool_t Run_RTD_Interrupt()
{
bool_t bQuit = FALSE;
int32_t minChannel;
int32_t maxChannel;
minChannel = 1;
maxChannel = naibrd_RTD_GetChannelCount(inputRTDConfig.modid);
// Query for Channels to Operate on
bQuit = naiapp_query_ForChannelRange(&inputRTDConfig.minChannel, &inputRTDConfig.maxChannel, minChannel, maxChannel);
// Query for Trigger Status of interrupts
if (!bQuit)
{
bQuit = GetRTDLatchStatusTriggerMode(&inputInterruptConfig.interrupt_Edge_Trigger);
}
// Query user if they'd like to be prompted for clearing interrupts
if (!bQuit)
{
bQuit = QueryUserForClearingInterruptPrompts(&inputInterruptConfig.bPromptForInterruptClear);
}
if (!bQuit)
{
bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
}
// Query user for location interrupt will be sent out to
if (!bQuit)
{
bQuit = GetIntSteeringTypeFromUser(&inputInterruptConfig.steering);
}
if (!bQuit)
{
if (inputInterruptConfig.displayData)
fifoDataFile = stdout;
else
fifoDataFile = fopen("fifoData.txt", "w+");
// Step 2: Bus Interrupt Handling
setIRQ(inputInterruptConfig.steering, &inputInterruptConfig.irq);
inputInterruptConfig.cardIndex = inputRTDConfig.cardIndex;
if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOnboardIsr, NULL));
}
else
{
check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOffboardIsr, (void*)&inputRTDConfig.cardIndex));
}
// Step 3: Configure Module to perform interrupts
configureRTDToInterruptOnRx(inputInterruptConfig, inputRTDConfig);
// Initialize Message Queue and Enable Interrupts
InitInterruptAppThread(ONBOARD_INT, 0);
nai_msDelay(10);
UpdateThreadState(RUN);
enableRTDInterrupts(inputRTDConfig, TRUE);
// Show Interrupt Handling
rtdIntProcessFunc = handleRTDInterrupt;
DisplayMessage_RTDInterrupt(MSG_BANNER_RTD_INT);
// Wait on program threads
while (!isThreadStateTerminated())
{
}
bQuit = TRUE;
if (!inputInterruptConfig.displayData)
fclose(fifoDataFile);
// Clear Module and Board Configurations
enableRTDInterrupts(inputRTDConfig, FALSE);
check_status(naibrd_UninstallISR(inputInterruptConfig.cardIndex));
}
return bQuit;
}
Description
-
Channel and Trigger Queries:
-
The function queries the user for channel ranges, interrupt edge trigger, prompt for clearing interrupts, and onboard/offboard interrupt processing.
-
It also queries the user for the location to which interrupts will be sent.
-
-
Bus Interrupt Handling:
-
Sets the IRQ and installs the respective ISR (either onboard or offboard).
-
-
Module Configuration:
-
Configures the RTD module to perform interrupts.
-
-
Initialization:
-
Initializes the message queue, enables interrupts, and sets the interrupt processing function.
-
-
Interrupt Handling:
-
Displays the RTD interrupt message and waits on program threads.
-
Clears module and board configurations.
-
Through these steps, the program successfully sets up and processes RTD interrupts based on user inputs and configurations.
/**************************************************************************************************************/
/**
<summary>
The RTD_Interrupt 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.
This application differs from RTD_Interrupt_Basic in that it could handle multiple interrupts at once.
It also queries the user for the edge trigger value and whether the user should be prompted to clear an interrupt.
The application also has support for offboard interrupts.
</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"
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_RTD_Interrupt.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_RTD_Interrupt();
/**************************************************************************************************************/
/***** 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(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();
}
}
}
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 the mailbox to see if any interrupts occurred.
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()
{
bool_t bQuit = FALSE;
int32_t minChannel;
int32_t maxChannel;
minChannel = 1;
maxChannel = naibrd_RTD_GetChannelCount(inputRTDConfig.modid);
/* Query for Channels to Operate on */
bQuit = naiapp_query_ForChannelRange(&inputRTDConfig.minChannel, &inputRTDConfig.maxChannel, minChannel, maxChannel);
/* Query for Trigger Status of interrupts */
if (!bQuit)
{
bQuit = GetRTDLatchStatusTriggerMode(&inputInterruptConfig.interrupt_Edge_Trigger);
}
/* Query user if they'd like to be prompted for clearing interrupts */
if (!bQuit)
{
bQuit = QueryUserForClearingInterruptPrompts(&inputInterruptConfig.bPromptForInterruptClear);
}
if (!bQuit)
{
bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
}
/* Query user for location interrupt will be sent out to */
if (!bQuit)
{
bQuit = GetIntSteeringTypeFromUser(&inputInterruptConfig.steering);
}
if (!bQuit)
{
if (inputInterruptConfig.displayData)
fifoDataFile = stdout;
else
fifoDataFile = fopen("fifoData.txt", "w+");
/**** 2. Implement Bus Interrupt Handling ****/
setIRQ(inputInterruptConfig.steering, &inputInterruptConfig.irq);
inputInterruptConfig.cardIndex = inputRTDConfig.cardIndex;
if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOnboardIsr, NULL));
}
else
{
check_status(naibrd_InstallISR(inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOffboardIsr, (void*)&inputRTDConfig.cardIndex));
}
/**** 3. configure Module to perform interrupts ****/
configureRTDToInterruptOnRx(inputInterruptConfig, inputRTDConfig);
/**** Initialize Message Queue ****/
InitInterruptAppThread(ONBOARD_INT, 0);
nai_msDelay(10);
UpdateThreadState(RUN);
/**** Enable Interrupts ****/
enableRTDInterrupts(inputRTDConfig, TRUE);
/*** 5. Show Interrupt Handling (contains step 6) ***/
rtdIntProcessFunc = handleRTDInterrupt;
/*** Display RTD Interrupt Message ***/
DisplayMessage_RTDInterrupt(MSG_BANNER_RTD_INT);
/**** Wait on program threads ****/
while (!isThreadStateTerminated())
{
}
bQuit = TRUE;
if (!inputInterruptConfig.displayData)
fclose(fifoDataFile);
/***** 7. Clear Module Configurations *****/
enableRTDInterrupts(inputRTDConfig, FALSE);
/***** 8. Clear Board Configurations *****/
check_status(naibrd_UninstallISR(inputInterruptConfig.cardIndex));
}
return bQuit;
}