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

SUM1553 RT PingPong

SUM1553 RT Ping-Pong Sample Application (SSK 1.x)

Overview

The SUM1553 RT Ping-Pong sample application demonstrates how to configure a SUMMIT 1553 channel as a Remote Terminal (RT) with ping-pong buffer management using the NAI Software Support Kit (SSK 1.x). Ping-pong buffering is a hardware feature of the SUMMIT 1553 core that maintains two alternating data buffers per subaddress. While the 1553 core writes incoming data to one buffer, the host application reads from the other — eliminating the risk of reading a buffer that is being modified mid-transaction.

This sample configures the RT to:

  • Accept BC-to-RT (receive) messages on all subaddresses.

  • Respond to RT-to-BC (transmit) requests on all subaddresses.

  • Use ping-pong buffering so the host can safely read received data without bus timing conflicts.

After configuration, the interactive loop lets you:

  • Press Enter — read and display received BC-to-RT messages from all subaddresses.

  • Press 'U' — update the RT transmit data for subaddress 2 (the data sent in response to RT-to-BC requests).

  • Press 'Q' — disable RT execution and exit.

Important

This sample uses the naibrd_SUM1553_* API for SUMMIT 1553 modules (N7, N8, NA, NB, NC). If you are using FTx modules (FT0—​FTF, FTJ, FTK), see the M1553 RT sample guides which use the naibrd_1553_* API. The two APIs target different hardware cores and are not interchangeable.

Supported Modules

This sample supports SUMMIT 1553 module types: N7, N8, NA, NB, and NC. The helper function IsSUMMIT1553(modid) is used at runtime to confirm that the selected module slot contains a supported SUMMIT 1553 device. Each SUMMIT 1553 module provides up to 2 channels.

Note
The SUM1553 RT Ping-Pong sample can run in conjunction with the SUM1553_BC_Scheduler or SUM1553_BC_RTtoRT companion samples to exercise BC and RT operations together on the same 1553 bus.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a SUMMIT 1553 module installed (N7, N8, NA, NB, or NC).

  • 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.

  • A Bus Controller running on the same bus (for example, the SUM1553_BC_Scheduler sample) to send messages to this RT.

How to Run

Launch the SUM1553_RT_PingPong executable from your build output directory. On startup the application looks for a configuration file (default_SUM1553_RTPP.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, you select an RT channel and RT address, and the RT begins listening on 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 SUMMIT 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_SUM1553_RTPP.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() and pass it to Run_SUM1553_RT_PingPong() for channel configuration.

#if defined (__VXWORKS__)
int32_t SUM1553_RT_PingPong(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_SUM1553_RT_PingPong(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 SUMMIT 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 and SUM1553_RT_PingPong() on VxWorks. Both follow the same logic: run the board menu, then loop over card/module selection until the user quits.

Module Detection

After the user selects a module slot, naibrd_GetModuleID() returns the module identifier. The helper IsSUMMIT1553(modid) (called inside Get1553RTCfg()) validates that the module is a supported SUMMIT 1553 type. SUMMIT 1553 modules provide up to 2 channels.

User Input Flow

The application walks the user through four selection steps before starting the RT:

  1. Card index — naiapp_query_CardIndex() prompts for the board to use.

  2. Module slot — naiapp_query_ModuleNumber() prompts for the slot containing the SUMMIT 1553 module.

  3. RT channel — Get1553RTCfg() prompts for the channel to configure as a Remote Terminal (default channel 1).

  4. RT address — Get1553RTCfg() prompts for the RT bus address (default address 1, range 0—​31).

Once the channel and address are selected, Run_SUM1553_RT_PingPong() configures the channel and starts RT execution.

Interactive Loop

After the RT starts, the hardware responds to BC messages autonomously. The application enters an interactive loop where:

  • Enter — scans all 32 subaddresses for new BC-to-RT data and displays any received messages.

  • 'U' — increments a counter and updates the transmit data block for subaddress 2, following the ping-pong safe update protocol.

  • 'Q' — disables RT execution and returns to the card/module selection prompt.

The RT runs entirely in hardware between user interactions. The bus is never stalled by the host polling or updating data.

Ping-Pong Buffer Architecture

The SUMMIT 1553 core’s ping-pong buffer feature addresses a fundamental timing problem in 1553 RT operation: the host needs to read received data and update transmit data, but the 1553 core may be writing to or reading from those same buffers during a bus transaction.

How Ping-Pong Works

When ping-pong is enabled, the SUMMIT 1553 core maintains two data buffers per subaddress descriptor — a primary buffer and a secondary buffer. The core and the host alternate between the two buffers:

  • On each new message, the core switches to the alternate buffer for the next transaction.

  • The host reads from (or writes to) the buffer that the core is not currently using.

This double-buffering ensures that the host never reads a partially-written receive buffer or modifies a transmit buffer while the core is reading it for an active transaction.

Ping-Pong vs. Processor Control

This sample uses ping-pong buffering with processor control explicitly disabled (naibrd_SUM1553_Proc_SetCtrl(cardIndex,module,rtchan,0)). The companion SUM1553_RT_ProcCtrl sample takes a different approach — it enables the on-module processor to manage buffer servicing and event notification. The two approaches serve different use cases:

  • Ping-pong (this sample) — the host polls for new data at its own pace. Simpler to implement, suitable when the host can poll frequently enough.

  • Processor control — the on-module processor generates interrupts and delivers data via Ethernet IDR messages. Better for high-throughput or latency-sensitive applications where polling is not fast enough.

RT Configuration

The Run_SUM1553_RT_PingPong() function configures the channel as an RT through a sequence of API calls. Each call sets one aspect of the RT’s behavior.

Channel Reset and Mode Selection

/* Reset RT channel */
check_status(naibrd_SUM1553_Reset(cardIndex,module,rtchan));

/* Wait for channels to reset */
while(check_status(naibrd_SUM1553_IsResetting(cardIndex,module,rtchan,&resetting)) == NAI_SUCCESS && resetting);

/* Configure RT */
check_status(naibrd_SUM1553_SetMode(cardIndex,module,rtchan,NAI_SUM1553_OPSTATUS_RT_MODE)); /* Set to RT mode */

The channel is reset and polled until the reset completes. Then naibrd_SUM1553_SetMode() places the channel into Remote Terminal mode.

Bus and Address Configuration

check_status(naibrd_SUM1553_RT_SetBusEnable(cardIndex,module,rtchan,1,1)); /* Enable bus A and bus B */
check_status(naibrd_SUM1553_RT_SetAddress(cardIndex,module,rtchan,rtaddr)); /* Set RT address */

To enable the RT to respond on both Bus A and Bus B, call naibrd_SUM1553_RT_SetBusEnable() with both parameters set to 1. The RT address is then set to the value selected by the user (default: 1). This address determines which command words on the bus this RT responds to.

Ping-Pong Setup

check_status(naibrd_SUM1553_RT_ConfigureForPingPong(cardIndex,module,rtchan)); /* Set up descriptor table with ping pong buffers */
check_status(naibrd_SUM1553_RT_SetPingPongEnable(cardIndex,module,rtchan,1)); /* Enable ping pong */

naibrd_SUM1553_RT_ConfigureForPingPong() initializes the descriptor table so that each subaddress has two data block entries (primary and secondary). naibrd_SUM1553_RT_SetPingPongEnable() then activates the ping-pong mechanism so the core alternates between these buffers on each transaction. Both calls are required — configuring the descriptor table without enabling ping-pong leaves the feature inactive.

Subaddress Legalization

check_status(naibrd_SUM1553_RT_Legalize(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_RX,0xFFFFFFFF,1)); /* Legalize for rx */
check_status(naibrd_SUM1553_RT_Legalize(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_TX,0xFFFFFFFF,1)); /* Legalize for tx */

By default, the SUMMIT 1553 core illegalizes (rejects) messages to all subaddresses. To accept messages, you must explicitly legalize each subaddress. The 0xFFFFFFFF mask legalizes all 32 subaddresses in a single call. The NAI_SUM1553_SAMCTYPE_SA flag selects subaddress descriptors, and the RX/TX flags control the direction. In your own application, you can legalize only the subaddresses you need by setting specific bits in the mask.

Disabling Processor Control

check_status(naibrd_SUM1553_Proc_SetCtrl(cardIndex,module,rtchan,0));

This explicitly disables the on-module processor. In ping-pong mode, the host handles all buffer servicing directly through the API. If processor control were left enabled, the processor would attempt to manage buffers and events, which would conflict with the host-driven approach used in this sample.

Loading Initial Transmit Data and Starting Execution

/* Load the subaddress transmit data */
Update_SUM1553_RTSAXmitData(cardIndex,module,rtchan,0, FALSE);

/* Run the RT */
check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,rtchan,1));

Before starting execution, the transmit data block for subaddress 2 is loaded with initial values. The FALSE parameter indicates that ping-pong is not yet active during this initial load (it has been configured but the RT is not yet executing), so the safe disable/re-enable protocol is not needed. After loading the initial data, naibrd_SUM1553_EnableExecution() starts the RT — it will now respond to commands from any BC on the bus.

Important
  • Reset not completing — the hardware is not responding. Verify that the module is present and the card connection is active.

  • RT not responding to BC commands — verify that the RT address matches the address the BC is targeting, that the relevant subaddresses are legalized, and that both Bus A and Bus B are enabled (or whichever bus the BC is using).

  • Subaddress illegalized — if a specific subaddress does not respond, check the legalization mask. An illegalized subaddress causes the RT to not respond to that particular command, which the BC sees as a timeout or BAME error.

Retrieving BC-to-RT Messages

The Retrieve_SUM1553_BCRTMessages() function scans all 32 subaddresses for new received data. For each subaddress, it checks the Block Accessed (BAC) flag in the control word to determine whether new data has arrived since the last read.

static void Retrieve_SUM1553_BCRTMessages(int32_t cardIndex, int32_t module, int32_t rtchan)
{
   uint16_t ctrl;
   uint16_t rxdatablock[32], rxwordcnt;
   uint16_t timestamp;
   uint8_t sa;
   int32_t i;

   for (sa = 0; sa < 32; sa++)
   {
      check_status(naibrd_SUM1553_RT_GetControlWord(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_RX,sa,&ctrl));
      if (ctrl & NAI_SUM1553_RT_CTL_BAC) /* new data */
      {
         check_status(naibrd_SUM1553_RT_ReadRxDataBlock(cardIndex,module,rtchan,TRUE,sa,&rxwordcnt,&timestamp,rxdatablock));
         check_status(naibrd_SUM1553_RT_ClearBlockAccess(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_RX,sa));
         if (rxwordcnt == 0)
            rxwordcnt = 32;

         printf("SA %d ", sa);
         printf("TimeTag: %04X ", timestamp);
         printf("Data: ");

         for (i = 0; i < rxwordcnt; i++)
         {
            if (i != 0)
               printf(",");
            printf ("%04X", rxdatablock[i]);
         }
         printf("\n");
      }
   }
}

The retrieval sequence for each subaddress follows three steps:

  1. Check the control word — naibrd_SUM1553_RT_GetControlWord() reads the subaddress descriptor’s control word. The NAI_SUM1553_RT_CTL_BAC (Block Accessed) bit indicates that the core has written new data to this subaddress since the last time it was cleared.

  2. Read the data block — naibrd_SUM1553_RT_ReadRxDataBlock() reads the received data from the ping-pong buffer. The TRUE parameter indicates that this is a ping-pong read (read from the buffer the core is not currently using). The function also returns the word count and a hardware timestamp for the message.

  3. Clear the BAC flag — naibrd_SUM1553_RT_ClearBlockAccess() resets the Block Accessed bit so the next poll only reports genuinely new messages. If you skip this step, the same data will appear as "new" on every poll.

Note
A word count of 0 returned by naibrd_SUM1553_RT_ReadRxDataBlock() means 32 words (the MIL-STD-1553 convention where a word count field of 0 represents 32).
Important
  • No data displayed — if no subaddresses show the BAC flag set, no BC has sent messages to this RT since the last poll. Verify that a BC is running and targeting this RT’s address.

  • Stale data appearing repeatedly — the BAC flag was not cleared after reading. Ensure naibrd_SUM1553_RT_ClearBlockAccess() is called after each successful read.

Updating RT Transmit Data (Ping-Pong Safe)

The Update_SUM1553_RTSAXmitData() function updates the data that the RT sends in response to RT-to-BC requests on subaddress 2. Because ping-pong is active while the RT is running, updating the transmit buffer requires a specific protocol to avoid writing to the buffer the core is currently reading from.

static void Update_SUM1553_RTSAXmitData(int32_t cardIndex, int32_t module, int32_t rtchan, uint8_t increment, bool_t bPingPongEnabled)
{
   uint16_t sa = DEF_RT_SUBADDR;
   uint16_t txdatablock[32];
   uint8_t msb, lsb;
   int32_t i;
   bool_t enabled;

   msb = (uint8_t)(sa << 4) + (increment & 0x0F);
   lsb = 0;
   for (i = 0; i < 32; i++)
   {
      txdatablock[i] = (msb << 8) | (uint8_t)(lsb + i);
   }
   /* Update the data */
   if (bPingPongEnabled)
   {
      naibrd_SUM1553_RT_SetPingPongEnable(cardIndex, module, rtchan, 0);
      /* Wait for ping pong to be disabled */
      while(check_status(naibrd_SUM1553_RT_GetPingPongEnabled(cardIndex,module,rtchan,&enabled)) == NAI_SUCCESS && (enabled != 0));
   }
   check_status(naibrd_SUM1553_RT_LoadTxDataBlock(cardIndex,module,rtchan,TRUE, sa,txdatablock));
   if (bPingPongEnabled)
   {
      naibrd_SUM1553_RT_SetPingPongEnable(cardIndex, module, rtchan, 1);
   }
}

Ping-Pong Safe Update Protocol

To safely update the transmit buffer while the RT is running with ping-pong active, the protocol is:

  1. Disable ping-pong — call naibrd_SUM1553_RT_SetPingPongEnable(cardIndex, module, rtchan, 0). This stops the core from alternating buffers.

  2. Wait for confirmation — poll naibrd_SUM1553_RT_GetPingPongEnabled() until it returns enabled == 0. The hardware may need one bus cycle to complete the transition. Do not write to the buffer until ping-pong is confirmed disabled.

  3. Write the secondary buffer — call naibrd_SUM1553_RT_LoadTxDataBlock() with the TRUE flag to write to the secondary (inactive) buffer.

  4. Re-enable ping-pong — call naibrd_SUM1553_RT_SetPingPongEnable(cardIndex, module, rtchan, 1). The core resumes alternating buffers and will pick up the new data on the next transaction.

This protocol is documented in the SUMMIT 1553 core register description: the host disables ping-pong (PPEN bit), verifies the MSGTO bit confirms the transition, services the secondary buffer, and re-enables ping-pong.

Data Pattern

The transmit data follows a simple identifiable pattern: the upper byte of each word encodes the subaddress (upper 4 bits) and an increment counter (lower 4 bits), while the lower byte is a sequential offset (0x00 through 0x1F). Each press of 'U' advances the increment counter, making it easy to verify on the BC side that the RT’s transmit data has changed.

Initial Load vs. Runtime Update

The function accepts a bPingPongEnabled parameter. During the initial load before the RT starts executing, this is FALSE — the ping-pong disable/re-enable protocol is unnecessary because the core is not yet running. During runtime updates from the interactive loop, this is TRUE and the full safe protocol is used.

Important
  • Data update not appearing on the BC side — verify that the ping-pong re-enable step completed. If ping-pong remains disabled, the core is stuck on one buffer and may not pick up the updated secondary buffer.

  • Corrupted transmit data — if you write to the buffer without disabling ping-pong first, the core may be reading from the buffer you are modifying, resulting in a mix of old and new data in a single transaction.

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. If file doesn’t exist, configure and save from board menu.

Module not recognized as SUMMIT 1553

Selected module is not N7/N8/NA/NB/NC. IsSUMMIT1553() returned false.

Verify module type at the selected slot.

Reset not completing

Hardware not responding after reset

Verify module is powered and seated properly.

RT not responding to BC commands

Wrong RT address, subaddresses not legalized, bus not enabled

Verify RT address matches BC target, all needed subaddresses are legalized, and Bus A/B are enabled.

No data displayed when polling

No BC has sent messages to this RT since last poll

Verify a BC is running and targeting this RT’s address and subaddresses.

Stale data appearing repeatedly

BAC flag not cleared after reading

Ensure naibrd_SUM1553_RT_ClearBlockAccess() is called after each read.

Transmit data update not taking effect

Ping-pong not re-enabled after buffer write, or wrote to wrong buffer

Follow the full disable/wait/write/re-enable protocol. Use TRUE flag for secondary buffer.

Corrupted transmit data on the bus

Buffer written while core was reading (ping-pong not disabled first)

Always disable ping-pong before writing, wait for confirmation, then re-enable.

Processor control conflict

Processor control not disabled for ping-pong mode

Call naibrd_SUM1553_Proc_SetCtrl(cardIndex,module,rtchan,0) during RT configuration.

Full Source

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

Full Source — SUM1553_RT_PingPong.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.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_sum1553.h"

static const int8_t *CONFIG_FILE = (int8_t *)"default_SUM1553_RTPP.txt";

/* Function prototypes */
static bool_t Run_SUM1553_RT_PingPong(int32_t cardIndex, int32_t module, uint32_t modid);
static void Retrieve_SUM1553_BCRTMessages(int32_t cardIndex, int32_t module, int32_t rtchan);
static void Update_SUM1553_RTSAXmitData(int32_t cardIndex, int32_t module, int32_t rtchan, uint8_t increment, bool_t PingPongEnabled);

static const int32_t DEF_RT_CHANNEL       = 1;
static const uint8_t DEF_RT_ADDRESS       = 1;
static const uint8_t DEF_RT_SUBADDR       = 2;

static uint16_t datablock[32][32];

/**************************************************************************************************************/
/**
<summary>
The purpose of the SUM1553_RT_PingPong is to illustrate the methods to call in the naibrd library to configure
the 1553 channel as a Remote Terminal and receiving BC-RT messages and sending responses to RT-BC messages.

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

 Note, the SUM1553_RT_PingPong can run in conjunction with the SUM1553_BC_Scheduler applications to illustrate
 BC and RT operations together with the NAI 1553 module.
</summary>
*/
/**************************************************************************************************************/
#if defined (__VXWORKS__)
int32_t SUM1553_RT_PingPong(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_SUM1553_RT_PingPong(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;
}

/**************************************************************************************************************/
/**
<summary>
Run_SUM1553_RT_PingPong queries the user for the module and channel to configure as the Remote Terminal (RT).
After getting the module/channel selection, methods in the naibrd library are invoked to setup this channel
as a RT configured to run with Buffer Ping Pong.

Once the RT is configured and running, the user can:
1) Type the Enter key to view the BC-RT messages that are received from all subaddresses.
2) Type 'U' to change the data in the RT-BC message.
3) Type 'Q' to quit stop the RT execution and exit the routine.
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_SUM1553_RT_PingPong(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit;
   bool_t bContinue = TRUE;
   bool_t resetting = TRUE;
   int32_t rtchan = 1;
   uint8_t rtaddr = 1;
   uint8_t increment = 0;
   int32_t i, j;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   bQuit = Get1553RTCfg(modid, DEF_RT_CHANNEL, DEF_RT_ADDRESS, &rtchan, &rtaddr);
   if (!bQuit)
   {
      /* Reset RT channel */
      check_status(naibrd_SUM1553_Reset(cardIndex,module,rtchan));

      /* Wait for channels to reset */
      while(check_status(naibrd_SUM1553_IsResetting(cardIndex,module,rtchan,&resetting)) == NAI_SUCCESS && resetting);

      /* Configure RT */
      check_status(naibrd_SUM1553_SetMode(cardIndex,module,rtchan,NAI_SUM1553_OPSTATUS_RT_MODE)); /* Set to RT mode */
      check_status(naibrd_SUM1553_RT_SetBusEnable(cardIndex,module,rtchan,1,1)); /* Enable bus A and bus B  */
      check_status(naibrd_SUM1553_RT_SetAddress(cardIndex,module,rtchan,rtaddr)); /* Set RT address */
      check_status(naibrd_SUM1553_RT_ConfigureForPingPong(cardIndex,module,rtchan)); /* Set up descriptor table with ping pong buffers */
      check_status(naibrd_SUM1553_RT_SetPingPongEnable(cardIndex,module,rtchan,1)); /* Enable ping pong */
      check_status(naibrd_SUM1553_RT_Legalize(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_RX,0xFFFFFFFF,1)); /* Legalize the subaddresses we want for rx */
      check_status(naibrd_SUM1553_RT_Legalize(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_TX,0xFFFFFFFF,1)); /* Legalize the subaddresses we want for tx*/

      /* Disable processor control */
      check_status(naibrd_SUM1553_Proc_SetCtrl(cardIndex,module,rtchan,0));

      /* Load the subaddress transmit data */
      Update_SUM1553_RTSAXmitData(cardIndex,module,rtchan,0, FALSE);

      for (i = 0; i < 32; i++)
         for (j = 0; j < 32; j++)
             datablock[i][j] = 0;

      /* Run the RT */
      check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,rtchan,1));
   }
   if (bQuit)
      bContinue = FALSE;

   while (bContinue)
   {
      printf("\nType Enter key BC-RT to view BC-RT message or U to update the subaddress transmit data or %c to quit: ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (toupper(inputBuffer[0]) == 'U')
         {
            increment++;
            Update_SUM1553_RTSAXmitData(cardIndex,module,rtchan,increment, TRUE);
         }
         else
         {
            Retrieve_SUM1553_BCRTMessages(cardIndex, module, rtchan);
         }
      }
      else
         bContinue = FALSE;
   }

   /* Disable the RT */
   check_status(naibrd_SUM1553_EnableExecution(cardIndex,module,rtchan,0));

   return bQuit;
}

/**************************************************************************************************************/
/**
<summary>
Retrieve_SUM1553_BCRTMessages reads the Control Word for the BC-RT (i.e. Receive) Subaddress. If the Block
Accessed (BAC) bit is set, indicating a new message, the Data block associated with the BC-RT message is
read and displayed.
</summary>
*/
/**************************************************************************************************************/
static void Retrieve_SUM1553_BCRTMessages(int32_t cardIndex, int32_t module, int32_t rtchan)
{
   uint16_t ctrl;
   uint16_t rxdatablock[32], rxwordcnt;
   uint16_t timestamp;
   uint8_t sa;
   int32_t i;

   for (sa = 0; sa < 32; sa++)
   {
      check_status(naibrd_SUM1553_RT_GetControlWord(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_RX,sa,&ctrl));
      if (ctrl & NAI_SUM1553_RT_CTL_BAC) /* new data */
      {
         check_status(naibrd_SUM1553_RT_ReadRxDataBlock(cardIndex,module,rtchan,TRUE,sa,&rxwordcnt,&timestamp,rxdatablock));
         check_status(naibrd_SUM1553_RT_ClearBlockAccess(cardIndex,module,rtchan,NAI_SUM1553_SAMCTYPE_SA|NAI_SUM1553_SAMCTYPE_RX,sa));
         if (rxwordcnt == 0)
            rxwordcnt = 32;

         printf("SA %d ", sa);
         printf("TimeTag: %04X ", timestamp);
         printf("Data: ");

         for (i = 0; i < rxwordcnt; i++)
         {
            if (i != 0)
               printf(",");
            printf ("%04X", rxdatablock[i]);
         }
         printf("\n");
      }
   }
}

/**************************************************************************************************************/
/**
<summary>
Update_SUM1553_RTSAXmitData changes the data that is sent in response to the RT-BC messages sent to the
"DEF_RT_SUBADDR" Subaddress.

Note: To properly implement buffer servicing while the core is using the ping pong buffering scheme, the
host or subsystem needs to do the following:
   - Disable the ping pong mode by setting PPEN (Ping Pong Enable) (Core Register 0, bit 2) to 0.
   - Verify that ping pong mode has been disabled by querying bit MSGTO (Message Timeout) (Core Register 0, bit 9)
     is set to 0.
   - Service the secondary buffer
   - Re-enable ping pong mode (setting PPEN) to 1.
   - Verify that ping pong mode has been enabled by querying MSGTO to be set to 1.
</summary>
*/
/**************************************************************************************************************/
static void Update_SUM1553_RTSAXmitData(int32_t cardIndex, int32_t module, int32_t rtchan, uint8_t increment, bool_t bPingPongEnabled)
{
   uint16_t sa = DEF_RT_SUBADDR;
   uint16_t txdatablock[32];
   uint8_t msb, lsb;
   int32_t i;
   bool_t enabled;

   msb = (uint8_t)(sa << 4) + (increment & 0x0F); /* upper byte (subaddress=upper 4 bits | increment=lower 4 bits)) */
   lsb = 0;
   for (i = 0; i < 32; i++)
   {
      txdatablock[i] = (msb << 8) | (uint8_t)(lsb + i);     /* incremental data */
   }
   /* Update the data */
   if (bPingPongEnabled)
   {
      naibrd_SUM1553_RT_SetPingPongEnable(cardIndex, module, rtchan, 0);
      /* Wait for ping pong to be disabled */
      while(check_status(naibrd_SUM1553_RT_GetPingPongEnabled(cardIndex,module,rtchan,&enabled)) == NAI_SUCCESS && (enabled != 0));
   }
   check_status(naibrd_SUM1553_RT_LoadTxDataBlock(cardIndex,module,rtchan,TRUE, sa,txdatablock));
   if (bPingPongEnabled)
   {
      naibrd_SUM1553_RT_SetPingPongEnable(cardIndex, module, rtchan, 1);
   }
}

Help Bot

X