AR Interrupt Ethernet
Edit this on GitLab
AR Interrupt Ethernet
Explanation
About the AR_Interrupt_Ethernet Sample Application
This document provides an explanation of the AR_Interrupt_Ethernet sample application code. This program demonstrates how to perform an interrupt when a specific channel receives an AR (ARINC 429) message using the North Atlantic Industries (NAI) naibrd library and embedded function modules. This document provides detailed insights into the structure and functionality of the code.
Key File and Module Inclusions
-
Header Files:
-
stdio.h
,stdlib.h
,string.h
,time.h
: Standard C libraries. -
NAI-specific headers for AR and Ethernet functionalities such as
nai_ar_int_ether.h
,nai_ar_int.h
,nai_ar_cfg.h
, etc. -
Include declarations for board access, interrupt handling, and utility functions.
Static Variables and Constants
-
Static Data Declarations:
-
IPv4 address for receiving responses.
-
Command buffer for Ethernet IDR commands.
-
Boolean flag for displaying Ethernet UPR.
-
Configuration file name.
Main Routine
The main routine is responsible for initializing configurations, querying user inputs, and running the board menu. Here’s a breakdown of its key steps:
-
Initialization:
-
Initializes the AR configurations, interrupt configurations, and IDR configurations.
-
-
Running the Board Menu:
-
Obtains user input to select card index and module number.
-
Validates the chosen module ID.
-
Calls
Run_AR_Interrupt_Basic_Ethernet()
to handle the Ethernet-specific interrupt logic.
-
-
Loop Control:
-
Provides an option to quit or restart the application.
-
Closes all open cards before exiting.
-
Run_AR_Interrupt_Basic_Ethernet Function
This function contains the core logic for handling Ethernet-based AR interrupts. The major steps are:
-
Validations:
-
Checks if the AR module supports Generation 4 Ethernet commands.
-
Queries the user for channel number, interrupt trigger status, IDR configuration, onboard/offboard interrupt processing, and more.
-
-
Configurations:
-
Sets up IDR to handle interrupts.
-
Configures the module to generate interrupts when receiving AR messages.
-
Sets bit timing and enables specific channels to receive ARINC messages.
-
-
Interrupt Handling:
-
Starts the IDR and waits for interrupts.
-
Displays or logs the interrupt data.
-
-
Cleanup:
-
Disables receiving for the specific channel.
-
Clears the IDR and module configurations.
-
Internal Function Prototypes
The internal functions used for configuration and querying user input are declared as static:
-
initializeARConfigurations()
,initializeInterruptConfigurations()
,initializeIDRConfigurations()
: Set initial configurations. -
naiapp_RunBoardMenu()
: Runs the board access menu. -
naiapp_query_CardIndex()
,naiapp_query_ModuleNumber()
: Queries user for card index and module number.
Key API Calls and Usage
The sample application uses various API functions from the naibrd library to configure and handle Ethernet interrupts, such as:
-
naibrd_Ether_SetIDRConfig()
,naibrd_Ether_StartIDR()
,naibrd_Ether_ClearIDRConfig()
. -
naibrd_AR_SetInterruptEdgeLevel()
,naibrd_AR_SetIntVector()
,naibrd_AR_SetInterruptSteering()
,naibrd_AR_SetIntEnable()
. -
naibrd_AR_SetBitTiming()
,naibrd_AR_SetRxEnable()
,naibrd_AR_ClearStatus()
.
These functions are responsible for setting up Ethernet IDR, enabling module interrupts, configuring AR channels, and handling interrupts.
Conclusion
The AR_Interrupt_Ethernet sample application demonstrates how to set up and handle interrupts for ARINC 429 messages over Ethernet using NAI’s function modules and the naibrd library. By following the steps outlined in the code and the associated naibrd SSK Quick Guide, users can effectively configure and manage AR interrupts in their embedded applications.
/**************************************************************************************************************/
/**
<summary>
The AR_Interrupt_Ethernet 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.
</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_ether.h"
#include "nai_ar_int.h"
#include "nai_ar_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_ar.h"
#include "maps/nai_map_ar.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];
bool_t bDisplayEtherUPR;
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_AR_Interrupt_Ethernet.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_AR_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 AR_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;
initializeARConfigurations( 0, 0, 0, 0, 0, 0, MAX_FIFO_COUNT, DEF_AR_TIMESTAMP, FALSE);
initializeInterruptConfigurations(FALSE,FALSE,FALSE,0,0,0,0);
initializeIDRConfigurations(0,0,DEF_RX_RESPONSE_PROTOCOL,DEF_RX_RESPONSE_PORT,
DEF_RX_RESPONSE_IPv4_ADDR, DEF_RX_RESPONSE_IPv4_LENGTH,
COMMANDS,0,ETHERNET_OVERHEAD_FIFO_COMMAND,DEF_ETHERNET_AR_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);
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_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 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 defined in nai_ar_cfg.h
It also enables the particular channel on the module to receive ARINC messages
API CALLS - naibrd_AR_SetBitTiming , naibrd_AR_SetRxEnable
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_AR_SetRxEnable, naibrd_AR_ClearStatus
8. Clear Board Configurations
API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_AR_Interrupt_Basic_Ethernet()
{
bool_t bQuit = FALSE;
bool_t bGen4ArIDRCommands;
inputARConfig.maxChannel = naibrd_AR_GetChannelCount( inputARConfig.modid );
inputARConfig.minChannel = 1;
/* check if AR module supports GEN 4 Ethernet */
bGen4ArIDRCommands = SupportsGen4Ether( inputARConfig.cardIndex );
if ( !bGen4ArIDRCommands )
{
printf( "AR Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n" );
bQuit = TRUE;
}
if (!bQuit)
{
bQuit = naiapp_query_ChannelNumber( inputARConfig.maxChannel, inputARConfig.minChannel, &inputARConfig.channel );
}
/* Query user for Trigger Status of interrupts */
if (!bQuit)
{
bQuit = GetARLatchStatusTriggerMode( &inputInterruptConfig.interrupt_Edge_Trigger );
}
if (!bQuit)
{
bQuit = QueryIDRConfigInformation( &inputIDRConfig );
}
if (!bQuit)
{
bQuit = QueryUserForOnboardOffboardInterrupts( &inputInterruptConfig.bProcessOnboardInterrupts );
}
if (!bQuit)
{
bQuit = QueryUserForEtherIDRMsgDisplay( &bDisplayEtherUPR );
}
if (!bQuit)
{
bQuit = QueryUserForDisplayingData( &inputInterruptConfig.displayData );
}
if (!bQuit)
{
bQuit = QueryUserForTimeStampEnable( &inputARConfig.timeStampEnable );
}
if (!bQuit)
{
if ( inputInterruptConfig.displayData )
fifoDataFile = stdout;
else
fifoDataFile = fopen( "AR_Interrupt_FIFO_Data.txt", "w+" );
/**** 2. Setup IDR to Handle Interrupt (also contains step 6) ****/
if ( inputInterruptConfig.bProcessOnboardInterrupts == TRUE )
{
inputIDRConfig.cardIndex = inputARConfig.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;
}
setupIDRConfiguration_AR( inputARConfig, &inputIDRConfig, bGen4ArIDRCommands );
check_status( naibrd_Ether_StartIDR( inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_AR_IDR_ID ) );
/**** 3. configure module To Interrupt ****/
configureARToInterruptOnRx( inputInterruptConfig, inputARConfig );
enableARInterrupts( inputARConfig, AR_RX_DATA_AVAIL );
/**** 4. Configure AR to cause Interrupts ****/
Cfg_Rx_AR( inputARConfig );
/**** 5. Show Interrupt Handling ****/
AR_ClearInterrupt = ClearInterrupt_AR;
arEtherIntFunc = HandleAREtherInterrupt;
bQuit = runIDRServer( inputIDRConfig );
/***** 7. Clear Module Configurations *****/
check_status( naibrd_AR_SetRxEnable( inputARConfig.cardIndex, inputARConfig.module, inputARConfig.channel, FALSE ) );
enableARInterrupts( inputARConfig, FALSE );
/***** 8. Clear Board Configurations *****/
check_status( naibrd_Ether_StopIDR( inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_AR_IDR_ID ) );
check_status( naibrd_Ether_ClearIDRConfig( inputIDRConfig.cardIndex, DEF_ETHERNET_AR_IDR_ID ) );
}
return bQuit;
}