M1553 ModeCode TxLastCmdWord
Edit this on GitLab
M1553 ModeCode TxLastCmdWord Sample Application (SSK 1.x)
Overview
The M1553 ModeCode TxLastCmdWord sample application demonstrates a two-phase MIL-STD-1553 Bus Controller (BC) operation using the NAI Software Support Kit (SSK 1.x): first, send a regular BC-to-RT (or RT-to-BC) message, then send a "Transmit Last Command Word" mode code (mode code 0x12) to the same RT. The RT should respond to the mode code by returning the command word from the first message as its data word. This sequence verifies that the RT correctly received and processed the most recent command.
Unlike most other BC samples, this application splits the work across two functions that share a device handle. The first function (RunSendMessage()) opens the device, initializes the BC, creates the regular message with its frame hierarchy, and loads data — but does not start the BC. The second function (RunSendModeCodeMessage()) reuses the already-open device, creates the mode code message and a new minor frame containing both the original message and the mode code, starts the BC, and reads back both results.
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 and mode code definitions, 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).
-
An RT at address 1 that supports the Transmit Last Command Word mode code (0x12).
-
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_ModeCode_TxLastCmdWord executable from your build output directory. On startup the application looks for a configuration file (default_1553_RTReceive.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 a channel, logical device number, message direction (BC-to-RT or RT-to-BC), bus, and software override setting, then sends the regular message followed by the mode code and displays both responses.
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_1553_RTReceive.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.
The mode code value 0x12 (Transmit Last Command Word), the gap time, and the bus for the mode code are hardcoded in main():
int16_t devnum = 0;
uint16_t gapTime = 100;
uint16_t modeTransmitLastCommandWord = 0x12;
uint32_t channel = 1;
The gap time of 100 (10 ms in 0.1 ms units) provides spacing between the regular message and the mode code message on the bus.
After module selection, main() calls two functions in sequence:
/* First: send a regular BC message (opens device, creates message, loads data) */
stop = Run_M1553_BC_SendMessage(cardIndex, module, moduleID);
/* Second: send Transmit Last Command Word mode code (reuses open device) */
RunSendModeCodeMessage(devnum, channel, modeTransmitLastCommandWord, gapTime);
|
Important
|
Common Connection Errors
|
Program Structure
The application is organized into four functions:
-
main()— standard SSK 1.x startup, then calls the two-phase operation:Run_M1553_BC_SendMessage()followed byRunSendModeCodeMessage(). -
Run_M1553_BC_SendMessage()— validates the module supports 1553 viaIsFTx1553(), queries for a channel number, and callsRunSendMessage(). -
RunSendMessage()— opens the device, initializes as BC, creates a regular BC-to-RT (or RT-to-BC) message with its frame hierarchy, and loads data. Does NOT start the BC. -
RunSendModeCodeMessage()— creates the mode code message, builds a new minor frame containing both the original message and the mode code, starts the BC, and decodes both responses.
The sample defines these constants:
/* Messages */
#define MSG1 1 /* Regular message (BC-to-RT or RT-to-BC) */
#define MSG2 2 /* Transmit Last Command Word mode code */
/* Opcodes */
#define OP1 1 /* Execute MSG1 */
#define OP2 2 /* Call MNR1 (first minor frame) */
#define OP3 3 /* Execute MSG2 (mode code) */
#define OP4 4 /* Call MNR2 (combined minor frame) */
/* Frames */
#define MNR1 1 /* Minor frame for MSG1 alone */
#define MNR2 2 /* Minor frame for MSG1 + MSG2 combined */
#define MJR 3 /* Major frame (first phase, unused at runtime) */
#define MJR1 4 /* Major frame (second phase, actually executed) */
/* Data blocks */
#define DBLK1 1 /* Data block for the regular message */
#define DBLK2 2 /* Data block for the mode code */
#define RT_ADDRESS 1 /* Target RT address */
#define RT_SUBADDRESS 2 /* Target subaddress */
#define WORDCOUNT 11 /* Data words per message */
Phase 1: Regular BC Message Setup
The first function initializes the device and prepares a regular message without starting the BC:
/* Open and initialize */
status = naibrd_1553_Open(cardIndex, module, channel, devnum);
if (bSoftware)
naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000);
else
naibrd_1553_WriteAuxReg(devnum, 0x2, 0x0000);
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x1);
Sleep(100);
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x0);
status = naibrd_1553_Initialize(devnum, NAI_1553_ACCESS_CARD, NAI_1553_MODE_BC, 0, 0, 0);
Then it creates the data block, message (direction chosen by the user), frame hierarchy, and loads data:
/* Create data block and message */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, WORDCOUNT, NULL, 0);
if (bcToRtMsg)
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
else
status = naibrd_1553_BcMessageCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
/* Build frame hierarchy for MSG1 */
status = naibrd_1553_BcCommandCreate(devnum, OP1,
NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
status = naibrd_1553_BcCommandCreate(devnum, OP2,
NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrameCreate(devnum, MJR, NAI_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, 0);
/* Load data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
aData[i] = increment++;
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
Note that RunSendMessage() does NOT call naibrd_1553_BcStart(). It prepares all message objects and data, then returns. The device remains open and initialized for the second phase.
|
Important
|
Common Errors
|
Phase 2: Transmit Last Command Word Mode Code
RunSendModeCodeMessage() creates the mode code message and a combined minor frame that sends both the original message and the mode code in sequence:
/* Create mode code data block and message */
sResult = naibrd_1553_BcDataBlockCreate(swDevice, DBLK2, WORDCOUNT, NULL, 0);
sResult = naibrd_1553_BcMessageCreateMode(swDevice, MSG2, DBLK2, RT_ADDRESS,
NAI_1553_CMD_TX, wModeCommand, wGapTime, NAI_1553_BC_CTRL_BUS_A);
The parameters for naibrd_1553_BcMessageCreateMode() are:
-
MSG2(2) — a unique message ID for the mode code. -
DBLK2(2) — the data block ID for storing the mode code response. -
RT_ADDRESS(1) — the target RT address (same as the first message). -
NAI_1553_CMD_TX— this is a transmit mode code: the RT transmits data back to the BC. -
wModeCommand(0x12) — the specific mode code: Transmit Last Command Word. -
wGapTime(100) — gap time in 0.1 ms units (10 ms) before the next message. -
NAI_1553_BC_CTRL_BUS_A— hardcoded to Bus A for the mode code.
Combined Frame Hierarchy
A new minor frame (MNR2) includes both the original message execute opcode (OP1, from Phase 1) and the mode code execute opcode (OP3). This ensures the regular message is sent first, immediately followed by the mode code:
/* Create mode code execute opcode */
status = naibrd_1553_BcCommandCreate(swDevice, OP3,
NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG2, 0, 0);
/* Create call subroutine for the combined minor frame */
status = naibrd_1553_BcCommandCreate(swDevice, OP4,
NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR2, 0, 0);
/* Minor frame with both messages: OP1 (regular msg) then OP3 (mode code) */
aOpCodes[0] = OP1;
aOpCodes[1] = OP3;
status = naibrd_1553_BcFrameCreate(swDevice, MNR2, NAI_1553_BC_FRAME_MINOR, aOpCodes, 2, 0, 0);
/* New major frame calling the combined minor frame */
aOpCodes[0] = OP4;
status = naibrd_1553_BcFrameCreate(swDevice, MJR1, NAI_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, 0);
The order of opcodes in MNR2 is critical: OP1 (MSG1) must come before OP3 (MSG2) so that the regular message is the "last command" when the mode code executes. The RT will then respond with MSG1’s command word as its data.
Execute and Decode Both Results
/* Start BC for one iteration of the combined frame */
status = naibrd_1553_BcStart(swDevice, MJR1, 1);
/* Allow time for execution */
nai_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(swDevice);
After execution, decode both message results:
/* Decode the regular message (MSG1) result */
status = naibrd_1553_BcMessageGetByIdDecoded(swDevice, MSG1, &DecodedMsgStruct, 1);
if (status > 0)
{
printf("Control Word: 0x%04X\n", DecodedMsgStruct.wBcControlWord);
printf("Command Word: 0x%04X\n", DecodedMsgStruct.wCommandWord1);
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);
}
/* Decode the mode code (MSG2) result */
status = naibrd_1553_BcMessageGetByIdDecoded(swDevice, MSG2, &DecodedMsgStruct, 1);
if (status > 0)
{
printf("Control Word: 0x%04X\n", DecodedMsgStruct.wBcControlWord);
printf("Command Word: 0x%04X\n", DecodedMsgStruct.wCommandWord1);
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);
printf("Data:");
for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
printf("\n");
printf("0x%04X ", DecodedMsgStruct.waData[i]);
}
}
The mode code response’s waData[0] should contain the command word from the first message (MSG1). This allows you to verify that the RT correctly received and processed the previous command. If the data word does not match the expected command word, the RT may have a different interpretation of the "last command" or may not fully implement mode code 0x12.
|
Important
|
Common Errors
|
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 |
Module not recognized as 1553 |
Selected module is not an FT-series or CM with 1553 |
Verify the module type using the board menu |
Regular message creation fails |
Invalid RT address/subaddress, data block not created |
Check parameter ranges, create data block before message |
Mode code message creation fails |
Invalid RT address, data block not created, invalid mode code |
Check RT address range (0-30), create DBLK2 before MSG2 |
|
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 at address 1, check cabling, try other bus |
RT does not support mode code |
Mode code 0x12 (Transmit Last Command Word) not implemented by the target RT |
Consult the RT documentation. Not all RTs implement all mode codes. |
Mode code data does not match command word |
RT processed a different command, or RT implementation differs |
Verify MNR2 sends MSG1 immediately before MSG2 with no intervening messages |
First message error |
Bus error on the regular message (check block status word) |
Verify RT address, subaddress, word count, and physical bus connections |
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_ModeCode_TxLastCmdWord.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"
#include "nai_1553_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_1553_RTReceive.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);
static bool_t RunSendModeCodeMessage(int16_t swDevice, int32_t channel, uint16_t wModeCommand, uint16_t wGapTime);
/* define message constants */
#define MSG1 1
#define MSG2 2
/* define opcodes */
#define OP1 1
#define OP2 2
#define OP3 3
#define OP4 4
/* define frame constants */
#define MNR1 1
#define MNR2 2
#define MJR 3
#define MJR1 4
/* 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 2
#define DEF_M1553_DEVNUM 0
#define RT_ADDRESS 1
#define RT_SUBADDRESS 2
#define WORDCOUNT 11
#if defined (__VXWORKS__)
int32_t M1553_ModeCode_TxLastCmdWord(void)
#else
int32_t main(void)
#endif
{
bool_t stop = FALSE;
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
uint32_t moduleID = 0;
int16_t devnum = 0;
uint16_t gapTime = 100;
uint16_t modeTransmitLastCommandWord = 0x12;
uint32_t channel = 1;
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))
{
/* First 1553 message */
stop = Run_M1553_BC_SendMessage(cardIndex, module, moduleID);
/* 1553 Mode Code "Transmit Last Command Word" */
RunSendModeCodeMessage(devnum, channel, modeTransmitLastCommandWord, gapTime);
}
}
}
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;
}
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 };
int16_t devnum;
bool_t bcToRtMsg = TRUE;
bool_t bSoftware;
/* Get the Logical Device Number */
bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUM, &devnum);
if (!bQuit)
{
/* Get Msg Direction */
bQuit = GetMsgDirection(&bcToRtMsg);
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 (modid == NAI_MODULE_ID_FT8)
{
/* Simplex Enable (for NAI internal testing only, do not enable) */
/*naibrd_1553_WriteAuxReg(devnum, 0x3, 0x4000);
naibrd_1553_WriteAuxReg(devnum, 0xF, 0x0001);*/
}
/* 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;
}
/* Create BC Data Block */
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;
}
if (bcToRtMsg)
{
/* Create BC to RT Message */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
return TRUE;
}
}
else
{
/* Create RT to BC Message */
status = naibrd_1553_BcMessageCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageCreateRtToBc status = %d", status);
return TRUE;
}
}
/* Create Execute Message Command */
status = naibrd_1553_BcCommandCreate(devnum, OP1, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
return TRUE;
}
/* Create Call Subroutine Command */
status = naibrd_1553_BcCommandCreate(devnum, OP2, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
return TRUE;
}
/* Create Minor Frame */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Create Major Frame */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrameCreate(devnum,MJR,NAI_1553_BC_FRAME_MAJOR,aOpCodes,1,1000,0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Load BC data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
return TRUE;
}
}
}
}
}
return bQuit;
}
static bool_t RunSendModeCodeMessage(int16_t swDevice, int32_t channel, uint16_t wModeCommand, uint16_t wGapTime)
{
int32_t i;
naiDecodedMessageStructure DecodedMsgStruct;
nai_1553_t status = 0;
int16_t aOpCodes[20] = { 0 };
nai_1553_t sResult = 0;
sResult = naibrd_1553_BcDataBlockCreate(swDevice, DBLK2, WORDCOUNT, NULL, 0);
if(sResult != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, sResult);
return TRUE;
}
/* Set up "Transmit Last Command Word" Mode code message */
sResult = naibrd_1553_BcMessageCreateMode(swDevice, MSG2, DBLK2, RT_ADDRESS, NAI_1553_CMD_TX, wModeCommand, wGapTime,
NAI_1553_BC_CTRL_BUS_A);
/* Create Execute Message Command */
status = naibrd_1553_BcCommandCreate(swDevice, OP3, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG2, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
return TRUE;
}
/* Create Call Subroutine Command */
status = naibrd_1553_BcCommandCreate(swDevice, OP4, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR2, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
return TRUE;
}
/* Create Minor Frame */
aOpCodes[0] = OP1;
aOpCodes[1] = OP3;
status = naibrd_1553_BcFrameCreate(swDevice, MNR2, NAI_1553_BC_FRAME_MINOR, aOpCodes, 2, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Create Major Frame */
aOpCodes[0] = OP4;
status = naibrd_1553_BcFrameCreate(swDevice,MJR1,NAI_1553_BC_FRAME_MAJOR,aOpCodes,1,1000,0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Start BC */
status = naibrd_1553_BcStart(swDevice,MJR1,1);
if (status != 0)
{
printf("Error: naibrd_1553_BcStart status = %d", status);
return TRUE;
}
/* This delay is necessary to allow the BC to run */
nai_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(swDevice);
if (status != 0)
{
printf("Error: naibrd_1553_BcStop status = %d", status);
return TRUE;
}
/* Get Decoded Msg Structure */
status = naibrd_1553_BcMessageGetByIdDecoded(swDevice, MSG1, &DecodedMsgStruct, 1);
if (status < 0)
{
printf("Error: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
return TRUE;
}
else if (status > 0)
{
printf("Control Word: 0x%04X\n", DecodedMsgStruct.wBcControlWord);
printf("Command Word: 0x%04X\n", DecodedMsgStruct.wCommandWord1);
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);
printf("\n\n");
}
/* Get Decoded Msg Structure */
status = naibrd_1553_BcMessageGetByIdDecoded(swDevice, MSG2, &DecodedMsgStruct, 1);
if (status < 0)
{
printf("Error: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
return TRUE;
}
else if (status > 0)
{
printf("Control Word: 0x%04X\n", DecodedMsgStruct.wBcControlWord);
printf("Command Word: 0x%04X\n", DecodedMsgStruct.wCommandWord1);
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);
printf("Data:");
for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", DecodedMsgStruct.waData[i]);
}
printf("\n\n");
}
return TRUE;
}