M1553 BC SendMessageSchedule
Edit this on GitLab
M1553 BC SendMessageSchedule Sample Application (SSK 1.x)
Overview
The M1553 BC SendMessageSchedule sample application demonstrates how to configure a MIL-STD-1553 Bus Controller (BC) to send multiple messages at different periodic rates using the NAI Software Support Kit (SSK 1.x). This is the key BC sample for multi-rate scheduling — real systems rarely send every message at the same rate. Instead, high-priority or fast-changing data runs at a higher frequency while slower telemetry runs at a lower rate. The BC frame hierarchy handles all timing in hardware, with no software polling or timer interrupts required.
This sample sends three BC-to-RT messages at three different rates:
-
Message 1 — 40 Hz (every 25 ms) to RT subaddress 1, 11 data words
-
Message 2 — 20 Hz (every 50 ms) to RT subaddress 2, 21 data words
-
Message 3 — 10 Hz (every 100 ms) to RT subaddress 8, 30 data words
The different rates are achieved by composing three minor frames (each 25 ms) in a specific order within the major frame. The major frame period is 100 ms (four minor frames at 25 ms each). By including different combinations of messages in each minor frame, each message achieves its target rate without any software intervention during execution.
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).
-
An RT at address 1 configured to accept messages on subaddresses 1, 2, and 8.
-
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_SendMessageSchedule executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessageSchedule.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, bus selection, and software override setting, then runs the multi-rate schedule continuously for approximately 10 seconds.
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_SendMessageSchedule.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_SendMessageSchedule(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_SendMessageSchedule(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_SendMessageSchedule()— validates the module supports 1553 viaIsFTx1553(), queries for a channel number, and callsRunSendMessageSchedule(). -
RunSendMessageSchedule()— the core BC workflow: opens the device, initializes as BC, creates three messages with different word counts and subaddresses, builds the multi-rate frame hierarchy, runs the schedule for 10 seconds, and decodes the last Message 1 response.
The sample defines these constants for the three messages and the frame hierarchy:
/* Messages */
#define MSG1 1
#define MSG2 2
#define MSG3 3
/* Opcodes: execute-message and call-subroutine */
#define OP1 1 /* Execute MSG1 */
#define OP2 2 /* Execute MSG2 */
#define OP3 3 /* Execute MSG3 */
#define OP4 4 /* Call MNR1 */
#define OP5 5 /* Call MNR2 */
#define OP6 6 /* Call MNR3 */
/* Frames */
#define MNR1 1 /* Minor frame 1: MSG1 + MSG2 + MSG3 */
#define MNR2 2 /* Minor frame 2: MSG1 + MSG2 */
#define MNR3 3 /* Minor frame 3: MSG1 only */
#define MJR 4 /* Major frame */
/* Data blocks */
#define DBLK1 1
#define DBLK2 2
#define DBLK3 3
/* RT addressing */
#define RT_ADDRESS 1
#define RT_SUBADDRESS1 1 /* Subaddress for Message 1 */
#define RT_SUBADDRESS2 2 /* Subaddress for Message 2 */
#define RT_SUBADDRESS3 8 /* Subaddress for Message 3 */
/* Word counts */
#define WORDCOUNT1 11 /* Data words for Message 1 */
#define WORDCOUNT2 21 /* Data words for Message 2 */
#define WORDCOUNT3 30 /* Data words for Message 3 */
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, 1);
nai_msDelay(1);
naibrd_1553_WriteAuxReg(devnum, 0x1, 0);
/* 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 Data Blocks and Messages
Three data blocks and three BC-to-RT messages are created, each targeting a different subaddress with a different word count:
/* Create three data blocks (one per message) */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, NAI_1553_BC_DATABLOCK_SINGLE, NULL, 0);
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK2, NAI_1553_BC_DATABLOCK_SINGLE, NULL, 0);
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK3, NAI_1553_BC_DATABLOCK_SINGLE, NULL, 0);
/* Create BC-to-RT messages */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS1, WORDCOUNT1, 0, usBus);
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG2, DBLK2, RT_ADDRESS, RT_SUBADDRESS2, WORDCOUNT2, 0, usBus);
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS3, WORDCOUNT3, 0, usBus);
Each message targets a different subaddress (1, 2, 8) and carries a different number of data words (11, 21, 30). All three messages go to the same RT address (1). The NAI_1553_BC_DATABLOCK_SINGLE constant creates a single-buffer data block.
An execute-message opcode is then created for each message:
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_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG2, 0, 0);
status = naibrd_1553_BcCommandCreate(devnum, OP3, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG3, 0, 0);
|
Important
|
Common Errors
|
Building the Multi-Rate Frame Hierarchy
This is the key feature of this sample. The multi-rate behavior is achieved entirely through the composition of minor frames within the major frame. Each minor frame runs for 25 ms (250 units, where 1 unit = 0.1 ms), and contains a different combination of message opcodes.
Minor Frames
Three minor frames are created with different message combinations:
/* Minor Frame 1: Messages 1, 2, and 3 (all three) */
aOpCodes[0] = OP1;
aOpCodes[1] = OP2;
aOpCodes[2] = OP3;
status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 3, 250, 0);
/* Minor Frame 2: Messages 1 and 2 only */
aOpCodes[0] = OP1;
aOpCodes[1] = OP2;
status = naibrd_1553_BcFrameCreate(devnum, MNR2, NAI_1553_BC_FRAME_MINOR, aOpCodes, 2, 250, 0);
/* Minor Frame 3: Message 1 only */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrameCreate(devnum, MNR3, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 250, 0);
The 250 parameter is the frame time in units of 0.1 ms, which gives each minor frame a 25 ms period.
Major Frame
The major frame chains the minor frames via call-subroutine opcodes in a specific order. The order is critical to achieving the correct per-message rates:
/* Create Call Subroutine Commands (one per minor frame) */
status = naibrd_1553_BcCommandCreate(devnum, OP4, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
status = naibrd_1553_BcCommandCreate(devnum, OP5, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR2, 0, 0);
status = naibrd_1553_BcCommandCreate(devnum, OP6, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR3, 0, 0);
/* Major Frame: MNR1 -> MNR3 -> MNR2 -> MNR3 */
aOpCodes[0] = OP4; /* Minor Frame 1 */
aOpCodes[1] = OP6; /* Minor Frame 3 */
aOpCodes[2] = OP5; /* Minor Frame 2 */
aOpCodes[3] = OP6; /* Minor Frame 3 */
status = naibrd_1553_BcFrameCreate(devnum, MJR, NAI_1553_BC_FRAME_MAJOR, aOpCodes, 4, 0, 0);
|
Note
|
The frameTime parameter for the major frame is set to 0. This is critical — setting a non-zero value here would override all individual minor frame times with that single value, destroying the per-minor-frame timing you set in naibrd_1553_BcFrameCreate() for each minor frame. Always leave the major frame time at 0 when using per-minor-frame timing.
|
Resulting Schedule
The four minor frames execute in this order within each 100 ms major frame cycle:
| Time Slot | Minor Frame | Messages Executed |
|---|---|---|
0-25 ms |
MNR1 |
Messages 1, 2, 3 |
25-50 ms |
MNR3 |
Message 1 |
50-75 ms |
MNR2 |
Messages 1, 2 |
75-100 ms |
MNR3 |
Message 1 |
Over one complete 100 ms cycle:
-
Message 1 executes in all four minor frames = 4 times per 100 ms = 40 Hz
-
Message 2 executes in MNR1 and MNR2 = 2 times per 100 ms = 20 Hz
-
Message 3 executes in MNR1 only = 1 time per 100 ms = 10 Hz
To achieve a different set of rates for your own application, adjust which messages appear in which minor frames and how those minor frames are ordered in the major frame. The frame time units (0.1 ms) and the number of minor frames per major frame determine your base scheduling granularity.
|
Important
|
Common Errors
|
Data Loading and Continuous Execution
The application loads each data block with distinct data patterns, then runs the BC schedule continuously for approximately 10 seconds:
/* Load data block 1 with incrementing values */
for (i = 0; i < WORDCOUNT1; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT1, 0);
/* Load data block 2 with 0x5566 */
for (i = 0; i < WORDCOUNT2; i++)
{
aData[i] = 0x5566;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK2, aData, WORDCOUNT2, 0);
/* Load data block 3 with 0xBBCC */
for (i = 0; i < WORDCOUNT3; i++)
{
aData[i] = 0xBBCC;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK3, aData, WORDCOUNT3, 0);
/* Start BC running continuously */
status = naibrd_1553_BcStart(devnum, MJR, NAI_1553_BC_FRAME_RUN_FOREVER);
NAI_1553_BC_FRAME_RUN_FOREVER causes the major frame to repeat indefinitely until naibrd_1553_BcStop() is called. During this time, the hardware autonomously walks the frame hierarchy, sending each message at its configured rate. No software intervention is needed while the schedule runs.
After approximately 10 seconds (nai_msDelay(10000)), the application stops the BC and reads back the most recent result for Message 1:
status = naibrd_1553_BcStop(devnum);
/* Decode the last Message 1 response */
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);
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);
}
Note that naibrd_1553_BcMessageGetByIdDecoded() returns only the most recent result for a given message ID. Over a 10-second run with NAI_1553_BC_FRAME_RUN_FOREVER, Message 1 is sent approximately 400 times. To capture every transaction, use the FIFO-mode variant (M1553_BC_SendMessageSchedule_FIFO).
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 |
Data block or message creation returns non-zero |
Invalid RT address/subaddress, data block not created, duplicate ID |
Check parameter ranges, create data blocks before messages, use unique IDs |
All messages at same rate |
Major frame |
Set the major frame |
Message not executing in schedule |
Opcode not included in minor frame, or minor frame not called from major frame |
Verify each message has an execute opcode, each minor frame includes correct opcodes, major frame calls all minor frames |
|
Incomplete frame hierarchy, device not initialized as BC |
Verify all opcodes, minor frames, and major frame are created before starting |
No response from RT |
RT not on bus, bus wiring issue, wrong bus (A/B) selected |
Verify RT is active at address 1, 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_SendMessageSchedule.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_SendMessageSchedule.txt";
/* Function prototypes */
static bool_t Run_M1553_BC_SendMessageSchedule(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunSendMessageSchedule(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid);
/* define message constants */
#define MSG1 1
#define MSG2 2
#define MSG3 3
/* define opcodes */
#define OP1 1
#define OP2 2
#define OP3 3
#define OP4 4
#define OP5 5
#define OP6 6
/* define frame constants */
#define MNR1 1
#define MNR2 2
#define MNR3 3
#define MJR 4
/* define data block numbers */
#define DBLK1 1
#define DBLK2 2
#define DBLK3 3
#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_SUBADDRESS1 1 /* Subaddress for Message 1 */
#define RT_SUBADDRESS2 2 /* Subaddress for Message 2 */
#define RT_SUBADDRESS3 8 /* Subaddress for Message 3 */
#define WORDCOUNT1 11 /* Data Word count for Message 1 */
#define WORDCOUNT2 21 /* Data Word count for Message 2 */
#define WORDCOUNT3 30 /* Data Word count for Message 3 */
#if defined (__VXWORKS__)
int32_t M1553_BC_SendMessageSchedule(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_SendMessageSchedule(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;
}
static bool_t Run_M1553_BC_SendMessageSchedule(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 = RunSendMessageSchedule(cardIndex, module, channel, modid);
}
}
else
printf("\nThis module does not support 1553 functionality.\n");
return bQuit;
}
static bool_t RunSendMessageSchedule(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;
naiDecodedMessageStructure DecodedMsgStruct;
bool_t bSoftware;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get the Logical Device Number */
bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUM, &devnum);
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, 0);
}
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, 1);
nai_msDelay(1);
naibrd_1553_WriteAuxReg(devnum, 0x1, 0);
/* 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 1 */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, NAI_1553_BC_DATABLOCK_SINGLE, NULL, 0);
if(status != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
return TRUE;
}
/* Create BC Data Block 2 */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK2, NAI_1553_BC_DATABLOCK_SINGLE, NULL, 0);
if(status != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
return TRUE;
}
/* Create BC Data Block 3 */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK3, NAI_1553_BC_DATABLOCK_SINGLE, NULL, 0);
if(status != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
return TRUE;
}
/* Create BC to RT Message 1 */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS1, WORDCOUNT1, 0, usBus);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
return TRUE;
}
/* Create BC to RT Message 2 */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG2, DBLK2, RT_ADDRESS, RT_SUBADDRESS2, WORDCOUNT2, 0, usBus);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
return TRUE;
}
/* Create BC to RT Message 3 */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS3, WORDCOUNT3, 0, usBus);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
return TRUE;
}
/* Create Execute Message Command 1 */
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 Execute Message Command 2 */
status = naibrd_1553_BcCommandCreate(devnum, OP2, 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 Execute Message Command 3 */
status = naibrd_1553_BcCommandCreate(devnum, OP3, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG3, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
return TRUE;
}
/* Create Minor Frame 1 */
aOpCodes[0] = OP1; /* Execute Message 1 Command */
aOpCodes[1] = OP2; /* Execute Message 2 Command */
aOpCodes[2] = OP3; /* Execute Message 3 Command */
status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 3, 250, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Create Minor Frame 2 */
aOpCodes[0] = OP1; /* Execute Message 1 Command */
aOpCodes[1] = OP2; /* Execute Message 2 Command */
status = naibrd_1553_BcFrameCreate(devnum, MNR2, NAI_1553_BC_FRAME_MINOR, aOpCodes, 2, 250, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Create Minor Frame 3 */
aOpCodes[0] = OP1; /* Execute Message 1 Command */
status = naibrd_1553_BcFrameCreate(devnum, MNR3, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 250, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
/* Create Call Subroutine Command 1 */
status = naibrd_1553_BcCommandCreate(devnum, OP4, 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 Call Subroutine Command 2 */
status = naibrd_1553_BcCommandCreate(devnum, OP5, 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 Call Subroutine Command 3 */
status = naibrd_1553_BcCommandCreate(devnum, OP6, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR3, 0, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
return TRUE;
}
/* Create Major Frame */
aOpCodes[0] = OP4; /* Minor Frame 1 */
aOpCodes[1] = OP6; /* Minor Frame 3 */
aOpCodes[2] = OP5; /* Minor Frame 2 */
aOpCodes[3] = OP6; /* Minor Frame 3 */
status = naibrd_1553_BcFrameCreate(devnum,MJR,NAI_1553_BC_FRAME_MAJOR,aOpCodes,4,0,0);
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
while (bContinue)
{
/* Load BC data block 1 with incremental data */
for (i = 0; i < WORDCOUNT1; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT1, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
return TRUE;
}
/* Load BC data block 2 with 0x5566 */
for (i = 0; i < WORDCOUNT2; i++)
{
aData[i] = 0x5566;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK2, aData, WORDCOUNT2, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
return TRUE;
}
/* Load BC data block 3 with 0xBBCC */
for (i = 0; i < WORDCOUNT3; i++)
{
aData[i] = 0xBBCC;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK3, aData, WORDCOUNT3, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
return TRUE;
}
/* Start BC */
status = naibrd_1553_BcStart(devnum,MJR,NAI_1553_BC_FRAME_RUN_FOREVER);
if (status != 0)
{
printf("Error: naibrd_1553_BcStart status = %d", status);
return TRUE;
}
printf("BC Running for approximately 10 seconds...\n");
/* Run the schedule for 10 seconds */
nai_msDelay(10000);
/* Stop BC */
status = naibrd_1553_BcStop(devnum);
if (status != 0)
{
printf("Error: naibrd_1553_BcStop status = %d", status);
return TRUE;
}
printf("BC Halted.\n");
/* Get Decoded Msg Structure */
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, 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("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;
}
}
}
}
}
/* Free 1553 Device */
status = naibrd_1553_Free(devnum);
if (status != 0)
{
printf("Error: naibrd_1553_Free status = %d", status);
return TRUE;
}
return bQuit;
}