M1553 Ext Loopback FIFO
Edit this on GitLab
M1553 Ext Loopback FIFO Sample Application (SSK 2.x)
Overview
The M1553 Ext Loopback FIFO sample application demonstrates how to configure two channels on the same module for an external loopback test — one channel as a Bus Controller (BC) and another as a Remote Terminal (RT) — using the NAI Software Support Kit (SSK 2.x). The BC sends a message over the 1553 bus and the RT receives it, verifying end-to-end bus communication between two channels.
The BC channel operates in normal (non-FIFO) mode while the RT channel operates in Message FIFO mode. This combination demonstrates that the two modes can coexist on different channels of the same module. The BC sends a message, then both the BC response (decoded by message ID) and the RT response (decoded from the FIFO) are displayed side by side.
This sample requires two channels on the same module connected over a 1553 bus (external loopback cabling).
|
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.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a 1553 module installed (FTA-FTF) with at least two channels.
-
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.
-
External loopback cabling connecting two channels on the same module over a 1553 bus.
How to Run
Launch the m1553_ext_loopback_fifo executable from your build output directory. On startup the application looks for a configuration file (default_1553_External_Loopback.txt). Once connected, the application prompts for the BC channel number, BC logical device number, message type, bus, software override, RT logical device number, RT channel, and RT subaddress. The application then sends messages in a loop, displaying both BC and RT 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.
|
Important
|
Common Connection Errors
|
Program Structure
Dual-Channel Configuration
This sample uses two separate channels on the same 1553 module — one configured as a Bus Controller (BC) and the other as a Remote Terminal (RT) in FIFO mode. Each channel gets its own logical device number and is opened/initialized independently. The BC and RT must be externally cabled together on the same 1553 bus.
BC Channel Setup
The BC channel is opened, optionally configured for software override, reset, and initialized in BC mode:
/* Open 1553 Device */
status = naibrd_1553_Open(cardIndex, module, channelBC, devnumBC);
/* Software override for BC_DISABLE and M1760 pins */
if (bSoftware)
{
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_MISC_BITS,
NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_BC_DISABLE |
NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_M1760);
}
else
{
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0);
}
/* Reset Device */
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_RESET, 1);
naibrd_msDelay(1);
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_RESET, 0);
/* Initialize as BC */
status = naibrd_1553_Init(devnumBC, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC, 0, 0, 0);
The software override allows the BC to operate even when external BC_DISABLE and M1760 hardware pins are not driven high. The device reset via NAIBRD_1553_AUX_ADDRESS_RESET clears any previous state before initialization. A brief delay (naibrd_msDelay(1)) is required between asserting and deasserting the reset.
RT Channel Setup
The RT channel is opened on a different channel number and initialized with the NAIBRD_1553_MESSAGE_FIFO_MODE flag OR’ed into the mode parameter. This tells the hardware to store incoming messages in a FIFO rather than in per-subaddress data blocks:
status = naibrd_1553_Open(cardIndex, module, channelRT, devnumRT);
/* Initialize Device in RT + FIFO mode */
status = naibrd_1553_Init(devnumRT, NAIBRD_1553_ACCESS_CARD,
NAIBRD_1553_MODE_RT | NAIBRD_1553_MESSAGE_FIFO_MODE, 0, 0, 0);
After initialization, the RT address is configured. When software addressing is selected, the application enables the software RT address control bits and programs the address:
if (bSoftwareRTAddr)
{
/* Set RTAD_SW_EN and RT_ADR_LAT in software */
status = naibrd_1553_WriteAuxRegister(devnumRT, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0x0018);
status = naibrd_1553_RtSetAddrSrc(devnumRT, NAIBRD_1553_RT_ADDR_SOURCE_INTERNAL);
status = naibrd_1553_RtSetAddr(devnumRT, rtaddr);
}
else
{
/* Unset RTAD_SW_EN and set RT_ADR_LAT in software */
status = naibrd_1553_WriteAuxRegister(devnumRT, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0x0008);
status = naibrd_1553_RtSetAddrSrc(devnumRT, NAIBRD_1553_RT_ADDR_SOURCE_EXTERNAL);
}
The value 0x0018 sets both RTAD_SW_EN and RT_ADR_LAT bits. When hardware addressing is used, only RT_ADR_LAT (0x0008) is set so the address comes from external pins.
|
Important
|
The BC and RT must use different logical device numbers ( |
BC Message Creation and Frame Hierarchy
After BC initialization, the sample creates a complete BC frame hierarchy: data block, message, opcodes, minor frame, and major frame. The message type is selected interactively and the sample supports all four MIL-STD-1553 message types.
Data Block Creation
A data block must be allocated before creating any message:
/* Create BC Data Block */
status = naibrd_1553_BcDataBlkCreate(devnumBC, DBLK1, WORDCOUNT, NULL, 0);
For mode code messages, a separate data block is created using the mode command value as the size parameter:
status = naibrd_1553_BcDataBlkCreate(devnumBC, DBLK2, modeCommand, NULL, 0);
Message Creation by Type
The sample creates one of four message types depending on user selection:
if (msgType == M1553_MSGTYPE_BCTORT)
{
/* Create BC to RT Message */
status = naibrd_1553_BcMsgCreateBcToRt(devnumBC, MSG1, DBLK1,
RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
}
else if (msgType == M1553_MSGTYPE_RTTOBC)
{
/* Create RT to BC Message */
status = naibrd_1553_BcMsgCreateRtToBc(devnumBC, MSG1, DBLK1,
RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
/* Create Mode Code Message */
status = naibrd_1553_BcMsgCreateMode(devnumBC, MSG1, DBLK1, RT_ADDRESS,
(msgType == M1553_MSGTYPE_MODECODE_TX) ?
NAIBRD_1553_DIRECTION_TX : NAIBRD_1553_DIRECTION_RX,
modeCommand, 0, usBus);
}
else if (msgType == M1553_MSGTYPE_RTTORT)
{
/* Create RT to RT Message */
status = naibrd_1553_BcMsgCreateRtToRt(devnumBC, MSG1, DBLK1,
RT_ADDRESS_2, RT_SUBADDRESS, WORDCOUNT,
RT_ADDRESS, RT_SUBADDRESS, 0, usBus);
}
Each message creation function takes the logical device number, a message ID (MSG1), the data block ID, target RT address(es), subaddress, word count, and bus selection (Bus A or Bus B).
Opcode and Frame Hierarchy
The BC requires a frame hierarchy to execute messages. The sample builds this as: major frame → minor frame → execute-message opcode → message:
/* Create Execute Message Command */
status = naibrd_1553_BcCmdCreate(devnumBC, OP1,
NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
/* Create Call Subroutine Command (calls the minor frame) */
status = naibrd_1553_BcCmdCreate(devnumBC, OP2,
NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
/* Create Minor Frame containing the execute opcode */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrmCreate(devnumBC, MNR1,
NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
/* Create Major Frame containing the call-subroutine opcode */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrmCreate(devnumBC, MJR,
NAIBRD_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, 0);
The hierarchy is: the major frame (MJR) contains opcode OP2, which calls minor frame MNR1. The minor frame contains opcode OP1, which executes message MSG1. The major frame timeout of 1000 microseconds sets the frame period.
RT Data Block Creation
The RT channel creates four data blocks: one double-buffered Rx block, one double-buffered broadcast block, and two single Tx blocks for ping-pong buffering. Each block is mapped to the user-selected subaddress:
/* Create Rx data block and map to subaddress */
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_RX,
NAIBRD_1553_RT_DATABLOCK_DOUBLE, NULL, 0);
status = naibrd_1553_RtDataBlkMapToSA(devnumRT, DATA_BLOCK_ID_RX, sa,
NAIBRD_1553_RT_MESSAGE_TYPE_RX, NAIBRD_1553_RT_DATABLOCK_IRQ_NONE, 1);
/* Create Broadcast Rx data block and map to subaddress */
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_BCST,
NAIBRD_1553_RT_DATABLOCK_DOUBLE, NULL, 0);
status = naibrd_1553_RtDataBlkMapToSA(devnumRT, DATA_BLOCK_ID_BCST, sa,
NAIBRD_1553_RT_MESSAGE_TYPE_BROADCAST, NAIBRD_1553_RT_DATABLOCK_IRQ_NONE, 1);
/* Create two Tx data blocks (ping-pong) and map the first to subaddress */
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_TX1,
NAIBRD_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_TX2,
NAIBRD_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
status = naibrd_1553_RtDataBlkMapToSA(devnumRT, DATA_BLOCK_ID_TX1, sa,
NAIBRD_1553_RT_MESSAGE_TYPE_TX, NAIBRD_1553_RT_DATABLOCK_IRQ_NONE, 1);
currDataBlock = DATA_BLOCK_ID_TX1;
The Rx and broadcast blocks use NAIBRD_1553_RT_DATABLOCK_DOUBLE (double-buffered) so the hardware can write to one buffer while the application reads the other. The two Tx blocks (DATA_BLOCK_ID_TX1 and DATA_BLOCK_ID_TX2) are single 32-word buffers used for ping-pong buffering — only one is mapped to the subaddress at a time, and they are swapped atomically using naibrd_1553_RtTxDataBlkSwap().
Running the Loopback Test
Each loop iteration performs a complete BC send / RT receive cycle. The RT must be started before the BC sends so that it is listening when the message arrives on the bus:
/* Clear the RT FIFO before each iteration */
status = naibrd_1553_ClearMsgFIFO(devnumRT);
/* Start RT first so it is listening */
status = naibrd_1553_RtStart(devnumRT);
/* Load BC data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlkWrite(devnumBC, DBLK1, aData, WORDCOUNT, 0);
/* Start BC for one major frame */
status = naibrd_1553_BcStart(devnumBC, MJR, 1);
/* Allow time for the BC to complete */
naibrd_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(devnumBC);
After stopping the BC, the application decodes the BC response using naibrd_1553_BcMsgGetByIdDecoded() to retrieve block status, time tag, command words, and data. It then calls ProcessMessages() to decode the RT FIFO, and finally stops the RT:
/* Decode BC response */
status = naibrd_1553_BcMsgGetByIdDecoded(devnumBC, MSG1, &DecodedMsgStruct, 1);
/* Decode RT FIFO messages */
ProcessMessages(devnumRT, sa);
/* Stop RT */
status = naibrd_1553_RtStop(devnumRT);
The naibrd_1553_BcStart() third parameter (1) tells the BC to execute the major frame once rather than continuously. The 200 ms delay gives the BC time to complete the frame before the application stops it.
FIFO Message Reading and Decoding (ProcessMessages)
The ProcessMessages() function is the core of this sample. It reads all messages from the RT FIFO and decodes them one at a time. Unlike the standard RT stack-based approach (RtMsgGetFromStackRaw / RtMsgDecodeRaw), the FIFO approach reads the entire FIFO into a local buffer and then iterates through it using an index-based decoder:
static int32_t ProcessMessages(uint16_t devnum, naibrd_1553_rt_subaddress_t Subaddress)
{
int32_t status;
int32_t i;
uint32_t fifoCount;
int32_t currBlockIndex = 0, nextBlockIndex = 0;
naibrd_1553_msgstructFIFO_t DecodedMsgStruct;
uint32_t fifoData[1024];
bool_t FIFOfullStatusBit;
/* Step 1: Get the number of words in the FIFO */
status = naibrd_1553_GetMsgFIFOCount(devnum, &fifoCount);
If the FIFO contains data, it is read into a local buffer and decoded in a loop:
if (fifoCount > 0)
{
currBlockIndex = 0;
memset(fifoData, 0, sizeof(fifoData));
/* Step 2: Read the entire FIFO into a local buffer */
status = naibrd_1553_ReadMsgFIFO(devnum, fifoCount, fifoData);
/* Step 3: Decode messages one at a time */
do
{
status = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex,
&nextBlockIndex, &DecodedMsgStruct);
if (status == 0)
{
if ((DecodedMsgStruct.commandWord1 & 0x0400) != 0x0400)
{
/* Rx message -- display block status, time tag, command word, data */
naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
for (i = 0; i < DecodedMsgStruct.dataWordCount; i++)
naiif_printf("0x%04X ", DecodedMsgStruct.data[i]);
}
else
{
/* Tx message -- display status only (no data payload) */
}
}
/*** IMPORTANT: advance the index to the next message ***/
currBlockIndex = nextBlockIndex;
naibrd_msDelay(1);
} while (status == NAI_SUCCESS);
}
Key points about the FIFO decode loop:
-
naibrd_1553_GetMsgFIFOCount()returns the number of 32-bit words in the FIFO, not the number of messages. -
naibrd_1553_ReadMsgFIFO()reads the raw FIFO data into a local array. ThefifoDataarray must be zeroed first because old data could be misinterpreted by the decoder. -
naibrd_1553_DecodeFIFOMsg()decodes one message starting atcurrBlockIndexand returns the index of the next message innextBlockIndex. The loop advancescurrBlockIndex = nextBlockIndexafter each decode. -
The loop terminates when
DecodeFIFOMsgreturns a non-zero status (typicallyNAIBRD_1553_CMD_NO_MSG_TO_DECODE). -
The decoded
naibrd_1553_msgstructFIFO_tstructure containsblockStatus,timeTag,commandWord1,dataWordCount, anddata[]— similar to the standardnaibrd_1553_msgstruct_tbut adapted for FIFO mode.
After processing all messages, the application checks whether the FIFO overflowed:
status = naibrd_1553_GetMsgFIFOFullStatus(devnum, NAIBRD_1553_STATUS_REALTIME, &FIFOfullStatusBit);
If FIFOfullStatusBit is NAI_TRUE, the FIFO was full and messages may have been lost. In production, you should monitor this status and increase the polling frequency or reduce the message rate if overflows occur.
Tx Buffer Management (Ping-Pong Buffering)
Inside ProcessMessages(), after reading the FIFO, the application updates the RT Tx data block using a ping-pong (double-buffer) scheme. This ensures the BC never reads a partially-written buffer during an RT-to-BC transfer:
static int32_t UpdateTxDataBlock(uint16_t DevNum, naibrd_1553_rt_subaddress_t Subaddress)
{
if (currDataBlock == DATA_BLOCK_ID_TX1)
{
/* Write new data to the inactive block (TX2) */
UpdateTxBuffer(DevNum, DATA_BLOCK_ID_TX2);
/* Atomically swap TX2 into the active position */
naibrd_1553_RtTxDataBlkSwap(DevNum, DATA_BLOCK_ID_TX2, Subaddress);
currDataBlock = DATA_BLOCK_ID_TX2;
}
else
{
/* Write new data to the inactive block (TX1) */
UpdateTxBuffer(DevNum, DATA_BLOCK_ID_TX1);
/* Atomically swap TX1 into the active position */
naibrd_1553_RtTxDataBlkSwap(DevNum, DATA_BLOCK_ID_TX1, Subaddress);
currDataBlock = DATA_BLOCK_ID_TX1;
}
return 0;
}
The UpdateTxBuffer() helper increments all 32 data words and writes them to the inactive data block:
static int32_t UpdateTxBuffer(uint16_t DevNum, uint16_t nDataBlkID)
{
static uint16_t wBuffer[32] = { 0x0000 };
uint16_t i;
/* Increment Tx buffer data */
for (i = 0; i < 32; i++)
wBuffer[i] += 1;
/* Write new data to Tx buffer */
result = naibrd_1553_RtDataBlkWrite(DevNum, nDataBlkID, wBuffer, RTBC_WORDCNT, 0);
return 1;
}
The ping-pong pattern works as follows:
-
Determine which Tx block is currently active (mapped to the subaddress).
-
Write updated data to the inactive block using
naibrd_1553_RtDataBlkWrite(). -
Call
naibrd_1553_RtTxDataBlkSwap()to atomically swap the inactive block into the active position. -
Track which block is now active in the
currDataBlockglobal variable.
This guarantees the BC always reads a complete, consistent data set — it never sees a buffer that is being modified mid-write.
Cleanup
Both logical devices must be freed when the application exits. Each channel that was opened with naibrd_1553_Open() must have a corresponding naibrd_1553_Free() call:
/* Free BC device */
status = naibrd_1553_Free(devnumBC);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Free status = %d", status);
}
/* Free RT device */
status = naibrd_1553_Free(devnumRT);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Free status = %d", status);
}
Failing to call naibrd_1553_Free() leaves the logical device number reserved, which will cause naibrd_1553_Open() to fail on subsequent runs until the board is power-cycled or the application process terminates.
Troubleshooting Reference
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
|
Same logical device number used for both channels |
Use different logical device numbers for BC and RT |
BC sends but RT FIFO is empty |
Channels not connected on same bus, wrong bus selected |
Verify external loopback cabling, try both Bus A and Bus B |
RT does not respond (BC block status shows error) |
RT address mismatch, RT not started before BC |
Ensure RT is started before BC sends, verify RT address matches |
FIFO mode not supported |
Module is FTJ/FTK (1760) |
FIFO mode is only available on FTA-FTF modules |
Both channels on same logical device number |
Logical device conflict |
Use DEF_M1553_DEVNUMBC=0 and DEF_M1553_DEVNUMRT=1 |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — m1553_ext_loopback_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_1553_External_Loopback.txt";
/* Function prototypes */
static bool_t Run_m1553_ext_loopback_fifo(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunExternalLoopbackFIFO(int32_t cardIndex, int32_t module, int32_t channelBC, uint32_t modid);
static int32_t ProcessMessages(uint16_t devnum, naibrd_1553_rt_subaddress_t Subaddress);
static int32_t UpdateTxDataBlock(uint16_t DevNum, naibrd_1553_rt_subaddress_t Subaddress);
static int32_t UpdateTxBuffer(uint16_t DevNum, uint16_t nDataBlkID);
/* define message constants */
#define MSG1 1
/* define opcodes */
#define OP1 1
#define OP2 2
/* define frame constants */
#define MNR1 1
#define MJR 2
/* define data block numbers */
#define DBLK1 1
#define DBLK2 2
#define DEF_M1553_CARD_INDEX 0
#define DEF_M1553_MODULE 1
#define DEF_M1553_CHANNEL 1
#define DEF_M1553_RT_CHANNEL 2
#define DEF_M1553_DEVNUMBC 0
#define DEF_M1553_DEVNUMRT 1
#define DEF_RT_ADDRESS 1
#define DEF_RT_SUBADDR 2
#define RT_ADDRESS 1
#define RT_ADDRESS_2 2
#define RT_SUBADDRESS 2
#define WORDCOUNT 32
#define DATA_BLOCK_ID_TX1 1
#define DATA_BLOCK_ID_TX2 2
#define DATA_BLOCK_ID_RX 3
#define DATA_BLOCK_ID_BCST 4
#define RTBC_WORDCNT 32
/* Global Variables */
static int32_t currDataBlock;
/**************************************************************************************************************/
/** \defgroup M1553_ExternalLoopback_FIFO
\brief This sample application demonstrates how to configure and use two channels for external loopback transmission.
The purpose of the m1553_ext_loopback_fifo is to illustrate the methods to call in the naibrd library to configure
one 1553 channel as a Bus Controller and another 1553 channel as a Remote Terminal and complete a 1553 Message
transaction between the two channels. For the message transaction to complete successfully, the Bus Controller
channel and Remote Terminal channel must be on the same module and connected over a 1553 bus. The BC channel is
configured for normal (non-Message FIFO) mode and the RT channel is configured for Message FIFO mode.
The message on the RT channel will be decoded using FIFO mode.
Note: FIFO mode is available for the FTA-FTF only.
The main steps include:
- Querying the user for the card index and module number.
- Configuring one channel for Bus Controller functionality.
- Configuring another channel for Remote Terminal functionality in FIFO mode.
- Transmitting a message from the BC.
- Receiving the transmitted data on the RT and displaying it.
*/
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_ext_loopback_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_ext_loopback_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_ext_loopback_fifo(int32_t cardIndex, int32_t module, uint32_t modid)
{
bool_t bQuit = NAI_FALSE;
int32_t channelBC;
int32_t MaxChannel = 4;
if (IsFTx1553(modid))
{
MaxChannel = 4;
/* Get the channel number of the Bus Controller */
naiif_printf("\r\n\r\n\r\nSelect Channel Number of Bus Controller channel\r\n");
bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channelBC);
if (!bQuit)
{
naiif_printf("\r\n\r\n\r\n");
bQuit = RunExternalLoopbackFIFO(cardIndex, module, channelBC, modid);
}
}
else
naiif_printf("\r\nThis module does not support 1553 functionality.\r\n");
return bQuit;
}
static bool_t RunExternalLoopbackFIFO(int32_t cardIndex, int32_t module, int32_t channelBC, 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 devnumBC, devnumRT;
naibrd_1553_rt_address_t rtaddr;
naibrd_1553_rt_subaddress_t sa = DEF_RT_SUBADDR;
bool_t bSoftware;
M1553MsgType_t msgType;
M1553ModeCodes_t modeCommand;
bool_t bValidModeCode;
int32_t channelRT = 0;
naibrd_1553_msgstruct_t DecodedMsgStruct;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get the Logical Device Number */
naiif_printf("\r\n\r\n\r\nEnter Logical Device Number of Bus Controller channel\r\n");
bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUMBC, &devnumBC);
if (!bQuit)
{
naiif_printf("\r\n\r\n\r\n");
/* Get Msg Direction */
bQuit = GetMsgTypeAndCheckForQuit(&msgType);
if (!bQuit)
{
/* Which bus are we firing on? */
bQuit = GetBus(&usBus);
if (!bQuit)
{
bQuit = Get1553BCSoftwareOverride(NAI_TRUE, &bSoftware);
if (!bQuit)
{
/* Open 1553 Device(s) */
status = naibrd_1553_Open(cardIndex, module, channelBC, devnumBC);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Open Ch %d, status = %d", channelBC, status);
return NAI_TRUE;
}
/*******************************************************************************/
/*******************************************************************************/
/********************* BUS CONTROLLER CONFIGURATION ****************************/
/*******************************************************************************/
/*******************************************************************************/
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_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_MISC_BITS,
NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_BC_DISABLE | NAIBRD_1553_AUX_REG_MISC_BITS_MASK_OVERRIDE_M1760);
}
else
{
/* Do not override external BC_DISABLE and M1760 Inputs */
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0);
}
if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
do
{
bQuit = AskAndCheckForValidModeCodeAndCheckForQuit((msgType == M1553_MSGTYPE_MODECODE_TX) ?
M1553_MSGTYPE_MODECODE_DIRECTION_TX : M1553_MSGTYPE_MODECODE_DIRECTION_RX, &modeCommand, &bValidModeCode);
} while ((!bQuit) && (!bValidModeCode));
}
/* Reset Device */
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_RESET, 1);
naibrd_msDelay(1);
naibrd_1553_WriteAuxRegister(devnumBC, NAIBRD_1553_AUX_ADDRESS_RESET, 0);
/* Initialize 1553 Device(s) */
status = naibrd_1553_Init(devnumBC, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_BC, 0, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Init Ch %d, status = %d", channelBC, status);
return NAI_TRUE;
}
if ((msgType != M1553_MSGTYPE_MODECODE_TX) || (msgType != M1553_MSGTYPE_MODECODE_RX))
{
/* Create BC Data Block */
status = naibrd_1553_BcDataBlkCreate(devnumBC, DBLK1, WORDCOUNT, NULL, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcDataBlkCreate Ch %d, status = %d", channelBC, status);
return NAI_TRUE;
}
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
status = naibrd_1553_BcDataBlkCreate(devnumBC, DBLK2, modeCommand, NULL, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcDataBlkCreate Ch %d, status = %d", channelBC, status);
return NAI_TRUE;
}
}
if (msgType == M1553_MSGTYPE_RTTOBC)
{
/* Create RT to BC Message */
status = naibrd_1553_BcMsgCreateRtToBc(devnumBC, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMessageCreateRtToBc status = %d", status);
return NAI_TRUE;
}
}
else if (msgType == M1553_MSGTYPE_BCTORT)
{
/* Create BC to RT Message */
status = naibrd_1553_BcMsgCreateBcToRt(devnumBC, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 1, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
return NAI_TRUE;
}
}
else if ((msgType == M1553_MSGTYPE_MODECODE_TX) || (msgType == M1553_MSGTYPE_MODECODE_RX))
{
/* Create Mode Code Tx Message */
status = naibrd_1553_BcMsgCreateMode(devnumBC, MSG1, DBLK1, RT_ADDRESS, (msgType == M1553_MSGTYPE_MODECODE_TX) ?
NAIBRD_1553_DIRECTION_TX : NAIBRD_1553_DIRECTION_RX, modeCommand, 0, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMessageCreateMode status = %d", status);
return NAI_TRUE;
}
}
else if (msgType == M1553_MSGTYPE_RTTORT)
{
/* Create RT to RT Message */
status = naibrd_1553_BcMsgCreateRtToRt(devnumBC, MSG1, DBLK1, RT_ADDRESS_2, RT_SUBADDRESS, WORDCOUNT, RT_ADDRESS, RT_SUBADDRESS, 0, usBus);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcMsgCreateRtToRt status = %d", status);
return NAI_TRUE;
}
}
/* Create Execute Message Command */
status = naibrd_1553_BcCmdCreate(devnumBC, OP1, NAIBRD_1553_OPCODE_EXECUTE_MESSAGE, NAIBRD_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcCmdCreate status = %d", status);
return NAI_TRUE;
}
/* Create Call Subroutine Command */
status = naibrd_1553_BcCmdCreate(devnumBC, OP2, NAIBRD_1553_OPCODE_CALL_SUBROUTINE, NAIBRD_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcCmdCreate status = %d", status);
return NAI_TRUE;
}
/* Create Minor Frame */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrmCreate(devnumBC, MNR1, NAIBRD_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcFrmCreate status = %d", status);
return NAI_TRUE;
}
/* Create Major Frame */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrmCreate(devnumBC, MJR, NAIBRD_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcFrmCreate status = %d", status);
return NAI_TRUE;
}
/*******************************************************************************/
/*******************************************************************************/
/********************* REMOTE TERMINAL CONFIGURATION ***************************/
/*******************************************************************************/
/*******************************************************************************/
/* Get the Logical Device Number */
naiif_printf("\r\n\r\n\r\nEnter Logical Device Number of Remote Terminal channel\r\n");
bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUMRT, &devnumRT);
if (bQuit)
{
return bQuit;
}
naiif_printf("\r\n\r\n\r\n");
/* Get Card, Module, Channel Numbers and Open a Handle */
bQuit = Get1553RTCfg(modid, DEF_M1553_RT_CHANNEL, DEF_RT_ADDRESS, &channelRT, &rtaddr);
if (bQuit)
{
return bQuit;
}
naiif_printf("Enter Subaddress\r\n");
bQuit = Get1553Address(NAIBRD_1553_RT_SA_31_MODECODE, DEF_RT_SUBADDR, &sa);
status = naibrd_1553_Open(cardIndex, module, channelRT, devnumRT);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Open Ch %d, status = %d", channelRT, status);
return NAI_TRUE;
}
/* Initialize Device */
status = naibrd_1553_Init(devnumRT, NAIBRD_1553_ACCESS_CARD, NAIBRD_1553_MODE_RT | NAIBRD_1553_MESSAGE_FIFO_MODE, 0, 0, 0);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_Init %d", status);
return bQuit;
}
if (bSoftware)
{
/* Set RTAD_SW_EN and RT_ADR_LAT in software */
status = naibrd_1553_WriteAuxRegister(devnumRT, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0x0018);
status = naibrd_1553_RtSetAddrSrc(devnumRT, NAIBRD_1553_RT_ADDR_SOURCE_INTERNAL);
/* Set RT address */
status = naibrd_1553_RtSetAddr(devnumRT, rtaddr);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtSetAddr %d", status);
return bQuit;
}
}
else
{
/* Unset RTAD_SW_EN and set RT_ADR_LAT in software */
status = naibrd_1553_WriteAuxRegister(devnumRT, NAIBRD_1553_AUX_ADDRESS_MISC_BITS, 0x0008);
status = naibrd_1553_RtSetAddrSrc(devnumRT, NAIBRD_1553_RT_ADDR_SOURCE_EXTERNAL);
}
/* Create a Rx Buffer data block and map to the desired subaddress */
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_RX, NAIBRD_1553_RT_DATABLOCK_DOUBLE, NULL, 0);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkCreate %d", status);
return bQuit;
}
status = naibrd_1553_RtDataBlkMapToSA(devnumRT, DATA_BLOCK_ID_RX, sa, NAIBRD_1553_RT_MESSAGE_TYPE_RX,
NAIBRD_1553_RT_DATABLOCK_IRQ_NONE, 1);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkMapToSA %d", status);
return bQuit;
}
/* Create a Broadcast Rx Buffer data block and map to the desired subaddress */
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_BCST, NAIBRD_1553_RT_DATABLOCK_DOUBLE, NULL, 0);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkCreate %d", status);
return bQuit;
}
status = naibrd_1553_RtDataBlkMapToSA(devnumRT, DATA_BLOCK_ID_BCST, sa, NAIBRD_1553_RT_MESSAGE_TYPE_BROADCAST,
NAIBRD_1553_RT_DATABLOCK_IRQ_NONE, 1);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkMapToSA %d", status);
return bQuit;
}
/* Create two Tx Buffer data blocks and map the first to the desired subaddress */
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_TX1, NAIBRD_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkCreate %d", status);
return bQuit;
}
status = naibrd_1553_RtDataBlkCreate(devnumRT, DATA_BLOCK_ID_TX2, NAIBRD_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkCreate %d", status);
return bQuit;
}
status = naibrd_1553_RtDataBlkMapToSA(devnumRT, DATA_BLOCK_ID_TX1, sa, NAIBRD_1553_RT_MESSAGE_TYPE_TX,
NAIBRD_1553_RT_DATABLOCK_IRQ_NONE, 1);
if (status < 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtDatBlkMapToSA %d", status);
return bQuit;
}
currDataBlock = DATA_BLOCK_ID_TX1;
while (bContinue)
{
status = naibrd_1553_ClearMsgFIFO(devnumRT);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_ClearMsgFIFO %d", status);
return bQuit;
}
/* Start RT */
status = naibrd_1553_RtStart(devnumRT);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtStart %d", status);
return bQuit;
}
/* Load BC data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
{
aData[i] = increment++;
}
status = naibrd_1553_BcDataBlkWrite(devnumBC, DBLK1, aData, WORDCOUNT, 0);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcDataBlkWrite status = %d", status);
return NAI_TRUE;
}
/* Start BC */
status = naibrd_1553_BcStart(devnumBC, MJR, 1);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcStart status = %d", status);
return NAI_TRUE;
}
/* This delay is necessary to allow the BC to run */
naibrd_msDelay(200);
/* Stop BC */
status = naibrd_1553_BcStop(devnumBC);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_BcStop status = %d", status);
return NAI_TRUE;
}
/* Get BC Block Status and RT Response Status */
status = naibrd_1553_BcMsgGetByIdDecoded(devnumBC, MSG1, &DecodedMsgStruct, 1);
if (status < 0)
{
naiif_printf("Error: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
return NAI_TRUE;
}
else if (status > 0)
{
naiif_printf("\r\n\r\n\r\n");
naiif_printf("********** BC MESSAGE BLOCK **********\r\n");
naiif_printf("Control Word: 0x%04X\r\n", DecodedMsgStruct.bcControlWord);
naiif_printf("Command Word: 0x%04X\r\n", DecodedMsgStruct.commandWord1);
if (DecodedMsgStruct.isCommandWord2Relevant)
naiif_printf("Command Word 2: 0x%04X\r\n", DecodedMsgStruct.commandWord2);
naiif_printf("Block Status: 0x%04X\r\n", DecodedMsgStruct.blockStatus);
naiif_printf("Time Tag: 0x%04X\r\n", DecodedMsgStruct.timeTag);
naiif_printf("Word Count: 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
naiif_printf("RT Status Word: 0x%04X\r\n", DecodedMsgStruct.status1);
if (DecodedMsgStruct.isStatus2Relevant)
naiif_printf("RT Status Word 2: 0x%04X\r\n", DecodedMsgStruct.status2);
if ((msgType == M1553_MSGTYPE_RTTOBC) || (msgType == M1553_MSGTYPE_MODECODE_TX))
{
naiif_printf((DecodedMsgStruct.dataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < DecodedMsgStruct.dataWordCount; i++)
{
if (i % 8 == 0)
{
naiif_printf("\r\n");
}
naiif_printf("0x%04X ", DecodedMsgStruct.data[i]);
}
}
naiif_printf("\r\n***************************************");
naiif_printf("\r\n\r\n");
}
naiif_printf("********** RT MESSAGE BLOCK **********\r\n");
/* Process New Messages */
ProcessMessages(devnumRT, sa);
naiif_printf("\r\n***************************************");
/* Stop RT */
status = naibrd_1553_RtStop(devnumRT);
if (status != 0)
{
bQuit = NAI_TRUE;
naiif_printf("Error: naibrd_1553_RtStop %d", status);
return bQuit;
}
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;
}
}
}
}
}
}
/* Free 1553 Device */
status = naibrd_1553_Free(devnumBC);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Free status = %d", status);
return NAI_TRUE;
}
status = naibrd_1553_Free(devnumRT);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_Free status = %d", status);
return NAI_TRUE;
}
return bQuit;
}
static int32_t ProcessMessages(uint16_t devnum, naibrd_1553_rt_subaddress_t Subaddress)
{
int32_t status;
int32_t i;
uint32_t fifoCount;
int32_t currBlockIndex = 0, nextBlockIndex = 0;
naibrd_1553_msgstructFIFO_t DecodedMsgStruct;
uint32_t fifoData[1024];
int32_t count = 0;
bool_t FIFOfullStatusBit;
status = naibrd_1553_GetMsgFIFOCount(devnum, &fifoCount);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_GetMsgFIFOCount %d", status);
return NAI_TRUE;
}
else
{
/* Update the Tx buffer data */
UpdateTxDataBlock(devnum, Subaddress);
if (fifoCount > 0)
{
currBlockIndex = 0;
/* This is necessary because otherwise, fifoData array gets used over and over without getting zero'ed out. */
/* When the array gets decoded, old data may get decoded unintentionally */
memset(fifoData, 0, sizeof(fifoData));
/* Read Message FIFO */
status = naibrd_1553_ReadMsgFIFO(devnum, fifoCount, fifoData);
if (status != 0)
{
naiif_printf("Error: naibrd_1553_ReadMsgFIFO %d", status);
return NAI_TRUE;
}
else
{
/* Read Messages */
do
{
status = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &DecodedMsgStruct);
if (status == 0)
{
if ((DecodedMsgStruct.commandWord1 & 0x0400) != 0x0400) /* If this is a Rx message */
{
naiif_printf("Rx Msg Received\r\n");
naiif_printf("\r\n\r\nDecoded Message:\r\n\r\n");
naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
naiif_printf((DecodedMsgStruct.dataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < DecodedMsgStruct.dataWordCount; i++)
{
if (i % 8 == 0)
{
naiif_printf("\r\n");
}
naiif_printf("0x%04X ", DecodedMsgStruct.data[i]);
}
naiif_printf("count: %d\r\n", count++);
naiif_printf("\r\n\r\n");
}
else
{
naiif_printf("Tx Msg Received\r\n");
naiif_printf("\r\n\r\nDecoded Message:\r\n\r\n");
naiif_printf("Block Status - 0x%04X\r\n", DecodedMsgStruct.blockStatus);
naiif_printf("Time Tag - 0x%04X\r\n", DecodedMsgStruct.timeTag);
naiif_printf("Command Word - 0x%04X\r\n", DecodedMsgStruct.commandWord1);
naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);
naiif_printf("count: %d\r\n", count++);
naiif_printf("\r\n\r\n");
}
}
else if(status != NAIBRD_1553_CMD_NO_MSG_TO_DECODE)
{
naiif_printf("Error: naibrd_1553_DecodeFIFOMsg %d", status);
return NAI_TRUE;
}
/*** IMPORTANT !!! ***/
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");
}
else
{
naiif_printf("Error: naibrd_1553_GetMsgFIFOFullStatus %d", status);
return NAI_TRUE;
}
}
}
return 1;
}
static int32_t UpdateTxDataBlock(uint16_t DevNum, naibrd_1553_rt_subaddress_t Subaddress)
{
/* Update Data in TX Data Block */
if (currDataBlock == DATA_BLOCK_ID_TX1)
{
UpdateTxBuffer(DevNum, DATA_BLOCK_ID_TX2);
/* Change data pointer to block 2 */
naibrd_1553_RtTxDataBlkSwap(DevNum, DATA_BLOCK_ID_TX2, Subaddress);
currDataBlock = DATA_BLOCK_ID_TX2;
}
else
{
UpdateTxBuffer(DevNum, DATA_BLOCK_ID_TX1);
/* Change data pointer to block 1 */
naibrd_1553_RtTxDataBlkSwap(DevNum, DATA_BLOCK_ID_TX1, Subaddress);
currDataBlock = DATA_BLOCK_ID_TX1;
}
return 0;
}
static int32_t UpdateTxBuffer(uint16_t DevNum, uint16_t nDataBlkID)
{
static uint16_t wBuffer[32] = { 0x0000 };
uint16_t i = 0x0000;
uint32_t result;
/* Increment Tx buffer data */
for (i = 0; i < 32; i++)
{
wBuffer[i] += 1;
}
/* Write new data to Tx buffer */
result = naibrd_1553_RtDataBlkWrite(DevNum, nDataBlkID, wBuffer, RTBC_WORDCNT, 0);
if (result < 0)
{
naiif_printf("Error: naibrd_1553_RtDatBlkWrite %d\r\n\r\n", result);
return 0;
}
else
{
naiif_printf("New data written to Tx Buffer\r\n\r\n");
}
return 1;
}