AR Interrupt Basic
Edit this on GitLab
AR Interrupt Basic
Explanation
About AR_Interrupt_Basic C Sample Code
This sample application demonstrates how to handle interrupts on a single channel when an Automatic Repeat (AR) message is received using North Atlantic Industries (NAI) libraries. The application highlights the interaction with NAI’s embedded function modules via the naibrd
library.
Key Functional Areas 1. Include Declarations: These manage essential libraries and headers required for the application’s functionality. 2. Configurations: Configuring the device and module according to predefined settings specified in the configuration file. 3. Interrupt Handling: Setting up interrupts and the appropriate handler routines. 4. Main Function: Orchestrate the board access and interactions. 5. Interrupt Execution: Running the AR interrupt procedure step-by-step, as outlined in the NAI SSK Quick Guide.
Include Declarations
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Specific module and common includes
#include "nai_ar_int.h"
#include "nai_ar_cfg.h"
// Sample program includes
#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"
// Specific NAI Board Library files
#include "functions/naibrd_ar.h"
These includes allow the application to access necessary functions and definitions from the NAI libraries, ensuring proper control over the AR interrupts and board configuration.
Application Name and Revision Declaration
static const int8_t *CONFIG_FILE = (int8_t *)"default_AR_Interrupt_Basic.txt";
The configuration file named default_AR_Interrupt_Basic.txt
is utilized to load predefined settings for the application.
Internal Function Prototypes
static bool_t Run_AR_Interrupt_Basic();
A static function prototype is declared to encapsulate the interrupt running logic.
Main Routine
#if defined (__VXWORKS__)
int32_t AR_Interrupt_Basic(void)
#else
int32_t main(void)
#endif
{
// Function logic here...
}
The main function conditionally supports different operating systems (like VXWORKS). It handles: - Accessing and configuring the board, - Querying user inputs for card and module numbers, - Running the AR interrupt.
Key Steps in Main Function 1. Initialization:
initializeARConfigurations(0,0,0,0,0,0,MAX_FIFO_COUNT, DEF_AR_TIMESTAMP,FALSE);
initializeInterruptConfigurations(FALSE,FALSE,FALSE,0,0,0,0);
-
Menu Interaction:
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
// Queries and logic here ...
}
-
User Queries: For card index and module number.
-
Run AR Interrupt Process:
if ((inputARConfig.modid != 0))
{
Run_AR_Interrupt_Basic();
}
-
Finalization:
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
Run_AR_Interrupt_Basic Function
This function executes the main interrupt handling procedure:
Major Steps: 1. Configure Interrupt Handling:
setIRQ(inputInterruptConfig.steering, &inputInterruptConfig.irq);
check_status(naibrd_InstallISR(inputARConfig.cardIndex, inputInterruptConfig.irq, basic_ISR_AR, NULL));
-
Enable Module Interrupts:
configureARToInterruptOnRx(inputInterruptConfig, inputARConfig);
enableARInterrupts(inputARConfig, TRUE);
-
Set Module to Cause Rx Interrupt:
Cfg_Rx_AR(inputARConfig);
-
Check for Interrupts:
bQuit = checkForARInterrupt(inputARConfig);
-
Clear Configurations:
check_status(naibrd_AR_SetRxEnable(inputARConfig.cardIndex, inputARConfig.module, inputARConfig.channel, FALSE));
check_status(naibrd_AR_ClearStatus(inputARConfig.cardIndex, inputARConfig.module, inputARConfig.channel, 0xFFFF));
check_status(naibrd_UninstallISR(inputARConfig.cardIndex));
This thorough procedure ensures the module is properly set up to receive, handle, and clear interrupts, adhering to best practices for embedded interrupt handling as guided by NAI’s documentation.
This documentation should aid users in understanding the purpose and flow of the provided AR_Interrupt_Basic sample code. It provides a clear step-by-step explanation of how to configure and manage interrupts for an AR message using NAI’s libraries and functions.
/**************************************************************************************************************/
/**
<summary>
The AR_Interrupt_Basic 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.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"
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_AR_Interrupt_Basic.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_AR_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 AR_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;
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_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 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_cfg.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 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_AR_ClearStatusRaw
7. Clear Module Configurations
API CALLS - naibrd_AR_SetRxEnable
8. Clear Board Configurations
API CALLS - naibrd_UninstallISR
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_AR_Interrupt_Basic()
{
bool_t bQuit = FALSE;
inputARConfig.maxChannel = NAI_GEN5_AR_MAX_CHANNEL_COUNT;
inputARConfig.minChannel = 1;
/* Query user for RX channel */
if (!bQuit)
{
printf( "\nWhich channel would you like to Receive on? \n" );
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 );
}
/* Query user for location interrupt will be sent out to */
if (!bQuit)
{
bQuit = GetIntSteeringTypeFromUser( &inputInterruptConfig.steering );
}
if (!bQuit)
{
bQuit = QueryUserForTimeStampEnable( &inputARConfig.timeStampEnable );
}
if (!bQuit)
{
/**** 2. Implement Bus Interrupt Handling ****/
setIRQ( inputInterruptConfig.steering, &inputInterruptConfig.irq );
check_status( naibrd_InstallISR( inputARConfig.cardIndex, inputInterruptConfig.irq, basic_ISR_AR, NULL ) );
/**** 3. configure Module to perform interrupts ****/
configureARToInterruptOnRx( inputInterruptConfig, inputARConfig );
enableARInterrupts( inputARConfig, TRUE );
/**** 4. Configure Module to cause Interrupts ****/
Cfg_Rx_AR( inputARConfig );
/**** 5. Show Interrupt Handling (contains step 6) ****/
bQuit = checkForARInterrupt( inputARConfig );
/***** 7. Clear Module Configurations *****/
check_status( naibrd_AR_SetRxEnable( inputARConfig.cardIndex, inputARConfig.module, inputARConfig.channel, FALSE ) );
check_status( naibrd_AR_ClearStatus( inputARConfig.cardIndex, inputARConfig.module, inputARConfig.channel, 0xFFFF ) );
/***** 8. Clear Board Configurations *****/
check_status( naibrd_UninstallISR( inputARConfig.cardIndex ) );
}
return bQuit;
}