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 BC SendMessage WithRetries

M1553 BC SendMessageWithRetries Sample Application (SSK 1.x)

Overview

The M1553 BC SendMessageWithRetries sample application demonstrates how to configure a MIL-STD-1553 Bus Controller (BC) to send messages with automatic hardware-level retry on failure. The retry mechanism is implemented in the 1553 hardware module — the application configures the retry policy and per-message retry enable flag, and the module automatically re-transmits failed messages on the same or alternate bus without software intervention.

This sample supports the following 1553 module types:

  • FT0 through FTF (4-channel MIL-STD-1553)

  • FTJ / FTK (2-channel MIL-STD-1760)

  • Combination modules CM1, CM5, and CM8

The application detects the installed module variant at runtime and adjusts the available channel count accordingly. IsFTx1553() identifies FT-series modules (4 channels) and IsFTx1760() identifies FTJ/FTK modules (2 channels).

For detailed 1553 protocol specifications, message formats, and hardware register descriptions, see the FTA-FTF Manual. For FTJ/FTK (MIL-STD-1760) specifics, see the FTJ-FTK Manual.

Prerequisites

Before running this sample, make sure you have:

  • An NAI board with a 1553 module installed (FT0-FTF, FTJ/FTK, or a combination module with 1553 functionality).

  • 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_BC_SendMessage_WithRetries executable from your build output directory. On startup the application looks for a configuration file (default_1553BC_SendMessage_WithRetries.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 selecting a channel, message direction, bus, and retry settings, then begins sending messages.

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_1553BC_SendMessage_WithRetries.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. Query for a channel number within the selected module.

#if defined (__VXWORKS__)
int32_t M1553_BC_SendMessage_WithRetries(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_BC_SendMessage_WithRetries(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

The application entry point is main() (or M1553_BC_SendMessage_WithRetries() on VxWorks). After the board connection is established and a module is selected, control passes to Run_M1553_BC_SendMessage_WithRetries(), which detects the module type and queries the user for a channel number.

Module Detection and Channel Selection

Run_M1553_BC_SendMessage_WithRetries() checks the module ID to determine the module family and the number of available channels:

  • IsFTx1553(modid) — FT-series 1553 modules with 4 channels.

  • IsFTx1760(modid) — FTJ/FTK 1760 modules with 2 channels.

If neither check matches, the function prints an error and returns.

static bool_t Run_M1553_BC_SendMessage_WithRetries(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = FALSE;
   int32_t channel;
   int32_t MaxChannel = 4;

   if (IsFTx1553(modid))
   {
      MaxChannel = 4;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
      if (!bQuit)
      {
         bQuit = RunSendMessage(cardIndex, module, channel, modid);
      }
   }
   else if (IsFTx1760(modid))
   {
      MaxChannel = 2;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
      if (!bQuit)
      {
         bQuit = RunSendMessage(cardIndex, module, channel, modid);
      }
   }
   else
      printf("\nThis module does not support 1553 functionality.\n");

   return bQuit;
}

User Input Flow

Once a channel is selected, RunSendMessage() collects the remaining configuration from the user through a series of utility function calls. Unlike menu-driven samples, this application uses a linear send-check-repeat flow — each parameter is requested once, then the application enters a loop that sends messages until the user quits.

The utility functions called in sequence are:

  1. Get1553LogicalDevNum() — prompts for the logical device number. The default is 1. This number maps the physical channel to a software handle used by all subsequent naibrd_1553_*() calls.

  2. GetMsgDirection() — asks "BC to RT?" The default is yes (BC-to-RT). If the user selects no, the application creates an RT-to-BC message instead, which reverses the data flow direction.

  3. GetBus() — asks "Bus A or B?" The default is Bus A. The selected bus is stored as a control word flag: NAI_1553_BC_CTRL_BUS_A (0x0080) for Bus A, or NAI_1553_BC_CTRL_BUS_B (0x0000) for Bus B. This flag is OR’d into the message control word when the message is created.

  4. Get1553BCSoftwareOverride() — asks whether to override the external BC_DISABLE and M1760 input pins in software. When enabled, the application writes to an auxiliary register to force BC mode regardless of the external pin state. This is useful in bench setups where the hardware pins are not driven.

BC Frame Hierarchy

A Bus Controller does not simply "send a message" — it operates as a real-time scheduler that walks a structured hierarchy of objects to determine what to transmit, when, and in what order. Understanding this hierarchy is essential for building anything beyond the simplest demos. Messages are organized into frames, frames contain opcodes, and opcodes reference messages and data blocks. The hardware executes this hierarchy autonomously once started, freeing the host processor from per-message timing concerns.

The components are described below in bottom-up order, starting with the lowest-level building block and working up to the top-level execution unit.

Data Block

A data block is a memory buffer allocated on the 1553 module that holds the transmit or receive payload for a message. For BC-to-RT transfers, the application writes outbound data into a data block before the message executes. For RT-to-BC transfers, the module fills the data block with the data received from the RT.

Data blocks are created and populated with:

naibrd_1553_BcDataBlockCreate()
naibrd_1553_BcDataBlockWrite()

Every message references exactly one data block. Multiple messages may share a data block if they operate on the same data, but in most designs each message has its own.

Message

A message represents a single 1553 bus transaction — a command word sent to a Remote Terminal, optionally accompanied by data words, with the expectation of a status word response. The message definition includes the RT address, subaddress, word count, data direction, and per-message options such as which bus to use and whether hardware retries are enabled for this particular transaction.

Messages are created with direction-specific API calls:

naibrd_1553_BcMessageCreateBcToRt()
naibrd_1553_BcMessageCreateRtToBc()

Each message references a data block and carries a control word that encodes bus selection, retry enable, and other per-message flags.

Opcode (Command)

An opcode is an instruction to the BC scheduler. Rather than sending messages directly, the application builds a sequence of opcodes that the hardware walks at runtime. The two key opcode types are:

  • NAI_1553_OPCODE_EXECUTE_MESSAGE — tells the scheduler to transmit a specific message.

  • NAI_1553_OPCODE_CALL_SUBROUTINE — tells the scheduler to jump into a minor frame and execute its opcodes before returning.

Every opcode includes a condition field that controls whether it executes. NAI_1553_OPCODE_COND_ALWAYS means the opcode runs unconditionally on every pass. Other condition codes allow execution based on the result of a previous message (status word bits, no-response, etc.), enabling conditional branching within the schedule.

Opcodes are created with:

naibrd_1553_BcCommandCreate()

Minor Frame

A minor frame is a container that groups related opcodes into a logical unit. Think of it as a subroutine in the BC schedule — it holds a sequence of EXECUTE_MESSAGE and other opcodes that should run together. Minor frames are called from the major frame via CALL_SUBROUTINE opcodes.

Minor frames are created with:

naibrd_1553_BcFrameCreate()  /* with type NAI_1553_BC_FRAME_MINOR */

A typical system has multiple minor frames, each responsible for a group of messages with similar timing requirements or functional purpose.

Major Frame

The major frame is the top-level execution unit in the BC schedule. It defines the overall repetition rate — the time between successive passes through the entire schedule. In this sample, the major frame period is 1000 ms. The major frame contains opcodes (typically CALL_SUBROUTINE opcodes) that invoke minor frames in a defined order.

Major frames are created with:

naibrd_1553_BcFrameCreate()  /* with type NAI_1553_BC_FRAME_MAJOR */

The major frame runs in a loop. When the scheduler reaches the end of the major frame, it waits for the remainder of the frame period (if any time remains), then starts again from the top.

Execution Flow

Once the frame hierarchy is fully constructed, the application starts the BC scheduler:

naibrd_1553_BcStart()

The hardware then walks the hierarchy autonomously: Major Frame → Minor Frame → Opcodes → Messages → Data Blocks. The host processor is free to monitor results, update data blocks, or modify the schedule while the BC runs.

Note
This sample uses the simplest possible frame structure — one major frame calling one minor frame containing one message. Production systems typically have multiple minor frames with many messages organized by timing requirements and bus utilization. Consult your module’s manual for advanced frame scheduling, conditional opcodes, and multi-message frames.

Device Initialization

After the user has provided all configuration inputs, RunSendMessage() initializes the 1553 hardware. This sequence opens the device, optionally overrides external control pins, resets the module, and places it in Bus Controller mode.

Open Device

The first step is to open the 1553 interface on the selected channel and assign it a logical device number:

status = naibrd_1553_Open(cardIndex, module, channel, devnum);
if(status != 0)
{
   printf("Error: naibrd_1553_Open Ch %d, status = %d", channel, status);
   return TRUE;
}

naibrd_1553_Open() binds the physical channel (identified by card index, module slot, and channel number) to a logical device number (devnum). All subsequent naibrd_1553_*() calls use this logical device number to address the channel. If the call fails, no further initialization is possible — the function prints the error status and returns immediately.

Software Override of External Pins

The module has two external hardware pins that affect BC operation:

  • BC_DISABLE — when asserted externally, this pin prevents the channel from operating as a Bus Controller.

  • M1760 (CHx-STANDARD) — on FTJ/FTK modules, this pin controls the MIL-STD-1760 RT powerup mode.

If these pins are not driven by external hardware (which is typical in Ethernet-connected bench setups and most test environments), BC initialization will fail unless the application overrides them in software:

if (bSoftware)
{
   /* Override external BC_DISABLE and M1760 */
   naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000);
}
else
{
   /* Do not override external BC_DISABLE and M1760 Inputs */
   naibrd_1553_WriteAuxReg(devnum, 0x2, 0x0000);
}

Writing 0xA000 to auxiliary register 0x2 overrides both pins in software, forcing BC operation to be allowed regardless of the external pin state. Writing 0x0000 leaves the hardware pins in control — use this only when external circuitry actively drives the pins to the correct levels.

Most users connecting over Ethernet or running on a test bench should enable the software override. If you are unsure, enable it. See the FTA-FTF Manual for the full auxiliary register map and pin descriptions.

Hardware Reset

Before initializing the device, the application performs a hardware reset by writing to auxiliary register 0x1:

naibrd_1553_WriteAuxReg(devnum, 0x1, 0x1);
#if defined (__VXWORKS__)
            taskDelay(1);
#elif defined (LINUX)
            usleep(100000);
#else
            Sleep(100);
#endif
naibrd_1553_WriteAuxReg(devnum, 0x1, 0x0);

The reset sequence writes 0x1 to assert the reset, waits for the module to complete its internal reset cycle, then writes 0x0 to de-assert the reset. The delay between assert and de-assert is platform-specific:

  • VxWorks — taskDelay(1) yields for one OS tick (typically 1-16 ms depending on the tick rate).

  • Linux — usleep(100000) sleeps for 100 ms.

  • Windows — Sleep(100) sleeps for 100 ms.

The delay ensures the module has enough time to complete its internal reset before the application proceeds. Skipping or shortening this delay may cause the subsequent initialization call to fail.

Initialize Device

With the device open, pins overridden, and the hardware reset complete, the application initializes the 1553 core in Bus Controller mode:

status = naibrd_1553_Initialize(devnum, NAI_1553_ACCESS_CARD, NAI_1553_MODE_BC, 0, 0, 0);
if(status != 0)
{
   printf("Error: naibrd_1553_Initialize Ch %d, status = %d", channel, status);
   return TRUE;
}

The parameters are:

  • devnum — the logical device number assigned during naibrd_1553_Open().

  • NAI_1553_ACCESS_CARD — access mode. Card-level access means the driver communicates with the module through the board’s standard register interface.

  • NAI_1553_MODE_BC — operating mode. This places the channel in Bus Controller mode.

  • 0, 0, 0 — memory base address, register base address, and options. Passing zero for all three tells the driver to auto-detect these values from the hardware configuration. Manual override is only needed in specialized multi-card or shared-memory topologies.

If initialization fails, the function prints the status code and returns. The most common cause of initialization failure is that the BC_DISABLE pin is asserted and the software override was not enabled.

Important

Common errors during device initialization:

  • Device open failure — naibrd_1553_Open() returns a non-zero status. Verify that the card index, module slot, and channel number are correct and that the selected module is a 1553 type (FT-series, FTJ/FTK, or a combination module with 1553 functionality).

  • Initialization failure — naibrd_1553_Initialize() returns a non-zero status. The device may already be in use by another process, or the BC_DISABLE pin is asserted externally. Enable the software override by calling naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000) before initialization.

  • Reset not completing — the module does not respond after the reset sequence. Verify that the hardware is physically present and functioning. Check board power and the module seating in its slot.

  • BC mode not available — the channel cannot enter Bus Controller mode because the external BC_DISABLE pin is asserted and the software override is not enabled. Set naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000) to override the pin in software.

Retry Policy Configuration

This is the headline feature of the sample — configuring automatic hardware-level retries for failed 1553 messages. The retry system has two parts: a global retry policy that defines how retries behave, and a per-message enable flag that controls which messages actually use retries.

Setting the Retry Policy

After device initialization, the application configures the global retry policy:

status = naibrd_1553_BcSetMessageRetryPolicy(devnum,
   NAI_1553_MESSAGE_RETRY_TWICE,   /* 2 retries max */
   NAI_1553_MESSAGE_RETRY_SAME,    /* First retry: same bus */
   NAI_1553_MESSAGE_RETRY_ALT,     /* Second retry: alternate bus */
   0);                              /* Reserved */

The parameters are:

  • Retry count — how many times to retry a failed message. Valid values are NAI_1553_MESSAGE_RETRY_NONE (0, no retries), NAI_1553_MESSAGE_RETRY_ONCE (1, one retry), or NAI_1553_MESSAGE_RETRY_TWICE (2, two retries).

  • First retry bus — which bus to use for the first retry attempt. NAI_1553_MESSAGE_RETRY_SAME (0) retries on the same bus as the original attempt. NAI_1553_MESSAGE_RETRY_ALT (1) retries on the alternate bus.

  • Second retry bus — which bus to use for the second retry attempt (only meaningful when retry count is TWICE). Same options as above: NAI_1553_MESSAGE_RETRY_SAME (0) or NAI_1553_MESSAGE_RETRY_ALT (1).

  • Reserved — pass 0.

The strategy chosen by this sample — first retry on the same bus, second retry on the alternate bus — is a common dual-redundant configuration. The first retry on the same bus recovers from transient errors (noise, timing glitches). If that fails, the second retry on the alternate bus recovers from a single-bus failure (broken cable, failed coupler). This gives the system two chances to deliver the message across two independent failure modes.

Per-Message Retry Enable

The retry policy alone does not enable retries. Each message must also have the NAI_1553_BC_CTRL_RETRY_ENABLED flag (0x0100) set in its control/options word when created. The sample does this by OR-ing the flag into the bus selection word:

usBus | NAI_1553_BC_CTRL_RETRY_ENABLED

This is passed as the last parameter to the message creation call (naibrd_1553_BcMessageCreateBcToRt() or naibrd_1553_BcMessageCreateRtToBc()). The two-part design — global policy plus per-message enable — allows selective retry behavior. Critical messages can have retries enabled while non-critical or time-sensitive messages skip retries to avoid adding latency to the schedule.

How Retries Execute in Hardware

Once the retry policy is configured and a message has NAI_1553_BC_CTRL_RETRY_ENABLED set, the 1553 module handles retries entirely in hardware. When a message fails (no response, status error, etc.), the module automatically re-transmits according to the policy without any software intervention. The application does not see individual retry attempts — it only sees the final result after all retries have been exhausted or one succeeds.

To determine how many retries were actually performed, read the block status word for the message. Bits 5-6 (NAI_1553_BC_BLOCK_STATUS_WORD_RETRIES_COUNT, mask 0x0060) indicate the retry count: 0 means the message succeeded on the first attempt, 1 means one retry was needed, and 2 means two retries were performed.

When to Use Retries

Retries are most valuable in the following scenarios:

  • Noisy bus environments — electrical noise or EMI can cause transient failures. Same-bus retries recover from these without involving the alternate bus.

  • Dual-redundant bus configurations — systems with Bus A and Bus B benefit from alternating retries. If one bus has a persistent fault (cable damage, coupler failure), the alternate bus provides a fallback path.

  • Critical data transfers — messages that must be delivered reliably (weapon release commands, flight-critical telemetry) should have retries enabled to maximize delivery probability.

For single-bus systems, configure both retries to use the same bus (NAI_1553_MESSAGE_RETRY_SAME) to recover from transient errors. For dual-bus systems, use alternating retries as shown in this sample for maximum fault tolerance.

For detailed register descriptions, retry timing, and advanced retry configurations, see the FTA-FTF Manual.

Important

Common errors related to retry configuration:

  • Retries not occurring — the retry policy is configured but messages are not being retried on failure. The most likely cause is that NAI_1553_BC_CTRL_RETRY_ENABLED (0x0100) was not included in the message options word. The policy defines how retries behave; the per-message flag enables whether retries occur for that message.

  • Retry policy rejected — naibrd_1553_BcSetMessageRetryPolicy() returns a non-zero status. Verify that the retry count is 0, 1, or 2, and that the bus parameters are NAI_1553_MESSAGE_RETRY_SAME (0) or NAI_1553_MESSAGE_RETRY_ALT (1). Any other values are invalid.

  • All retries exhausted on every message — every message is failing through all retry attempts. This indicates a persistent bus or RT problem, not a transient error. Check physical bus connections, bus termination resistors, RT power, and RT address configuration.

Message Creation and Execution

With the device initialized, the retry policy configured, and the channel in Bus Controller mode, the application creates the message objects that define what to send on the bus, assembles them into the frame hierarchy described in [_bc_frame_hierarchy], loads data, and executes the schedule.

Create Data Block

The first step is to allocate a data block on the 1553 module. The data block holds the transmit payload for BC-to-RT messages or receives the incoming data for RT-to-BC messages:

status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, WORDCOUNT, NULL, 0);

The parameters are:

  • devnum — the logical device number assigned during naibrd_1553_Open().

  • DBLK1 (1) — a unique numeric ID for this data block. Messages reference data blocks by this ID.

  • WORDCOUNT (11) — the number of 16-bit words the block can hold.

  • NULL — pointer to initial data. Passing NULL tells the device to allocate the buffer internally without pre-loading data. The application writes data into the block later with naibrd_1553_BcDataBlockWrite().

  • 0 — reserved, pass 0.

Every message must reference exactly one data block. The block must be created before the message that references it.

Create Message

The application creates a direction-specific message object. For BC-to-RT (the default direction in this sample):

status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1,
   RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0,
   usBus | NAI_1553_BC_CTRL_RETRY_ENABLED);

The parameters are:

  • devnum — the logical device number.

  • MSG1 (1) — a unique numeric ID for this message. Opcodes reference messages by this ID.

  • DBLK1 (1) — the data block ID created in the previous step.

  • RT_ADDRESS (1) — the Remote Terminal address, range 0-30. This must match the RT’s configured address on the bus.

  • RT_SUBADDRESS (2) — the subaddress within the RT, range 1-30. Subaddresses 0 and 31 are reserved for mode codes per MIL-STD-1553.

  • WORDCOUNT (11) — the number of data words to transfer, range 1-32. A value of 0 is treated as 32 words per the 1553 standard.

  • 0 — gap time in microseconds between this message and the next. Zero uses the module’s default inter-message gap.

  • usBus | NAI_1553_BC_CTRL_RETRY_ENABLED — the options word. This combines the bus selection flag (NAI_1553_BC_CTRL_BUS_A or NAI_1553_BC_CTRL_BUS_B) with the per-message retry enable flag (NAI_1553_BC_CTRL_RETRY_ENABLED, 0x0100). As described in [_retry_policy_configuration], the retry enable flag must be set on each message that should use the global retry policy.

If the user selected RT-to-BC direction instead, the application calls naibrd_1553_BcMessageCreateRtToBc() with the same parameters. The only difference is the data flow direction — for RT-to-BC, the RT transmits data and the BC receives it into the data block.

Build Frame Hierarchy

With the data block and message created, the application assembles the frame hierarchy described in [_bc_frame_hierarchy]. This consists of two opcodes, one minor frame, and one major frame:

/* Create Execute Message Command */
status = naibrd_1553_BcCommandCreate(devnum, OP1,
   NAI_1553_OPCODE_EXECUTE_MESSAGE,
   NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);

/* Create Call Subroutine Command */
status = naibrd_1553_BcCommandCreate(devnum, OP2,
   NAI_1553_OPCODE_CALL_SUBROUTINE,
   NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);

/* Create Minor Frame containing OP1 */
aOpCodes[0] = OP1;
status = naibrd_1553_BcFrameCreate(devnum, MNR1,
   NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);

/* Create Major Frame containing OP2 (which calls MNR1) */
aOpCodes[0] = OP2;
status = naibrd_1553_BcFrameCreate(devnum, MJR,
   NAI_1553_BC_FRAME_MAJOR, aOpCodes, 1, 1000, 0);

The execution chain works as follows:

  1. OP1 (EXECUTE_MESSAGE, always, MSG1) — when executed, this opcode transmits the message MSG1 on the bus.

  2. OP2 (CALL_SUBROUTINE, always, MNR1) — when executed, this opcode jumps into minor frame MNR1 and runs all of its opcodes.

  3. MNR1 (minor frame) — contains OP1. When called, it executes the message.

  4. MJR (major frame, 1000 ms period) — contains OP2. The scheduler starts here, calls the minor frame via OP2, which executes MSG1 via OP1.

The major frame period of 1000 ms means the entire schedule repeats once per second when running continuously. In this sample, the BC is started for a single iteration, so the period acts as a timeout rather than a repetition rate.

Write Data and Execute

The application enters a loop where it loads data, runs the schedule, and reads back results:

/* Load BC data block with incremental data */
for (i = 0; i < WORDCOUNT; i++)
{
   aData[i] = increment++;
}
status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT, 0);

/* Start BC for one iteration */
status = naibrd_1553_BcStart(devnum, MJR, 1);

/* Allow time for execution including retries */
nai_msDelay(200);

/* Stop BC */
status = naibrd_1553_BcStop(devnum);

naibrd_1553_BcDataBlockWrite() loads the data block with incrementing test values. Each iteration through the loop produces a new data pattern, making it easy to verify that the RT is receiving fresh data on each cycle.

naibrd_1553_BcStart(devnum, MJR, 1) starts the BC scheduler at the major frame MJR for exactly 1 iteration. The third parameter (1) means the major frame executes once and then the scheduler stops automatically.

The 200 ms delay (nai_msDelay(200)) gives the hardware time to transmit the message and complete any retry attempts. With two retries configured and typical 1553 bus timing, 200 ms provides sufficient margin. After the delay, naibrd_1553_BcStop() ensures the scheduler has halted before reading results.

Retrieve and Interpret Results

After execution completes, the application reads back the decoded message structure:

status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG1, &DecodedMsgStruct, 1);

The return value indicates the result:

  • status < 0 — an error occurred retrieving the message. The error code identifies the specific failure.

  • status == 0 — no data available. The message may not have executed yet.

  • status > 0 — valid decoded data is available in DecodedMsgStruct.

When the call succeeds, the application prints the key fields from the decoded message structure:

  • wBcControlWord — the BC control word echoed back, confirming bus selection and retry settings.

  • wCommandWord1 — the 1553 command word that was sent on the bus, encoding the RT address, subaddress, and word count.

  • wBlockStatus — the block status word. This contains the overall result of the transaction including error flags and retry count.

  • wTimeTag — a hardware timestamp indicating when the message completed.

  • wDataWordCount — the number of data words in the transaction.

  • wStatus1 — the RT status word received from the Remote Terminal. This reflects the RT’s view of the transaction including any error flags set by the RT.

  • waData[] — for RT-to-BC messages, this array contains the data words received from the RT. For BC-to-RT messages, the data was sent outbound and is not echoed back here.

For RT-to-BC messages, the application prints the received data array so the user can verify the RT responded with the expected payload.

Interpreting Retry Count

Bits 5-6 of the wBlockStatus field (NAI_1553_BC_BLOCK_STATUS_WORD_RETRIES_COUNT, mask 0x0060) indicate how many retry attempts the hardware performed:

  • 00 (0x0000) — no retries. The message succeeded on the first attempt.

  • 01 (0x0020) — one retry was performed. The original attempt failed, and the first retry (on the same bus, per the configured policy) succeeded.

  • 10 (0x0040) — two retries were performed. Both the original attempt and the first retry failed; the second retry (on the alternate bus, per the configured policy) was attempted.

A non-zero retry count with a successful final result means the message was ultimately delivered, but additional attempts were needed. This is normal in noisy environments. A non-zero retry count with a failure result means all attempts were exhausted and the message could not be delivered — this indicates a persistent problem requiring investigation.

Important

Common errors during message creation and execution:

  • No RT response — the Remote Terminal is not responding on the bus. Verify that the RT is powered on, configured to the correct address (RT_ADDRESS = 1 in this sample), and physically connected to the same bus. Check the block status word for no-response indicators.

  • Message error in RT status — the RT received the message but reported an error in its status word. Verify that the RT address, subaddress, and word count match the RT’s configuration. A subaddress mismatch or unsupported word count will cause the RT to set error bits.

  • Data block write failure — naibrd_1553_BcDataBlockWrite() returns a non-zero status. The data block was not created or the block ID does not match. Ensure naibrd_1553_BcDataBlockCreate() was called successfully with the same DBLK1 ID before writing.

  • BcStart error — naibrd_1553_BcStart() returns a non-zero status. The frame hierarchy is incomplete. All opcodes, frames, and messages referenced in the hierarchy must exist before the scheduler can start. Verify that all BcCommandCreate(), BcFrameCreate(), and message creation calls completed successfully.

  • Block status retries exhausted — the block status word shows two retries were performed and the message still failed. This indicates a persistent bus issue rather than a transient error. Check physical bus connections, bus termination resistors, RT power, and RT address configuration. See the FTA-FTF Manual for bus troubleshooting procedures.

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.

Diagnosing 1553 BC Message Failures

When a 1553 BC message fails, check two fields in the decoded message structure:

  1. Block status word (wBlockStatus) — tells you whether the message was attempted, whether retries occurred (bits 5-6), and the nature of the hardware-level failure (no response, format error, etc.). This is the BC’s own record of what happened on the bus.

  2. RT status word (wStatus1) — if the RT responded, this word provides the RT’s perspective: message error (bit 9), busy (bit 16), service request (bit 11), subsystem fault (bit 17), or terminal flag (bit 20). If the RT did not respond, this field will not be populated.

Together these two fields narrow down most 1553 communication issues. If neither provides a clear answer, verify the physical bus connections, termination (both ends of each bus must be terminated), and RT address assignment. Consult the FTA-FTF Manual for complete block status word and RT status word bit definitions.

Error / Symptom Possible Causes Suggested Resolution

No board found or connection timeout

Board not powered, incorrect or missing configuration file, network issue

Verify hardware is powered and connected. If the configuration file exists, check interface and address. If not, configure and save from board menu.

Module not recognized as 1553

Selected module is not an FT-series or CM with 1553. IsFTx1553() and IsFTx1760() both returned false.

Verify the module type installed at the selected slot. Use the board menu to check module IDs.

Device open failure

Wrong card/module/channel combination, or device already opened by another application

Verify card index, module number, and channel number. Close any other application using this channel.

Initialization failure

Device in use, or BC_DISABLE pin preventing BC mode

Enable software override (WriteAuxReg(0x2, 0xA000)) to take control of BC_DISABLE and M1760 pins.

Reset not completing

Hardware not responding after reset assert/de-assert sequence

Verify module is powered and seated. Try increasing the post-reset delay. Consult module manual for reset timing.

Retry policy not taking effect

NAI_1553_BC_CTRL_RETRY_ENABLED not set in message options. Policy defines how to retry; per-message flag enables whether to retry.

OR the retry flag into the message options: `usBus

NAI_1553_BC_CTRL_RETRY_ENABLED`

All retries exhausted

Persistent bus or RT problem — not a transient error

Check physical bus connections, termination resistors, RT power, and RT address configuration.

No RT response

RT not powered, wrong RT address, bus not connected, or RT not configured for the specified subaddress

Check block status word for "no response." Verify RT is operational and address matches.

Message error in RT status word

RT detected error in the BC command (wrong parameters or format)

Verify RT address, subaddress, and word count match the RT’s configuration.

Wrong data received (RT-to-BC)

Stale data in data block, wrong data block ID, or RT transmitting unexpected data

Verify data block ID matches between message creation and data block write. Check RT’s transmit subaddress data.

Frame hierarchy error (BcStart fails)

Not all referenced opcodes, frames, or messages were created before starting execution

Create all components (data blocks, messages, opcodes, minor frames, major frame) before calling BcStart().

BC_DISABLE pin preventing BC mode

External hardware signal blocking BC operation; software override not enabled

Set naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000) to override. See FTA-FTF Manual Miscellaneous Bits register.

Platform-specific reset timing

Post-reset delay too short for the hardware to complete initialization

Full Source

The complete source for this sample is provided below for reference. The sections above explain each part in detail. This sample depends on two shared utility files that provide 1553 device detection and BC user-prompt functions.

Full Source — M1553_BC_SendMessage_WithRetries.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#if defined (__VXWORKS__)
 #include "taskLib.h"
#endif
/* 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"
#include "BC/nai_1553_bc_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_1553BC_SendMessage_WithRetries.txt";

/* Function prototypes */
static bool_t Run_M1553_BC_SendMessage_WithRetries(int32_t cardIndex, int32_t module, uint32_t modid);
static bool_t RunSendMessage(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid);

/* define message constants */
#define MSG1         1

/* define opcodes */
#define OP1          1
#define OP2          2

/* define frame constants */
#define MNR1         1
#define MJR          2

/* define data block numbers */
#define DBLK1        1

#define DEF_M1553_CARD_INDEX                 0
#define DEF_M1553_MODULE                     1
#define DEF_M1553_CHANNEL                    1
#define DEF_M1553_DEVNUM                     1

#define RT_ADDRESS                           1
#define RT_SUBADDRESS                        2

#define WORDCOUNT                            11

/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_BC_SendMessage_WithRetries is to illustrate the methods to call in the naibrd library\
to configure the 1553 channel as a Bus Controller and to send a 1553 message out. This code also sends a retry
message if the initial message fails to send or returns an error. The retry policy is set by the user.

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_BC_SendMessage_WithRetries(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_BC_SendMessage_WithRetries(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_M1553_BC_SendMessage_WithRetries initializes the 1553 device as a bus controller (BC) and sends out a message.
This routine demonstrates the following API functions in the 1553 naibrd library:
naibrd_1553_Open
naibrd_1553_Initialize
naibrd_1553_BcDataBlockCreate
naibrd_1553_BcMessageCreateBcToRt
naibrd_1553_BcCommandCreate
naibrd_1553_BcFrameCreate
naibrd_1553_BcDataBlockWrite
naibrd_1553_BcStart
naibrd_1553_BcStop
naibrd_1553_Free
</summary>
*/
/**************************************************************************************************************/
static bool_t Run_M1553_BC_SendMessage_WithRetries(int32_t cardIndex, int32_t module, uint32_t modid)
{
   bool_t bQuit = FALSE;
   int32_t channel;
   int32_t MaxChannel = 4;

   if (IsFTx1553(modid))
   {
      MaxChannel = 4;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
      if (!bQuit)
      {
         bQuit = RunSendMessage(cardIndex, module, channel, modid);
      }
   }
   else if (IsFTx1760(modid))
   {
      MaxChannel = 2;
      bQuit = naiapp_query_ChannelNumber(MaxChannel, DEF_M1553_CHANNEL, &channel);
      if (!bQuit)
      {
         bQuit = RunSendMessage(cardIndex, module, channel, modid);
      }
   }
   else
      printf("\nThis module does not support 1553 functionality.\n");

   return bQuit;
}

static bool_t RunSendMessage(int32_t cardIndex, int32_t module, int32_t channel, uint32_t modid)
{
   int32_t i;
   bool_t bQuit = FALSE;
   uint32_t usBus;
   nai_1553_t status;
   uint16_t increment = 0;
   uint16_t aData[32] = {0};
   int16_t aOpCodes[20] = { 0 };
   bool_t bContinue = TRUE;
   int16_t devnum;
   bool_t bcToRtMsg = TRUE;
   naiDecodedMessageStructure DecodedMsgStruct;
   bool_t bSoftware;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Get the Logical Device Number */
   bQuit = Get1553LogicalDevNum(DEF_M1553_DEVNUM, &devnum);
   if (!bQuit)
   {
      /* Get Msg Direction */
      bQuit = GetMsgDirection(&bcToRtMsg);
      if (!bQuit)
      {
         /* Which bus are we firing on? */
         bQuit = GetBus(&usBus);
         if (!bQuit)
         {
            bQuit = Get1553BCSoftwareOverride(TRUE, &bSoftware);
            if (!bQuit)
            {
               /* Open 1553 Device(s) */
               status = naibrd_1553_Open(cardIndex, module, channel, devnum);
               if(status != 0)
               {
                  printf("Error: naibrd_1553_Open Ch %d, status = %d", channel, status);
                  return TRUE;
               }

               if (bSoftware)
               {
                  /* Override external BC_DISABLE and M1760 (In order to configure as BC, this needs to */
                  /* be set if BC_DISABLE and M1760 pins are not driven high) */
                  naibrd_1553_WriteAuxReg(devnum, 0x2, 0xA000);
               }
               else
               {
                  /* Do not override external BC_DISABLE and M1760 Inputs */
                  naibrd_1553_WriteAuxReg(devnum, 0x2, 0x0000);
               }

               if (modid == NAI_MODULE_ID_FT8)
               {
                  /* Simplex Enable (for NAI internal testing only, do not enable) */
                  /*naibrd_1553_WriteAuxReg(devnum, 0x3, 0x4000);
                    naibrd_1553_WriteAuxReg(devnum, 0xF, 0x0001);*/
               }

               /* Reset Device */
               naibrd_1553_WriteAuxReg(devnum, 0x1, 0x1);
#if defined (__VXWORKS__)
               taskDelay(1);
#elif defined (LINUX)
               usleep(100000);
#else
               Sleep(100);
#endif
               naibrd_1553_WriteAuxReg(devnum, 0x1, 0x0);

               /* Initialize 1553 Device(s) */
               status = naibrd_1553_Initialize(devnum, NAI_1553_ACCESS_CARD,NAI_1553_MODE_BC,0,0,0);
               if(status != 0)
               {
                  printf("Error: naibrd_1553_Initialize Ch %d, status = %d", channel, status);
                  return TRUE;
               }

               /* Set message retry policy
                  NOTE: The call below will setup the retry policy such that the first retry will go out on the same bus and the second retry will go out on the alternate bus.
                        The user may choose to retry on the same bus or alternate bus for both retries, or retry on the alternate bus first then back on the same bus.
                  */
               status = naibrd_1553_BcSetMessageRetryPolicy(devnum, NAI_1553_MESSAGE_RETRY_TWICE, NAI_1553_MESSAGE_RETRY_SAME, NAI_1553_MESSAGE_RETRY_ALT, 0);
               if(status != 0)
               {
                  printf("Error: naibrd_1553_BcSetMessageRetryPolicy Ch %d, status = %d", channel, status);
                  return TRUE;
               }

               /* Create BC Data Block */
               status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, WORDCOUNT, NULL, 0);
               if(status != 0)
               {
                  printf("Error: naibrd_1553_BcDataBlockCreate Ch %d, status = %d", channel, status);
                  return TRUE;
               }

               if (bcToRtMsg)
               {
                  /* Create BC to RT Message */
                  status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus | NAI_1553_BC_CTRL_RETRY_ENABLED);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
                     return TRUE;
                  }
               }
               else
               {
                  /* Create RT to BC Message */
                  status = naibrd_1553_BcMessageCreateRtToBc(devnum, MSG1, DBLK1, RT_ADDRESS, RT_SUBADDRESS, WORDCOUNT, 0, usBus | NAI_1553_BC_CTRL_RETRY_ENABLED);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcMessageCreateRtToBc status = %d", status);
                     return TRUE;
                  }
               }

               /* Create Execute Message Command */
               status = naibrd_1553_BcCommandCreate(devnum, OP1, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
               if (status != 0)
               {
                  printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
                  return TRUE;
               }

               /* Create Call Subroutine Command */
               status = naibrd_1553_BcCommandCreate(devnum, OP2, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
               if (status != 0)
               {
                  printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
                  return TRUE;
               }

               /* Create Minor Frame */
               aOpCodes[0] = OP1;
               status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
               if (status != 0)
               {
                  printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
                  return TRUE;
               }

               /* Create Major Frame */
               aOpCodes[0] = OP2;
               status = naibrd_1553_BcFrameCreate(devnum,MJR,NAI_1553_BC_FRAME_MAJOR,aOpCodes,1,1000,0);
               if (status != 0)
               {
                  printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
                  return TRUE;
               }

               while (bContinue)
               {
                  /* Load BC data block with incremental data */
                  for (i = 0; i < WORDCOUNT; i++)
                  {
                     aData[i] = increment++;
                  }
                  status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, aData, WORDCOUNT, 0);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
                     return TRUE;
                  }

                  /* Start BC */
                  status = naibrd_1553_BcStart(devnum,MJR,1);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcStart status = %d", status);
                     return TRUE;
                  }

                  /* This delay is necessary to allow the BC to run */
                  nai_msDelay(200);

                  /* Stop BC */
                  status = naibrd_1553_BcStop(devnum);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcStop status = %d", status);
                     return TRUE;
                  }

                  /* Get Decoded Msg Structure */
                  status = naibrd_1553_BcMessageGetByIdDecoded(devnum, MSG1, &DecodedMsgStruct, 1);
                  if (status < 0)
                  {
                     printf("Error: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
                     return TRUE;
                  }
                  else if (status > 0)
                  {
                     printf("Control Word: 0x%04X\n", DecodedMsgStruct.wBcControlWord);
                     printf("Command Word: 0x%04X\n", DecodedMsgStruct.wCommandWord1);
                     printf("Block Status: 0x%04X\n", DecodedMsgStruct.wBlockStatus);
                     printf("Time Tag: 0x%04X\n", DecodedMsgStruct.wTimeTag);
                     printf("Word Count: 0x%04X\n", DecodedMsgStruct.wDataWordCount);
                     printf("RT Status Word: 0x%04X\n", DecodedMsgStruct.wStatus1);
                     if (!bcToRtMsg)
                     {
                        printf("Data:");
                        for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
                        {
                           if (i % 8 == 0)
                           {
                             printf("\n");
                           }
                           printf("0x%04X ", DecodedMsgStruct.waData[i]);
                        }
                     }
                     printf("\n\n");
                  }

                  printf("\nPress any key to send another message or Q to quit.");
                  bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
                  if (bQuit)
                  {
                     bContinue = FALSE;
                  }
               }
            }
         }
      }
   }

   /* Free 1553 Device */
   status = naibrd_1553_Free(devnum);
   if (status != 0)
   {
      printf("Error: naibrd_1553_Free status = %d", status);
      return TRUE;
   }

   return bQuit;
}
Full Source — nai_1553_utils.c (SSK 1.x)
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

/* Common Sample Program include files */
#include "include/naiapp_interrupt.h"
#include "include/naiapp_interrupt_ether.h"
#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"
#include "nai_1553_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
#include "maps/nai_map_1553.h"

static int32_t g_MenuCmdCnt = 0;

bool_t Get1553Address(int32_t maxaddress, int8_t defaddress, uint8_t *address)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   if (maxaddress > 1)
   {
      while (bContinue)
      {
         printf("\nEnter address [default=%d]: ", defaddress);
         bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
         if (!bQuit)
         {
            if (inputResponseCnt == 0)
               *address = defaddress;
            else
               *address = (uint8_t)atol((const char*)inputBuffer);
            if ((*address < 0) || (*address > maxaddress))
               printf("ERROR: Invalid address value.\n\n");
            else
               bContinue = FALSE;
         }
      }
   }
   else
      *address = 0;
   return bQuit;
}

bool_t Get1553MTCfg(uint32_t modid, int32_t defchan, int32_t *rtchan )
{
   bool_t bQuit = FALSE;
   int32_t MaxChannel;

   if (IsSUMMIT1553(modid))
   {
      /* Get the number of 1553 channels on the module */
      MaxChannel = 2;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
   }
   else if (IsFTx1553(modid))
   {
      MaxChannel = 4;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
   }
   else
      printf("ERROR: Module selected does not support 1553 Functionality\n");

   return bQuit;
}

bool_t Get1553RTCfg(uint32_t modid, int32_t defchan, uint8_t defaddr, int32_t *rtchan, uint8_t *rtaddr )
{
   bool_t bQuit = FALSE;
   int32_t MaxChannel;

   if (IsSUMMIT1553(modid))
   {
      /* Get the number of 1553 channels on the module */
      MaxChannel = 2;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
      if (!bQuit)
      {
         printf("1553 RT Address Selection:");
         bQuit = Get1553Address(31, defaddr, rtaddr);
      }
   }
   else if (IsFTx1553(modid))
   {
      MaxChannel = 4;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1553 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
      if (!bQuit)
      {
         printf("1553 RT Address Selection:");
         bQuit = Get1553Address(31, defaddr, rtaddr);
      }
   }
   else if (IsFTx1760(modid))
   {
      MaxChannel = 4;
      /* Get the RT channel */
      printf("\nRemote Terminal Setup\n");
      printf("---------------------\n");
      printf("1760 RT Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, rtchan);
      if (!bQuit)
      {
         printf("1760 RT Address Selection:");
         bQuit = Get1553Address(31, defaddr, rtaddr);
      }
   }
   else
      printf("ERROR: Module selected does not support 1553 Functionality\n");

   return bQuit;
}

bool_t Get1553BCCfg(uint32_t modid, int32_t defchan, int32_t *bcchan )
{
   bool_t bQuit = FALSE;
   int32_t MaxChannel;

   if (IsSUMMIT1553(modid))
   {
      MaxChannel = 2;

      /* Get the BC channel */
      printf("\nBus Controller Setup:\n");
      printf("---------------------\n");
         printf("1553 BC Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, bcchan);
   }
   else if (IsFTx1553(modid))
   {
      MaxChannel = 4;

      /* Get the BC channel */
      printf("\nBus Controller Setup:\n");
      printf("---------------------\n");
         printf("1553 BC Channel Selection:");
      bQuit = naiapp_query_ChannelNumber(MaxChannel, defchan, bcchan);
   }
   else
      printf("ERROR: Module selected does not support Summit 1553 Functionality\n");

   return bQuit;
}

bool_t IsSUMMIT1553(uint32_t moduleID)
{
   bool_t bSupportSUM1553Func = FALSE;
   switch (moduleID)
   {
      case NAI_MODULE_ID_N7:
      case NAI_MODULE_ID_N8:
      case NAI_MODULE_ID_NA:
      case NAI_MODULE_ID_NB:
      case NAI_MODULE_ID_NC:
         bSupportSUM1553Func = TRUE;
         break;
      default:
         bSupportSUM1553Func = FALSE;
         break;
   }
   return bSupportSUM1553Func;
}

bool_t IsFTx1553(uint32_t moduleID)
{
   bool_t bSupportFTx1553Func = FALSE;
   switch (moduleID)
   {
      case NAI_MODULE_ID_FT0:
      case NAI_MODULE_ID_FT1:
      case NAI_MODULE_ID_FT2:
      case NAI_MODULE_ID_FT3:
      case NAI_MODULE_ID_FT4:
      case NAI_MODULE_ID_FT5:
      case NAI_MODULE_ID_FT6:
      case NAI_MODULE_ID_FT7:
      case NAI_MODULE_ID_FT8:
      case NAI_MODULE_ID_FT9:
      case NAI_MODULE_ID_FTA:
      case NAI_MODULE_ID_FTB:
      case NAI_MODULE_ID_FTC:
      case NAI_MODULE_ID_FTD:
      case NAI_MODULE_ID_FTE:
      case NAI_MODULE_ID_FTF:
      case NAI_MODULE_ID_FTPIB:
      case NAI_MODULE_ID_FTK:
      case NAI_MODULE_ID_CM1:
      case NAI_MODULE_ID_CM5:
      case NAI_MODULE_ID_CM8:
      case NAI_MODULE_ID_IF2:
         bSupportFTx1553Func = TRUE;
         break;
      default:
         bSupportFTx1553Func = FALSE;
         break;
   }
   return bSupportFTx1553Func;
}

bool_t IsFTx1760(uint32_t moduleID)
{
   bool_t bSupportFTx1760Func = FALSE;
   switch (moduleID)
   {
      case NAI_MODULE_ID_FTK:
         bSupportFTx1760Func = TRUE;
         break;
      default:
         bSupportFTx1760Func = FALSE;
         break;
   }
   return bSupportFTx1760Func;
}

bool_t Get1553LogicalDevNum(int16_t defdevnum, int16_t *devnum)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nSelect Logical Device Number (0-31). This must be a unique number specific to this channel/device. [Default=%d]: ", defdevnum);
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *devnum = defdevnum;
            bValidEntry = TRUE;
         }
         else if (atoi((char *)inputBuffer) < 0 || atoi((char *)inputBuffer) > 31)
            printf("\nPlease Select a Valid Logical Device Number (0-31) [Default=%d]: ", defdevnum);
         else
         {
            *devnum = (int16_t)atoi((char *)inputBuffer);
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553RTAddressSource(bool_t defSoftware, bool_t *bSoftware)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nSelect RT Address Source (S - Software, E - External Inputs) [Default=%s]: ", defSoftware ? "S" : "E");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bSoftware = defSoftware;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'S') && (toupper(inputBuffer[0]) != 'E'))
            printf("\nPlease Select a Valid RT Address Source (S - Software, E - External Inputs) [Default=%s]: ", defSoftware ? "S" : "E");
         else
         {
            *bSoftware = (toupper(inputBuffer[0]) == 'S') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553BCSoftwareOverride(bool_t defSoftware, bool_t *bSoftware)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nOverride External Inputs (Y or N)? [Default=%s]: ", defSoftware ? "Y" : "N");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bSoftware = defSoftware;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'Y') && (toupper(inputBuffer[0]) != 'N'))
            printf("\nPlease Input Y or N. Override External Inputs? [Default=%s]: ", defSoftware ? "Y" : "N");
         else
         {
            *bSoftware = (toupper(inputBuffer[0]) == 'Y') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553BCAsyncMsgType(bool_t defPriorityHigh, bool_t *bHighPriority)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nAsync Message Type High or Low (H or L)? [Default=%s]: ", defPriorityHigh ? "H" : "L");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bHighPriority = defPriorityHigh;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'H') && (toupper(inputBuffer[0]) != 'L'))
            printf("\nPlease Input H or L. Async Message Type High or Low (H or L)? [Default=%s]: ", defPriorityHigh ? "H" : "L");
         else
         {
            *bHighPriority = (toupper(inputBuffer[0]) == 'H') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1760EEPROMCopy(bool_t defCopyToEEPROM, bool_t* bCopyToEEPROM)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nWrite Memory Contents to EEPROM? [Default=%s]: ", defCopyToEEPROM ? "Y" : "N");
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *bCopyToEEPROM = defCopyToEEPROM;
            bValidEntry = TRUE;
         }
         else if ((toupper(inputBuffer[0]) != 'Y') && (toupper(inputBuffer[0]) != 'N'))
            printf("\nPlease Input Y or N. Write Memory Contents to EEPROM? [Default=%s]: ", defCopyToEEPROM ? "Y" : "N");
         else
         {
            *bCopyToEEPROM = (toupper(inputBuffer[0]) == 'Y') ? TRUE : FALSE;
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

bool_t Get1553RxBufferType(uint16_t defrxbuffertype, uint16_t *rxbuffertype)
{
   bool_t bQuit = FALSE;
   bool_t bValidEntry = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   printf("\nSelect Rx Buffer Mode:\n\n");
   printf("Single Buffer                        1-32 (number represents size of buffer)\n");
   printf("Double Buffer                        33\n");
   printf("Circular Buffer - 128 words          34\n");
   printf("Circular Buffer - 256 words          35\n");
   printf("Circular Buffer - 512 words          36\n");
   printf("Circular Buffer - 1024 words         37\n");
   printf("Circular Buffer - 2048 words         38\n");
   printf("Circular Buffer - 4096 words         39\n");
   printf("Circular Buffer - 8192 words         40\n");
   printf("Global Circular Buffer - 128 words   41\n");
   printf("Global Circular Buffer - 256 words   42\n");
   printf("Global Circular Buffer - 512 words   43\n");
   printf("Global Circular Buffer - 1024 words  44\n");
   printf("Global Circular Buffer - 2048 words  45\n");
   printf("Global Circular Buffer - 4096 words  46\n");
   printf("Global Circular Buffer - 8192 words  47\n");
   printf("\n\nEnter a Number between 1 and 47 [Default=%d]: ", defrxbuffertype);
   while (!bValidEntry)
   {
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *rxbuffertype = defrxbuffertype;
            bValidEntry = TRUE;
         }
         else if (atoi((char *)inputBuffer) < 1 || atoi((char *)inputBuffer) > 47)
            printf("\nPlease Enter a valid Number between 1 and 47 [Default=%d]: ", defrxbuffertype);
         else
         {
            *rxbuffertype = (uint16_t)atoi((char *)inputBuffer);
            bValidEntry = TRUE;
         }
      }
   }

   return bQuit;
}

/****** Command Tables *******/
static nai_1553_cmdtbl_type NAI_MenuCmds[25];

void Load1553MenuCommands(int32_t menuCmdCnt, nai_1553_cmdtbl_type menuCmds[])
{
   int32_t i;
   g_MenuCmdCnt = menuCmdCnt;
   /* Load the NAI_MenuCmds structure */
   for (i = 0; i < g_MenuCmdCnt; i++)
   {
      strcpy((char *)NAI_MenuCmds[i].cmdstr, (const char *)menuCmds[i].cmdstr);
      strcpy((char *)NAI_MenuCmds[i].menustr, (const char *)menuCmds[i].menustr);
      NAI_MenuCmds[i].cmdnum = menuCmds[i].cmdnum;
      NAI_MenuCmds[i].func = menuCmds[i].func;
   }
}

void Display1553MenuCommands(int8_t *menuTitle)
{
   int32_t i;

   printf("\n\n\n\t\t %s\n ", menuTitle);
   printf("\n ======== Command Selections ===============");
   for (i=0; i < g_MenuCmdCnt && NAI_MenuCmds[i].cmdstr != NULL; i++)
      printf ("\n %-8s \t%s", NAI_MenuCmds[i].cmdstr, NAI_MenuCmds[i].menustr);
   printf("\n");
}

bool_t Get1553CmdNum(int32_t cmdrequestCnt, int8_t *cmdrequest, int32_t* cmdNum)
{
   bool_t bCmdFound = FALSE;
   int32_t i;

   for (i = 0; i < g_MenuCmdCnt; i++)
   {
      if (naiapp_strnicmp(cmdrequest, NAI_MenuCmds[i].cmdstr, cmdrequestCnt) == 0)
      {
         bCmdFound = TRUE;
         *cmdNum = i;
         break;
      }
   }
   return bCmdFound;
}

void Menu1553Command(int32_t cmd, int16_t devnum)
{
   NAI_MenuCmds[cmd].func(devnum);
}

void LoadIllegalization(int16_t devnum, int32_t channel)
{
   uint8_t filename[128];
   FILE* deffile = NULL;
   int8_t buffer[128];
   int8_t *pval;
   uint32_t count = 0;

   sprintf((char *)filename, "illegalizationCh%d.txt", channel);
   deffile = fopen((const char *)filename,"r");
   if (deffile != NULL)
   {
      while (fgets((char*)buffer,sizeof(buffer),deffile) && count < 0x100)
      {
         pval = (int8_t*)strchr((char*)buffer,'\n');
         if (pval)
            *pval = '\0'; /* Remove LF */
         naibrd_1553_WriteMem(devnum, 0x300+count, (uint16_t)atol((const char*)buffer));
         count++;
      }
      fclose(deffile);
   }
}

void SaveIllegalization(int16_t devnum, int32_t channel)
{
   uint8_t filename[128];
   FILE* deffile = NULL;
   int32_t i;

   sprintf((char *)filename, "illegalizationCh%d.txt", channel);
   deffile = fopen((const char *)filename,"w");
   if (deffile != NULL)
   {
      for (i = 0x300; i <= 0x3FF; i++)
      {
         fprintf(deffile, "%d\n", naibrd_1553_ReadMem(devnum, i));
      }
   }
   fclose(deffile);
}

bool_t M1553_Config_Registers(int16_t devnum)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   uint16_t registervalue;
   uint32_t registeraddr;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Display current state of registers */
   DisplayRegisters(devnum);

   while (bContinue)
   {
      /* Prompt User to change the value of a particular register */
      printf("\nSelect Register Address (0x00-0x1F) to Set (or Q to quit): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         registeraddr = naiapp_utils_HexStrToDecUInt32((int8_t*)inputBuffer);

         if (registeraddr >= 0 && registeraddr < 32)
         {
            while (bContinue)
            {
               printf("\nEnter the value (0x0000-0xFFFF) to set (or Q to quit): ");
               bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if (!bQuit)
               {
                  if (inputResponseCnt > 0)
                  {
                     registervalue = naiapp_utils_HexStrToDecUInt16((int8_t*)inputBuffer);
                     check_status(naibrd_1553_WriteReg(devnum, registeraddr, registervalue));
                     bContinue = FALSE;
                  }
                  else
                     printf("\nInvalid Value. \n");
               }
               else
                  bContinue = FALSE;
            }
         }
         else
            printf("\nInvalid Value. \n");
      }
      else
         bContinue = FALSE;
   }

   return FALSE;
}

bool_t M1553_Aux_Registers(int16_t devnum)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   uint16_t registervalue;
   uint32_t registeraddr;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   /* Display current state of aux registers */
   DisplayAuxRegisters(devnum);

   while (bContinue)
   {
      /* Prompt User to change the value of a particular register */
      printf("\nSelect Auxiliary Register Address (0x00-0xF) to Set (or Q to quit): ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         registeraddr = naiapp_utils_HexStrToDecUInt32((int8_t*)inputBuffer);

         if (registeraddr >= 0 && registeraddr < 32)
         {
            while (bContinue)
            {
               printf("\nEnter the value (0x0000-0xFFFF) to set (or Q to quit): ");
               bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
               if (!bQuit)
               {
                  if (inputResponseCnt > 0)
                  {
                     registervalue = naiapp_utils_HexStrToDecUInt16((int8_t*)inputBuffer);
                     check_status(naibrd_1553_WriteAuxReg(devnum, registeraddr, registervalue));
                     bContinue = FALSE;
                  }
                  else
                     printf("\nInvalid Value. \n");
               }
               else
                  bContinue = FALSE;
            }
         }
         else
            printf("\nInvalid Value. \n");
      }
      else
         bContinue = FALSE;
   }

   return FALSE;
}

void DisplayRegisters(int16_t devnum)
{
   int32_t i;
   uint16_t registervalue;

   printf("\n\n");
   printf("********** CONFIGURATION REGISTERS **********\n");
   printf("ADDRESS        VALUE                         \n");

   for (i = 0; i < 32; i++)
   {
      registervalue = naibrd_1553_ReadReg(devnum, i);
      printf(" 0x%02X      0x%02X                       \n", i, registervalue);
   }
   printf("\n\n");
}

void DisplayAuxRegisters(int16_t devnum)
{
   int32_t i;
   uint16_t registervalue;

   printf("\n\n");
   printf("********** AUXILLARY REGISTERS **********\n");
   printf("ADDRESS        VALUE                     \n");

   for (i = 0; i < 16; i++)
   {
      registervalue = naibrd_1553_ReadAuxReg(devnum, i);
      printf(" 0x%02X      0x%02X                       \n", i, registervalue);
   }
   printf("\n\n");
}

bool_t GetRTAddress(int32_t* nRTaddress)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int32_t value;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nWhat is the RT Address of the command word (0 to 31)? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         value = atoi((const char*)inputBuffer);
         if (value >= 0 && value < 32)
         {
            *nRTaddress = value;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetTxRx(bool_t* bTxMsg)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nReceive (R) or Transmit (T) Message? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (toupper(inputBuffer[0]) == 'R')
         {
            *bTxMsg = FALSE;
            bContinue = FALSE;
         }
         else if (toupper(inputBuffer[0]) == 'T')
         {
            *bTxMsg = TRUE;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetSubaddress(int32_t* nSubaddress)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int32_t value;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nSubaddress (0 to 31)? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         value = atoi((const char*)inputBuffer);
         if (value >= 0 && value < 32)
         {
            *nSubaddress = value;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetWordCount(int32_t* nWordCount)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int32_t value;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nWord Count (1 to 32)? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         value = atoi((const char*)inputBuffer);
         if (value > 0 && value <= 32)
         {
            *nWordCount = value;
            bContinue = FALSE;
         }
         else
            printf("\nInvalid Command.\n");
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

int32_t MemoryTest(int16_t devnum)
{
   int32_t counter = 0;
   int32_t ErrCnt = 0;
   uint16_t testValues[6] = {0x0000, 0x5555, 0xAAAA, 0xA5A5, 0x5A5A, 0xFFFF};
   uint16_t readValue;
   int32_t i;

   printf("\nDevNum %d - Memory Test started. Please wait for test to complete...\n\n", devnum);

   while (counter < NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY)
   {
      for (i = 0; i < sizeof(testValues)/sizeof(testValues[0]); i++)
      {
         naibrd_1553_WriteMem(devnum, counter, testValues[i]);
         readValue = naibrd_1553_ReadMem(devnum, counter);
         /* If write/read values do not match */
         if (readValue != testValues[i])
         {
            ErrCnt++;
            printf("\nData Mismatch! Memory Location: 0x%04X, WriteVal: 0x%04X, ReadVal: 0x%04X, ErrCnt: %d\n\n", counter, testValues[i], readValue, ErrCnt);
         }
      }

      counter++;

      /* Display Progress */
      if ((counter % 1000) == 250)
         printf("\\ %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
      else if ((counter % 1000) == 500)
         printf("| %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
      else if ((counter % 1000) == 750)
         printf("/ %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
      else if ((counter % 1000) == 0)
         printf("- %d%% Complete\r", (counter*100)/NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY);
   }

   printf("\nDevNum %d - Memory Test Complete. ErrCnt = %d\n\n", devnum, ErrCnt);

   return ErrCnt;
}

int32_t MemoryTestFast(int16_t cardIndex, int16_t module, int16_t channel)
{
   int32_t ErrCnt = 0;
   uint16_t testValues[6] = {0x0000, 0x5555, 0xAAAA, 0xA5A5, 0xFFFF};
   uint32_t testValues32[6] = {0x00000000, 0x55555555, 0xAAAAAAAA, 0xA5A5A5A5, 0xFFFFFFFF};
   int32_t i,j,testIndex;
   uint16_t data[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint32_t data32[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint16_t readdata[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint32_t readdata32[NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY];
   uint32_t M1553memory[4] = NAI_1553_GEN5_REG_MEMORY_ADD;
   uint32_t M1553memory32[4] = NAI_1553_GEN5_32BIT_REG_MEMORY_ADD;
   uint32_t modid;
   int32_t maxmemorysize;
   uint32_t modprocrev, modfpgarev;

   printf("\nChannel %d - Memory Test started. Please wait for test to complete...\n\n", channel);

   modid = naibrd_GetModuleID(cardIndex, module);
   naibrd_GetModuleRev(cardIndex, module, &modprocrev, &modfpgarev);

   if (modfpgarev >= 0x100)
      memcpy(M1553memory, M1553memory32, sizeof(uint32_t)*4);

   if (modid == NAI_MODULE_ID_FT3 || modid == NAI_MODULE_ID_FT6 || modid == NAI_MODULE_ID_FT9)
      maxmemorysize = NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY / 2;
   else
      maxmemorysize = NAI_1553_MAX_SIZE_OF_DEVICE_MEMORY;

   for (i = 0; i < sizeof(testValues)/sizeof(testValues[0]); i++)
   {
      for (testIndex = 0; testIndex < maxmemorysize; testIndex++)
      {
         if (i == 0)
         {
            data[testIndex] = testValues[i]++;
            if (modfpgarev >= 0x100)
               data32[testIndex] = testValues32[i]++;
            else
               data32[testIndex] = testValues[i]++;
         }
         else
         {
            data[testIndex] = testValues[i];
            if (modfpgarev >= 0x100)
               data32[testIndex] = testValues32[i];
            else
               data32[testIndex] = testValues[i];
         }
      }
      if (i == 0)
         printf("Writing Incremental Data to %d words in RAM\n", maxmemorysize);
      else
      {
         if (modfpgarev >= 0x100)
            printf("Writing 0x%08X to %d words in RAM\n", testValues32[i], maxmemorysize);
         else
            printf("Writing 0x%04X to %d words in RAM\n", testValues[i], maxmemorysize);
      }
      if (modfpgarev >= 20)
         naibrd_Write32(cardIndex, module, M1553memory[channel - 1] << 1, 4, maxmemorysize, NAI_REG32, data32);
      else
         naibrd_Write16(cardIndex, module, M1553memory[channel - 1], 2, maxmemorysize, NAI_REG16, data);
      printf("Reading %d words in RAM\n", maxmemorysize);
      if (modfpgarev >= 20)
         naibrd_Read32(cardIndex, module, M1553memory[channel - 1] << 1, 4, maxmemorysize, NAI_REG32, &readdata32[0]);
      else
         naibrd_Read16(cardIndex, module, M1553memory[channel - 1], 2, maxmemorysize, NAI_REG16, &readdata[0]);
      for (j = 0; j < maxmemorysize; j++)
      {
         /* If write/read values do not match */
         if (modfpgarev >= 20)
         {
            if (readdata32[j] != data32[j])
            {
               ErrCnt++;
               printf("\nData Mismatch! Memory Location: 0x%04X, WriteVal: 0x%04X, ReadVal: 0x%04X, ErrCnt: %d\n\n", j, data32[j], readdata32[j], ErrCnt);
            }
         }
         else
         {
            if (readdata[j] != data[j])
            {
               ErrCnt++;
               printf("\nData Mismatch! Memory Location: 0x%04X, WriteVal: 0x%04X, ReadVal: 0x%04X, ErrCnt: %d\n\n", j, data[j], readdata[j], ErrCnt);
            }
         }
      }
      if (ErrCnt == 0)
      {
         printf("Test Passed\n");
      }
   }

   printf("\nChannel %d - Memory Test Complete. ErrCnt = %d\n\n", channel, ErrCnt);

   return ErrCnt;
}
Full Source — nai_1553_bc_utils.c (SSK 1.x)
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.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"
#include "nai_1553_bc_utils.h"
#include "nai_1553_utils.h"

/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"

#define     DBLK1    1

#define     MSG1     1

#define     OP1      1
#define     OP2      2

#define     MNR1     1
#define     MJR      2

enum M1553SendMsgMenu_commands
{
   BC_QUICK_MESSAGE,
   BC_CREATE_MESSAGE,
   BC_SEND_FRAME,
   BC_SENDMSGCMD_COUNT
};

const M1553ModeCodes_t validTxModeCodeCommands[TXMODECODE_NUM_OF_VALIDCOMMANDS] = { DynamicBusControl_0x00, Syncronize_0x01, TransmitStatusWord_0x02,
InitiateSelfTest_0x03, TransmitterShutdown_0x04, OverrideTransmitterShutdown_0x05, InhibitTerminalFlag_0x06,
OverrideInhibitTerminalFlag_0x07, ResetRemoteTerminal_0x08, TransmitVectorWord_0x10, TransmitLastCommandWord_0x12,
TransmitBITWord_0x13 };

const M1553ModeCodes_t validRxModeCodeCommands[RXMODECODE_NUM_OF_VALIDCOMMANDS] = { SyncronizeWdata_0x11, SelectedTransmitterShutDown_0x14,
Ovveride_SelectedTransmitter_Shoutdown_0x15 };

static nai_1553_cmdtbl_type M1553_SendMsgMenuCmds[] = {
   {"BCQUICK       ", "BC Send a Message Now               ", BC_QUICK_MESSAGE,        BC_QuickMessage         }
};

bool_t BC_SendMessages(int16_t devnum)
{
   bool_t bQuit = FALSE;
   bool_t bContinue = TRUE, bCmdFound;
   int32_t cmd;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      /* Display BC Menu Options */
      Load1553MenuCommands(BC_SENDMSGCMD_COUNT, M1553_SendMsgMenuCmds);
      Display1553MenuCommands((int8_t *)"************************\n                 *                      *\n                 *   BC Messages Menu   *\n                 *                      *\n                 ************************");
      printf("\nType Menu command or %c to quit : ", NAI_QUIT_CHAR);
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt > 0)
         {
            bCmdFound = Get1553CmdNum(inputResponseCnt, inputBuffer, &cmd);
            if (bCmdFound)
            {
               switch (cmd)
               {
                  case BC_QUICK_MESSAGE:
                  case BC_CREATE_MESSAGE:
                  case BC_SEND_FRAME:
                     M1553_SendMsgMenuCmds[cmd].func(devnum);
                     break;
                  default:
                     printf("Invalid command entered");
                     break;
               }
            }
         }
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t BC_QuickMessage(int16_t devnum)
{
   bool_t bQuit = FALSE;
   bool_t bTxMsg = FALSE;
   uint32_t usBus;
   int32_t nRTaddress, nSubaddress, nWordCount;
   nai_1553_t status;
   int32_t i;
   uint16_t wapBuffer[32];
   int16_t aOpCodes[20]     = { 0 };
   naiDecodedMessageStructure DecodedMsgStruct;

   /* Ask user what bus we are sending on */
   bQuit = GetBus(&usBus);
   if (!bQuit)
   {
      /* Ask user what the RT address is */
      bQuit = GetRTAddress(&nRTaddress);
      if (!bQuit)
      {
         /* Ask user if it is Tx or Rx message */
         bQuit = GetTxRx(&bTxMsg);
         if (!bQuit)
         {
            /* Ask user what subaddress the message is sent to */
            bQuit = GetSubaddress(&nSubaddress);
            if (!bQuit)
            {
               /* Ask user what the data word count is */
               bQuit = GetWordCount(&nWordCount);
               if (!bQuit)
               {
                  /*** Send a message ***/
                  /* Create BC Data Block */
                  status = naibrd_1553_BcDataBlockCreate(devnum, DBLK1, 32, NULL, 0);
                  if(status != 0)
                  {
                     printf("Error: naibrd_1553_BcDataBlockCreate Status = %d", status);
                     return bQuit;
                  }

                  /* Load data block with incremental data */
                  for (i = 0; i < 32; i++)
                  {
                     wapBuffer[i] = (uint16_t)i;
                  }
                  status = naibrd_1553_BcDataBlockWrite(devnum, DBLK1, wapBuffer, 32, 0);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcDataBlockWrite status = %d", status);
                     return bQuit;
                  }

                  if (bTxMsg)
                  {
                     /* Create RT to BC message */
                     status = naibrd_1553_BcMessageCreateRtToBc(devnum, MSG1, DBLK1, (uint16_t)nRTaddress, (uint16_t)nSubaddress, 32, 0, usBus);
                     if (status != 0)
                     {
                        printf("Error: naibrd_1553_BcMessageCreateRtToBc status = %d", status);
                        return bQuit;
                     }
                  }
                  else
                  {
                     /* Create BC to RT message */
                     status = naibrd_1553_BcMessageCreateBcToRt(devnum, MSG1, DBLK1, (uint16_t)nRTaddress, (uint16_t)nSubaddress, 32, 0, usBus);
                     if (status != 0)
                     {
                        printf("Error: naibrd_1553_BcMessageCreateBcToRt status = %d", status);
                        return bQuit;
                     }
                  }

                  status = naibrd_1553_BcCommandCreate(devnum, OP1, NAI_1553_OPCODE_EXECUTE_MESSAGE, NAI_1553_OPCODE_COND_ALWAYS, MSG1, 0, 0);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
                     return bQuit;
                  }
                  status = naibrd_1553_BcCommandCreate(devnum, OP2, NAI_1553_OPCODE_CALL_SUBROUTINE, NAI_1553_OPCODE_COND_ALWAYS, MNR1, 0, 0);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcCommandCreate status = %d", status);
                     return bQuit;
                  }

                  /* Create Minor Frame */
                  aOpCodes[0] = OP1;
                  status = naibrd_1553_BcFrameCreate(devnum, MNR1, NAI_1553_BC_FRAME_MINOR, aOpCodes, 1, 0, 0);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
                     return bQuit;
                  }

                  /* Create Major Frame */
                  aOpCodes[0] = OP2;
                  status = naibrd_1553_BcFrameCreate(devnum,MJR,NAI_1553_BC_FRAME_MAJOR,aOpCodes,1,1000,0);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcFrameCreate status = %d", status);
                     return bQuit;
                  }

                  /* Start BC */
                  status = naibrd_1553_BcStart(devnum,MJR,1);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcStart status = %d", status);
                     return bQuit;
                  }

            #if defined (__VXWORKS__)
                  taskDelay(sysClkRateGet() * 1);
            #elif defined (LINUX)
                  usleep(1000*1000);
            #else
                  Sleep(1 * 1000);
            #endif

                  /* Read Status Response */
                  status = naibrd_1553_BcMessageGetByIdDecoded(devnum,MSG1,&DecodedMsgStruct,1);
                  if (status < 0)
                  {
                     printf("Error: naibrd_1553_BcMessageGetByIdDecoded status = %d", status);
                     return bQuit;
                  }
                  printf("\nStatus: 0x%04X\n", DecodedMsgStruct.wStatus1);

                  /* Read Data Block, if Tx message was sent */
                  if (bTxMsg)
                  {
                     status = naibrd_1553_BcDataBlockRead(devnum,DBLK1,wapBuffer,32,0);
                     if (status != 0)
                     {
                        printf("Error: naibrd_1553_BcDataBlockRead status = %d", status);
                        return bQuit;
                     }
                     printf("\nData:\n");
                     for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
                     {
                        printf("0x%04X ", DecodedMsgStruct.waData[i]);
                     }
                     printf("\n\n");
                  }

                  /* Stop BC */
                  status = naibrd_1553_BcStop(devnum);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcStop status = %d", status);
                     return bQuit;
                  }

                  /* Delete Major Frame */
                  status = naibrd_1553_BcFrameDelete(devnum,MJR);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcFrameDelete MJR status = %d", status);
                     return bQuit;
                  }

                  /* Delete Minor Frame */
                  aOpCodes[0] = OP1;
                  status = naibrd_1553_BcFrameDelete(devnum, MNR1);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcFrameDelete MNR1 status = %d", status);
                     return bQuit;
                  }

                  status = naibrd_1553_BcCommandDelete(devnum, OP2);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcCommandDelete OP2 status = %d", status);
                     return bQuit;
                  }

                  status = naibrd_1553_BcCommandDelete(devnum, OP1);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcCommandDelete OP1 status = %d", status);
                     return bQuit;
                  }

                  status = naibrd_1553_BcMessageDelete(devnum, MSG1);
                  if (status != 0)
                  {
                     printf("Error: naibrd_1553_BcMessageDelete status = %d", status);
                     return bQuit;
                  }

                  /* Delete BC Data Block */
                  status = naibrd_1553_BcDataBlockDelete(devnum, DBLK1);
                  if(status != 0)
                  {
                     printf("Error: naibrd_1553_BcDataBlockDelete Status = %d", status);
                     return bQuit;
                  }
               }
            }
         }
      }
   }

   return bQuit;
}

bool_t GetBus(uint32_t* usBus)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nWhich bus are we firing on (A or B) [default = A]? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         *usBus = NAI_1553_BC_CTRL_BUS_A;
         if (inputResponseCnt == 0)
         {
            *usBus = NAI_1553_BC_CTRL_BUS_A;
            bContinue = FALSE;
         }
         if (inputResponseCnt > 0)
         {
            if (toupper(inputBuffer[0]) == 'B')
            {
               *usBus = NAI_1553_BC_CTRL_BUS_B;
               bContinue = FALSE;
            }
            else if (toupper(inputBuffer[0]) == 'A')
            {
               *usBus = NAI_1553_BC_CTRL_BUS_A;
               bContinue = FALSE;
            }
            else
            {
               printf("\nInvalid command entered.\n\n");
            }
         }
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetMsgDirection(bool_t* bcToRt)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nIs the message BC to RT (n is RT to BC) [default = y]? ");
      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         *bcToRt = TRUE;
         if (inputResponseCnt == 0)
         {
            *bcToRt = TRUE;
            bContinue = FALSE;
         }
         else if (inputResponseCnt > 0)
         {
            if (toupper(inputBuffer[0]) == 'Y')
            {
               *bcToRt = TRUE;
               bContinue = FALSE;
            }
            else if (toupper(inputBuffer[0]) == 'N')
            {
               *bcToRt = FALSE;
               bContinue = FALSE;
            }
            else
            {
               printf("\nInvalid command entered.\n\n");
            }
         }
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t GetMsgTypeAndCheckForQuit(M1553MsgType_t* msgType)
{
   bool_t bContinue = TRUE;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   while (bContinue)
   {
      printf("\nChoose message type:\n");
      printf("press 1 for BC to RT\n");
      printf("press 2 for RT to BC\n");
      printf("press 3 for RT to RT\n");
      printf("press 4 for Tx Mode Code\n");
      printf("press 5 for Rx Mode Code\n");
      printf("[default = 1] ?\n");

      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt == 0)
         {
            *msgType = M1553_MSGTYPE_BCTORT;
            bContinue = FALSE;
         }
         else if (inputResponseCnt > 0)
         {
            if ((atoi((char *)inputBuffer) < 1) || (atoi((char *)inputBuffer) > 5))
            {
               printf("\nInvalid command entered.\n\n");
            }
            else if (inputBuffer[0] == '1')
            {
               *msgType = M1553_MSGTYPE_BCTORT;
               bContinue = FALSE;
            }
            else if (inputBuffer[0] == '2')
            {
               *msgType = M1553_MSGTYPE_RTTOBC;
               bContinue = FALSE;
            }
            else if (inputBuffer[0] == '3')
            {
               *msgType = M1553_MSGTYPE_RTTORT;
               bContinue = FALSE;
            }
            else if (inputBuffer[0] == '4')
            {
               *msgType = M1553_MSGTYPE_MODECODE_TX;
               bContinue = FALSE;
            }
            else if (inputBuffer[0] == '5')
            {
               *msgType = M1553_MSGTYPE_MODECODE_RX;
               bContinue = FALSE;
            }
            else
            {
               printf("\nInvalid command entered.\n\n");
            }
         }
      }
      else
         bContinue = FALSE;
   }

   return bQuit;
}

bool_t AskAndCheckForValidModeCodeAndCheckForQuit(M1553MsgDirectionForModeCode_t modeCodeDirection, M1553ModeCodes_t* modeCodeCommand, bool_t* isValidModeCodeCommand)
{
   uint8_t i;
   bool_t bQuit = FALSE;
   int8_t inputBuffer[80];
   int32_t inputResponseCnt;

   *isValidModeCodeCommand = FALSE;

   while (!(*isValidModeCodeCommand))
   {
      printf("\nPlease choose the desired Mode Code number in decimal:\n(0 - 8, 16, 18 - 19 for Tx) or (17, 20 - 21 for Rx)\n");

      (modeCodeDirection == M1553_MSGTYPE_MODECODE_DIRECTION_TX) ? (printf("[default] = %d\n", DynamicBusControl_0x00)) : (printf("[default] = %d\n", SyncronizeWdata_0x11));

      printf("\nOr type Q to quit\n");

      bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
      if (!bQuit)
      {
         if (inputResponseCnt)
         {
            *modeCodeCommand = (M1553ModeCodes_t)atoi((char *)inputBuffer);

            /* Check user input for a valid integer. This is needed because atoi will return 0 for a non-integer, and 0 is a valid mode code */
            for (i = 0; i < inputResponseCnt; i++)
            {
               if (inputBuffer[i] != ' ')
               {
                  if (isdigit(inputBuffer[i]) == 0)
                  {
                     *isValidModeCodeCommand = FALSE;
                     printf((modeCodeDirection == M1553_MSGTYPE_MODECODE_DIRECTION_TX) ? ("\n\nInvalid Tx Mode Code Command\n\n") :
                        ("\n\nInvalid Rx Mode Code Command\n\n"));
                     break;
                  }
                  else
                     *isValidModeCodeCommand = TRUE;
               }
               else
                  *isValidModeCodeCommand = TRUE;
            }

            if (*isValidModeCodeCommand)
            {
               if (((atoi((char *)inputBuffer) < (int)DynamicBusControl_0x00) || (atoi((char *)inputBuffer) > (int)ResetRemoteTerminal_0x08)) &&
                  ((atoi((char *)inputBuffer) < (int)TransmitVectorWord_0x10) || (atoi((char *)inputBuffer) > (int)Ovveride_SelectedTransmitter_Shoutdown_0x15)))
                  *isValidModeCodeCommand = FALSE;
               else if (modeCodeDirection == (uint16_t)M1553_MSGTYPE_MODECODE_DIRECTION_TX)
               {
                  for (i = 0; i < TXMODECODE_NUM_OF_VALIDCOMMANDS; i++)
                  {
                     if (*modeCodeCommand == validTxModeCodeCommands[i])
                     {
                        *isValidModeCodeCommand = TRUE;
                        break;
                     }
                     else
                        *isValidModeCodeCommand = FALSE;
                  }
               }
               else if (modeCodeDirection == M1553_MSGTYPE_MODECODE_DIRECTION_RX)
               {
                  for (i = 0; i < RXMODECODE_NUM_OF_VALIDCOMMANDS; i++)
                  {
                     if (*modeCodeCommand == (uint16_t)validRxModeCodeCommands[i])
                     {
                        *isValidModeCodeCommand = TRUE;
                        break;
                     }
                     else
                        *isValidModeCodeCommand = FALSE;
                  }
               }
               else
               {
                  *isValidModeCodeCommand = FALSE;
                  break;
               }

               if (*isValidModeCodeCommand)
                  break;
               else
                  printf((modeCodeDirection == M1553_MSGTYPE_MODECODE_DIRECTION_TX) ? ("\n\nInvalid Tx Mode Code Command\n\n") :
                  ("\n\nInvalid Rx Mode Code Command\n\n"));
            }
         }
         else
         {
            if (modeCodeDirection == (uint16_t)M1553_MSGTYPE_MODECODE_DIRECTION_TX)
            {
               *modeCodeCommand = DynamicBusControl_0x00;
               *isValidModeCodeCommand = TRUE;
               break;
            }
            else
            {
               *modeCodeCommand = SyncronizeWdata_0x11;
               *isValidModeCodeCommand = TRUE;
               break;
            }
         }
      }
      else
      {
         break;
      }
   }

   return bQuit;
}

Help Bot

X