RTD Interrupt Ethernet
Edit this on GitLab
RTD Interrupt Ethernet
Explanation
About the Code:
This sample C application from North Atlantic Industries (NAI) utilizes their Software Support Kit (SSK) to interact with embedded function modules on their boards via Ethernet. Specifically, the code demonstrates how to check for RTD (Resistance Temperature Detector) Open interrupts. Below is a detailed explanation of the code structure and the key functions.
Definitions and Inclusions:
-
Include Files: The application includes standard C libraries (
stdio.h
,stdlib.h
,string.h
,time.h
) and several specific include files relevant to NAI modules and their utility functions. These files are grouped as: -
RTD specific (
nai_rtd_int_ether.h
,nai_rtd_int.h
,nai_rtd_cfg.h
) -
General application files (
naiapp_interrupt.h
,naiapp_boardaccess_menu.h
, etc.) -
NAI board library files (
nai.h
,naibrd.h
) -
Specific NAI RTD functions (
naibrd_rtd.h
,nai_map_rtd.h
) -
Configuration Variables:
c static uint8_t DEF_RX_RESPONSE_IPv4_ADDR[] = { 192,168,1,100 }; static uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT]; bool_t bDisplayEtherUPR; static const int8_t *CONFIG_FILE = (int8_t *)"default_RTD_Interrupt_Ethernet.txt";
Main Routine:
-
Function:
c int32_t main(void)
-
Purpose: The
main()
function initializes the RTD and interrupt configurations and interacts with the user to select the appropriate board and module. -
Key Actions:
-
Initialization:
c initializeRTDConfigurations(0, 0, 0, 0, 0, 0); initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, NAIBRD_INT_STEERING_ON_BOARD_1, -1, 0); initializeIDRConfigurations(0, 0, DEF_RX_RESPONSE_PROTOCOL, DEF_RX_RESPONSE_PORT, DEF_RX_RESPONSE_IPv4_ADDR, DEF_RX_RESPONSE_IPv4_LENGTH, COMMANDS, 0, 0, DEF_ETHERNET_RTD_IDR_ID);
-
Running Board Menu:
c if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
-
-
This checks and loads the configuration for the board if available.
-
User Interactions:
-
-
Queries for card index and module using
naiapp_query_CardIndex
andnaiapp_query_ModuleNumber
. -
Checks the module ID and if valid, calls
Run_RTD_Interrupt_Basic_Ethernet
.-
Exit Handling:
c printf("\nType the Enter key to exit the program: "); naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt); naiapp_access_CloseAllOpenCards(); return 0;
-
RTD Interrupt Handling Function:
-
Function:
c static bool_t Run_RTD_Interrupt_Basic_Ethernet()
-
Purpose: This function encapsulates the process of setting up and handling RTD Open interrupts over Ethernet. It follows the steps outlined in the naibrd SSK Quick Guide.
-
Key Actions:
-
Channel Query:
c bQuit = naiapp_query_ChannelNumber(inputRTDConfig.maxChannel, inputRTDConfig.minChannel, &inputRTDConfig.channel);
-
IDR (Interrupt Data Register) Setup:
-
-
Configures the IDR to handle Ethernet-based interrupts:
c check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RTD_IDR_ID));
-
Module Interrupt Configuration:
-
-
Configures the RTD module to raise interrupts:
c configureRTDToInterruptOnRx(inputInterruptConfig, inputRTDConfig); enableRTDInterrupts(inputRTDConfig, TRUE);
-
Interrupt Handling:
-
-
Handles the display and decoding of interrupt data:
c RTD_ClearInterrupt = ClearInterrupt_RTD; rtdEtherIntFunc = HandleRTDEtherInterrupt; bQuit = runIDRServer(inputIDRConfig);
-
Cleanup Configurations:
-
-
Clears configurations and stops the IDR:
c enableRTDInterrupts(inputRTDConfig, FALSE); check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RTD_IDR_ID)); check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RTD_IDR_ID));
-
The
Run_RTD_Interrupt_Basic_Ethernet
function ensures that interrupts are appropriately set up and handled, demonstrating how to use NAI’s SSK for practical interrupt management over an Ethernet connection.
Conclusion: This application is a comprehensive sample showcasing the use of NAI’s SSK for processing RTD interrupts via Ethernet. It includes initialization, configuration, user interaction for module selection, setting up interrupts, and handling interrupt responses. Each step is clearly demarcated and follows the guidelines provided in NAI’s documentation.
/**************************************************************************************************************/
/**
<summary>
The RTD_Interrupt_Ethernet program demonstrates how to check for RTD Open interrupts via Ethernet 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_ether.h"
#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"
#include "maps/nai_map_rtd.h"
static uint8_t DEF_RX_RESPONSE_IPv4_ADDR[] = { 192,168,1,100 };
static uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT];
/*********************************************/
/* Program Configurations */
/*********************************************/
bool_t bDisplayEtherUPR;
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_RTD_Interrupt_Ethernet.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_RTD_Interrupt_Basic_Ethernet();
/**************************************************************************************************************/
/***** 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_Ethernet(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, NAIBRD_INT_STEERING_ON_BOARD_1, -1, 0);
initializeIDRConfigurations(0, 0, DEF_RX_RESPONSE_PROTOCOL, DEF_RX_RESPONSE_PORT, DEF_RX_RESPONSE_IPv4_ADDR, DEF_RX_RESPONSE_IPv4_LENGTH, COMMANDS, 0, 0, DEF_ETHERNET_RTD_IDR_ID);
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_Ethernet();
}
}
}
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.
2a. Ethernet Interrupt Handling - Setup IDR to handle interrupt
API CALLS - naibrd_Ether_SetIDRConfig, naibrd_Ether_StartIDR,naibrd_Ether_ClearIDRConfig
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 - The IDR server will listen on the boards ports for IDRs indicating an interrupt.
These results will be decoded and displayed to the user.
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, the write command is included in the IDR.
API CALLS - nai_ether_BeginWriteMessage, nai_ether_WriteMessageData, nai_ether_FinishMessage
7. Clear Module Configurations
API CALLS - naibrd_RTD_SetInterruptEnableRaw
8. Clear Board Configurations
API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_RTD_Interrupt_Basic_Ethernet()
{
bool_t bQuit = FALSE;
bool_t bGen4RtdIDRCommands;
inputRTDConfig.maxChannel = naibrd_RTD_GetChannelCount(inputRTDConfig.modid);
inputRTDConfig.minChannel = 1;
/* check if RTD module supports GEN 4 Ethernet */
bGen4RtdIDRCommands = SupportsGen4Ether(inputRTDConfig.cardIndex);
if (!bGen4RtdIDRCommands)
{
printf("RTD Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
bQuit = TRUE;
}
if (!bQuit)
{
bQuit = naiapp_query_ChannelNumber(inputRTDConfig.maxChannel, inputRTDConfig.minChannel, &inputRTDConfig.channel);
}
if (!bQuit)
{
bQuit = QueryIDRConfigInformation(&inputIDRConfig);
}
if (!bQuit)
{
bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
}
if (!bQuit)
{
bQuit = QueryUserForEtherIDRMsgDisplay(&bDisplayEtherUPR);
}
if (!bQuit)
{
if (inputInterruptConfig.displayData)
fifoDataFile = stdout;
else
fifoDataFile = fopen("RTD_Interrupt_FIFO_Data.txt", "w+");
/**** 2. Setup IDR to Handle Interrupt (also contains step 6) ****/
if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
inputIDRConfig.cardIndex = inputRTDConfig.cardIndex;
inputIDRConfig.boardInterface = NAI_INTF_ONBOARD;
inputInterruptConfig.steering = NAIBRD_INT_STEERING_ON_BOARD_1;
}
else /* OffBoard Interrupt */
{
inputIDRConfig.cardIndex = 0;
inputIDRConfig.boardInterface = NAI_INTF_PCI;
inputInterruptConfig.steering = NAIBRD_INT_STEERING_CPCI_APP;
/* Setting steering on master to listener */
}
check_status(naibrd_RTD_ClearStatusRaw(inputRTDConfig.cardIndex, inputRTDConfig.module, NAI_RTD_STATUS_OPEN_LATCHED, 0x0));
setupRTDIDRConfiguration(inputRTDConfig, &inputIDRConfig, bGen4RtdIDRCommands);
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RTD_IDR_ID));
/**** 3. configure module To Interrupt ****/
configureRTDToInterruptOnRx(inputInterruptConfig, inputRTDConfig);
enableRTDInterrupts(inputRTDConfig, TRUE);
/**** 4. Configure RTD to cause Interrupts ****/
/* Nothing needs to be done for the RTD module */
/**** 5. Show Interrupt Handling ****/
RTD_ClearInterrupt = ClearInterrupt_RTD;
rtdEtherIntFunc = HandleRTDEtherInterrupt;
bQuit = runIDRServer(inputIDRConfig);
/**** 6. Prompt User To Clear Interrupt Statuses ****/
/* Taken care of in step 2 */
/***** 7. Clear Module Configurations *****/
enableRTDInterrupts(inputRTDConfig, FALSE);
/***** 8. Clear Board Configurations *****/
check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RTD_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_RTD_IDR_ID));
}
return bQuit;
}