SUM1553 BC RTtoRT
Edit this on GitLab
SUM1553 BC RTtoRT
Explanation
About This Sample Application Code
This C-based application is designed to interact with North Atlantic Industries' (NAI) embedded function modules, particularly for configuring and sending RT-to-RT messages using a 1553 bus controller (BC). The code leverages NAI’s libraries to manage board and module interactions. Below is a detailed breakdown of what each part of the code does:
Includes The initial lines of the code include necessary standard libraries and various NAI-specific header files:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.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_1553_utils.h"
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_sum1553.h"
These headers provide functions for board access, user interactions, and 1553 operations.
Definitions and Declarations Constants, function prototypes, and global variables are defined:
static const int8_t *CONFIG_FILE = (int8_t *)"default_SUM1553_BCRTtoRT.txt";
static bool_t Run_SUM1553_BC_RTtoRT(int32_t cardIndex, int32_t module, uint32_t modid);
static const int32_t DEF_BC_CHANNEL = 1;
static const uint8_t DEF_RT_ADDR1 = 1;
static const uint8_t DEF_RT_ADDR2 = 2;
static const uint8_t DEF_RT_SUBADDR1 = 2;
static const uint8_t DEF_RT_SUBADDR2 = 2;
static const uint16_t BLOCKC = 2;
static uint16_t datablock[3][32];
Main Routine
The main function controls the program flow and user interactions. Depending on the operating system (VXWorks or general-purpose OS), it has different function names (SUM1553_BC_RTtoRT
or main
).
#if defined (__VXWORKS__)
int32_t SUM1553_BC_RTtoRT(void)
#else
int32_t main(void)
#endif
{
// Variable declarations and initial setup
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
// Main menu and user input loop
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
Run_SUM1553_BC_RTtoRT(cardIndex, module, moduleID);
}
}
}
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;
}
-
naiapp_RunBoardMenu(CONFIG_FILE)
initializes and displays a menu based on a configuration file. -
The user is queried for the appropriate card index and module.
-
The identified module is configured and tested by calling
Run_SUM1553_BC_RTtoRT
.
Core Function
The Run_SUM1553_BC_RTtoRT
function handles configuring the Bus Controller (BC) and sending RT-to-RT messages.
static bool_t Run_SUM1553_BC_RTtoRT(int32_t cardIndex, int32_t module, uint32_t modid)
{
// Variable declarations
bool_t bQuit;
bool_t bContinue = TRUE;
int32_t bcchan = 2;
const uint16_t FIRST_CMD = 0;
bool_t resetting;
uint32_t ncmd = 0;
int32_t wordcnt = 32;
uint8_t rt1addr = DEF_RT_ADDR1;
uint8_t rt2addr = DEF_RT_ADDR2;
uint8_t rt1subaddr = DEF_RT_SUBADDR1;
uint8_t rt2subaddr = DEF_RT_SUBADDR2;
uint16_t ctrl;
uint16_t cmd1, cmd2;
uint16_t datablocknum;
uint16_t branchblock;
uint32_t timerus;
int32_t i;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
// Get 1553 BC configuration
bQuit = Get1553BCCfg(modid, DEF_BC_CHANNEL, &bcchan);
if (!bQuit)
{
// Reset channel and wait for reset
check_status(naibrd_SUM1553_Reset(cardIndex,module,bcchan));
while(check_status(naibrd_SUM1553_IsResetting(cardIndex,module,bcchan,&resetting)) == NAI_SUCCESS && resetting);
// Configure as BC and load command blocks
check_status(naibrd_SUM1553_SetMode(cardIndex,module,bcchan,NAI_SUM1553_OPSTATUS_BC_MODE));
check_status(naibrd_SUM1553_BC_SetCmdBlockPtr(cardIndex,module,bcchan,FIRST_CMD));
while (bContinue)
{
// Display options and query user
printf("\n1) Rx: RT Addr %d, SA %d; Tx: RT Addr %d, SA %d\n", DEF_RT_ADDR1, DEF_RT_SUBADDR1, DEF_RT_ADDR2, DEF_RT_SUBADDR2);
printf("2) Rx: RT Addr %d, SA %d; Tx: RT Addr %d, SA %d\n", DEF_RT_ADDR2, DEF_RT_SUBADDR2, DEF_RT_ADDR1, DEF_RT_SUBADDR1);
printf("\nSelect a number to send another RT-to-RT message or %c to quit: ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
// Handle user input to configure RT-to-RT message
if (inputBuffer[0] == '1')
{
rt1addr = DEF_RT_ADDR1;
rt1subaddr = DEF_RT_SUBADDR1;
rt2addr = DEF_RT_ADDR2;
rt2subaddr = DEF_RT_SUBADDR2;
}
else if (inputBuffer[0] == '2')
{
rt1addr = DEF_RT_ADDR2;
rt1subaddr = DEF_RT_SUBADDR2;
rt2addr = DEF_RT_ADDR1;
rt2subaddr = DEF_RT_SUBADDR1;
}
else
{
printf("\nInvalid value.\n");
continue;
}
// Set up and load command blocks
ncmd = FIRST_CMD;
wordcnt = 32;
ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_EXEBLK_CONT,1,1,1,0);
cmd1 = NAI_SUM1553_COMMAND_WORD(rt1addr,0,rt1subaddr,wordcnt);
cmd2 = NAI_SUM1553_COMMAND_WORD(rt2addr,1,rt2subaddr,wordcnt);
datablocknum = BLOCKC;
branchblock = 0;
timerus = 0;
check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
for (i = 0; i < wordcnt; i++)
datablock[BLOCKC][i] = (uint16_t)(0xC000 + i);
check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKC,datablock[BLOCKC]));
// End of list
ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_ENDOFLIST,1,1,0,0);
cmd1 = 0;
cmd2 = 0;
datablocknum = 0;
branchblock = 0;
timerus = 0;
check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
// Start and enable BC execution
check_status(naibrd_SUM1553_BC_SetCmdBlockPtr(cardIndex,module,bcchan,FIRST_CMD));
check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,bcchan,1));
}
else
bContinue = FALSE;
}
// Disable BC
check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,bcchan,0));
}
return bQuit;
}
The function performs the following steps: 1. Retrieves and resets the BC channel. 2. Configures the BC channel. 3. Prompts the user to select between two RT-to-RT message configurations. 4. Loads command and data blocks as per user selection. 5. Enables execution of the configured BC. 6. Continuously queries the user for further actions until they opt to quit.
Summary This sample application code is for configuring and sending RT-to-RT messages via a 1553 bus controller using North Atlantic Industries' embedded function modules. It guides the user through selecting a module and configuring a 1553 BC channel to send and receive messages between two RT addresses using the NAI libraries.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Common Sample Program include files */
#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"
/* Common 1553 Sample Program include files */
#include "nai_1553_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_sum1553.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_SUM1553_BCRTtoRT.txt";
/* Function prototypes */
static bool_t Run_SUM1553_BC_RTtoRT(int32_t cardIndex, int32_t module, uint32_t modid);
static const int32_t DEF_BC_CHANNEL = 1;
static const uint8_t DEF_RT_ADDR1 = 1;
static const uint8_t DEF_RT_ADDR2 = 2;
static const uint8_t DEF_RT_SUBADDR1 = 2;
static const uint8_t DEF_RT_SUBADDR2 = 2;
static const uint16_t BLOCKC = 2;
static uint16_t datablock[3][32];
/**************************************************************************************************************/
/**
<summary>
The purpose of the SUM1553_BC_RTtoRT is to illustrate the methods to call in the naibrd library to send an RT-to-RT
message.
The following system configuration routines from the nai_sys_cfg.c file are called to assist with the configuration
setup for this program prior to calling the naibrd 1553 routines.
- ConfigDevice
- DisplayDeviceCfg
- GetBoardSNModCfg
- CheckModule
Note, the SUM1553_BC_RTtoRT can run in conjunction with the SUM1553_RT_PingPong or SUM1553_RT_ProcCtrl
applications to illustrate BC and RT operations together with the NAI 1553 module.
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SUM1553_BC_RTtoRT(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(CONFIG_FILE) == TRUE)
{
while (stop != TRUE)
{
/* Query the user for the card index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Query the user for the module number */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != TRUE)
{
moduleID = naibrd_GetModuleID(cardIndex, module);
if ((moduleID != 0))
{
Run_SUM1553_BC_RTtoRT(cardIndex, module, moduleID);
}
}
}
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>
Run_SUM1553_BC_RTtoRT queries the user for the module and channel to configure as the Bus Controller (BC).
After getting the module/channel selection, methods in the naibrd library are invoked to setup this channel
as a BC with either of the following 1553 messages:
1) RT-RT message with 32 words of data for which the Rx command is to the "DEF_RT_ADDR1" RT Address and
"DEF_RT_SUBADDR1" Subaddress and the Tx command is to the "DEF_RT_ADDR2" RT Address and "DEF_RT_SUBADDR2"
Subaddress
2) RT-RT message with 32 words of data for which the Rx command is to the "DEF_RT_ADDR2" RT Address and
"DEF_RT_SUBADDR2" Subaddress and the Tx command is to the "DEF_RT_ADDR1" RT Address and "DEF_RT_SUBADDR1"
Subaddress
Once the BC is configured and running, the user can:
1) Type the Enter key to send another RT-to-RT message.
3) Type 'Q' to quit stop the BC execution and exit the routine.
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_SUM1553_BC_RTtoRT(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit;
bool_t bContinue = TRUE;
int32_t bcchan = 2;
const uint16_t FIRST_CMD = 0;
bool_t resetting;
uint32_t ncmd = 0;
int32_t wordcnt = 32;
uint8_t rt1addr = DEF_RT_ADDR1;
uint8_t rt2addr = DEF_RT_ADDR2;
uint8_t rt1subaddr = DEF_RT_SUBADDR1;
uint8_t rt2subaddr = DEF_RT_SUBADDR2;
uint16_t ctrl;
uint16_t cmd1, cmd2;
uint16_t datablocknum;
uint16_t branchblock;
uint32_t timerus;
int32_t i;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
bQuit = Get1553BCCfg(modid, DEF_BC_CHANNEL, &bcchan);
if (!bQuit)
{
/* Reset the channel */
check_status(naibrd_SUM1553_Reset(cardIndex,module,bcchan));
/* Wait for channels to reset */
while(check_status(naibrd_SUM1553_IsResetting(cardIndex,module,bcchan,&resetting)) == NAI_SUCCESS && resetting);
/* Setup the BC */
check_status(naibrd_SUM1553_SetMode(cardIndex,module,bcchan,NAI_SUM1553_OPSTATUS_BC_MODE)); /* Configure as BC */
/* Start with the first command */
check_status(naibrd_SUM1553_BC_SetCmdBlockPtr(cardIndex,module,bcchan,FIRST_CMD));
while (bContinue)
{
printf("\n1) Rx: RT Addr %d, SA %d; Tx: RT Addr %d, SA %d\n", DEF_RT_ADDR1, DEF_RT_SUBADDR1, DEF_RT_ADDR2, DEF_RT_SUBADDR2);
printf("2) Rx: RT Addr %d, SA %d; Tx: RT Addr %d, SA %d\n", DEF_RT_ADDR2, DEF_RT_SUBADDR2, DEF_RT_ADDR1, DEF_RT_SUBADDR1);
printf("\nSelect a number to send another RT-to-RT message or %c to quit: ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
if (inputBuffer[0] == '1')
{
rt1addr = DEF_RT_ADDR1;
rt1subaddr = DEF_RT_SUBADDR1;
rt2addr = DEF_RT_ADDR2;
rt2subaddr = DEF_RT_SUBADDR2;
}
else if (inputBuffer[0] == '2')
{
rt1addr = DEF_RT_ADDR2;
rt1subaddr = DEF_RT_SUBADDR2;
rt2addr = DEF_RT_ADDR1;
rt2subaddr = DEF_RT_SUBADDR1;
}
else
{
printf("\nInvalid value.\n");
continue;
}
/* First command block */
ncmd = FIRST_CMD;
/* RTRT Message with 32 words to RT SubAddress */
wordcnt = 32;
ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_EXEBLK_CONT,1,1,1,0);
cmd1 = NAI_SUM1553_COMMAND_WORD(rt1addr,0,rt1subaddr,wordcnt);
cmd2 = NAI_SUM1553_COMMAND_WORD(rt2addr,1,rt2subaddr,wordcnt);
datablocknum = BLOCKC;
branchblock = 0;
timerus = 0;
check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
for (i = 0; i < wordcnt; i++)
datablock[BLOCKC][i] = (uint16_t)(0xC000 + i);
check_status(naibrd_SUM1553_BC_LoadDataBlock(cardIndex,module,bcchan,BLOCKC,datablock[BLOCKC]));
/* Load EOL */
ctrl = NAI_SUM1553_BC_CTRL_WORD(NAI_SUM1553_OPCODE_ENDOFLIST,1,1,0,0);
cmd1 = 0;
cmd2 = 0;
datablocknum = 0;
branchblock = 0;
timerus = 0;
check_status(naibrd_SUM1553_BC_LoadCmdBlock(cardIndex,module,bcchan,ncmd++,ctrl,cmd1,cmd2,datablocknum,branchblock,timerus));
/* Start with the first command */
check_status(naibrd_SUM1553_BC_SetCmdBlockPtr(cardIndex,module,bcchan,FIRST_CMD));
/* Run the BC */
check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,bcchan,1));
}
else
bContinue = FALSE;
}
/* Disable the BC */
check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,bcchan,0));
}
return bQuit;
}