M1553 BC SendMsg
Edit this on GitLab
M1553 BC SendMsg Sample Application (SSK 2.x)
Overview
The M1553 BC SendMsg sample application demonstrates the fundamental MIL-STD-1553 Bus Controller (BC) message sending workflow using the NAI Software Support Kit (SSK 2.x). This is the foundational BC sample — it shows how to open a 1553 channel, initialize it as a BC, create a message of any supported type (BC-to-RT, RT-to-BC, RT-to-RT, or mode code), build the frame hierarchy, send the message, and decode the response.
Unlike the more specialized BC samples (Async, FIFO, Schedule), this sample focuses on single-shot message sending with interactive message type selection. It serves as the best starting point for understanding the BC message creation and execution pipeline.
This sample supports the following 1553 module types:
-
FT0 through FTF — 4-channel MIL-STD-1553 modules
-
FTJ, FTK — 2-channel MIL-STD-1760 modules
-
Combination modules CM1, CM5, CM8, and CMR
The application detects the installed module variant at runtime using IsFTx1553() and IsFTx1760().
For detailed 1553 protocol specifications, message formats, and hardware register descriptions, see the FTA-FTF Manual.
For the SSK 1.x version, see M1553 BC SendMessage (SSK 1.x).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a 1553 module installed (FT0-FTF, FTJ/FTK, or a combination module with 1553 functionality).
-
SSK 2.x installed on your development host.
-
The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.
How to Run
Launch the m1553_bc_send_msg executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessage.txt). On the first run, this file will not exist — the application will present an interactive board menu where you configure a board connection, card index, and module slot. You can save this configuration so that subsequent runs skip the menu and connect automatically. Once connected, the application prompts for channel, message type, bus selection, and software override settings, then sends messages in a loop.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to 1553. |
The main() function follows a standard SSK 2.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_1553BC_SendMessage.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleName()so downstream code can adapt to the specific 1553 variant installed.
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_bc_send_msg(void)
#else
int32_t main(void)
#endif
{
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
bool_t stop = NAI_FALSE;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_m1553_bc_send_msg(cardIndex, module, moduleID);
}
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiapp_access_CloseAllOpenCards();
return 0;
}
|
Important
|
Common Connection Errors
|
Program Structure
The application is organized into three functions:
-
main()— standard SSK 2.x startup: board menu, card/module selection, then delegates to the run function. -
Run_m1553_bc_send_msg()— validates the module supports 1553 viaIsFTx1553()or 1760 viaIsFTx1760(), queries for a channel number, and callsRunSendMessage(). -
RunSendMessage()— the core BC workflow: opens the device, initializes as BC, creates message structures, sends messages in a loop, and decodes responses.
The sample defines these constants for its frame hierarchy:
#define MSG1 1 /* Message ID */
#define OP1 1 /* Execute message opcode */
#define OP2 2 /* Call subroutine opcode */
#define MNR1 1 /* Minor frame ID */
#define MJR 2 /* Major frame ID */
#define DBLK1 1 /* Data block for standard messages */
#define DBLK2 2 /* Data block for mode code messages */
#define RT_ADDRESS 1 /* Target RT address */
#define RT_SUBADDRESS 2 /* Target subaddress */
#define RT_ADDRESS_2 2 /* Second RT address (RT-to-RT) */
#define WORDCOUNT 32 /* Data words per message */
Utility Files
The 1553 samples in SSK 2.x share two utility modules located under the m1553_common_utils/ directory:
-
m1553_common_utils.c— module detection (IsFTx1553(),IsFTx1760()), logical device number selection (Get1553LogicalDevNum()), software override prompts (Get1553BCSoftwareOverride()), and register display helpers. -
BC/m1553_bc_common_utils.c— BC-specific helpers: bus selection (GetBus()), message type selection (GetMsgTypeAndCheckForQuit()), mode code validation (AskAndCheckForValidModeCodeAndCheckForQuit()), and message type/mode code enumerations.
These utilities handle interactive input and validation. In your own application you would replace them with your application’s configuration values, but the underlying naibrd_1553_*() API calls remain the same.
Opening and Initializing the 1553 Channel
To configure a channel as a Bus Controller, first call naibrd_1553_Open() to associate the hardware channel with a logical device number, then naibrd_1553_Init() in NAIBRD_1553_MODE_BC mode.
Before opening, the sample prompts for several configuration values:
-
Logical device number (0-31) — a unique identifier for this channel instance.
-
Message type — BC-to-RT, RT-to-BC, RT-to-RT, Tx mode code, or Rx mode code.
-
Bus — Bus A or Bus B.
-
Software override — whether to override external BC_DISABLE and M1760 pins.
/* Open 1553 Device */
status = naibrd_1553_Open(cardIndex, module, channel, devnum);
/* Software override for BC_DISABLE and M1760 pins */
if (bSoftware)
{
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS,
NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_BC_DISABLE |
NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_M1760);
}
else
{
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0);
}
/* Reset Device */
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET, 1);
naibrd_msDelay(1);
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET, 0);
/* Initialize as BC */
status = naibrd_1553_Init(devnum, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC, 0, 0, 0);
The software override allows the BC to operate even when the external BC_DISABLE and M1760 hardware pins are not driven high. In production, these pins should be properly wired and the software override disabled.
The device reset via the NAIBRD_1553_AUX_ADDRESS_RESET auxiliary register clears any previous state before initialization. A brief delay (naibrd_msDelay(1)) is required between asserting and deasserting the reset.
|
Note
|
SSK 2.x uses named constants (NAIBRD_1553_AUX_ADDRESS_MISC_BITS, NAIBRD_1553_AUX_ADDRESS_RESET) and the naibrd_1553_WriteAuxRegister() function for auxiliary register access. SSK 1.x uses raw register addresses (0x2, 0x1) and naibrd_1553_WriteAuxReg(). The underlying hardware operation is the same.
|
|
Important
|
Common Errors
|
Creating Messages
This sample supports all four MIL-STD-1553 message types plus mode codes. The user selects the type interactively via GetMsgTypeAndCheckForQuit(), and the application creates the appropriate message structure. Before creating any message, a data block must be allocated.
Data Block Creation
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK1, NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE, NULL, 0);
The data block size constant NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE allocates a single 32-word buffer. For mode code messages, the sample creates a separate data block (DBLK2).
BC-to-RT Message
To send data from the BC to an RT, call naibrd_1553_BcMsgCreateBcToRt():
status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
The usBus parameter selects Bus A or Bus B for the transmission.
RT-to-BC Message
To request data from an RT, call naibrd_1553_BcMsgCreateRtToBc():
status = naibrd_1553_BcMsgCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
RT-to-RT Message
To command a transfer between two RTs, call naibrd_1553_BcMsgCreateRtToRt():
status = naibrd_1553_BcMsgCreateRtToRt(devnum, MSG1, DBLK1, RT_ADDRESS_2, RT_SUBADDRESS, WORDCOUNT, RT_ADDRESS, RT_SUBADDRESS, 0, usBus);
This message commands RT at RT_ADDRESS to transmit and RT at RT_ADDRESS_2 to receive.
Mode Code Message
To send a mode code command (transmit or receive), call naibrd_1553_BcMsgCreateMode():
status = naibrd_1553_BcMsgCreateMode(devnum, MSG1, DBLK1, RT_ADDRESS,
(msgType == M1553_MSGTYPE_MODECODE_TX) ? NAIBRD_1553_DIRECTION_TX : NAIBRD_1553_DIRECTION_RX,
modeCommand, 0, usBus);
The modeCommand value is validated by AskAndCheckForValidModeCodeAndCheckForQuit() before use. Valid transmit mode codes include Dynamic Bus Control (0x00), Synchronize (0x01), Transmit Status Word (0x02), and others. Valid receive mode codes include Synchronize With Data (0x11) and Selected Transmitter Shutdown (0x14).
|
Important
|
Common Errors
|
Building the Frame Hierarchy
The BC executes messages through a hierarchy of opcodes, minor frames, and major frames. This sample creates the simplest possible hierarchy: one message, one opcode, one minor frame, one major frame.
/* Create Execute Message Command -- runs MSG1 unconditionally */
status = naibrd_1553_BcCmdCreate(devnum, OP1, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE,
NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
/* Create Call Subroutine Command -- calls minor frame MNR1 */
status = naibrd_1553_BcCmdCreate(devnum, OP2, NAIBRD_1553_OPCODE_CALL_SUBROUTINE,
NAIBRD_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
/* Create Minor Frame containing one execute-message opcode */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrmCreate(devnum, MNR1, NAIBRD_1553_BC_FRAME_MINOR,
aOpCodes, 1, 0, NAIBRD_1553_BC_FRAME_DEFAULT);
/* Create Major Frame containing one call-subroutine opcode */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrmCreate(devnum, MJR, NAIBRD_1553_BC_FRAME_MAJOR,
aOpCodes, 1, 1000, NAIBRD_1553_BC_FRAME_DEFAULT);
The hierarchy works as follows:
-
The major frame (
MJR) contains one opcode (OP2), which calls the minor frame. -
The minor frame (
MNR1) contains one opcode (OP1), which executes the message. -
The time value of 1000 on the major frame sets the cycle period (100 ms in 0.1 ms units).
For more complex scheduling with multiple messages at different rates, see the M1553 BC Run Schedule sample.
|
Note
|
SSK 2.x uses naibrd_1553_BcCmdCreate() and naibrd_1553_BcFrmCreate() with named constants like NAIBRD_1553_OPCODE_EXECUTE_MESSAGE and NAIBRD_1553_BC_FRAME_DEFAULT. SSK 1.x uses naibrd_1553_BcCommandCreate() and naibrd_1553_BcFrameCreate() with NAI_1553_OPCODE_EXECUTE_MESSAGE. The parameters and behavior are equivalent.
|
Sending Messages and Decoding Responses
The main loop writes data to the data block, starts the BC for a single major frame execution, waits for completion, stops the BC, and decodes the response:
/* Load data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlkWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
/* Start BC for 1 major frame */
status = naibrd_1553_BcStart(devnum, MJR, 1);
/* Wait for execution */
naibrd_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(devnum);
/* Decode the response */
status = naibrd_1553_BcMsgGetByIdDecoded(devnum, MSG1, &DecodedMsgStruct, 1);
The naibrd_1553_BcMsgGetByIdDecoded() function populates a naibrd_1553_msgstruct_t structure with the decoded response fields:
-
bcControlWord— BC control word for the message -
commandWord1— the first command word -
commandWord2— the second command word (RT-to-RT only; checkisCommandWord2Relevant) -
blockStatus— block status word indicating message completion and errors -
timeTag— time tag for the message -
dataWordCount— number of data words in the response -
status1— RT status word from the responding RT -
status2— second RT status word (RT-to-RT only; checkisStatus2Relevant) -
data[]— the data payload (for RT-to-BC and mode code Tx messages)
A positive return from naibrd_1553_BcMsgGetByIdDecoded() indicates a message was decoded. A negative return indicates an error. Zero means no message was found.
if (status > 0)
{
naiif_printf("Control Word: 0x%04X\r\n", DecodedMsgStruct.bcControlWord);
naiif_printf("Command Word: 0x%04X\r\n", DecodedMsgStruct.commandWord1);
naiif_printf("Block Status: 0x%04X\r\n", DecodedMsgStruct.blockStatus);
naiif_printf("Time Tag: 0x%04X\r\n", DecodedMsgStruct.timeTag);
naiif_printf("Word Count: 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
naiif_printf("RT Status Word: 0x%04X\r\n", DecodedMsgStruct.status1);
}
|
Important
|
Common Errors
|
Cleanup
When finished, free the logical device to release hardware resources:
status = naibrd_1553_Free(devnum);
Always call naibrd_1553_Free() before exiting, even if errors occurred during operation. The main function also calls naiapp_access_CloseAllOpenCards() to close all board connections.
Troubleshooting Reference
|
Note
|
This table summarizes errors covered in preceding sections. Consult the FTA-FTF Manual for hardware-specific diagnostics. |
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
|
Channel already open, invalid card/module/channel index |
Verify indices, ensure no other application holds the channel |
|
Device not reset, invalid mode flags |
Ensure device reset sequence completed, verify mode parameter is |
Message creation returns non-zero |
Invalid RT address/subaddress, data block not created |
Check parameter ranges (RT address 0-30, subaddress 0-31), create data block before message |
|
Incomplete frame hierarchy, device not initialized as BC |
Verify all opcodes, minor frames, and major frame are created |
No response from RT |
RT not on bus, bus wiring issue, wrong bus (A/B) selected |
Verify RT is active, check cabling, try other bus |
Block status shows errors |
RT not responding, bus contention, timeout |
Check RT status word, verify bus termination, consult module manual |
Software override needed |
BC_DISABLE or M1760 pins not externally driven high |
Enable software override when prompted for bench testing; wire pins properly in production |
Module not recognized as 1553 |
Module ID not in |
Verify the module type is FT0-FTF, FTJ/FTK, CM1, CM5, CM8, CMR, or IF2 |
Full Source
Full Source — m1553_bc_send_msg.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"
/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common 1553 Sample Program include files */
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/m1553_common_utils.h"
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/BC/m1553_bc_common_utils.h"
/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"
static const int8_t *DEF_CONFIG_FILE = (int8_t *)"default_1553BC_SendMessage.txt";
/* Function prototypes */
static bool_t Run_m1553_bc_send_msg(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunSendMessage(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid);
/* define message constants */
#define MSG1 1
/* define opcodes */
#define OP1 1
#define OP2 2
/* define frame constants */
#define MNR1 1
#define MJR 2
/* define data block numbers */
#define DBLK1 1
#define DBLK2 2
#define DEF_M1553_CARD_INDEX 0
#define DEF_M1553_MODULE 1
#define DEF_M1553_CHANNEL 1
#define DEF_M1553_DEVNUM 1
#define RT_ADDRESS 1
#define RT_SUBADDRESS 2
#define RT_ADDRESS_2 2
#define WORDCOUNT 32
/**************************************************************************************************************/
/** \defgroup M1553_BC_SendMessage
\brief This sample application demonstrates how to configure a channel as a Bus Controller and send a message.
The purpose of the m1553_bc_send_msg is to illustrate the methods to call in the naibrd library to configure
the 1553 channel as a Bus Controller and to send a 1553 message out.
The main steps include:
- Querying the user for the card index and module number.
- Configuring the channel for Bus Controller functionality.
- Configuring a frame with one message of a selected type.
- Starting the BC to transmit the configured message.
- Displaying the RT response and BC Status.
*/
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_bc_send_msg(void)
#else
int32_t main(void)
#endif
{
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
bool_t stop = NAI_FALSE;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
/* Select Card Index */
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
/* Select Module */
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_m1553_bc_send_msg(cardIndex, module, moduleID);
}
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiif_printf("\r\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
static bool_t Run_m1553_bc_send_msg(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = NAI_FALSE;
int32_t channel;
int32_t MaxChannel = 4;
if ((IsFTx1553(modid)) || (IsFTx1760(modid)))
{
MaxChannel = 4;
bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
if (!bQuit)
{
bQuit = RunSendMessage(cardIndex, module, channel, modid);
}
}
else
naiif_printf("\r\nThis module does not support 1553 functionality.\r\n");
return bQuit;
}
static bool_t RunSendMessage(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid)
{
int32_t i;
bool_t bQuit = NAI_FALSE;
uint32_t usBus;
naibrd_1553_t status;
uint16_t increment = 0;
uint16_t aData[32] = { 0 };
int16_t aOpCodes[20] = { 0 };
bool_t bContinue = NAI_TRUE;
int16_t devnum;
bool_t bValidModeCode;
M1553MsgType_t msgType;
naibrd_1553_msgstruct_t DecodedMsgStruct;
bool_t bSoftware;
M1553ModeCodes_t modeCommand;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get the Logical Device Number */
bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUM, &devnum);
if (!bQuit)
{
/* Get Msg Direction */
bQuit = GetMsgTypeAndCheckForQuit(&msgType);
if (!bQuit)
{
/* Which bus are we firing on? */
bQuit = GetBus(&usBus);
if (!bQuit)
{
bQuit = Get1553BCSoftwareOverride(NAI_TRUE, &bSoftware);
if (!bQuit)
{
/* Open 1553 Device(s) */
status = naibrd_1553_Open(cardIndex, module, channel, devnum);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Open Ch %d, status = %d", channel, status);
return NAI_TRUE;
}
if (bSoftware)
{
/* Override external BC_DISABLE and M1760 (In order to configure as BC, this needs to */
/* be set if BC_DISABLE and M1760 pins are not driven high) */
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS,
NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_BC_DISABLE | NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_M1760);
}
else
{
/* Do not override external BC_DISABLE and M1760 Inputs */
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0);
}
if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
do
{
bQuit = AskAndCheckForValidModeCodeAndCheckForQuit((msgType == M1553_MSGTYPE_MODECODE_TX) ?
M1553_MSGTYPE_MODECODE_DIRECTION_TX : M1553_MSGTYPE_MODECODE_DIRECTION_RX, &modeCommand, &bValidModeCode);
} while ((!bQuit) && (!bValidModeCode));
}
if (modid == NAIBRD_MODULE_ID_FT8)
{
/* Simplex Enable (for NAI internal testing only, do not enable) */
/*naibrd_1553_WriteAuxRegister(devnum, 0x3, 0x4000);*/
/*naibrd_1553_WriteAuxRegister(devnum, 0xF, 0x0001);*/
}
/* Reset Device */
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET, 1);
naibrd_msDelay(1);
naibrd_1553_WriteAuxRegister(devnum, NAIBRD_1553_AUX_ADDRESS_RESET, 0);
/* Initialize 1553 Device(s) */
status = naibrd_1553_Init(devnum, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC, 0, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Init Ch %d, status = %d", channel, status);
return NAI_TRUE;
}
if ((msgType != M1553_MSGTYPE_MODECODE_TX) || (msgType != M1553_MSGTYPE_MODECODE_RX))
{
/* Create BC Data Block */
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK1, NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE, NULL, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcDataBlkCreate Ch %d, status = %d", channel, status);
return NAI_TRUE;
}
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK2, NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE, NULL, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcDataBlkCreate Ch %d, status = %d", channel, status);
return NAI_TRUE;
}
}
if (msgType == M1553_MSGTYPE_RTTOBC)
{
/* Create RT to BC Message */
status = naibrd_1553_BcMsgCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMessageCreateRtToBc status = %d", status);
return NAI_TRUE;
}
}
else if (msgType == M1553_MSGTYPE_BCTORT)
{
/* Create BC to RT Message */
status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
return NAI_TRUE;
}
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
/* Create Mode Code Tx Message */
status = naibrd_1553_BcMsgCreateMode(devnum, MSG1, DBLK1, RT_ADDRESS, (msgType == M1553_MSGTYPE_MODECODE_TX) ?
NAIBRD_1553_DIRECTION_TX : NAIBRD_1553_DIRECTION_RX, modeCommand, 0, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMessageCreateMode status = %d", status);
return NAI_TRUE;
}
}
else if (msgType == M1553_MSGTYPE_RTTORT)
{
/* Create RT to RT Message */
status = naibrd_1553_BcMsgCreateRtToRt(devnum, MSG1, DBLK1, RT_ADDRESS_2, RT_SUBADDRESS, WORDCOUNT, RT_ADDRESS, RT_SUBADDRESS, 0, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMsgCreateRtToRt status = %d", status);
return NAI_TRUE;
}
}
/* Create Execute Message Command */
status = naibrd_1553_BcCmdCreate(devnum, OP1, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcCmdCreate status = %d", status);
return NAI_TRUE;
}
/* Create Call Subroutine Command */
status = naibrd_1553_BcCmdCreate(devnum, OP2, NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcCmdCreate status = %d", status);
return NAI_TRUE;
}
/* Create Minor Frame */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrmCreate(devnum, MNR1, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, NAIBRD_1553_BC_FRAME_DEFAULT);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcFrmCreate status = %d", status);
return NAI_TRUE;
}
/* Create Major Frame */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrmCreate(devnum, MJR, NAIBRD_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, NAIBRD_1553_BC_FRAME_DEFAULT);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcFrmCreate status = %d", status);
return NAI_TRUE;
}
while (bContinue)
{
/* Load BC data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlkWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcDataBlkWrite status = %d", status);
return NAI_TRUE;
}
/* Start BC */
status = naibrd_1553_BcStart(devnum, MJR, 1);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcStart status = %d", status);
return NAI_TRUE;
}
/* This delay is necessary to allow the BC to run */
naibrd_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(devnum);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcStop status = %d", status);
return NAI_TRUE;
}
/* Get Decoded Msg Structure */
status = naibrd_1553_BcMsgGetByIdDecoded(devnum, MSG1, &DecodedMsgStruct, 1);
if (status < 0)
{
naiif_printf("Error: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
return NAI_TRUE;
}
else if (status > 0)
{
naiif_printf("Control Word: 0x%04X\r\n", DecodedMsgStruct.bcControlWord);
naiif_printf("Command Word: 0x%04X\r\n", DecodedMsgStruct.commandWord1);
if (DecodedMsgStruct.isCommandWord2Relevant)
naiif_printf("Command Word 2: 0x%04X\r\n", DecodedMsgStruct.commandWord2);
naiif_printf("Block Status: 0x%04X\r\n", DecodedMsgStruct.blockStatus);
naiif_printf("Time Tag: 0x%04X\r\n", DecodedMsgStruct.timeTag);
naiif_printf("Word Count: 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
naiif_printf("RT Status Word: 0x%04X\r\n", DecodedMsgStruct.status1);
if (DecodedMsgStruct.isStatus2Relevant)
naiif_printf("RT Status Word 2: 0x%04X\r\n", DecodedMsgStruct.status2);
if ((msgType == M1553_MSGTYPE_RTTOBC) || (msgType == M1553_MSGTYPE_MODECODE_TX))
{
naiif_printf((DecodedMsgStruct.dataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < DecodedMsgStruct.dataWordCount; i++)
{
if (i % 8 == 0)
{
naiif_printf("\r\n");
}
naiif_printf("0x%04X ", DecodedMsgStruct.data[i]);
}
}
naiif_printf("\r\n\r\n");
}
naiif_printf("\r\nPress any key to send another message or Q to quit.");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (bQuit)
{
bContinue = NAI_FALSE;
}
}
}
}
}
}
/* Free 1553 Device */
status = naibrd_1553_Free(devnum);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Free status = %d", status);
return NAI_TRUE;
}
return bQuit;
}