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 MT Monitor FIFO

M1553 MT Monitor FIFO Sample Application (SSK 2.x)

Overview

The M1553 MT Monitor FIFO sample application demonstrates how to configure a MIL-STD-1553 channel as a Bus Monitor (MT) and capture bus traffic using Message FIFO mode with the NAI Software Support Kit (SSK 2.x). This sample extends the standard MT Monitor sample by using the hardware FIFO to capture messages instead of the MT command stack.

FIFO mode provides ordered, sequential access to all captured messages and is well-suited for high-rate traffic logging where the command stack might overflow. The sample demonstrates message filtering, FIFO reading, sequential message decoding, and FIFO full status checking. For Tx messages, data is only displayed if the message had no errors (checked via block status word flags).

Note
FIFO mode is available for the FTA-FTF modules only.

For detailed 1553 protocol specifications, message formats, and hardware register descriptions, see the FTA-FTF Manual.

For the SSK 1.x version, see M1553 MT Monitor FIFO (SSK 1.x).

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a 1553 module installed (FTA-FTF).

  • SSK 2.x installed on your development host.

  • The sample applications built. Refer to the SSK 2.x Software Development Guide for platform-specific build instructions.

  • Active 1553 bus traffic (BC and RT communicating) for the monitor to capture.

How to Run

Launch the m1553_mt_monitor_fifo executable from your build output directory. On startup the application looks for a configuration file (default_1553_MTMonitor_FIFO.txt). Once connected, the application prompts for MT channel and logical device number, then enters a loop where the user specifies a monitoring duration.

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.

Program Structure

Entry Point

The Run_M1553_MT_Monitor_FIFO() function configures the MT channel, opens the device, initializes in FIFO mode, applies message filtering, and enters the main loop.

Application Flow

Each iteration starts the MT, calls MonitorMessages() to poll the FIFO, then stops the MT.

MT Initialization in FIFO Mode

result = naibrd_1553_Init(DevNum, NAIBRD_1553_ACCESS_CARD,
   NAIBRD_1553_MODE_MT | NAIBRD_1553_MESSAGE_FIFO_MODE, 0, 0, 0);

/* Disable monitoring for RT 1, SA 3 */
result = naibrd_1553_MtMsgMonitoringDisable(DevNum, RT_DISABLE,
   NAIBRD_1553_DIRECTION_ALL, 1 << SA_DISABLE);

Monitoring Messages via FIFO

The MonitorMessages() function polls the FIFO every 10 ms:

result = naibrd_1553_GetMsgFIFOCount(DevNum, &fifoCount);
if (fifoCount > 0)
{
   memset(fifoData, 0, sizeof(fifoData));
   result = naibrd_1553_ReadMsgFIFO(DevNum, fifoCount, fifoData);

   do
   {
      result = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &DecodedMsgStruct);
      if (result == 0)
      {
         /* Display decoded message fields */
         /* For Tx messages, only display data if no errors: */
         if ((DecodedMsgStruct.blockStatus &
            (NAIBRD_1553_MT_BLK_STS_WORD_END_OF_MESSAGE | NAIBRD_1553_MT_BLK_STS_WORD_ERROR_FLAG))
            == NAIBRD_1553_MT_BLK_STS_WORD_END_OF_MESSAGE)
         {
            /* Safe to display data */
         }
      }
      currBlockIndex = nextBlockIndex;
   } while (result == NAI_SUCCESS);
}

The block status word check for Tx messages ensures data is only displayed when the END_OF_MESSAGE flag is set and the ERROR_FLAG is not set.

Troubleshooting Reference

Error / Symptom Possible Causes Suggested Resolution

naibrd_1553_Open returns non-zero

Channel already open, invalid indices

Verify indices, ensure no other application holds the channel

FIFO mode not supported

Module is FTJ/FTK (1760)

FIFO mode is only available on FTA-FTF modules

FIFO full during monitoring

High bus traffic rate

Poll FIFO more frequently or reduce monitoring duration

No messages captured

No bus traffic, monitoring disabled for all RT/SA

Verify BC and RT are communicating, check filter settings

Tx message data not displayed

Block status shows error

Check bus wiring and termination, inspect block status word

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail.

Full Source — m1553_mt_monitor_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.h"
#include "nai_libs/naiif/include/naiif_stdio.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"

/* Common 1553 Sample Program include files */
#include "nai_sample_apps/naiapp_src/board_modules/1553/m1553_common_utils/m1553_common_utils.h"

static const int8_t *DEF_CONFIG_FILE = (int8_t *)"default_1553_MTMonitor_FIFO.txt";

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

static const int32_t DEF_MT_CHANNEL       = 1;
static const int16_t DEF_MT_DEV_NUM       = 1;

#define RT_DISABLE      1
#define SA_DISABLE      3

/**************************************************************************************************************/
/** \defgroup M1553_MT_Monitor_FIFO

\brief This sample application demonstrates how to configure a channel as a Bus Monitor and log bus traffic in FIFO mode.

The purpose of the M1553_MT_Monitor_FIFO is to illustrate the methods to call in the naibrd library to configure
and run the 1553 channel as a Message Monitor in Message FIFO Mode. All messages are received via the Message
FIFO in this sample application. If an Rx message is detected on the bus, the Rx message will be displayed with
1553 data. If a Tx message is detected, the Tx message will be displayed but 1553 data will only be displayed
if there is 1553 data and if the message contained no errors. This application also demonstrates message filtering
using the naibrd_1553_MtMsgMonitoringDisable() function to disable monitoring messages sent on subaddress 3.

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 the channel for Bus Monitor functionality in FIFO mode.
- Starting the MT to start capturing traffic.
- Displaying any messages on the bus.
*/
/**************************************************************************************************************/
#if defined (NAIBSP_CONFIG_SOFTWARE_OS_VXWORKS)
int32_t m1553_mt_monitor_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)
      {
         /* Select Card Index */
         stop = naiapp_query_CardIndex(naiapp_GetBoardCnt(), 0, &cardIndex);
         if (stop != NAI_TRUE)
         {
            check_status(naibrd_GetModuleCount(cardIndex, &moduleCnt));

            /* Select Module */
            stop = naiapp_query_ModuleNumber(moduleCnt, 1, &module);
            if (stop != NAI_TRUE)
            {
               check_status(naibrd_GetModuleName(cardIndex, module, &moduleID));
               if ((moduleID != 0))
               {
                  Run_M1553_MT_Monitor_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_MT_Monitor_FIFO(int32_t cardIndex, int32_t module, uint32_t modid)
{
   /* Variables */
   bool_t bQuit = NAI_FALSE;
   int32_t mtchan;
   int16_t DevNum = 0;
   int32_t result;
   bool_t bContinue = NAI_TRUE;
   int32_t duration;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Get Card, Module, Channel Numbers and Open a Handle */
   bQuit = Get1553MTCfg(modid, DEF_MT_CHANNEL, &mtchan);
   if (bQuit)
   {
      return bQuit;
   }

   /* Get Logical Device # */
   bQuit = Get1553LogicalDevNum(DEF_MT_DEV_NUM, &DevNum);
   if (bQuit)
   {
      return bQuit;
   }

   /* Associate Card, Module and Channel Numbers with the Logical Device # */
   result = naibrd_1553_Open(cardIndex, module, mtchan, DevNum);
   if(result)
   {
      bQuit = NAI_TRUE;
      naiif_printf("Error: naibrd_1553_Open  %d", result);
      return bQuit;
   }

   /* Initialize Device */
   result = naibrd_1553_Init(DevNum,NAIBRD_1553_ACCESS_CARD,NAIBRD_1553_MODE_MT | NAIBRD_1553_MESSAGE_FIFO_MODE,0,0,0);
   if(result != 0)
   {
      bQuit = NAI_TRUE;
      naiif_printf("Error: naibrd_1553_Initialize  %d", result);
      return bQuit;
   }

   /* Disable Monitoring for RT 1, SA 3 Message Types (In default power on state, all messages are monitored) */
   result = naibrd_1553_MtMsgMonitoringDisable(DevNum, RT_DISABLE, NAIBRD_1553_DIRECTION_ALL, 1 << SA_DISABLE);
   if(result != 0)
   {
      bQuit = NAI_TRUE;
      naiif_printf("Error: naibrd_1553_Initialize  %d", result);
      return bQuit;
   }

   while (bContinue)
   {
      naiif_printf("\r\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 MT */
         result = naibrd_1553_MtStart(DevNum);
         if(result != 0)
         {
            bQuit = NAI_TRUE;
            naiif_printf("Error: naibrd_1553_MtStart  %d", result);
            return bQuit;
         }

         /* Start the monitor and display any new messages */
         MonitorMessages(DevNum, duration);

         /* Stop MT */
         result = naibrd_1553_MtStop(DevNum);
         if(result != 0)
         {
            bQuit = NAI_TRUE;
            naiif_printf("Error: naibrd_1553_MtStop  %d", result);
            return bQuit;
         }
      }
      else
         bContinue = NAI_FALSE;
   }

   /* Free 1553 Device */
   result = naibrd_1553_Free(DevNum);
   if(result != 0)
   {
      bQuit = NAI_TRUE;
      naiif_printf("Error: naibrd_1553_Free  %d", result);
      return bQuit;
   }

   return bQuit;
}

static int32_t MonitorMessages(uint16_t DevNum, int32_t duration)
{
   int32_t counter_mS = 0, end_mS = 0;
   uint32_t result;
   int32_t i;
   naibrd_1553_msgstructFIFO_t DecodedMsgStruct;
   uint32_t fifoData[1024];
   int32_t count = 0;
   int32_t currBlockIndex = 0, nextBlockIndex = 0;
   uint32_t fifoCount;
   bool_t FIFOfullStatusBit;

   end_mS = duration*1000;    /* in milliseconds */

   while (counter_mS < end_mS)
   {
      result = naibrd_1553_GetMsgFIFOCount(DevNum, &fifoCount);
      if (result != 0)
      {
         naiif_printf("Error: naibrd_1553_GetMsgFIFOCount  %d", result);
         return NAI_TRUE;
      }
      else
      {
         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 */
            result = naibrd_1553_ReadMsgFIFO(DevNum, fifoCount, fifoData);
            if (result != 0)
            {
               naiif_printf("Error: naibrd_1553_ReadMsgFIFO  %d", result);
               return NAI_TRUE;
            }
            else
            {
               /* Read Messages */
               do
               {
                  result = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &DecodedMsgStruct);
                  if (result == 0)
                  {
                     if ((DecodedMsgStruct.commandWord1 & 0x0400) != 0x0400)   /* If this is a Rx message */
                     {
                        naiif_printf("\r\n\r\n\r\nRx 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);

                        if(DecodedMsgStruct.isCommandWord2Relevant)
                           naiif_printf("Command Word 2 - 0x%04X\r\n", DecodedMsgStruct.commandWord2);

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

                        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("\r\n\r\n\r\nTx 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);

                        if (DecodedMsgStruct.isCommandWord2Relevant)
                           naiif_printf("Command Word 2 - 0x%04X\r\n", DecodedMsgStruct.commandWord2);

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

                        naiif_printf("Data Word Count - 0x%04X\r\n", DecodedMsgStruct.dataWordCount);

                        /* Only print data if message had no errors */
                        if ((DecodedMsgStruct.blockStatus & (NAIBRD_1553_MT_BLK_STS_WORD_END_OF_MESSAGE | NAIBRD_1553_MT_BLK_STS_WORD_ERROR_FLAG))
                           == NAIBRD_1553_MT_BLK_STS_WORD_END_OF_MESSAGE)
                        {
                           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 if (result != (uint32_t)NAIBRD_1553_CMD_NO_MSG_TO_DECODE)
                  {
                     naiif_printf("Error: naibrd_1553_DecodeFIFOMsg  %d", result);
                     return NAI_TRUE;
                  }

                  /*** IMPORTANT !!! ***/
                  currBlockIndex = nextBlockIndex;

                  naibrd_msDelay(1);

               } while (result == NAI_SUCCESS);
            }

            result = naibrd_1553_GetMsgFIFOFullStatus(DevNum, NAIBRD_1553_STATUS_REALTIME, &FIFOfullStatusBit);
            if (result == 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", result);
               return NAI_TRUE;
            }
         }
      }

      naibrd_msDelay(10);
      counter_mS += 10;
   }

   return 1;
}

Help Bot

X