AR Interrupt
Edit this on GitLab
AR Interrupt
Explanation
AR_Interrupt Application Overview
Application Description
The AR_Interrupt application demonstrates how to handle interrupts for a single channel when an AR message is received, leveraging the naibrd library for interaction with North Atlantic Industries (NAI) embedded function modules. This application extends the basic AR interrupt handling to support multiple interrupts simultaneously and allows for customizable edge trigger values. Additionally, it offers prompt options for user interaction and supports both onboard and offboard interrupts.
Include Declarations
The application includes necessary standard libraries and specific NAI headers:
- Standard Libraries: <stdio.h>
, <stdlib.h>
, <string.h>
, <time.h>
- NAI Specific Headers:
- nai_ar_int.h
, nai_ar_cfg.h
, nai_ar_utils.h
(AR module configurations)
- include/naiapp_interrupt.h
, include/naiapp_interrupt_ether.h
(Interrupt utilities)
- include/naiapp_boardaccess_query.h
, include/naiapp_boardaccess_access.h
, include/naiapp_boardaccess_display.h
, include/naiapp_boardaccess_utils.h
(Board access utilities)
- nai.h
, naibrd.h
(core library headers)
- functions/naibrd_ar.h
(AR specific functions)
Application Name and Revision Declaration
The configuration file is declared as:
static const int8_t *CONFIG_FILE = (int8_t *)"default_AR_Interrupt.txt";
Internal Function Prototypes
An internal function prototype is declared:
static bool_t Run_AR_Interrupt();
Main Routine
The main routine identifies and configures the board, then handles and routes the interrupts using the defined process.
Main Function Details
-
Initialization:
-
Configuration is initialized using
initializeARConfigurations
andinitializeInterruptConfigurations
with default values. -
Board Access and Configuration:
-
The application runs a board menu using
naiapp_RunBoardMenu(CONFIG_FILE)
to interact with the user and configure the board. -
It repeatedly queries the user for the card index and module number.
-
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt))
retrieves the number of modules on the card. -
Run_AR_Interrupt()
is invoked if a valid module ID is found. -
User Interaction Loop:
-
The user is prompted to restart the application or quit using
naiapp_query_ForQuitResponse
. -
Clean Up:
-
All open cards are closed with
naiapp_access_CloseAllOpenCards()
before exiting.
Run_AR_Interrupt Function
The Run_AR_Interrupt
function manages the core steps to configure and handle AR interrupts.
Function Steps
-
Channel Query:
-
Retrieves the range of channels to operate on using
naiapp_query_ForChannelRange
.
-
-
Trigger Status and User Prompts:
-
Queries the user for interrupt edge trigger settings using
GetARLatchStatusTriggerMode
. -
Prompts user interaction for clearing interrupts with
QueryUserForClearingInterruptPrompts
. -
Queries for onboard/offboard interrupt processing using
QueryUserForOnboardOffboardInterrupts
. -
Optionally, queries for displaying FIFO data using
QueryUserForDisplayingData
. -
Retrieves interrupt steering type with
GetIntSteeringTypeFromUser
.
-
-
Time Stamp and File Handling:
-
Enables/disables timestamp using
QueryUserForTimeStampEnable
. -
Opens the FIFO data file for writing.
-
-
Bus Interrupt Handling:
-
Sets up the IRQ using
setIRQ
. -
Installs the ISR for onboard or offboard interrupts using
naibrd_InstallISR
.
-
-
Module Configuration:
-
Configures the module to interrupt upon receiving an AR message using
configureARToInterruptOnRxMultiChan
.
-
-
Module and Interrupt Enable:
-
Enables the specific channels to receive interrupts using
enableARInterrupts
.
-
-
Interrupt Handling:
-
Displays necessary messages to guide users manually triggering interrupts.
-
Waits for the interrupts and handles with
handleARInterrupt
.
-
-
Clean Up:
-
Disables the interrupts for each channel and clears the status using
naibrd_AR_ClearStatus
. -
Uninstalls the ISR using
naibrd_UninstallISR
.
-
Conclusion
The AR_Interrupt example application showcases how to configure and handle interrupts on NAI embedded function modules using the naibrd library. The program provides user interaction, interrupt configuration, and handling details, making it a comprehensive guide for managing AR interrupts.
/**************************************************************************************************************/
/**
<summary>
The AR_Interrupt program demonstrates how to perform an interrupt when a single channel receives
an ar 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.
This application differs from AR_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_ar_int.h"
#include "nai_ar_cfg.h"
#include "nai_ar_utils.h"
/* 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"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_ar.h"
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_AR_Interrupt.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_AR_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 AR_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;
initializeARConfigurations(0,0,0,0,0,0,MAX_FIFO_COUNT, DEF_AR_TIMESTAMP,FALSE);
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);
inputARConfig.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);
inputARConfig.module = module;
if (stop != TRUE)
{
inputARConfig.modid = naibrd_GetModuleID(cardIndex, module);
if ((inputARConfig.modid != 0))
{
Run_AR_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 channel receives AR message.
API CALLS - naibrd_AR_SetInterruptEdgeLevel, naibrd_AR_SetIntVector, naibrd_AR_SetInterruptSteering, naibrd_AR_SetIntEnable
4. Configure Module to Cause Rx Interrupt - sets the BAUD Rate to 1mbit/s (AR AB) or 500k bits/s (AR J1939) as definted in nai_ar_utils.h
It also enables the particular channel on the module to receive ar messages
API CALLS - naibrd_AR_SetBitTiming , naibrd_AR_SetRxEnable
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_AR_ClearStatus
7. Clear Module Configurations
API CALLS - naibrd_AR_SetRxEnable
8. Clear Board Configurations
API CALLS - naibrd_UninstallISR
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_AR_Interrupt()
{
bool_t bQuit = FALSE;
int32_t minChannel;
int32_t maxChannel;
minChannel = 1;
maxChannel = naibrd_AR_GetChannelCount( inputARConfig.modid );
/* Query for Channels to Operate on */
bQuit = naiapp_query_ForChannelRange( &inputARConfig.minChannel, &inputARConfig.maxChannel, minChannel, maxChannel );
/* Query for Trigger Status of interrupts */
if (!bQuit)
{
bQuit = GetARLatchStatusTriggerMode( &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 if they'd like to display fifo data after interrupt */
if (!bQuit)
{
bQuit = QueryUserForDisplayingData( &inputInterruptConfig.displayData );
}
/* Query user for location interrupt will be sent out to */
if (!bQuit)
{
bQuit = GetIntSteeringTypeFromUser( &inputInterruptConfig.steering );
}
if (!bQuit)
{
bQuit = QueryUserForTimeStampEnable(&inputARConfig.timeStampEnable );
}
if (!bQuit)
{
int32_t chan;
if ( inputInterruptConfig.displayData )
fifoDataFile = stdout;
else
fifoDataFile = fopen( "fifoData.txt", "w+" );
/**** 2. Implement Bus Interrupt Handling ****/
setIRQ( inputInterruptConfig.steering, &inputInterruptConfig.irq );
if ( inputInterruptConfig.bProcessOnboardInterrupts == TRUE )
{
inputInterruptConfig.cardIndex = inputARConfig.cardIndex;
check_status( naibrd_InstallISR( inputInterruptConfig.cardIndex, inputInterruptConfig.irq, (nai_isr_t)IntOnboardIsr, NULL ) );
}
else
{
inputInterruptConfig.cardIndex = 0;
check_status( naibrd_AR_SetInterruptSteering( inputInterruptConfig.cardIndex, inputARConfig.module, inputARConfig.channel, NAIBRD_INT_STEERING_ON_BOARD_0 ) );
check_status( naibrd_InstallISR( inputInterruptConfig.cardIndex, NAIBRD_IRQ_ID_ON_BOARD_0, (nai_isr_t)IntOffboardIsr, (void*)&inputARConfig.cardIndex ) );
}
/**** 3. configure Module to perform interrupts ****/
configureARToInterruptOnRxMultiChan( inputInterruptConfig, inputARConfig );
/**** 4. Configure Module to cause Interrupts ****/
Cfg_Rx_AR( inputARConfig );
/**** Initialize Message Queue ****/
InitInterruptAppThread( ONBOARD_INT, 0 );
nai_msDelay( 10 );
UpdateThreadState( RUN );
/**** Enable Interrupts ****/
enableARInterrupts( inputARConfig, AR_RX_DATA_AVAIL );
/*** 5. Show Interrupt Handling (contains step 6) ***/
arIntProcessFunc = handleARInterrupt;
/*** Request user triggers interrupt ***/
DisplayMessage_ARInterrupt( MSG_BANNER_AR_INT );
DisplayMessage_ARInterrupt( MSG_USER_TRIGGER_AR_INT );
/**** Wait on program threads ****/
while ( !isThreadStateTerminated() )
{
}
bQuit = TRUE;
if ( !inputInterruptConfig.displayData )
fclose( fifoDataFile );
/***** 7. Clear Module Configurations *****/
enableARInterrupts( inputARConfig, FALSE );
for ( chan = inputARConfig.minChannel; chan <= inputARConfig.maxChannel; chan++ )
{
check_status( naibrd_AR_SetRxEnable( inputARConfig.cardIndex, inputARConfig.module, chan, FALSE ) );
check_status( naibrd_AR_ClearStatus( inputARConfig.cardIndex, inputARConfig.module, chan, 0xFFFF ) );
}
/***** 8. Clear Board Configurations *****/
check_status( naibrd_UninstallISR( inputInterruptConfig.cardIndex ) );
}
return bQuit;
}