M1553 BC Run Sched FIFO
Edit this on GitLab
M1553 BC Run Sched FIFO Sample Application (SSK 2.x)
Overview
The M1553 BC Run Sched FIFO sample application demonstrates how to run a multi-rate MIL-STD-1553 Bus Controller (BC) message schedule and retrieve all transaction results using Message FIFO mode with the NAI Software Support Kit (SSK 2.x). This sample combines the multi-rate scheduling from the BC Run Sched sample with the FIFO-based message retrieval from the BC SendMsg FIFO sample.
The schedule uses three 25 ms minor frames to achieve the following message rates:
-
Message 1 — sent at 40 Hz (every 25 ms), present in all three minor frames
-
Message 2 — sent at 20 Hz (every 50 ms), present in minor frames 1 and 2
-
Message 3 — sent at 10 Hz (every 100 ms), present in minor frame 1 only
After running for 10 seconds, the application reads the message FIFO and decodes all captured transactions sequentially.
|
Note
|
FIFO mode is available for the FTA-FTF modules only. |
For detailed 1553 protocol specifications, message formats, and hardware register descriptions, see the FTA-FTF Manual.
For the SSK 1.x version, see M1553 BC SendMessageSchedule FIFO (SSK 1.x).
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a 1553 module installed (FTA-FTF).
-
SSK 2.x installed on your development host.
-
The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.
-
A second 1553 device (RT) at address 1 connected on the same bus.
How to Run
Launch the m1553_bc_run_sched_fifo executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessageSchedule.txt). Once connected, the application prompts for channel, bus selection, and software override, then runs the schedule for 10 seconds and displays FIFO-decoded results.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. |
The main() function follows the standard SSK 2.x startup flow: board menu, card index query, module selection, and module ID retrieval via naibrd_GetModuleName().
|
Important
|
Common Connection Errors
|
Program Structure
Initialization in FIFO Mode
status = naibrd_1553_Init(devnum, NAIBRD_1553_ACCESS_CARD,
NAIBRD_1553_MODE_BC | NAIBRD_1553_MESSAGE_FIFO_MODE, 0, 0, 0);
Frame Hierarchy
The minor frame time is 250 (25 ms in 0.1 ms units), giving slower rates than the non-FIFO schedule sample:
/* Minor Frame 1: Messages 1, 2, and 3 -- 25 ms */
status = naibrd_1553_BcFrmCreate(devnum, MNR1, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 3, 250, 0);
/* Minor Frame 2: Messages 1 and 2 -- 25 ms */
status = naibrd_1553_BcFrmCreate(devnum, MNR2, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 2, 250, 0);
/* Minor Frame 3: Message 1 only -- 25 ms */
status = naibrd_1553_BcFrmCreate(devnum, MNR3, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 250, 0);
Running and Reading the FIFO
/* Clear FIFO before starting */
status = naibrd_1553_ClearMsgFIFO(devnum);
/* Run schedule for 10 seconds */
status = naibrd_1553_BcStart(devnum, MJR, NAIBRD_1553_BC_FRAME_RUN_FOREVER);
naibrd_msDelay(10000);
status = naibrd_1553_BcStop(devnum);
/* Read FIFO */
status = naibrd_1553_GetMsgFIFOCount(devnum, &fifoCount);
memset(fifoData, 0, sizeof(fifoData));
status = naibrd_1553_ReadMsgFIFO(devnum, fifoCount, fifoData);
/* Decode all messages */
do
{
status = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &msgStruct);
/* ... display decoded fields ... */
currBlockIndex = nextBlockIndex;
} while (status == NAI_SUCCESS);
After decoding, the FIFO full status is checked. If full, some messages may have been lost during the 10-second run.
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
|
Channel already open, invalid indices |
Verify indices, ensure no other application holds the channel |
FIFO mode not supported |
Module is FTJ/FTK (1760) |
FIFO mode is only available on FTA-FTF modules |
FIFO full after 10-second run |
High message rate fills FIFO |
Reduce run time or read FIFO periodically during execution |
No messages in FIFO |
RT not responding, BC did not execute |
Verify RT is on the bus, check BC start return status |
Software override needed |
BC_DISABLE or M1760 pins not externally driven high |
Enable software override when prompted for bench testing |
Full Source
Full Source — m1553_bc_run_sched_fifo.c (SSK 2.x)
/* nailib include files */
#include "nai_libs/nailib/include/naitypes.h"
#include "nai_libs/nailib/include/nailib.h"
#include "nai_libs/nailib/include/nailib_utils.h"
/* naibrd include files */
#include "nai_libs/naibrd/include/naibrd.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553_assisted.h"
#include "nai_libs/naibrd/include/functions/naibrd_1553_1760_status.h"
/* naiif include files */
#include "nai_libs/naiif/include/naiif_stdio.h"
/* Common 1553 Sample Program include files */
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/m1553_common_utils.h"
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/BC/m1553_bc_common_utils.h"
/* Common Sample Program include files */
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_menu.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_query.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_access.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_display.h"
#include "nai_sample_apps/naiapp_common/include/naiapp_boardaccess_utils.h"
static const int8_t *DEF_CONFIG_FILE = (int8_t *)"default_1553BC_SendMessageSchedule.txt";
static bool_t Run_m1553_bc_send_msgSchedule_fifo(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunSendMessageSchedule_fifo(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid);
#define MSG1 1
#define MSG2 2
#define MSG3 3
#define OP1 1
#define OP2 2
#define OP3 3
#define OP4 4
#define OP5 5
#define OP6 6
#define MNR1 1
#define MNR2 2
#define MNR3 3
#define MJR 4
#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
#define RT_SUBADDRESS2 2
#define RT_SUBADDRESS3 8
#define WORDCOUNT1 11
#define WORDCOUNT2 21
#define WORDCOUNT3 30
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_bc_run_sched_fifo(void)
#else
int32_t main(void)
#endif
{
int32_t cardIndex;
int32_t moduleCnt;
int32_t module;
bool_t stop = NAI_FALSE;
uint32_t moduleID = 0;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
if (naiapp_RunBoardMenu(DEF_CONFIG_FILE) == (bool_t)NAI_TRUE)
{
while (stop != NAI_TRUE)
{
stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));
stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
if (stop != NAI_TRUE)
{
check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
if ((moduleID != 0))
{
Run_m1553_bc_send_msgSchedule_fifo(cardIndex, module, moduleID);
}
}
}
naiif_printf("\r\nType Q to quit or Enter key to restart application:\r\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
naiif_printf("\r\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_send_msgSchedule_fifo(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = NAI_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_fifo(cardIndex, module, channel, modid);
}
}
else
naiif_printf("\r\nThis module does not support 1553 functionality.\r\n");
return bQuit;
}
static bool_t RunSendMessageSchedule_fifo(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid)
{
int32_t i;
bool_t bQuit = NAI_FALSE;
uint32_t usBus;
naibrd_1553_t status;
uint16_t increment = 0;
uint16_t aData[32] = { 0 };
int16_t aOpCodes[20] = { 0 };
bool_t bContinue = NAI_TRUE;
int16_t devnum;
naibrd_1553_msgstructFIFO_t msgStruct;
bool_t bSoftware;
uint32_t fifoCount = 0;
uint32_t fifoData[1024];
int32_t currBlockIndex = 0, nextBlockIndex = 0;
bool_t FIFOfullStatusBit;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUM, &devnum);
if (!bQuit)
{
bQuit = GetBus(&usBus);
if (!bQuit)
{
bQuit = Get1553BCSoftwareOverride(NAI_TRUE, &bSoftware);
if (!bQuit)
{
status = naibrd_1553_Open(cardIndex, module, channel, devnum);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Open Ch %d, status = %d", channel, status);
return NAI_TRUE;
}
if (bSoftware)
naibrd_1553_WriteAuxRegister(devnum, 0x2, 0xA000);
else
naibrd_1553_WriteAuxRegister(devnum, 0x2, 0);
naibrd_1553_WriteAuxRegister(devnum, 0x1, 1);
naibrd_msDelay(1);
naibrd_1553_WriteAuxRegister(devnum, 0x1, 0);
status = naibrd_1553_Init(devnum, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC | NAIBRD_1553_MESSAGE_FIFO_MODE, 0, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Initialize Ch %d, status = %d", channel, status);
return NAI_TRUE;
}
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK1, NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE, NULL, 0);
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK2, NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE, NULL, 0);
status = naibrd_1553_BcDataBlkCreate(devnum, DBLK3, NAIBRD_1553_BC_DATABLOCK_SIZE_32_SINGLE, NULL, 0);
status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS1, WORDCOUNT1, 0, usBus);
status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG2, DBLK2, RT_ADDRESS, RT_SUBADDRESS2, WORDCOUNT2, 0, usBus);
status = naibrd_1553_BcMsgCreateBcToRt(devnum, MSG3, DBLK3, RT_ADDRESS, RT_SUBADDRESS3, WORDCOUNT3, 0, usBus);
status = naibrd_1553_BcCmdCreate(devnum, OP1, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
status = naibrd_1553_BcCmdCreate(devnum, OP2, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG2, 0, 0);
status = naibrd_1553_BcCmdCreate(devnum, OP3, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG3, 0, 0);
aOpCodes[0] = OP1; aOpCodes[1] = OP2; aOpCodes[2] = OP3;
status = naibrd_1553_BcFrmCreate(devnum, MNR1, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 3, 250, 0);
aOpCodes[0] = OP1; aOpCodes[1] = OP2;
status = naibrd_1553_BcFrmCreate(devnum, MNR2, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 2, 250, 0);
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrmCreate(devnum, MNR3, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 250, 0);
status = naibrd_1553_BcCmdCreate(devnum, OP4, NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
status = naibrd_1553_BcCmdCreate(devnum, OP5, NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR2, 0, 0);
status = naibrd_1553_BcCmdCreate(devnum, OP6, NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR3, 0, 0);
aOpCodes[0] = OP4; aOpCodes[1] = OP6; aOpCodes[2] = OP5; aOpCodes[3] = OP6;
status = naibrd_1553_BcFrmCreate(devnum, MJR, NAIBRD_1553_BC_FRAME_MAJOR, aOpCodes, 4, 0, 0);
while (bContinue)
{
for (i = 0; i < WORDCOUNT1; i++) aData[i] = increment++;
status = naibrd_1553_BcDataBlkWrite(devnum, DBLK1, aData, WORDCOUNT1, 0);
for (i = 0; i < WORDCOUNT2; i++) aData[i] = 0x5566;
status = naibrd_1553_BcDataBlkWrite(devnum, DBLK2, aData, WORDCOUNT2, 0);
for (i = 0; i < WORDCOUNT3; i++) aData[i] = 0xBBCC;
status = naibrd_1553_BcDataBlkWrite(devnum, DBLK3, aData, WORDCOUNT3, 0);
status = naibrd_1553_ClearMsgFIFO(devnum);
status = naibrd_1553_BcStart(devnum, MJR, NAIBRD_1553_BC_FRAME_RUN_FOREVER);
naiif_printf("BC Running for approximately 10 seconds...\r\n");
naibrd_msDelay(10000);
status = naibrd_1553_BcStop(devnum);
naiif_printf("BC Halted.\r\n");
status = naibrd_1553_GetMsgFIFOCount(devnum, &fifoCount);
if (status == 0 && fifoCount > 0)
{
currBlockIndex = 0;
memset(fifoData, 0, sizeof(fifoData));
status = naibrd_1553_ReadMsgFIFO(devnum, fifoCount, fifoData);
if (status == 0)
{
do
{
status = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &msgStruct);
if (status == 0)
{
naiif_printf("Command Word: 0x%04X\r\n", msgStruct.commandWord1);
if (msgStruct.isCommandWord2Relevant)
naiif_printf("Command Word 2: 0x%04X\r\n", msgStruct.commandWord2);
naiif_printf("Block Status: 0x%04X\r\n", msgStruct.blockStatus);
naiif_printf("Time Tag: 0x%04X\r\n", msgStruct.timeTag);
naiif_printf("Word Count: 0x%04X\r\n", msgStruct.dataWordCount);
naiif_printf("RT Status Word: 0x%04X\r\n", msgStruct.status1);
if (msgStruct.isStatus2Relevant)
naiif_printf("RT Status Word 2: 0x%04X\r\n", msgStruct.status2);
naiif_printf("\r\n\r\n");
}
currBlockIndex = nextBlockIndex;
naibrd_msDelay(1);
} while (status == NAI_SUCCESS);
}
status = naibrd_1553_GetMsgFIFOFullStatus(devnum, NAIBRD_1553_STATUS_REALTIME, &FIFOfullStatusBit);
if (status == NAI_SUCCESS)
{
naiif_printf("FIFO status: %d", FIFOfullStatusBit);
naiif_printf((FIFOfullStatusBit == NAI_TRUE) ? " Full\r\n" : " Not full\r\n");
}
naiif_printf("\r\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 = NAI_FALSE;
}
}
}
}
}
status = naibrd_1553_Free(devnum);
return bQuit;
}