M1553 RT Receive StatusBits
Edit this on GitLab
M1553 RT Receive StatusBits Sample Application (SSK 1.x)
Overview
The M1553 RT Receive StatusBits sample application demonstrates how to configure a MIL-STD-1553 channel as a Remote Terminal (RT) with status bit configuration using the NAI Software Support Kit (SSK 1.x). The RT status word is returned to the Bus Controller (BC) with every response, and certain bits in that word can be set by the application to signal conditions such as busy, service request, or subsystem flags. This sample shows how to select status bits (including standard and alternate status modes), apply them to the RT, and observe the configured status mask in message output.
The key status bit API calls demonstrated are:
-
naibrd_1553_RtResponseStatusBitsUnset()— clears all or selected status bits. -
naibrd_1553_RtResponseStatusBitsSet()— sets selected status bits in the RT status word. -
naibrd_1553_RtResponseStatusBitsGet()— reads back the current status bit mask. -
naibrd_1553_RtDataBlockGetSize()— retrieves data block size information for command stack sizing. -
naibrd_1553_RtInitialize()— reinitializes the RT with option flags (used for alternate status mode).
This sample also supports MIL-STD-1760 modules, which have a unique NAI_1760_RT_STATUS_BIT_INSTRUMENTATION bit, and non-1760 modules in alternate status mode, which have a different set of status bit definitions.
This sample supports the following 1553 module types:
-
4-channel modules: FT0 through FT9 and FTA through FTF
-
2-channel 1760 modules: FTJ and FTK
-
Combination modules: CM1, CM5, and CM8
For detailed register maps and module-specific behavior, refer to the FTA-FTF Manual and FTJ-FTK Manual.
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a supported 1553 module installed.
-
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_RT_Receive_StatusBits executable from your build output directory. On startup the application looks for a configuration file (default_1553_RTReceive_StatusBits.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 walks you through RT-specific settings, prompts for alternate status mode (on non-1760 modules), prompts for status bit selection, and then enters a timed monitoring loop that processes messages and displays the status mask.
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_1553_RTReceive_StatusBits.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. -
If a valid module is found, call
Run_M1553_RT_Receive()withisAlternateMode = FALSEto begin RT configuration.
#if defined (__VXWORKS__)
int32_t M1553_RT_Receive_StatusBits(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_RT_Receive(cardIndex, module, moduleID, FALSE);
}
}
}
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;
}
|
Important
|
Common connection errors you may encounter at this stage:
|
Program Structure
Entry Point
The program entry point is main() on most platforms or M1553_RT_Receive_StatusBits() on VxWorks. After the board connection and module selection, the application calls Run_M1553_RT_Receive(), which handles all RT-specific configuration, status bit setup, and message processing.
User Input Flow
Run_M1553_RT_Receive() collects RT operating parameters through the standard utility functions:
-
Get1553RTCfg()— prompts for the 1553 channel number and RT address (defaults: channel 1, RT address 1). -
Get1553Address()— prompts for the subaddress to legalize for Tx and Rx traffic (default: subaddress 2). -
Get1553LogicalDevNum()— prompts for a logical device number (default: device 1). -
Get1553RTAddressSource()— asks whether to set the RT address in software or use the hardware address pins. -
Get1553RxBufferType()— prompts the user to select the Rx data block buffering mode (single, double, or circular).
After the standard setup, the application asks whether to use alternate status mode (only on non-1760 modules), then prompts for status bit selection.
|
Note
|
The menu system is a sample convenience — in your own code, call these API functions directly. |
RT Address Configuration
The RT address configuration follows the same pattern as other 1553 RT samples. To set the address in software, write RTAD_SW_EN and RT_ADR_LAT bits (value 0x0018) to auxiliary register 0x2 via naibrd_1553_WriteAuxReg(), then program the address with naibrd_1553_RtSetAddress(). For hardware pin addressing, set only RT_ADR_LAT (value 0x0008).
if (bSoftwareRTAddr)
{
swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0018);
swResult = naibrd_1553_RtSetAddress(DevNum, rtaddr);
}
else
{
swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0008);
}
For complete register bit definitions, refer to the FTA-FTF Manual.
|
Important
|
|
Alternate Status Mode
On non-1760 modules, the sample offers the option to enable alternate status mode. In alternate mode, the RT status word uses a different bit mapping that provides additional status fields (Terminal Flag, Subsystem Flag, Busy, Service Request, Instrumentation, and Message Error at different bit positions than standard mode).
To enable alternate status mode, the sample queries the data block size, computes an appropriate command stack size, and reinitializes the RT with the NAI_1553_RT_OPT_ALTERNATE_STATUS flag:
swResult = naibrd_1553_RtDataBlockGetSize(nDataBlockType, &wordSize, &dataBlockSize);
wRtCommandStackSize = ((65536 <= wordSize * 1024) ? NAI_1553_RT_CMDSTK_SIZE_2048 :
((32768 <= wordSize) ? NAI_1553_RT_CMDSTK_SIZE_1024 :
((16384 <= wordSize) ? NAI_1553_RT_CMDSTK_SIZE_512 : NAI_1553_RT_CMDSTK_SIZE_256)));
swResult = naibrd_1553_RtInitialize(DevNum, wRtCommandStackSize, NAI_1553_RT_OPT_ALTERNATE_STATUS);
naibrd_1553_RtDataBlockGetSize() returns the word size and data block size for the selected buffer type. This information is used to compute the correct command stack size — larger data blocks require a larger command stack to avoid overflow.
|
Note
|
1760 modules (FTJ, FTK) do not support alternate status mode. The sample skips this prompt when a 1760 module is detected via IsFTx1760().
|
|
Important
|
|
Status Bit Configuration
The SetStatusBits() function presents the available status bits based on the module type and status mode, then applies the user’s selection. The three operating contexts have different available bits:
Standard Mode (Non-1760)
| Selection | Constant | Value |
|---|---|---|
1 |
NO MASK |
0x0000 |
2 |
|
0x0800 |
3 |
|
0x0400 |
4 |
|
0x0200 |
5 |
|
0x0100 |
6 |
|
0x0080 |
Alternate Status Mode (Non-1760)
| Selection | Constant | Value |
|---|---|---|
1 |
NO MASK |
0x0000 |
2 |
|
0x0002 |
3 |
|
0x0008 |
4 |
|
0x0010 |
5 |
|
0x0200 |
6 |
|
0x0400 |
7 |
|
0x0800 |
Standard Mode (1760 Modules)
1760 modules in standard mode have the same bits as non-1760 standard mode, plus an additional instrumentation bit:
| Selection | Constant | Value |
|---|---|---|
7 |
|
0x0002 |
Applying Status Bits
The user can select multiple status bits by entering space-separated numbers. The selections are OR’d together to form a mask. The sample first clears all status bits, then sets the selected bits, and reads back the result:
/* Clear all status bits */
swResult = naibrd_1553_RtResponseStatusBitsUnset(DevNum, 0xFFFF);
/* Set selected status bits */
swResult = naibrd_1553_RtResponseStatusBitsSet(DevNum, *statusBitMask);
/* Read back the status mask */
swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, statusBitMask);
To configure status bits in your own application, first clear any existing bits with naibrd_1553_RtResponseStatusBitsUnset(), then set the desired bits with naibrd_1553_RtResponseStatusBitsSet(). The mask value is the OR of all NAI_1553_RT_STATUS_BIT_* constants you want to enable.
|
Important
|
|
Buffer Types and Data Block Configuration
This sample creates and maps data blocks for Rx and Tx traffic, following the same pattern as other RT Receive samples. Note that this sample does not create a broadcast Rx data block (unlike M1553_RT_Receive and M1553_RT_Receive_FIFO).
Rx Data Block
swResult = naibrd_1553_RtDataBlockCreate(DevNum, DATA_BLOCK_ID_RX, nDataBlockType, NULL, 0);
swResult = naibrd_1553_RtDataBlockMapToSubaddress(DevNum, DATA_BLOCK_ID_RX, sa, NAI_1553_RT_MESSAGE_TYPE_RX, 0, 1);
Tx Double-Buffering
swResult = naibrd_1553_RtDataBlockCreate(DevNum, DATA_BLOCK_ID_TX1, NAI_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
swResult = naibrd_1553_RtDataBlockCreate(DevNum, DATA_BLOCK_ID_TX2, NAI_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
swResult = naibrd_1553_RtDataBlockMapToSubaddress(DevNum, DATA_BLOCK_ID_TX1, sa, NAI_1553_RT_MESSAGE_TYPE_TX, 0, 1);
currDataBlock = DATA_BLOCK_ID_TX1;
|
Important
|
|
Message Processing Loop
The ProcessMessages() function runs for a user-specified duration (default 5 seconds), using stack-based message retrieval identical to the M1553_RT_Receive sample. On each iteration it reads raw messages, decodes them, and displays the current status bit mask alongside the decoded message fields.
The status mask display confirms that the configured bits are active in the RT status word:
/* After decoding a message */
printf("Status Bit mask = %X\n", statusMask);
This allows you to verify that the BC is receiving the expected status word in the RT’s response.
Tx Buffer Updates
The UpdateTxBuffer() function also prints the status mask after each write, confirming the bits remain set during normal operation:
printf("New data written to Tx Buffer\n\n");
printf("Status Bit mask = %X\n", statusMask);
|
Important
|
|
Troubleshooting Reference
This table summarizes common errors and symptoms covered in the sections above. For detailed context on each entry, refer to the relevant section. Consult your module’s manual for hardware-specific diagnostic procedures.
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found or connection timeout |
Board not powered, missing configuration file, network issue |
Verify hardware and configuration file. If file doesn’t exist, configure and save from board menu. |
Module not recognized as 1553 |
Selected module is not FT-series or CM with 1553 |
Verify module type at the selected slot. |
Device open or initialization failure |
Wrong card/module/channel, or device already in use |
Verify parameters. Close other applications using this channel. |
RT address mismatch |
RT address doesn’t match what BC is targeting |
Confirm address set via |
Status bits not in RT response |
|
Call |
Wrong status bits active |
Standard mode bits used in alternate mode, or vice versa |
Match status bit constants to the active mode (standard vs. alternate). |
Alternate status mode unavailable |
Module is FTJ/FTK (1760) which does not support alternate status |
Alternate status is only available on non-1760 modules. |
1760 instrumentation bit ignored |
|
This constant is only valid on FTJ/FTK modules. |
No messages appearing |
RT not started, subaddress not legalized, or BC not sending to this RT/subaddress |
Verify |
Data block creation or mapping failure |
Invalid block type, ID, or subaddress out of range |
Verify block type constants and subaddress range (1-30 for data, 0/31 for mode codes). |
Tx data stale from BC perspective |
|
Always swap after writing to the inactive block. Verify |
Stack overflow / lost messages |
Application not reading from stack frequently enough |
Increase polling rate or reduce loop delay. |
Full Source
The complete source for this sample is provided below for reference. The sections above explain each part in detail.
Full Source — M1553_RT_Receive_StatusBits.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* 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"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_1553_RTReceive_StatusBits.txt";
/* Function prototypes */
static bool_t Run_M1553_RT_Receive(int32_t cardIndex, int32_t module, uint32_t modid, bool_t isAlternateMode);
static int32_t UpdateTxDataBlock(uint16_t DevNum, uint8_t Subaddress);
static int32_t UpdateTxBuffer(uint16_t DevNum, uint16_t nDataBlkID);
static int32_t ProcessMessages(uint16_t DevNum, uint8_t Subaddress, int32_t duration);
static int32_t SetStatusBits(uint16_t DevNum, uint32_t modid, bool_t isAlternateMode, uint16_t *statusBitMask);
static const uint16_t DATA_BLOCK_ID_TX1 = 1;
static const uint16_t DATA_BLOCK_ID_TX2 = 2;
static const uint16_t DATA_BLOCK_ID_RX = 3;
static const int32_t DEF_RT_CHANNEL = 1;
static const int16_t DEF_RT_DEV_NUM = 1;
static const uint8_t DEF_RT_ADDRESS = 1;
static const uint8_t DEF_RT_SUBADDR = 2;
static const uint16_t DEF_RT_RX_BUF_TYPE = NAI_1553_RT_DATABLOCK_DOUBLE;
static const uint16_t RTBC_WORDCNT = 32;
/* Global Variables */
static int32_t currDataBlock;
#define NO_MASK 0x0000
static uint16_t statusMask;
/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_RT_Receive_StatusBits is to illustrate the methods to call in the naibrd library to configure
the 1553 channel as a Remote Terminal, legalize Subaddress 2 for both Tx and Rx, set the RT stautus bits, and set it up to receive data
using an Rx double buffer and transmit data from two alternating Tx buffers (active and inactive). If a Rx message
is received, the received data will be displayed. If a Tx message is received, the data in the active Tx buffer will be sent to the bus and
display the status word. While the RT is running, Tx buffer data will be updated periodically by incrementing all 32 data words of Tx data.
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_RT_Receive_StatusBits(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_RT_Receive(cardIndex, module, moduleID, FALSE);
}
}
}
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_RT_Receive(int32_t cardIndex, int32_t module, uint32_t modid, bool_t isAlternateMode)
{
/* Variables */
bool_t bQuit = FALSE;
int32_t rtchan;
uint8_t rtaddr;
uint8_t sa = DEF_RT_SUBADDR;
int16_t DevNum = 0;
int32_t swResult;
uint16_t nDataBlockType = 0;
bool_t bContinue = TRUE;
int32_t duration;
bool_t bSoftwareRTAddr;
uint16_t wordSize;
uint16_t dataBlockSize;
uint16_t wRtCommandStackSize;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get Card, Module, Channel Numbers and Open a Handle */
bQuit = Get1553RTCfg(modid, DEF_RT_CHANNEL, DEF_RT_ADDRESS, &rtchan, &rtaddr);
if (bQuit)
{
return bQuit;
}
printf("Enter Subaddress\n");
bQuit = Get1553Address(31, DEF_RT_SUBADDR, &sa);
/* Get Logical Device # */
bQuit = Get1553LogicalDevNum(DEF_RT_DEV_NUM, &DevNum);
if (bQuit)
{
return bQuit;
}
/* Associate Card, Module and Channel Numbers with the Logical Device # */
swResult = naibrd_1553_Open(cardIndex, module, rtchan, DevNum);
if(swResult)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Open %d", swResult);
return bQuit;
}
/* Initialize Device */
swResult = naibrd_1553_Initialize(DevNum,NAI_1553_ACCESS_CARD,NAI_1553_MODE_RT,0,0,0);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Initialize %d", swResult);
return bQuit;
}
/* Get RT Address Source from user */
bQuit = Get1553RTAddressSource(TRUE, &bSoftwareRTAddr);
if (bQuit)
{
return bQuit;
}
if (bSoftwareRTAddr)
{
/* Set RTAD_SW_EN and RT_ADR_LAT in software */
swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0018);
/* Set RT address */
swResult = naibrd_1553_RtSetAddress(DevNum, rtaddr);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtSetAddress %d", swResult);
return bQuit;
}
}
else
{
/* Unset RTAD_SW_EN and set RT_ADR_LAT in software */
swResult = naibrd_1553_WriteAuxReg(DevNum, 0x2, 0x0008);
}
if (modid == NAI_MODULE_ID_FT8)
{
/* Simplex Enable (for internal NAI testing only, do not enable) */
/*naibrd_1553_WriteAuxReg(DevNum, 0x3, 0x4000);
naibrd_1553_WriteAuxReg(DevNum, 0xF, 0x1);*/
}
/* Select Single Buffer, Double Buffer or Circular Buffer for Rx Messages */
bQuit = Get1553RxBufferType(DEF_RT_RX_BUF_TYPE, &nDataBlockType);
if (bQuit)
{
return bQuit;
}
if (!IsFTx1760(modid))
{
do
{
inputBuffer[0] = 'N';
printf("Do you want to use Alternate Status Mode? y or n default = No\n");
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (inputBuffer[0] == '\0')
{
inputBuffer[0] = 'n';
}
} while (inputBuffer[0] != 'y' && inputBuffer[0] != 'Y' && inputBuffer[0] != 'n' && inputBuffer[0] !='N');
if ((inputBuffer[0] == 'y') || (inputBuffer[0] == 'Y'))
{
isAlternateMode = TRUE;
swResult = naibrd_1553_RtDataBlockGetSize(nDataBlockType, &wordSize, &dataBlockSize);
if (swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtDataBlockGetSize %d", swResult);
return bQuit;
}
wRtCommandStackSize = ((65536 <= wordSize * 1024) ? NAI_1553_RT_CMDSTK_SIZE_2048 : ((32768 <= wordSize) ? NAI_1553_RT_CMDSTK_SIZE_1024 :
((16384 <= wordSize) ? NAI_1553_RT_CMDSTK_SIZE_512 : NAI_1553_RT_CMDSTK_SIZE_256)));
swResult = naibrd_1553_RtInitialize(DevNum, wRtCommandStackSize, NAI_1553_RT_OPT_ALTERNATE_STATUS);
if (swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtInitialize %d", swResult);
return bQuit;
}
}
}
/* Create a Rx Buffer data block and map to the desired subaddress */
swResult = naibrd_1553_RtDataBlockCreate(DevNum, DATA_BLOCK_ID_RX, nDataBlockType, NULL, 0);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtDataBlockCreate %d", swResult);
return bQuit;
}
swResult = naibrd_1553_RtDataBlockMapToSubaddress(DevNum, DATA_BLOCK_ID_RX, sa, NAI_1553_RT_MESSAGE_TYPE_RX, 0, 1);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtDataBlockMapToSubaddress %d", swResult);
return bQuit;
}
/* Create two Tx Buffer data blocks and map the first to the desired subaddress */
swResult = naibrd_1553_RtDataBlockCreate(DevNum, DATA_BLOCK_ID_TX1, NAI_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtDataBlockCreate %d", swResult);
return bQuit;
}
swResult = naibrd_1553_RtDataBlockCreate(DevNum, DATA_BLOCK_ID_TX2, NAI_1553_RT_DATABLOCK_SINGLE_32, NULL, 0);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtDataBlockCreate %d", swResult);
return bQuit;
}
swResult = naibrd_1553_RtDataBlockMapToSubaddress(DevNum, DATA_BLOCK_ID_TX1, sa, NAI_1553_RT_MESSAGE_TYPE_TX, 0, 1);
if(swResult < 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtDataBlockMapToSubaddress %d", swResult);
return bQuit;
}
currDataBlock = DATA_BLOCK_ID_TX1;
statusMask = 0;
/* Set status bits */
swResult = SetStatusBits(DevNum, modid, isAlternateMode, &statusMask);
if (swResult != 0)
{
bQuit = TRUE;
return bQuit;
}
while (bContinue)
{
printf("\nType duration (in seconds) to run RT or %c to quit (default: 5) : ", NAI_QUIT_CHAR);
fflush(stdin);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
duration = 5;
if (inputResponseCnt > 0)
{
duration = (int)atol((const char*)inputBuffer);
}
/* Start RT */
swResult = naibrd_1553_RtStart(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtStart %d", swResult);
return bQuit;
}
/* Process New Messages */
ProcessMessages(DevNum, sa, duration);
/* Stop RT */
swResult = naibrd_1553_RtStop(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_RtStop %d", swResult);
return bQuit;
}
}
else
bContinue = FALSE;
}
/* Free 1553 Device */
swResult = naibrd_1553_Free(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Free %d", swResult);
return bQuit;
}
return bQuit;
}
static int32_t UpdateTxDataBlock(uint16_t DevNum, uint8_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_RtTxDataBlockSwap(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_RtTxDataBlockSwap(DevNum, DATA_BLOCK_ID_TX1, Subaddress);
currDataBlock = DATA_BLOCK_ID_TX1;
}
return 0;
}
static int ProcessMessages(uint16_t DevNum, uint8_t Subaddress, int32_t duration)
{
time_t end, period;
uint32_t swResult;
int32_t i;
naiDecodedMessageStructure DecodedMsgStruct;
uint16_t wsBuffer[72] = { 0x0000 };
int32_t count = 0;
end = time(NULL) + duration;
period = time(NULL) + 1;
while (time(NULL) < end)
{
/* Update Tx Data Block periodically */
if (time(NULL) > period)
{
UpdateTxDataBlock(DevNum, Subaddress);
period = time(NULL) + 1;
}
/* If the stack pointer has updated (new data arrived), read one message at a time */
swResult = naibrd_1553_RtMessageGetFromStackRaw(DevNum, wsBuffer, NAI_1553_MAX_MESSAGE_SIZE_RT);
if (swResult < 0)
{
printf("Error: naibrd_1553_RtMessageGetFromStackRaw %d\n\n", swResult);
return 0;
}
else if (swResult > 0)
{
/* Decode Raw Message */
swResult = naibrd_1553_RtMessageDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);
if (swResult < 0)
{
printf("Error: naibrd_1553_RtMessageDecodeRaw %d\n\n", swResult);
return 0;
}
if ((DecodedMsgStruct.wCommandWord1 & 0x0400) != 0x0400) /* If this is a Rx message */
{
printf("Rx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("Data:");
for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", DecodedMsgStruct.waData[i]);
}
printf("count: %d\n", count++);
/* print out RT status word */
printf("Status Bit mask = %X\n", statusMask);
printf("\n\n");
}
else
{
printf("Tx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("count: %d\n", count++);
/* print out RT status word */
printf("Status Bit mask = %X\n", statusMask);
printf("\n\n");
}
}
nai_msDelay(10);
}
return 1;
}
static int32_t UpdateTxBuffer(uint16_t DevNum, uint16_t nDataBlkID)
{
static uint16_t wBuffer[32] = { 0x0000 };
uint16_t i = 0x0000;
uint32_t swResult;
/* Increment Tx buffer data */
for (i = 0; i < 32; i++)
{
wBuffer[i] += 1;
}
/* Write new data to Tx buffer */
swResult = naibrd_1553_RtDataBlockWrite(DevNum, nDataBlkID, wBuffer, RTBC_WORDCNT, 0);
if (swResult < 0)
{
printf("Error: naibrd_1553_RtDataBlockWrite %d\n\n", swResult);
return 0;
}
else
{
printf("\n");
printf("New data written to Tx Buffer\n\n");
/* print out RT status word */
printf("Status Bit mask = %X\n", statusMask);
}
return 1;
}
int32_t SetStatusBits(uint16_t DevNum, uint32_t modid, bool_t isAlternateMode, uint16_t *statusBitMask)
{
uint32_t i = 0;
int16_t swResult;
char maskInputArr[100] = { 0 };
bool_t validSelection = TRUE;
printf("\n\nChoose the desired OR'ed combinations to set the status bit mask:\n");
printf("Press:\n");
printf("1 - NO MASK = 0x0000\n");
/* module is not in 1553 alternate mode */
if (!isAlternateMode)
{
printf("2 - NAI_1553_RT_STATUS_BIT_DBCA = 0x0800\n");
printf("3 - NAI_1553_RT_STATUS_BIT_BUSY = 0x0400\n");
printf("4 - NAI_1553_RT_STATUS_BIT_SERVICE_REQUEST = 0x0200\n");
printf("5 - NAI_1553_RT_STATUS_BIT_SUBSYSTEM_FLAG = 0x0100\n");
printf("6 - NAI_1553_RT_STATUS_BIT_RT_FLAG = 0x0080\n\n");
}
/* module is not a 1760 module, and is in 1553 alternate status mode */
if (!IsFTx1760(modid) && (isAlternateMode))
{
printf("2 - NAI_1553_ALT_RT_STATUS_BIT_TERMINALFLAG = 0x0002,\n");
printf(" for 1553 alternate only\n");
printf("3 - NAI_1553_ALT_RT_STATUS_BIT_SUBSYSTEMFLAG = 0x0008,\n");
printf(" for 1553 alternate only\n");
printf("4 - NAI_1553_ALT_RT_STATUS_BIT_BUSY = 0x0010,\n");
printf(" for 1553 alternate only\n");
printf("5 - NAI_1553_ALT_RT_STATUS_BIT_SERVICE_REQUEST = 0x0200,\n");
printf(" for 1553 alternate only\n");
printf("6 - NAI_1553_ALT_RT_STATUS_BIT_INSTRUMENTATION = 0x0400,\n");
printf(" for 1553 alternate only\n");
printf("7 - NAI_1553_ALT_RT_STATUS_BIT_MESSAGE_ERROR = 0x0800,\n");
printf(" for 1553 alternate mode 1553 and 1760(is read only bit 1760)\n\n");
}
/* module is a 1760 module, and is not in 1553 alternate status mode */
if (IsFTx1760(modid) && (!isAlternateMode))
{
printf("7 - NAI_1760_RT_STATUS_BIT_INSTRUMENTATION = 0x0002,\n");
printf(" for 1760 only\n\n");
}
printf("If desired, use spaces as seperators, in between your choice(s) for multiple OR'ed combinations\n");
scanf(" %[^\n]c", maskInputArr);
do
{
for (i = 0; i < strlen(maskInputArr); i++)
{
if ((maskInputArr[i] != '1') && (maskInputArr[i] != '2') && (maskInputArr[i] != '3') && (maskInputArr[i] != '4') &&
(maskInputArr[i] != '5') && (maskInputArr[i] != '6') && (maskInputArr[i] != '7') && (maskInputArr[i] != ' '))
{
validSelection = FALSE;
if (!isAlternateMode)
{
if (IsFTx1760(modid))
{
printf("\nPlease enter a valid selection from combinations between 1 and 7.\n");
}
else
{
printf("\nPlease enter a valid selection from combinations between 1 and 6.\n");
}
}
else if(!IsFTx1760(modid) && (isAlternateMode))
{
printf("\nPlease enter a valid selection from combinations between 1 and 7.\n");
}
printf("Use spaces as sepreators, including spaces.\n");
scanf(" %[^\n]c", maskInputArr);
}
else
{
validSelection = TRUE;
}
}
} while (!validSelection);
if (maskInputArr != NULL)
{
/* parse string and set statusBitMask */
for (i = 0; i < strlen(maskInputArr); i++)
{
if ((maskInputArr[i] == '1') || (maskInputArr[i] == '2') || (maskInputArr[i] == '3') || (maskInputArr[i] == '4') ||
(maskInputArr[i] == '5') || (maskInputArr[i] == '6') || (maskInputArr[i] == '7'))
{
if (maskInputArr[i] == '1')
{
*statusBitMask |= NO_MASK;
}
else if (!isAlternateMode)
{
if (maskInputArr[i] == '2')
{
*statusBitMask |= NAI_1553_RT_STATUS_BIT_DBCA;
}
else if (maskInputArr[i] == '3')
{
*statusBitMask |= NAI_1553_RT_STATUS_BIT_BUSY;
}
else if (maskInputArr[i] == '4')
{
*statusBitMask |= NAI_1553_RT_STATUS_BIT_SERVICE_REQUEST;
}
else if (maskInputArr[i] == '5')
{
*statusBitMask |= NAI_1553_RT_STATUS_BIT_SUBSYSTEM_FLAG;
}
else if (maskInputArr[i] == '6')
{
*statusBitMask |= NAI_1553_RT_STATUS_BIT_RT_FLAG;
}
else if (maskInputArr[i] == '7')
{
if (IsFTx1760(modid))
{
*statusBitMask |= NAI_1760_RT_STATUS_BIT_INSTRUMENTATION;
}
}
}
else if ((!IsFTx1760(modid) && (isAlternateMode)))
{
if (maskInputArr[i] == '2')
{
*statusBitMask |= NAI_1553_ALT_RT_STATUS_BIT_TERMINALFLAG;
}
else if (maskInputArr[i] == '3')
{
*statusBitMask |= NAI_1553_ALT_RT_STATUS_BIT_SUBSYSTEMFLAG;
}
else if (maskInputArr[i] == '4')
{
*statusBitMask |= NAI_1553_ALT_RT_STATUS_BIT_BUSY;
}
else if (maskInputArr[i] == '5')
{
*statusBitMask |= NAI_1553_ALT_RT_STATUS_BIT_SERVICE_REQUEST;
}
else if (maskInputArr[i] == '6')
{
*statusBitMask |= NAI_1553_ALT_RT_STATUS_BIT_INSTRUMENTATION;
}
else if (maskInputArr[i] == '7')
{
*statusBitMask |= NAI_1553_ALT_RT_STATUS_BIT_MESSAGE_ERROR;
}
}
}
}
}
/* Clear masks */
swResult = naibrd_1553_RtResponseStatusBitsUnset(DevNum, 0xFFFF);
if (swResult != 0)
{
printf("Error: naibrd_1553_RtResponseStatusBitsUnset %d\n\n", swResult);
return swResult;
}
/* set status bits */
swResult = naibrd_1553_RtResponseStatusBitsSet(DevNum, *statusBitMask);
if (swResult != 0)
{
printf("Error: naibrd_1553_RtResponseStatusBitsSet %d\n\n", swResult);
return swResult;
}
/* Get status mask */
swResult = naibrd_1553_RtResponseStatusBitsGet(DevNum, statusBitMask);
if (swResult != 0)
{
printf("Error: naibrd_1553_RtResponseStatusBitsGet %d\n\n", swResult);
return swResult;
}
return swResult;
}