TTL Interrupt Ethernet
Edit this on GitLab
TTL Interrupt Ethernet
Explanation
About the Sample Application Code for NAI TTL Interrupt using Ethernet
Overview
This application code provides a detailed example for interacting with North Atlantic Industries (NAI) embedded function modules using NAI System Solution Kit (SSK) over Ethernet for TTL interrupts. The program demonstrates board access, configuration, and interrupt handling. Below is a clear breakdown of the various components and main routine functionality.
Include Files
Standard Libraries
- stdio.h
, stdlib.h
, string.h
, time.h
: These are standard C libraries for input/output operations, memory management, string manipulation, and time handling, respectively.
NAI Specific Libraries
- These libraries support interaction with NAI hardware and sample programs for various functions.
- nai_ttl_int.h
, nai_ttl_cfg.h
, nai_ttl_int_ether.h
: Libraries for TTL interrupt configurations and Ethernet-specific settings.
- naiapp_interrupt.h
, naiapp_interrupt_ether.h
: Libraries for handling interrupts both general and Ethernet-specific.
- naiapp_boardaccess_menu.h
, naiapp_boardaccess_query.h
, naiapp_boardaccess_access.h
, naiapp_boardaccess_display.h
, naiapp_boardaccess_utils.h
: Libraries for board access utility functions such as menus, queries, access, and display functionalities.
- nai.h
, naibrd.h
: General NAI board library files.
- naibrd_ttl.h
: Module-specific NAI board library for TTL functionalities.
Constants and Variables
-
CONFIG_FILE
: Static constant pointing to the configuration file for the default TTL interrupt settings. -
DEF_RX_RESPONSE_IPv4_ADDR
: Default IPv4 address for receiving responses over Ethernet. -
COMMANDS
: Array to store Ethernet IDR commands.
Internal Function Prototypes
-
Run_TTL_Interrupt_Ethernet()
: Function prototype for running the TTL interrupt handling over Ethernet.
Main Routine (Function: main
or TTL_Interrupt_Ethernet
)
The main routine is intended to facilitate access to the NAI board and interacts with the user to configure and handle TTL interrupts over Ethernet. It performs the following steps:
-
Initialization:
-
Set up configuration variables for TTL, Interrupts, and IDR (Interrupt Data Register) with default values.
-
-
Configuration and Access:
-
Uses helper functions to configure and access the board using the
CONFIG_FILE
. -
Queries the user for different configurations like card index, module number, and other specifics.
-
-
Execution Loop:
-
Runs the interrupt handling routine
Run_TTL_Interrupt_Ethernet
as long as the user decides not to quit. -
Provides an option for the user to quit or restart the application after a session.
-
-
Closing:
-
Closes all open card accesses and exits the program.
-
Interrupt Handling Routine (Function: Run_TTL_Interrupt_Ethernet
)
Steps Breakdown:
-
Ethernet Interrupt Handling Setup:
-
Configure the IDR (Interrupt Data Register) to handle interrupts via APIs like
naibrd_Ether_SetIDRConfig
,naibrd_Ether_StartIDR
, andnaibrd_Ether_ClearIDRConfig
.
-
-
Enable Module Interrupts:
-
Configure the module to generate an interrupt upon receiving a TTL message via APIs like
naibrd_TTL_SetInterruptEdgeLevel
,naibrd_TTL_SetIntVector
,naibrd_TTL_SetInterruptSteering
, andnaibrd_TTL_SetIntEnable
.
-
-
Show Interrupt Handling:
-
The IDR server listens for interrupts and decodes messages which are then displayed to the user.
-
-
Re-arm Interrupts:
-
Clear the status register to allow re-triggering of interrupts. This is achieved by writing to the status register.
-
-
Clear Configurations:
-
Clear module and board configurations to reset the system and free resources.
-
Summary
This code demonstrates a structured approach to interact with NAI embedded function modules using SSK for TTL interrupts over Ethernet. It covers initialization, user configuration, interrupt handling, and cleanup processes, making it a comprehensive example for developers working with NAI hardware.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/*Common Module Specific Sample Program include files*/
#include "nai_ttl_int.h"
#include "nai_ttl_cfg.h"
#include "nai_ttl_int_ether.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_ttl.h"
/*********************************************/
/* Application Name and Revision Declaration */
/*********************************************/
static const int8_t *CONFIG_FILE = (int8_t *)"default_TTL_Interrupt.txt";
/********************************/
/* Internal Function Prototypes */
/********************************/
static bool_t Run_TTL_Interrupt_Ethernet();
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];
/**************************************************************************************************************/
/***** 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 TTL_Interrupt_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;
initializeTTLConfigurations(0, 0, 0, 0, 0, 0);
initializeInterruptConfigurations(FALSE, FALSE, FALSE, 0, NAIBRD_INT_STEERING_ON_BOARD_1, 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, 0, DEF_ETHERNET_TTL_LOHI_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);
inputTTLConfig.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);
inputTTLConfig.module = module;
if (stop != TRUE)
{
inputTTLConfig.modid = naibrd_GetModuleID(cardIndex, module);
if ((inputTTLConfig.modid != 0))
{
Run_TTL_Interrupt_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 TTL message.
API CALLS - naibrd_TTL_SetInterruptEdgeLevel, naibrd_TTL_SetIntVector, naibrd_TTL_SetInterruptSteering, naibrd_TTL_SetIntEnable
4. Not applicable to this module
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_TTL_SetRxEnable, naibrd_TTL_ClearStatus
8. Clear Board Configurations
API CALLS - naibrd_Ether_StopIDR, naibrd_Ether_ClearIDRConfig
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_TTL_Interrupt_Ethernet()
{
bool_t bQuit = FALSE;
bool_t bGen4ttlIDRCommands;
int32_t maxChannel = naibrd_TTL_GetChannelCount(inputTTLConfig.modid);
int32_t minChannel = 1;
bGen4ttlIDRCommands = SupportsGen4Ether(inputTTLConfig.cardIndex);
if(!bGen4ttlIDRCommands)
{
printf("TTL Ethernet Interrupt Support Prior to Generation 4 Ethernet commands currently not supported\n");
bQuit = TRUE;
}
if(!bQuit){
bQuit = naiapp_query_ChannelNumber(maxChannel,minChannel,&inputTTLConfig.channel);
inputTTLConfig.maxChannel = inputTTLConfig.channel;
inputTTLConfig.minChannel = inputTTLConfig.channel;
}
if(!bQuit){
bQuit = QueryIDRConfigInformation(&inputIDRConfig);
}
if(!bQuit){
bQuit = QueryUserForOnboardOffboardInterrupts(&inputInterruptConfig.bProcessOnboardInterrupts);
}
if(!bQuit)
{
bQuit = QueryUserForEtherIDRMsgDisplay(&bDisplayEtherUPR);
}
if (!bQuit)
{
/****2. Setup IDR to Handle Interrupt (also contains step 6) ****/
if(inputInterruptConfig.bProcessOnboardInterrupts == TRUE)
{
inputIDRConfig.cardIndex = inputTTLConfig.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_TTL(inputTTLConfig,&inputIDRConfig,bGen4ttlIDRCommands);
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_TTL_LOHI_IDR_ID));
check_status(naibrd_Ether_StartIDR(inputIDRConfig.cardIndex,(uint16_t)DEF_ETHERNET_TTL_HILO_IDR_ID));
/****3. configure module To Interrupt****/
configureTTLToInterrupt(inputInterruptConfig,inputTTLConfig);
enableTTLInterrupts(inputTTLConfig,TRUE);
/****5. Show Interrupt Handling****/
TTL_ClearInterrupt = ClearInterrupt_TTL;
ttlEtherIntFunc = HandleTTLEtherInterrupt;
bQuit = runIDRServer(inputIDRConfig);
/***** 7. Clear Module Configurations *****/
enableTTLInterrupts(inputTTLConfig,FALSE);
/*****8. Clear Board Configurations *****/
check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_TTL_LOHI_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_TTL_LOHI_IDR_ID));
check_status(naibrd_Ether_StopIDR(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_TTL_HILO_IDR_ID));
check_status(naibrd_Ether_ClearIDRConfig(inputIDRConfig.cardIndex, (uint16_t)DEF_ETHERNET_TTL_HILO_IDR_ID));
}
return bQuit;
}