DS Interrupt Ethernet
Edit this on GitLab
DS Interrupt Ethernet
Explanation
About the DS_Interrupt_Ethernet Program
Overview:
The DS_Interrupt_Ethernet
program demonstrates how to perform an interrupt when a single channel receives a message. The purpose of this program is to show method calls in the naibrd
library for performing the interrupt. You can find more information on this process in the naibrd SSK Quick Guide(Interrupts)
file.
Include Declarations:
This program includes several standard C libraries and specific headers from NAI (North Atlantic Industries) necessary for defining various configurations, routines, and functionalities for interrupt handling over Ethernet.
Key Include Files:
- stdio.h
, stdlib.h
, string.h
, time.h
: Standard C libraries.
- nai_ds_int.h
, nai_ds_cfg.h
, nai_ds_int_ether.h
: DS Module related implementations like interrupt handling and configuration.
- nai.h
, naibrd.h
: NAI board-specific libraries.
- Various naiapp_*.h
files: Common application utilities for NAI board access, display, query, access and interrupt handling.
Configurations and Important Variables:
-
static uint8_t DEF_RX_RESPONSE_IPv4_ADDR[] = {192,168,1,100}
: Default RX Response IP address. -
static uint8_t COMMANDS[MAX_ETHER_IDR_CMD_CNT*MAX_ETHER_BLOCK_REG_CNT]
: Command buffer for Ethernet IDR commands. -
DsConfig inputDSConfig
: Stores DS configuration settings. -
InterruptConfig inputInterruptConfig
: Stores interrupt configuration settings.
Program Configurations:
-
static const int8_t *CONFIG_FILE
: Default configuration file used (default_DS_Interrupt_Ethernet.txt
).
Internal Function Prototypes:
-
static bool_t Run_DS_Interrupt_Basic_Ethernet()
: Handles the primary Ethernet interrupt processing.
Main Routine:
The main function initializes configurations, handles board access, and iteratively queries the user to run or exit the interrupt process.
Steps:
1. Initialize Configurations:
- Initializes DS configurations (e.g., initializeDSConfigurations
).
- Initializes Interrupt configurations (e.g., initializeInterruptConfigurations
).
-
Run Board Menu:
-
Checks if the board menu runs successfully using
naiapp_RunBoardMenu(CONFIG_FILE)
. -
If successful, it enters a loop to query card and module indices from the user.
-
Based on user input, it obtains module information and executes
Run_DS_Interrupt_Basic_Ethernet
.
-
-
Query Loop:
-
Continuously queries the user to either quit or restart the application.
-
Ends the application upon receiving a quit command.
-
Closes all open cards using
naiapp_access_CloseAllOpenCards()
.
-
Detailed Function Explanation: Run_DS_Interrupt_Basic_Ethernet()
This function is broken into several significant steps:
-
Setup IDR to Handle Interrupt:
-
Configuration for interrupt handling using
setupIDRConfiguration_DS
.
-
-
Enable Module Interrupts:
-
Configures module interrupts upon channel message receipt via APIs like
naibrd_DS_SetInterruptEdgeLevel
,naibrd_DS_SetIntVector
, etc.
-
-
Show Interrupt Handling:
-
Listens on board ports for IDRs indicating an interrupt and displays the results.
-
-
Clear Module Configurations.
-
Clear Board Configurations:
-
Stops and clears IDR configurations using
naibrd_Ether_StopIDR
andnaibrd_Ether_ClearIDRConfig
.
-
Function Steps:
-
Query for Channel Number:
-
Checks if DS module supports GEN 4 Ethernet and queries for the channel number.
-
-
Query for Interrupt and IDR Configurations:
-
Queries user for interrupt and IDR configuration preferences.
-
-
Configure and Process Interrupt:
-
Sets up and enables interrupts.
-
Handles the incoming Ethernet interrupts through the IDR server.
-
-
Clear Configurations:
-
Post processing, it clears both module and board configurations.
-
Note: Key functions to handle configurations and responses such as setupIDRConfiguration_DS
, runIDRServer
, configureDSToInterrupt
, and enableDSInterrupts
are crucial to efficiently manage interrupts in this application.
This application thus effectively sets up, manages, and processes Ethernet-based interrupts for NAI DS modules, providing a structured approach to handling such events programmatically.
/**************************************************************************************************************/
/**
<summary>
The DS_Interrupt_Ethernet 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_ds_int.h"
#include "nai_ds_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"
#include "nai_ds_int_ether.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
/* Module Specific NAI Board Library files */
#include "functions/naibrd_ds.h"
#include "maps/nai_map_ds.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 */
/*********************************************/
DsConfig inputDSConfig;
InterruptConfig inputInterruptConfig;
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_DS_Interrupt_Ethernet.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_DS_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 DS_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;
initializeDSConfigurations(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,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);
inputDSConfig.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);
inputDSConfig.module = module;
if (stop != TRUE)
{
inputDSConfig.modid = naibrd_GetModuleID(cardIndex, module);
if ((inputDSConfig.modid != 0))
{
Run_DS_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.
1. Ethernet Interrupt Handling - Setup IDR to handle interrupt
API CALLS - naibrd_Ether_SetIDRConfig, naibrd_Ether_StartIDR,naibrd_Ether_ClearIDRConfig
2. Enable Module Interrupts- Configures module to interrupt when channel receives DS message.
API CALLS - naibrd_DS_SetInterruptEdgeLevel, naibrd_DS_SetIntVector, naibrd_DS_SetInterruptSteering, naibrd_DS_SetIntEnable
3. 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.
4. Clear Module Configurations
5. Clear Board Configurations
API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_DS_Interrupt_Basic_Ethernet()
{
bool_t bQuit = FALSE;
bool_t bGen4DSIDRCommands;
inputDSConfig.maxChannel = naibrd_DS_GetChannelCount(inputDSConfig.modid);
inputDSConfig.minChannel = 1;
/*check if DS module supports GEN 4 Ethernet*/
bGen4DSIDRCommands = SupportsGen4Ether(inputDSConfig.cardIndex);
if (!bGen4DSIDRCommands)
{
printf("DS Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
bQuit = TRUE;
}
if (!bQuit)
{
bQuit = naiapp_query_ChannelNumber(inputDSConfig.maxChannel,inputDSConfig.minChannel,&inputDSConfig.channel);
}
if (!bQuit)
{
bQuit = QueryIDRConfigInformation(&inputIDRConfig);
}
if (!bQuit)
{
bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
}
if (!bQuit)
{
bQuit = QueryUserForEtherIDRMsgDisplay(&bDisplayEtherUPR);
}
if (!bQuit)
{
/****1. Setup IDR to Handle Interrupt (also contains step 6) ****/
if (inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
inputIDRConfig.cardIndex = inputDSConfig.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_DS(inputDSConfig,&inputIDRConfig,bGen4DSIDRCommands);
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,(uint16_t)DEF_ETHERNET_DS_BITLOSS_IDR_ID));
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,(uint16_t)DEF_ETHERNET_DS_REFLOSS_IDR_ID));
/****2. configure module To Interrupt****/
configureDSToInterrupt(inputInterruptConfig,inputDSConfig);
enableDSInterrupts(inputDSConfig,TRUE);
/****3. Show Interrupt Handling****/
dsEtherIntFunc = HandleDSEtherInterrupt;
bQuit = runIDRServer(inputIDRConfig);
/*****4. Clear Module Configurations*****/
enableDSInterrupts(inputDSConfig,FALSE);
/*****5. Clear Board Configurations *****/
check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DS_REFLOSS_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DS_REFLOSS_IDR_ID));
check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DS_BITLOSS_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_DS_BITLOSS_IDR_ID));
}
return bQuit;
}