Integrator Resources

The official home for NAI Support

Not sure where to start? Try Quick Start Guide or ask a question below!

Toggle Components with Visual Button
JavaScript Form Processing

M1553 RT BITWordSetByHost

M1553 RT BITWordSetByHost Sample Application (SSK 1.x)

Overview

The M1553 RT BITWordSetByHost sample application demonstrates how to configure a MIL-STD-1553 channel as a Remote Terminal (RT) and give the host application write access to the Built-In Test (BIT) word using the NAI Software Support Kit (SSK 1.x). By default, the 1553 core manages the BIT word internally — the host cannot write to it. This sample shows how to override that default so that the host can write a custom 16-bit value to the BIT word. When a Bus Controller (BC) sends a "Transmit BIT Word" mode code to this RT, the RT responds with the host-written BIT word rather than the core-managed value.

The key BIT word API calls demonstrated are:

  • naibrd_1553_RtBITWordConfigure() — enables host write access to the BIT word and selects the memory location.

  • naibrd_1553_RtBITWordWrite() — writes a 16-bit value to the BIT word from the host.

  • naibrd_1553_RtBITWordRead() — reads the BIT word from either the core-managed register or the host-managed memory location.

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_BITWordSetByHost executable from your build output directory. On startup the application looks for a configuration file (default_1553_RTBitWordSetByHost.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 (channel, RT address, address source) and then configures the BIT word, legalizes Tx mode codes, and enters a timed monitoring loop that processes messages from the bus.

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:

  1. Call naiapp_RunBoardMenu() to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_1553_RTBitWordSetByHost.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.

  2. Query the user for a card index with naiapp_query_CardIndex().

  3. Query for a module slot with naiapp_query_ModuleNumber().

  4. Retrieve the module ID with naibrd_GetModuleID() so downstream code can adapt to the specific 1553 variant installed.

  5. If a valid module is found, call Run_M1553_RT_BITWordSetByHost() to begin RT configuration and BIT word operations.

#if defined (__VXWORKS__)
int32_t M1553_RT_BITWordSetByHost(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_BITWordSetByHost(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;
}
Important

Common connection errors you may encounter at this stage:

  • No board found — verify that the board is powered on and physically connected. Check that the configuration file lists the correct interface and address.

  • Connection timeout — confirm network settings (for Ethernet connections) or bus configuration (for PCI/PCIe). Firewalls and IP mismatches are frequent causes.

  • Invalid card or module index — indices are zero-based for cards and one-based for modules. Ensure the values you pass match your hardware setup.

  • Module not present at selected slot — the slot you selected does not contain a 1553 module. Use the board menu to verify which slots are populated.

Program Structure

Entry Point

The program entry point is main() on most platforms or M1553_RT_BITWordSetByHost() on VxWorks. After the board connection and module selection described above, the application calls Run_M1553_RT_BITWordSetByHost(), which handles all RT-specific configuration, BIT word operations, and message processing.

User Input Flow

Once inside Run_M1553_RT_BITWordSetByHost(), the application collects RT operating parameters through a series of utility functions. Each function presents a prompt, accepts user input, and falls back to a compiled-in default if the user presses Enter without typing a value:

  1. Get1553RTCfg() — prompts for the 1553 channel number and RT address. It uses the module ID to determine valid channel ranges (4 channels for standard 1553 modules, 2 for 1760 modules). The defaults are channel 1 and RT address 1.

  2. Get1553LogicalDevNum() — prompts for a logical device number. The logical device number is a software handle that the naibrd library uses to associate a specific card/module/channel combination with subsequent API calls. The default is device 1.

  3. Get1553RTAddressSource() — asks whether to set the RT address in software or use the hardware address pins. When software addressing is selected, the application writes to the auxiliary registers to enable software RT address control and then calls naibrd_1553_RtSetAddress() to program the address. When hardware addressing is selected, the RT address is read from the module’s physical address pins.

Note
This sample does not prompt for a subaddress or Rx buffer type because it does not set up data subaddress blocks for normal Rx/Tx traffic. Instead, it legalizes Tx mode codes so the RT can respond to BC "Transmit BIT Word" mode code commands.

RT Address Configuration

The RT address can be set from two sources: software control or hardware address pins. The application calls Get1553RTAddressSource() to let the user choose, then executes the corresponding code path. Both paths write to auxiliary register 0x2 but with different bit masks.

Software Addressing

Set the RTAD_SW_EN and RT_ADR_LAT bits (value 0x0018) in auxiliary register 0x2 via naibrd_1553_WriteAuxReg(), then program the desired address with naibrd_1553_RtSetAddress(). This gives the application full control over the RT address. Software addressing is typical for development, test, and Ethernet-connected boards where the address needs to change without rewiring.

Hardware Pin Addressing

Set only the RT_ADR_LAT bit (value 0x0008) in auxiliary register 0x2 via naibrd_1553_WriteAuxReg(). The RT address is read from the module’s external address pins. The application does not call naibrd_1553_RtSetAddress() in this mode. Hardware pin addressing is required in some MIL-STD-1760 installations where the platform wiring determines the RT address.

Source Code

   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);
   }

For complete register bit definitions, refer to the FTA-FTF Manual.

Important
  • RT not responding — verify that the address and source mode match. A common mistake is configuring software addressing while the hardware is wired for pin addressing, or vice versa. If the source mode does not match, the RT will have the wrong address (or no valid address) and will not respond to BC commands.

  • RT address conflict — two RTs with the same address on the same bus cause unpredictable behavior. Each RT on a bus must have a unique address (0-30). Address 31 is reserved for broadcast and must not be assigned to any RT.

BIT Word Configuration and Host Write

Default BIT Word Behavior

By default, the 1553 core manages the BIT word internally. The core updates the BIT word based on its own built-in test results, and the host application has no write access. When the BC sends a "Transmit BIT Word" mode code (mode code 18 with the TR bit set), the RT responds with the core-managed BIT word value.

Enabling Host Write Access

To override the default and allow the host to write the BIT word, call naibrd_1553_RtBITWordConfigure() with NAI_1553_RT_BIT_MEMORY as the location and NAI_1553_RT_BIT_ENABLED as the enable flag. This tells the 1553 core to use the host-writable memory location for the BIT word instead of its internal register.

   /* Set the location of the BIT word */
   swResult = naibrd_1553_RtBITWordConfigure(DevNum, NAI_1553_RT_BIT_MEMORY, NAI_1553_RT_BIT_ENABLED);
   if (swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordConfigure status = %d", swResult);
      return TRUE;
   }

NAI_1553_RT_BIT_MEMORY selects the host-writable memory location. NAI_1553_RT_BIT_ENABLED enables host write access. After this call, any value written by the host via naibrd_1553_RtBITWordWrite() will be the value the RT transmits when the BC requests the BIT word.

Writing the BIT Word

To write a value to the BIT word from the host, call naibrd_1553_RtBITWordWrite(). The sample writes the value 0x6789:

   /* Write the BIT word */
   swResult = naibrd_1553_RtBITWordWrite(DevNum, wBitWord);
   if (swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordWrite status = %d", swResult);
      return TRUE;
   }

After this call, when the BC sends a "Transmit BIT Word" mode code to this RT, the RT will respond with 0x6789 as the data word.

Reading the BIT Word

The sample reads the BIT word from both locations to verify the configuration. The core-managed register and the host-managed memory location are independent:

   /* Read the BIT word from the memory/register location updated by the core */
   swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_REGISTER, &wData);
   if (swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordRead status = %d", swResult);
      return TRUE;
   }
   printf("\nCore BIT word: 0x%04X ", wData);

   /* Read the BIT word from the memory location updated by the host */
   swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_MEMORY, &wData);
   if (swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordRead status = %d", swResult);
      return TRUE;
   }
   printf("Host BIT word: 0x%04X\n", wData);

Pass NAI_1553_RT_BIT_REGISTER to read the core’s internal BIT word value. Pass NAI_1553_RT_BIT_MEMORY to read the host-written value. When host write access is enabled, the RT uses the memory location (host value) when responding to BC "Transmit BIT Word" requests.

Important
  • BIT word configure failure — verify that naibrd_1553_RtBITWordConfigure() is called after naibrd_1553_Initialize() but before naibrd_1553_RtStart(). Calling it on an uninitialized device or an unsupported module will return an error.

  • Host BIT word reads back as zero — ensure you passed NAI_1553_RT_BIT_MEMORY (not NAI_1553_RT_BIT_REGISTER) to the configure call, and that NAI_1553_RT_BIT_ENABLED was set. If the enable flag is not set, the core manages the BIT word and host writes are ignored.

  • BC receives wrong BIT word — the core-managed register and host-managed memory are separate locations. If you configured NAI_1553_RT_BIT_MEMORY but are reading from NAI_1553_RT_BIT_REGISTER, the values will differ. The RT transmits from whichever location was selected in naibrd_1553_RtBITWordConfigure().

Mode Code Legalization

Before the RT can respond to BC mode code commands, the relevant mode codes must be legalized. This sample legalizes all Tx mode codes so that the RT can respond to the "Transmit BIT Word" mode code:

   /* Legalize Tx Mode Codes */
   swResult = naibrd_1553_RtMessageLegalityEnable(DevNum, NAI_1553_RT_ADDRESS_OWN,
      NAI_1553_MT_FILTER_TX, NAI_1553_MODE_CODE1, NAI_1553_WORDCOUNT_OR_MODECODE_MASK_ALL);
   if (swResult != 0)
   {
      printf("Error: naibrd_1553_RtMessageLegalityEnable status = %d", swResult);
      return TRUE;
   }

NAI_1553_RT_ADDRESS_OWN targets the RT’s own address. NAI_1553_MT_FILTER_TX selects the Tx direction (RT-to-BC). NAI_1553_MODE_CODE1 selects the mode code message type. NAI_1553_WORDCOUNT_OR_MODECODE_MASK_ALL legalizes all mode codes in the Tx direction at once.

Without this legalization step, the RT will ignore "Transmit BIT Word" commands from the BC, even if the BIT word is correctly configured.

Important
  • RT ignores mode code commands — mode codes must be explicitly legalized with naibrd_1553_RtMessageLegalityEnable(). If this call is missing or targets the wrong direction (Rx instead of Tx), the RT will not respond to "Transmit BIT Word" requests.

  • Wrong address parameter — using NAI_1553_RT_ADDRESS_OWN is correct for legalizing mode codes on the RT’s own address. Using a different address constant will legalize mode codes for a different RT address, which will have no effect on this RT.

Message Processing Loop

The ProcessMessages() function is the core runtime loop. It runs for a user-specified duration (default 5 seconds), polling the RT stack for new messages every 10 ms (nai_msDelay(10)). This sample uses direct stack-based message retrieval (not host buffers), reading raw messages from the RT stack and decoding them.

Stack-Based Message Retrieval

Each iteration calls naibrd_1553_RtMessageGetFromStackRaw() to check for new messages on the RT stack. The return value indicates the number of messages retrieved. A negative return value indicates an error; zero means no new messages; a positive value is the message count.

   swResult = naibrd_1553_RtMessageGetFromStackRaw(DevNum, wsBuffer, NAI_1553_MAX_MESSAGE_SIZE_RT*2);
   if (swResult < 0)
   {
      printf("Error: naibrd_1553_RtMessageGetFromStackRaw %d\n\n", swResult);
      return 0;
   }
   else if (swResult > 0)
   {
      msgcount = swResult;

      for (j = 0; j < msgcount; j++)
      {
         /* Decode Raw Message */
         swResult = naibrd_1553_RtMessageDecodeRaw(DevNum, &wsBuffer[j*NAI_1553_MAX_MESSAGE_SIZE_RT], &DecodedMsgStruct);

The buffer size is NAI_1553_MAX_MESSAGE_SIZE_RT*2 to accommodate multiple messages. Each decoded message is accessed at offset j*NAI_1553_MAX_MESSAGE_SIZE_RT within the buffer.

Message Type Discrimination

The command word’s TR bit (bit 0x0400) distinguishes Rx from Tx messages. When the bit is 0, the BC sent data to the RT (Rx). When the bit is 1, the BC requested data from the RT (Tx). The sample prints different fields depending on direction — Rx messages include the full data payload, while Tx messages show only header fields.

Decoded Fields

Each decoded message (naiDecodedMessageStructure) contains:

  • Block Status (wBlockStatus) — hardware status flags for the message transfer.

  • Time Tag (wTimeTag) — hardware timestamp of when the message was received.

  • Command Word (wCommandWord1) — the 1553 command word containing the RT address, subaddress/mode code, TR bit, and word count.

  • Data Word Count (wDataWordCount) — number of data words in the message.

  • Payload (waData[]) — the actual data words (displayed for Rx messages only).

Important
  • No messages appearing — verify that the RT has been started with naibrd_1553_RtStart(), mode codes are legalized, and the BC is sending "Transmit BIT Word" mode code commands targeting this RT address.

  • BIT word not returned to BC — ensure naibrd_1553_RtBITWordConfigure() was called with NAI_1553_RT_BIT_MEMORY and NAI_1553_RT_BIT_ENABLED, and that naibrd_1553_RtBITWordWrite() was called before starting the RT.

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 RtSetAddress() or hardware pins matches BC command word.

RT address source conflict

Software address set but hardware pin mode active, or vice versa

Match WriteAuxReg(0x2, …​) value to desired source: 0x0018 for software, 0x0008 for hardware pins.

BIT word configure failure

Called before Initialize() or on unsupported module

Call RtBITWordConfigure() after Initialize() and before RtStart().

Host BIT word reads zero

Host write not enabled, or reading from wrong location

Verify NAI_1553_RT_BIT_MEMORY and NAI_1553_RT_BIT_ENABLED in configure call.

BC receives wrong BIT word

Core register vs. host memory mismatch

Verify configure call selects NAI_1553_RT_BIT_MEMORY. Read from same location to confirm.

RT ignores mode code commands

Mode codes not legalized

Call RtMessageLegalityEnable() with correct direction (NAI_1553_MT_FILTER_TX) before starting RT.

No messages appearing

RT not started, mode codes not legalized, or BC not sending to this RT

Verify RtStart() was called, mode codes are legalized, and BC targets correct RT address.

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_BITWordSetByHost.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_RTBitWordSetByHost.txt";

/* Function prototypes */
static bool_t Run_M1553_RT_BITWordSetByHost(int32_t cardIndex, int32_t module, uint32_t modid);
static int32_t ProcessMessages(uint16_t DevNum, int32_t duration);

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 uint16_t wBitWord            = 0x6789;

/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_RT_BITWordSetByHost is to illustrate the methods to call in the naibrd library to configure
and run the 1553 channel as a Remote Terminal, provide the host with write access to the Built-In Test (BIT) word
and write the value 0x6789 to the BIT word from the host. The FT[1-9] and FTJ/FTK modules possess the capability
for the BIT word to be written by the host. The default mode however does not allow the host to write the BIT word
and instead it is updated by the core. By calling naibrd_1553_RtBITWordConfigure() with the appropriate parameter,
the host can write the 16-bit BIT word and in turn, when the Bus Controller sends a "Transmit BIT Word" mode code,
the RT will respond with status and a data word that contains the BIT word written by the host.

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_BITWordSetByHost(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_BITWordSetByHost(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_RT_BITWordSetByHost(int32_t cardIndex, int32_t module, uint32_t modid)
{
   /* Variables */
   bool_t bQuit = FALSE;
   int32_t rtchan;
   uint8_t rtaddr;
   int16_t DevNum           = 0;
   int32_t swResult;
   bool_t bSoftwareRTAddr;
   uint16_t wData;
   bool_t bContinue = TRUE;
   int32_t duration;
   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;
   }

   /* 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);
   }

   /* Set the location of the BIT word */
   swResult = naibrd_1553_RtBITWordConfigure(DevNum, NAI_1553_RT_BIT_MEMORY, NAI_1553_RT_BIT_ENABLED);
   if(swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordConfigure status = %d", swResult);
      return TRUE;
   }

   /* Write the BIT word */
   swResult = naibrd_1553_RtBITWordWrite(DevNum, wBitWord);
   if(swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordWrite status = %d", swResult);
      return TRUE;
   }

   /* Read the BIT word from the memory/register location updated by the core */
   swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_REGISTER, &wData);
   if(swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordRead status = %d", swResult);
      return TRUE;
   }
   printf("\nCore BIT word: 0x%04X ", wData);

   /* Read the BIT word from the memory location updated by the host */
   swResult = naibrd_1553_RtBITWordRead(DevNum, NAI_1553_RT_BIT_MEMORY, &wData);
   if(swResult != 0)
   {
      printf("Error: naibrd_1553_RtBITWordRead status = %d", swResult);
      return TRUE;
   }
   printf("Host BIT word: 0x%04X\n", wData);

   /* Legalize Tx Mode Codes */
   swResult = naibrd_1553_RtMessageLegalityEnable(DevNum, NAI_1553_RT_ADDRESS_OWN, NAI_1553_MT_FILTER_TX, NAI_1553_MODE_CODE1, NAI_1553_WORDCOUNT_OR_MODECODE_MASK_ALL);
   if(swResult != 0)
   {
      printf("Error: naibrd_1553_RtMessageLegalityEnable status = %d", swResult);
      return TRUE;
   }

   while (bContinue)
   {
      printf("\nType duration (in seconds) to run RT or %c to quit (default: 5) : ", NAI_QUIT_CHAR);
      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, 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 ProcessMessages(uint16_t DevNum, int32_t duration)
{
   time_t end;
   uint32_t swResult;
   int32_t msgcount;
   uint16_t wsBuffer[72] = { 0x0000 };
   naiDecodedMessageStructure DecodedMsgStruct;
   int32_t i, j;
   int32_t count = 0;

   end = time(NULL) + duration;

   while (time(NULL) < end)
   {
      /* 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*2);
      if (swResult < 0)
      {
         printf("Error: naibrd_1553_RtMessageGetFromStackRaw %d\n\n", swResult);
         return 0;
      }
      else if (swResult > 0)
      {
         msgcount = swResult;

         for (j = 0; j < msgcount; j++)
         {
            /* Decode Raw Message */
            swResult = naibrd_1553_RtMessageDecodeRaw(DevNum, &wsBuffer[j*NAI_1553_MAX_MESSAGE_SIZE_RT], &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++);
               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++);
               printf("\n\n");
            }
         }
      }
      nai_msDelay(10);
   }

   return 1;
}

Help Bot

X