M1553 BC SendMessage Async
Edit this on GitLab
M1553 BC SendMessage Async Sample Application (SSK 1.x)
Overview
The M1553 BC SendMessage Async sample application demonstrates how to send asynchronous MIL-STD-1553 Bus Controller (BC) messages while a scheduled (synchronous) message runs continuously in the background. Using the NAI Software Support Kit (SSK 1.x), this sample shows how to configure the BC for asynchronous operation, create async BC-to-RT messages, and send them at either high or low priority using the ExecuteOnce functions.
In a typical 1553 system, the BC sends messages on a fixed schedule defined by the frame hierarchy. Asynchronous messages allow you to inject additional messages outside the normal schedule — for example, to send an urgent command or an event-driven data update without modifying the scheduled frame. The NAI 1553 hardware manages a separate async message queue that the BC processes between scheduled minor frames.
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_Async executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessage_Async.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, bus selection, async priority mode (high or low), and software override settings, then sends a scheduled BC-to-RT message continuously at 500 ms intervals while injecting asynchronous messages.
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_Async.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_Async(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_Async(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_Async()— validates the module supports 1553 viaIsFTx1553(), queries for a channel number, and callsRunSendMessage(). -
RunSendMessage()— the core BC workflow: opens the device, initializes as BC with async support, creates a scheduled BC-to-RT message and async messages, runs the BC continuously, injects async messages at the selected priority, decodes responses, and cleans up async resources.
The sample defines these constants for its frame hierarchy and timing:
#define MSG1 1 /* Scheduled message ID */
#define MSG3 3 /* Async message 1 ID */
#define MSG4 4 /* Async message 2 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 scheduled message */
#define DBLK3 3 /* Data block for async message 1 */
#define DBLK4 4 /* Data block for async message 2 */
#define RT_ADDRESS 1 /* Target RT address */
#define RT_SUBADDRESS 2 /* Target subaddress */
#define MNR_FRAME_TIME 500 /* Minor frame time in ms */
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.
Enabling Asynchronous Message Support
After initializing the BC, you must explicitly enable asynchronous messaging by calling naibrd_1553_BcConfig(). This sample enables both high and low priority async modes so you can use the ExecuteOnce send functions:
status = naibrd_1553_BcConfig(devnum,
NAI_1553_BC_ASYNCHRONOUS_BOTH_PRIORITY_MODES |
NAI_1553_BC_ASYNCHRONOUS_HIGH_PRIORITY_ONCE_ANYWAY);
The NAI_1553_BC_ASYNCHRONOUS_BOTH_PRIORITY_MODES flag enables both the high-priority and low-priority async queues. The NAI_1553_BC_ASYNCHRONOUS_HIGH_PRIORITY_ONCE_ANYWAY flag is required when using the _ExecuteOnce send functions — it tells the hardware to send the high-priority async message exactly once even if the BC is in continuous run mode. Both flags must be set together for the ExecuteOnce functions to work correctly.
Without this configuration step, calls to the async send functions will fail. The BC hardware does not process async messages by default — async support must be turned on after naibrd_1553_Initialize() but before starting the BC.
|
Important
|
Common Errors
|
Creating the Scheduled Message and Frame Hierarchy
The sample creates a single scheduled BC-to-RT message that runs continuously every 500 ms. This background message represents the normal scheduled bus traffic alongside which the async messages will be injected.
/* Create BC Data Block */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, 32, NULL, 0);
/* Create BC to RT Message */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, 32, 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 (500 ms period) */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrameCreate(devnum, MJR, NAI_1553_BC_FRAME_MAJOR, aOpCodes, 1, MNR_FRAME_TIME * 10, 0);
The major frame time is MNR_FRAME_TIME * 10 because the frame time parameter is in units of 0.1 ms. With MNR_FRAME_TIME set to 500, this yields a 500 ms cycle period. The scheduled BC-to-RT message (MSG1) repeats every 500 ms for as long as the BC is running.
Creating and Sending Asynchronous Messages
This is the key feature of this sample. Asynchronous messages are created separately from the scheduled frame hierarchy and injected into the bus traffic while the BC is running.
Creating Async Messages
To create an asynchronous BC-to-RT message, call naibrd_1553_BcAsynchronousMessageCreateBcToRt(). Unlike the standard naibrd_1553_BcMessageCreateBcToRt(), the async version accepts the data payload directly in the creation call:
/* Create BC to RT Async Message 1 (data = 0xBCBC) */
for (i = 0; i < 32; i++)
{
aData[i] = 0xBCBC;
}
status = naibrd_1553_BcAsynchronousMessageCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus, aData);
/* Create BC to RT Async Message 2 (data = 0xAAAA) */
for (i = 0; i < 32; i++)
{
aData[i] = 0xAAAA;
}
status = naibrd_1553_BcAsynchronousMessageCreateBcToRt(devnum, MSG4, DBLK4, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus, aData);
Each async message gets its own message ID (MSG3, MSG4) and data block ID (DBLK3, DBLK4), separate from the scheduled message’s IDs. The data payload is passed as the last parameter — the hardware stores it in the associated data block automatically.
Starting the BC in Continuous Mode
Before sending async messages, start the BC in continuous run mode so the scheduled message is actively transmitting:
status = naibrd_1553_BcStart(devnum, MJR, NAI_1553_BC_FRAME_RUN_FOREVER);
nai_msDelay(50);
The NAI_1553_BC_FRAME_RUN_FOREVER parameter tells the BC to repeat the major frame indefinitely. The 50 ms delay allows the BC to begin transmitting the scheduled message before async messages are injected.
Sending at High Priority
To send a single async message immediately at high priority, call naibrd_1553_BcAsynchronousMessageSendAtHighPriority_ExecuteOnce():
status = naibrd_1553_BcAsynchronousMessageSendAtHighPriority_ExecuteOnce(devnum, MSG3, 0);
if (status == NAI_1553_RC_ASYNCHRONOUS_MESSAGE_ERROR)
{
/* Decode the message to determine the error */
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG3, &DecodedMsgStruct, 1);
if (status > 0)
{
printf("\n%s", naibrd_1553_GetBlockStatusWordErrorString(NAI_1553_MODE_BC, DecodedMsgStruct.wBlockStatus));
}
}
else if (status == 0)
{
printf("\nASYNC msg sent successfully\n\n");
}
A high-priority async message is sent at the next available gap in the bus schedule — it takes priority over low-priority async messages and is injected before the next scheduled minor frame begins. The function returns 0 on success, NAI_1553_RC_ASYNCHRONOUS_MESSAGE_ERROR if the message was sent but the RT reported an error, or a negative value for API-level errors.
To diagnose a message-level error, call naibrd_1553_BcMessageGetByIdDecoded() on the async message ID and pass the block status word to naibrd_1553_GetBlockStatusWordErrorString() for a human-readable error description.
Sending at Low Priority
To send multiple async messages at low priority, call naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce() in a loop. Each call processes the next unsent message in the async queue:
do
{
status = naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce(devnum, &dummycount, 0);
if (status > 0)
{
printf("\nremaining async count: %d", status);
}
if (status == NAI_1553_RC_ASYNCHRONOUS_LIST_IS_EMPTY)
{
break;
}
nai_msDelay(MNR_FRAME_TIME);
}
while (status > 0);
A positive return value indicates the number of async messages remaining in the queue. NAI_1553_RC_ASYNCHRONOUS_LIST_IS_EMPTY means all queued messages have been sent. The delay between calls should match the minor frame time (or the smallest minor frame time if you have multiple minor frames) — this gives the hardware time to transmit each message within a frame gap before you request the next one.
After all low-priority messages are sent, you can optionally decode each message to check for errors:
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG3, &DecodedMsgStruct, 1);
if (status > 0)
{
printf("\nMSG3: %s", naibrd_1553_GetBlockStatusWordErrorString(NAI_1553_MODE_BC, DecodedMsgStruct.wBlockStatus));
}
|
Important
|
Common Errors
|
Cleaning Up Asynchronous Messages
After sending async messages (particularly in the low-priority path), you must explicitly delete the async message and its data block. The hardware retains these resources until you free them:
/* Delete async message and data block for MSG3 */
status = naibrd_1553_BcMessageDelete(devnum, MSG3);
status = naibrd_1553_BcDataBlockDelete(devnum, DBLK3);
/* Delete async message and data block for MSG4 */
status = naibrd_1553_BcMessageDelete(devnum, MSG4);
status = naibrd_1553_BcDataBlockDelete(devnum, DBLK4);
Always delete async messages and their data blocks after they have been sent. If you do not, the message and data block IDs remain allocated and cannot be reused in subsequent iterations. In this sample, the cleanup happens inside the main loop so that fresh async messages can be created on the next iteration.
The scheduled message (MSG1/DBLK1) is not deleted here because it persists across loop iterations and is cleaned up when naibrd_1553_Free() is called.
Stopping the BC and Cleanup
After async messages are sent and cleaned up, the sample waits briefly and then stops the BC:
/* Allow 1 more second before stopping BC */
nai_msDelay(1000);
/* Stop BC */
status = naibrd_1553_BcStop(devnum);
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 |
|
Device not initialized as BC |
Call |
Async messages not sent |
Async mode not enabled via |
Verify both |
|
RT not responding, bus wiring issue, wrong bus selected |
Decode block status with |
Low-priority queue does not drain |
Delay between |
Set delay to at least the minor frame time (500 ms in this sample) |
|
Invalid message ID, message not created |
Verify the message ID matches one created with |
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 |
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_Async.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_Async.txt";
/* Function prototypes */
static bool_t Run_M1553_BC_SendMessage_Async(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunSendMessage(int32_t cardIndex, int32_t module, int32_t channel);
/* define message constants */
#define MSG1 1
#define MSG2 2
#define MSG3 3
#define MSG4 4
#define MSG5 5
#define MSG6 6
/* define opcodes */
#define OP1 1
#define OP2 2
#define OP3 3
#define OP4 4
/* define frame constants */
#define MNR1 1
#define MNR2 3
#define MJR 2
/* define data block numbers */
#define DBLK1 1
#define DBLK2 2
#define DBLK3 3
#define DBLK4 4
#define DBLK5 5
#define DBLK6 6
#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 MNR_FRAME_TIME 500 /* in ms */
/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_BC_SendMessage_Async is to illustrate the methods to call in the naibrd library to configure
the 1553 channel as a Bus Controller and send asynchronous messages during normal BC message transmissions.
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_Async(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_Async(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_Async initializes the 1553 device as a bus controller (BC) and sets up a BC-to-RT message,
and while the message is being sent continuously every 500 ms, an asynchronous message (either Low or High priority)
is sent out. This routine demonstrates the following API functions in the 1553 naibrd library:
naibrd_1553_Open
naibrd_1553_WriteAuxReg
naibrd_1553_Initialize
naibrd_1553_BcConfig
naibrd_1553_BcDataBlockCreate
naibrd_1553_BcMessageCreateBcToRt
naibrd_1553_BcCommandCreate
naibrd_1553_BcFrameCreate
naibrd_1553_BcDataBlockWrite
naibrd_1553_BcAsynchronousMessageCreateBcToRt
naibrd_1553_BcStart
naibrd_1553_BcAsynchronousMessageSendAtHighPriority_ExecuteOnce
naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce
naibrd_1553_BcMessageGetByIdDecoded
naibrd_1553_GetBlockStatusWordErrorString
naibrd_1553_BcMessageDelete
naibrd_1553_BcDataBlockDelete
naibrd_1553_BcStop
naibrd_1553_Free
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_M1553_BC_SendMessage_Async(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);
}
}
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)
{
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;
uint16_t dummycount;
bool_t bSoftware, bHighPriority;
naiDecodedMessageStructure DecodedMsgStruct;
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 = Get1553BCAsyncMsgType(TRUE, &bHighPriority);
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)
{
/* 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_WriteAuxReg(devnum, 0x2, 0xA000);
}
else
{
/* Do not override external BC_DISABLE and M1760 Inputs */
naibrd_1553_WriteAuxReg(devnum, 0x2, 0x0000);
}
/* 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;
}
/* Enable Asynchronous Messages */
status = naibrd_1553_BcConfig(devnum, NAI_1553_BC_ASYNCHRONOUS_BOTH_PRIORITY_MODES | NAI_1553_BC_ASYNCHRONOUS_HIGH_PRIORITY_ONCE_ANYWAY); /* Both are needed to use the *_ExecuteOnce functions */
if(status != 0)
{
printf("Error: naibrd_1553_BcConfig Ch %d, status = %d", channel, status);
return TRUE;
}
/* Create BC Data Block */
status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, 32, NULL, 0);
if(status != 0)
{
printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
return TRUE;
}
/* Create BC to RT Message */
status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageCreateBcToRt 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,MNR_FRAME_TIME*10,0); /* wFrameTime: 1 = 0.1 ms */
if (status != 0)
{
printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
return TRUE;
}
while (bContinue)
{
/* Load Scheduled BC Message data block with incremental data */
for (i = 0; i < 32; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, 32, 0);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
return TRUE;
}
/**********************************************************************/
/*** ADD 2 MESSAGES TO THE ASYNC QUEUE (For Low priority messaging) ***/
/**********************************************************************/
/* Create BC to RT Async Message 1 */
for (i = 0; i < 32; i++)
{
aData[i] = 0xBCBC;
}
status = naibrd_1553_BcAsynchronousMessageCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus, aData);
/* Create BC to RT Async Message 2 */
for (i = 0; i < 32; i++)
{
aData[i] = 0xAAAA;
}
status = naibrd_1553_BcAsynchronousMessageCreateBcToRt(devnum, MSG4, DBLK4, RT_ADDRESS, RT_SUBADDRESS, 32, 0, usBus, aData);
/*********************************************************/
/* START BC TO TRANSMIT SYNCHRONOUS (SCHEDULED) MESSAGES */
/*********************************************************/
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;
}
nai_msDelay(50);
/*******************************/
/* SEND MSG WITH HIGH PRIORITY */
/*******************************/
if (bHighPriority)
{
/* Send High Priority Async Message */
status = naibrd_1553_BcAsynchronousMessageSendAtHighPriority_ExecuteOnce(devnum, MSG3, 0);
if (status == NAI_1553_RC_ASYNCHRONOUS_MESSAGE_ERROR)
{
/* OPTIONAL check to determine the message error type */
printf("\nASYNC msg error:");
{
/* Get Decoded Msg Structure for Message 3 */
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG3, &DecodedMsgStruct, 1);
if (status < 0)
{
printf("\nError: naibrd_1553_BcMessageGetByIdDecoded status = %d\n\n", status);
}
else if (status > 0)
{
printf("\n%s", naibrd_1553_GetBlockStatusWordErrorString(NAI_1553_MODE_BC, DecodedMsgStruct.wBlockStatus));
printf("\n\n");
}
}
}
else if (status == 0)
{
printf("\nASYNC msg sent successfully\n\n");
}
else
{
printf("Error: naibrd_1553_BcAsynchronousMessageSendAtHighPriority status = %d\n\n", status);
}
}
/**********************************/
/* OR SEND MSGS WITH LOW PRIORITY */
/**********************************/
else
{
do
{
/* Each call to naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce() will re-update */
/* the BC async message queue so that already transmitted messages are not re-sent. */
/* A positive value returned in status is the count of async messages in the queue that are not yet sent. */
status = naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce(devnum, &dummycount, 0);
if (status > 0)
{
printf("\nremaining async count: %d", status);
}
if (status == NAI_1553_RC_ASYNCHRONOUS_LIST_IS_EMPTY)
{
/* Exit loop */
break;
}
/* Delay between calls to naibrd_1553_BcAsynchronousMessageSendAtLowPriority_ExecuteOnce should be */
/* set to the minor frame time, or the smallest minor frame time if multiple minor frames exist */
nai_msDelay(MNR_FRAME_TIME);
}
while (status > 0);
printf("\nasync transmission complete");
/* OPTIONAL check errors in async messages, if any */
/* Get Decoded Msg Structure for Message 3 */
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG3, &DecodedMsgStruct, 1);
if (status < 0)
{
printf("\nError: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
}
else if (status > 0)
{
printf("\nMSG3: %s", naibrd_1553_GetBlockStatusWordErrorString(NAI_1553_MODE_BC, DecodedMsgStruct.wBlockStatus));
}
/* Get Decoded Msg Structure for Message 4 */
status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG4, &DecodedMsgStruct, 1);
if (status < 0)
{
printf("\nError: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
}
else if (status > 0)
{
printf("\nMSG4: %s", naibrd_1553_GetBlockStatusWordErrorString(NAI_1553_MODE_BC, DecodedMsgStruct.wBlockStatus));
printf("\n\n");
}
/* Delete async message */
status = naibrd_1553_BcMessageDelete(devnum, MSG3);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageDelete status = %d", status);
return TRUE;
}
/* Delete async message data block */
status = naibrd_1553_BcDataBlockDelete(devnum, DBLK3);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockDelete status = %d", status);
return TRUE;
}
/* Delete async message */
status = naibrd_1553_BcMessageDelete(devnum, MSG4);
if (status != 0)
{
printf("Error: naibrd_1553_BcMessageDelete status = %d", status);
return TRUE;
}
/* Delete async message data block */
status = naibrd_1553_BcDataBlockDelete(devnum, DBLK4);
if (status != 0)
{
printf("Error: naibrd_1553_BcDataBlockDelete status = %d", status);
return TRUE;
}
}
/* Allow 1 more second before stopping BC */
nai_msDelay(1000);
/* Stop BC */
status = naibrd_1553_BcStop(devnum);
if (status != 0)
{
printf("Error: naibrd_1553_BcStop status = %d", status);
return TRUE;
}
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;
}