RLY Interrupt Basic
Edit this on GitLab
RLY Interrupt Basic
Explanation
About the Sample Application Code: RLY_Interrupt_Basic
Overview
The RLY_Interrupt_Basic
program demonstrates the implementation of an interrupt mechanism when a single channel receives a relay (RLY) message. This program is designed to illustrate the use of method calls from the naibrd
library to perform interrupts. Detailed documentation on this process can be found in the naibrd
SSK Quick Guide under the Interrupts section.
Code Structure
Include Declarations
The program begins by including necessary header files for functionality and configuration:
- Standard C libraries for basic functionalities: stdio.h
, stdlib.h
, string.h
, and time.h
.
- Sample program-specific headers (e.g., nai_rly_cfg.h
, nai_rly_int.h
).
- General sample program headers (e.g., naiapp_interrupt.h
, naiapp_boardaccess_menu.h
).
- naibrd
library headers (e.g., nai.h
, naibrd.h
).
- Relay-specific board library header: naibrd_rly.h
.
Internal Function Prototypes
Prototype for the main function that runs the RLY Interrupt Basic program:
static bool_t Run_RLY_Interrupt_Basic();
Main Routine
The main routine is the entry point of the application, responsible for initializing configurations, querying user inputs, and managing the main loop to handle board and interrupt configurations.
#if defined (__VXWORKS__)
int32_t RLY_Interrupt_Basic(void)
#else
int32_t main(void)
#endif
{
// Local variables initialization
// Configuration initialization
// Conditional execution based on configuration
// Query card index and module number
// Handle user inputs and restart logic
// Close open cards and exit
}
Function: Run_RLY_Interrupt_Basic
This function carries out the core logic for handling interrupts in a sequence of steps, as per the naibrd
SSK Quick Guide:
-
Bus Interrupt Handling - Install ISR: Use
naibrd_InstallISR
to install an Interrupt Service Routine (ISR). -
Enable Module Interrupts: Configure the relay module to generate interrupts on receiving messages by invoking:
-
naibrd_RLY_SetInterruptEdgeLevel
-
naibrd_RLY_SetIntVector
-
naibrd_RLY_SetInterruptSteering
-
naibrd_RLY_SetIntEnable
-
-
Show Interrupt Handling: Monitor and report interrupts using the
checkForRLYInterrupt
method. -
Re-arm Interrupts: Clear the status register to allow future interrupts via
naibrd_RLY_ClearStatusRaw
. -
Clear Module and Board Configurations: Disable interrupts and uninstall the ISR using
naibrd_UninstallISR
.
static bool_t Run_RLY_Interrupt_Basic()
{
// Query user for RX channel and interrupt steering type
// Install ISR
// Configure module to generate interrupts
// Show and re-arm interrupts
// Clear configurations
}
Key Functions and API Calls
The primary API calls used in the program include: - naibrd_InstallISR: Install an ISR for handling interrupts. - naibrd_RLY_SetInterruptEdgeLevel: Set the edge level triggering for relay interrupts. - naibrd_RLY_SetIntVector: Set the interrupt vector for the relay. - naibrd_RLY_SetInterruptSteering: Configure the steering for interrupts. - naibrd_RLY_SetIntEnable: Enable the configured interrupts. - naibrd_RLY_ClearStatusRaw: Clear the status register to re-arm interrupts. - naibrd_UninstallISR: Uninstall the ISR and clear configurations.
Conclusion
This sample application provides a clear example of how to manage relay interrupts using North Atlantic Industries' naibrd
library. It includes proper configurations, user input queries, and clean-up routines to ensure efficient and correct usage of the relays and interrupts. Detailed study of the accompanying functions and API calls will give further insights into the practical handling of hardware interrupts in embedded systems using NAI products.
/**************************************************************************************************************/
/**
<summary>
The RLY_Interrupt_Basic program demonstrates how to perform an interrupt when a single channel receives
a 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_rly_cfg.h"
#include "nai_rly_int.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_rly.h"
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
/*
static const int8_t *App_Name = "RLY Interrupt Basic";
static const int8_t *App_Rev = "1.0";
*/
static const int8_t *CONFIG_FILE = (int8_t *)"default_RLY_Interrupt_Basic.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_RLY_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 RLY_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;
initializeRLYConfigurations(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);
inputRLYConfig.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);
inputRLYConfig.module = module;
if (stop != TRUE)
{
inputRLYConfig.modid = naibrd_GetModuleID(cardIndex, module);
if ((inputRLYConfig.modid != 0))
{
Run_RLY_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 interrupter when channel receives RLY message.
API CALLS - naibrd_RLY_SetInterruptEdgeLevel, naibrd_RLY_SetIntVector, naibrd_RLY_SetInterruptSteering, naibrd_RLY_SetIntEnable
4. Not applicable to DSW 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_RLY_ClearStatusRaw
7. Clear Module Configurations
8. Clear Board Configurations
API CALLS - naibrd_UninstallISR
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_RLY_Interrupt_Basic()
{
bool_t bQuit = FALSE;
/* Query user for RX channel */
inputRLYConfig.maxChannel = naibrd_RLY_GetChannelCount(inputRLYConfig.modid);
inputRLYConfig.minChannel = 1;
/*if(!bQuit)
{
printf("\nWhich channel would you like to Receive on? \n");
bQuit = GetChannelNumber(inputDSWConfig.maxChannel,inputDSWConfig.minChannel,&inputDSWConfig.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(inputRLYConfig.cardIndex, inputInterruptConfig.irq, basic_ISR_RLY, NULL);
/****3. configure Module to perform interrupts****/
configureRLYToInterruptOnRx(inputInterruptConfig, inputRLYConfig);
enableRLYInterrupts(inputRLYConfig, TRUE);
/****5. Show Interrupt Handling (contains step 6)****/
bQuit = checkForRLYInterrupt(inputRLYConfig);
/*****7. Clear Module Configurations*****/
enableRLYInterrupts(inputRLYConfig, FALSE);
/*****8. Clear Board Configurations *****/
check_status(naibrd_UninstallISR(inputRLYConfig.cardIndex));
}
return bQuit;
}