M1553 BC SendMessageSchedule FIFO
Edit this on GitLab
M1553 BC SendMessageSchedule FIFO Sample Application (SSK 1.x)
Overview
The M1553 BC SendMessageSchedule FIFO sample application demonstrates how to combine multi-rate message scheduling with FIFO-based message retrieval using the NAI Software Support Kit (SSK 1.x). It configures the same three-rate schedule as the M1553_BC_SendMessageSchedule sample (40 Hz, 20 Hz, 10 Hz) but initializes the device with NAI_1553_MESSAGE_FIFO_MODE and retrieves message results through the hardware FIFO instead of the standard per-message decoded structure. This approach captures every transaction record from the schedule, making it suitable for logging, bus analysis, or compliance verification.
|
Note
|
FIFO mode is available on FTA, FTB, FTC, FTD, and FTF modules only. Other FT-series modules do not support FIFO retrieval. Check the FTA-FTF Manual for FIFO availability on your specific module. |
The three BC-to-RT messages run at these 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
This sample supports the following 1553 module types:
-
FT0 through FTF — 4-channel MIL-STD-1553 modules (FIFO requires FTA/FTB/FTC/FTD/FTF)
-
Combination modules CM1, CM5, and CM8
The application detects the installed module variant at runtime using IsFTx1553().
For detailed 1553 protocol specifications and hardware register descriptions, see the FTA-FTF Manual.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a FIFO-capable 1553 module installed (FTA, FTB, FTC, FTD, or FTF).
-
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_FIFO executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessageSchedule_FIFO.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 for approximately 10 seconds and reads results from the FIFO.
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_FIFO.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_FIFO(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_FIFO(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_FIFO()— validates the module supports 1553 viaIsFTx1553(), queries for a channel number, and callsRunSendMessageSchedule(). -
RunSendMessageSchedule()— the core BC workflow: opens the device, initializes as BC with FIFO mode, creates three messages with the multi-rate frame hierarchy, runs the schedule for 10 seconds, and reads results from the FIFO.
The sample uses the same constants as the non-FIFO SendMessageSchedule variant:
/* Messages */
#define MSG1 1
#define MSG2 2
#define MSG3 3
/* Opcodes */
#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
Device Initialization with FIFO Mode
The initialization follows the standard BC pattern with one key difference — the NAI_1553_MESSAGE_FIFO_MODE flag is OR’d into the mode parameter of naibrd_1553_Initialize():
/* 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 with FIFO mode */
status = naibrd_1553_Initialize(devnum, NAI_1553_ACCESS_CARD,
NAI_1553_MODE_BC | NAI_1553_MESSAGE_FIFO_MODE, 0, 0, 0);
The NAI_1553_MESSAGE_FIFO_MODE flag tells the module hardware to record each completed message transaction into a FIFO buffer. Without this flag, the module only retains the most recent result per message ID. With this flag, every transaction is captured in sequence.
|
Important
|
Common Errors
|
Multi-Rate Schedule Setup
The schedule setup is identical to the non-FIFO M1553_BC_SendMessageSchedule sample. Three data blocks, three BC-to-RT messages, three minor frames, and one major frame are created. The frame hierarchy produces the same rate schedule:
-
MNR1 (25 ms): Messages 1, 2, 3
-
MNR2 (25 ms): Messages 1, 2
-
MNR3 (25 ms): Message 1 only
-
Major frame order: MNR1 → MNR3 → MNR2 → MNR3
This produces Message 1 at 40 Hz, Message 2 at 20 Hz, and Message 3 at 10 Hz. For a detailed explanation of how the frame hierarchy achieves these rates, see the M1553_BC_SendMessageSchedule guide.
/* Create three data blocks */
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 three 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);
Data Loading, FIFO Clear, and Execution
Before starting each run, load the data blocks with their respective patterns, then clear the FIFO to discard any stale entries from previous runs:
/* 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);
/* Clear FIFO before starting */
status = naibrd_1553_ClearMsgFIFO(devnum);
/* Start BC running continuously */
status = naibrd_1553_BcStart(devnum, MJR, NAI_1553_BC_FRAME_RUN_FOREVER);
To clear the FIFO before each run, call naibrd_1553_ClearMsgFIFO(). This prevents stale data from a previous run from being decoded. NAI_1553_BC_FRAME_RUN_FOREVER causes the major frame to repeat indefinitely. The application lets the schedule run for approximately 10 seconds before stopping:
printf("BC Running for approximately 10 seconds...\n");
nai_msDelay(10000);
status = naibrd_1553_BcStop(devnum);
printf("BC Halted.\n");
|
Important
|
Common Errors
|
FIFO-Based Message Retrieval
After the BC stops, the application reads and decodes all messages from the FIFO. This is the key difference from the non-FIFO variant: instead of reading only the most recent result per message ID, the FIFO contains a sequential record of every transaction.
Read the FIFO
status = naibrd_1553_GetMsgFIFOCount(devnum, &fifoCount);
if (fifoCount > 0)
{
currBlockIndex = 0;
memset(fifoData, 0, sizeof(fifoData));
status = naibrd_1553_ReadMsgFIFO(devnum, fifoCount, fifoData);
To retrieve FIFO data, first call naibrd_1553_GetMsgFIFOCount() to determine how many 32-bit words are available. Then call naibrd_1553_ReadMsgFIFO() to bulk-read that many words into a local buffer. Always zero the fifoData buffer with memset() before reading — this prevents old data from being decoded unintentionally if the buffer is reused across iterations.
Decode Messages from the FIFO
To walk through the FIFO data and decode each message record, call naibrd_1553_DecodeFIFOMsg() in a loop:
do
{
status = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &msgStruct);
if (status == 0)
{
printf("Command Word: 0x%04X\n", msgStruct.wCommandWord1);
if (msgStruct.bIsCommandWord2Relevant)
printf("Command Word 2: 0x%04X\n", msgStruct.wCommandWord2);
printf("Block Status: 0x%04X\n", msgStruct.wBlockStatus);
printf("Time Tag: 0x%04X\n", msgStruct.wTimeTag);
printf("Word Count: 0x%04X\n", msgStruct.wDataWordCount);
printf("RT Status Word: 0x%04X\n", msgStruct.wStatus1);
if (msgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", msgStruct.wStatus2);
}
/*** IMPORTANT !!! ***/
currBlockIndex = nextBlockIndex;
nai_msDelay(1);
} while ((status == NAI_SUCCESS) && (bContinue));
}
The currBlockIndex / nextBlockIndex pair tracks position in the FIFO data buffer. After each call, you must set currBlockIndex = nextBlockIndex to advance to the next message. Without this assignment, the loop decodes the same message indefinitely.
The decoded structure (naiDecodedMessageStructureFIFO) is similar to the non-FIFO naiDecodedMessageStructure but does not include the BC control word field. It includes: command word(s), block status, time tag, word count, RT status word(s), and data.
With a 10-second run and three messages at different rates, the FIFO will contain approximately 700 transaction records (400 for Message 1, 200 for Message 2, 100 for Message 3). The FIFO has a finite hardware buffer size, so with high message rates or long run times, the FIFO may fill up and drop messages.
Check FIFO Full Status
After reading all messages, check whether the FIFO overflowed during the run:
status = naibrd_1553_GetMsgFIFOFullStatus(devnum, NAI_1553_STATUS_REALTIME, &FIFIOfullStatusBit);
if (status == NAI_SUCCESS)
{
printf("FIFO status: %d", FIFIOfullStatusBit);
printf((FIFIOfullStatusBit == TRUE) ? " Full\r\n" : " Not full\r\n");
}
If FIFIOfullStatusBit is TRUE, the FIFO was full at some point during the run, meaning some messages were lost. For long-running multi-rate schedules, consider reading and clearing the FIFO periodically (in a separate thread or between BC stop/start cycles) rather than only at the end.
|
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, FIFO not supported |
Ensure reset sequence completed. Only FTA/FTB/FTC/FTD/FTF support FIFO mode. |
FIFO mode not available |
Module does not support FIFO (not FTA/FTB/FTC/FTD/FTF) |
Use the non-FIFO M1553_BC_SendMessageSchedule sample, or install a supported module |
All messages at same rate |
Major frame |
Set the major frame |
FIFO full / messages lost |
Too many messages captured before the FIFO was read (10 seconds produces approximately 700 messages) |
Read and clear the FIFO more frequently, or reduce the run duration |
Stale data in decoded messages |
|
Call |
Decode loop hangs |
|
Ensure |
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 |
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_FIFO.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"
#include "functions/naibrd_1553_assisted.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_1553BC_SendMessageSchedule_FIFO.txt";
/* Function prototypes */
static bool_t Run_M1553_BC_SendMessageSchedule_FIFO(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_FIFO(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_FIFO(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_FIFO(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;
naiDecodedMessageStructureFIFO msgStruct;
bool_t bSoftware;
uint32_t fifoCount = 0;
uint32_t fifoData[1024];
int32_t currBlockIndex = 0, nextBlockIndex = 0;
bool_t FIFIOfullStatusBit;
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 | NAI_1553_MESSAGE_FIFO_MODE,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;
}
status = naibrd_1553_ClearMsgFIFO(devnum);
if (status != 0)
{
printf("Error: naibrd_1553_ClearMsgFIFO 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");
status = naibrd_1553_GetMsgFIFOCount(devnum, &fifoCount);
if (status != 0)
{
printf("Error: naibrd_1553_GetMsgFIFOCount %d", status);
return TRUE;
}
else
{
if (fifoCount > 0)
{
currBlockIndex = 0;
memset(fifoData, 0, sizeof(fifoData));
/* Read Message FIFO */
status = naibrd_1553_ReadMsgFIFO(devnum, fifoCount, fifoData);
if (status != 0)
{
printf("Error: naibrd_1553_ReadMsgFIFO %d", status);
return TRUE;
}
else
{
/* Read Messages */
do
{
status = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &msgStruct);
if (status == 0)
{
printf("Command Word: 0x%04X\n", msgStruct.wCommandWord1);
if (msgStruct.bIsCommandWord2Relevant)
printf("Command Word 2: 0x%04X\n", msgStruct.wCommandWord2);
printf("Block Status: 0x%04X\n", msgStruct.wBlockStatus);
printf("Time Tag: 0x%04X\n", msgStruct.wTimeTag);
printf("Word Count: 0x%04X\n", msgStruct.wDataWordCount);
printf("RT Status Word: 0x%04X\n", msgStruct.wStatus1);
if (msgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", msgStruct.wStatus2);
printf("\n\n");
}
else if (status != NAI_1553_CMD_NO_MSG_TO_DECODE)
{
printf("Error: naibrd_1553_DecodeFIFOMsg %d", status);
return TRUE;
}
/*** IMPORTANT !!! ***/
currBlockIndex = nextBlockIndex;
nai_msDelay(1);
} while ((status == NAI_SUCCESS) && (bContinue));
}
printf("\n\n");
status = naibrd_1553_GetMsgFIFOFullStatus(devnum, NAI_1553_STATUS_REALTIME, &FIFIOfullStatusBit);
if (status == NAI_SUCCESS)
{
printf("FIFO status: %d", FIFIOfullStatusBit);
printf((FIFIOfullStatusBit == TRUE) ? " Full\r\n" : " Not full\r\n");
}
else
{
printf("Error: naibrd_1553_GetMsgFIFOFullStatus %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;
}