M1553 BC SendMessage
Edit this on GitLab
M1553 BC SendMessage Sample Application (SSK 1.x)
Overview
The M1553 BC SendMessage sample application demonstrates the fundamental MIL-STD-1553 Bus Controller (BC) message sending workflow using the NAI Software Support Kit (SSK 1.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, WithRetries), 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
-
Combination modules CM1, CM5, and CM8
The application detects the installed module variant at runtime using IsFTx1553().
For detailed 1553 protocol specifications, message formats, and hardware register descriptions, see the FTA-FTF Manual.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a 1553 module installed (FT0-FTF or a combination module with 1553 functionality).
-
SSK 1.x installed on your development host.
-
The sample applications built. Refer to the SSK 1.x build instructions for your platform if you have not already compiled them.
How to Run
Launch the M1553_BC_SendMessage 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 1.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_GetModuleID()so downstream code can adapt to the specific 1553 variant installed. -
Query for a channel number within the selected module.
#if defined (__VXWORKS__)
int32_t M1553_BC_SendMessage(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)
{
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_M1553_BC_SendMessage(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);
}
}
naiapp_access_CloseAllOpenCards();
return 0;
}
|
Important
|
Common Connection Errors
|
Program Structure
The application is organized into three functions:
-
main()— standard SSK 1.x startup: board menu, card/module selection, then delegates to the run function. -
Run_M1553_BC_SendMessage()— validates the module supports 1553 viaIsFTx1553(), 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 WORDCOUNT 32 /* Data words per message */
Opening and Initializing the 1553 Channel
To configure a channel as a Bus Controller, call naibrd_1553_Open() to associate the hardware channel with a logical device number, then naibrd_1553_Initialize() in NAI_1553_MODE_BC mode.
/* Open 1553 Device */
status = naibrd_1553_Open(cardIndex, module, channel, devnum);
/* Software override for BC_DISABLE and M1760 pins */
if (bSoftware)
{
naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000);
}
/* Reset Device */
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x1);
Sleep(100);
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x0);
/* Initialize as BC */
status = naibrd_1553_Initialize(devnum, NAI_1553_ACCESS_CARD, NAI_1553_MODE_BC, 0, 0, 0);
The software override (0xA000 written to auxiliary register 0x2) 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 should be disabled.
The device reset via auxiliary register 0x1 clears any previous state before initialization. A brief delay is required between asserting and deasserting the reset.
Creating Messages
This sample supports all four MIL-STD-1553 message types. The user selects the type interactively via GetMsgTypeAndCheckForQuit(), and the application creates the appropriate message structure:
BC-to-RT Message
To send data from the BC to an RT, call naibrd_1553_BcMessageCreateBcToRt():
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, WORDCOUNT, NULL, 0);
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, 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_BcMessageCreateRtToBc():
status = naibrd_1553_BcMessageCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
RT-to-RT Message
To command a transfer between two RTs, call naibrd_1553_BcMessageCreateRtToRt():
status = naibrd_1553_BcMessageCreateRtToRt(devnum, MSG1, DBLK1, RT_ADDRESS_2, RT_SUBADDRESS, WORDCOUNT, RT_ADDRESS, RT_SUBADDRESS, 0, usBus);
Mode Code Message
To send a mode code command (transmit or receive), call naibrd_1553_BcMessageCreateMode():
status = naibrd_1553_BcMessageCreateMode(devnum, MSG1, DBLK1, RT_ADDRESS,
(msgType == M1553_MSGTYPE_MODECODE_TX) ? NAI_1553_CMD_TX : NAI_1553_CMD_RX,
modeCommand, 0, usBus);
The modeCommand value is validated by AskAndCheckForValidModeCodeAndCheckForQuit() before use.
|
Important
|
Common Errors
|
Building and Executing 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 */
status = naibrd_1553_BcCommandCreate(devnum, OP1, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
/* Create Call Subroutine Command */
status = naibrd_1553_BcCommandCreate(devnum, OP2, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
/* Create Minor Frame containing one message */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
/* Create Major Frame containing one minor frame */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrameCreate(devnum, MJR, NAI_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, 0);
The major frame time of 1000 (100 ms in 0.1 ms units) sets the cycle period. For more complex scheduling with multiple messages at different rates, see the M1553_BC_SendMessageSchedule guide.
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_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
/* Start BC for 1 major frame */
status = naibrd_1553_BcStart(devnum, MJR, 1);
/* Wait for execution */
nai_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(devnum);
/* Decode the response */
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG1, &DecodedMsgStruct, 1);
The decoded message structure contains the BC control word, command word(s), block status, time tag, data word count, RT status word(s), and the data payload. For RT-to-BC and mode code Tx messages, the data words contain the RT’s response data.
A positive return from naibrd_1553_BcMessageGetByIdDecoded() indicates a message was decoded. A negative return indicates an error. Zero means no message was found.
|
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 |
Message creation returns non-zero |
Invalid RT address/subaddress, data block not created |
Check parameter ranges, 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 (aux reg 0x2 = 0xA000) for bench testing |
Full Source
Full Source — M1553_BC_SendMessage.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#if defined (__VXWORKS__)
#include "taskLib.h"
#endif
/* 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"
#include "BC/nai_1553_bc_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_1553BC_SendMessage.txt";
/* Function prototypes */
static bool_t Run_M1553_BC_SendMessage(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
/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_BC_SendMessage 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 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
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t M1553_BC_SendMessage(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_M1553_BC_SendMessage(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_M1553_BC_SendMessage initializes the 1553 device as a bus controller (BC) and sends out a message.
This routine demonstrates the following API functions in the 1553 naibrd library:
naibrd_1553_Open
naibrd_1553_Initialize
naibrd_1553_BcDataBlockCreate
naibrd_1553_BcMessageCreateBcToRt
naibrd_1553_BcMessageCreateRtToBc
naibrd_1553_BcMessageCreateMode
naibrd_1553_BcMessageCreateRtToRt
naibrd_1553_BcCommandCreate
naibrd_1553_BcFrameCreate
naibrd_1553_BcDataBlockWrite
naibrd_1553_BcStart
naibrd_1553_BcStop
naibrd_1553_Free
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_M1553_BC_SendMessage(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = FALSE;
int32_t channel;
int32_t MaxChannel = 4;
if (IsFTx1553(modid))
{
MaxChannel = 4;
bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
if (!bQuit)
{
bQuit = RunSendMessage(cardIndex, module, channel, modid);
}
}
else
printf("\nThis module does not support 1553 functionality.\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 = FALSE;
uint32_t usBus;
nai_1553_t status;
uint16_t increment = 0;
uint16_t aData[32] = {0};
int16_t aOpCodes[20] = { 0 };
bool_t bContinue = TRUE;
int16_t devnum;
bool_t isValidModeCode;
M1553MsgType_t msgType;
naiDecodedMessageStructure DecodedMsgStruct;
bool_t bSoftware;
M1553ModeCodes_t modeCommand = (M1553ModeCodes_t)0;
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(TRUE, &bSoftware);
if (!bQuit)
{
/* Open 1553 Device(s) */
status = naibrd_1553_Open(cardIndex, module, channel, devnum);
if(status != 0)
{
printf("Error: naibrd_1553_Open Ch %d, status = %d", channel, status);
return TRUE;
}
if (bSoftware)
{
naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000);
}
else
{
naibrd_1553_WriteAuxReg(devnum, 0x2, 0x0000);
}
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, &isValidModeCode);
} while ((!bQuit) && (!isValidModeCode));
}
/* Reset Device */
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x1);
#if defined (__VXWORKS__)
taskDelay(1);
#elif defined (LINUX)
usleep(100000);
#else
Sleep(100);
#endif
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x0);
/* Initialize 1553 Device(s) */
status = naibrd_1553_Initialize(devnum, NAI_1553_ACCESS_CARD,NAI_1553_MODE_BC,0,0,0);
if(status != 0)
{
printf("Error: naibrd_1553_Initialize Ch %d, status = %d", channel, status);
return TRUE;
}
if ((msgType != M1553_MSGTYPE_MODECODE_TX) || (msgType != M1553_MSGTYPE_MODECODE_RX))
{
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, WORDCOUNT, NULL, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
return TRUE;
}
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK2, modeCommand, NULL, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
return TRUE;
}
}
if (msgType == M1553_MSGTYPE_RTTOBC)
{
status = naibrd_1553_BcMessageCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
}
else if (msgType == M1553_MSGTYPE_BCTORT)
{
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
status = naibrd_1553_BcMessageCreateMode(devnum, MSG1, DBLK1, RT_ADDRESS, (msgType == M1553_MSGTYPE_MODECODE_TX) ?
NAI_1553_CMD_TX : NAI_1553_CMD_RX, modeCommand, 0, usBus);
}
else if (msgType == M1553_MSGTYPE_RTTORT)
{
status = naibrd_1553_BcMessageCreateRtToRt(devnum, MSG1, DBLK1, RT_ADDRESS_2, RT_SUBADDRESS, WORDCOUNT, RT_ADDRESS, RT_SUBADDRESS, 0, usBus);
}
/* Create Execute Message Command */
status = naibrd_1553_BcCommandCreate(devnum, OP1, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
/* Create Call Subroutine Command */
status = naibrd_1553_BcCommandCreate(devnum, OP2, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
/* Create Minor Frame */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
/* Create Major Frame */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrameCreate(devnum,MJR,NAI_1553_BC_FRAME_MAJOR,aOpCodes,1,1000,0);
while (bContinue)
{
for (i = 0; i < WORDCOUNT; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
status = naibrd_1553_BcStart(devnum,MJR,1);
nai_msDelay(200);
status = naibrd_1553_BcStop(devnum);
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG1, &DecodedMsgStruct, 1);
if (status > 0)
{
printf("Control Word: 0x%04X\n", DecodedMsgStruct.wBcControlWord);
printf("Command Word: 0x%04X\n", DecodedMsgStruct.wCommandWord1);
if (DecodedMsgStruct.bIsCommandWord2Relevant)
printf("Command Word 2: 0x%04X\n", DecodedMsgStruct.wCommandWord2);
printf("Block Status: 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag: 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Word Count: 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("RT Status Word: 0x%04X\n", DecodedMsgStruct.wStatus1);
if (DecodedMsgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", DecodedMsgStruct.wStatus2);
if ((msgType == M1553_MSGTYPE_RTTOBC) || (msgType == M1553_MSGTYPE_MODECODE_TX))
{
printf((DecodedMsgStruct.wDataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
{
if (i % 8 == 0) printf("\n");
printf("0x%04X ", DecodedMsgStruct.waData[i]);
}
}
printf("\n\n");
}
printf("\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 = FALSE;
}
}
}
}
}
status = naibrd_1553_Free(devnum);
return bQuit;
}