M1553 MT Monitor
Edit this on GitLab
M1553 MT Monitor Sample Application (SSK 1.x)
Overview
The M1553 MT Monitor sample application demonstrates passive MIL-STD-1553 bus monitoring using Monitor Terminal (MT) mode with the NAI Software Support Kit (SSK 1.x). Unlike the Bus Controller (BC), which initiates transactions, and the Remote Terminal (RT), which responds to commands, the MT passively captures all bus traffic without transmitting. This makes it the right tool for bus analysis, debugging, and data logging.
The SSK ships two variants of this sample that share the same initialization and filtering logic but differ in how they retrieve captured messages:
-
Stack-based polling (
M1553_MT_Monitor.c, 272 lines) — retrieves one message at a time from the MT stack. Simple and easy to follow; best suited to low-to-moderate traffic rates. -
FIFO-based bulk retrieval (
M1553_MT_Monitor_FIFO.c, 353 lines) — reads messages in bulk from a FIFO buffer. More efficient under high traffic because it reduces the number of API calls per monitoring cycle.
Both variants also demonstrate message filtering using naibrd_1553_MtMessageMonitoringDisable() to selectively ignore traffic from specific RT addresses and subaddresses.
|
Note
|
This guide covers the third 1553 operating mode. For BC operations, see the M1553 BC SendMessageWithRetries guide. For RT operations, see the M1553 RT HBuff guide. |
This sample supports the following 1553 module types:
-
FT0 through FTF — 4-channel 1553 modules
-
FTJ / FTK — 2-channel MIL-STD-1760 modules
-
CM1, CM5, CM8 — combination modules with 1553 functionality
Prerequisites
Before running this sample, make sure you have:
-
An NAI board with a 1553 module installed (FT0-FTF, FTJ, FTK, CM1, CM5, or CM8).
-
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_MT_Monitor executable (stack variant) or M1553_MT_Monitor_FIFO executable (FIFO variant) from your build output directory. On startup the application looks for a configuration file (default_1553_MTMonitor.txt for the stack variant, default_1553_MTMonitor_FIFO.txt for the FIFO variant). 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 prompts for monitoring parameters and begins capturing bus traffic.
Board Connection and Module Selection
|
Note
|
This startup sequence is common to all NAI sample applications. The board connection and module selection code shown here is not specific to 1553. |
The main() function follows a standard SSK 1.x startup flow:
-
Call
naiapp_RunBoardMenu()to load a saved configuration file (if one exists) or present the interactive board menu. The configuration file (default_1553_MTMonitor.txt) is not included with the SSK — it is created when the user saves their connection settings from the board menu. On the first run, the menu will always appear. -
Query the user for a card index with
naiapp_query_CardIndex(). -
Query for a module slot with
naiapp_query_ModuleNumber(). -
Retrieve the module ID with
naibrd_GetModuleID()so downstream code can adapt to the specific 1553 variant installed.
#if defined (__VXWORKS__)
int32_t M1553_MT_Monitor(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_MT_Monitor(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:
|
Program Structure
The entry point is main() on most platforms, or M1553_MT_Monitor() on VxWorks. Both resolve to the same logic.
The SSK provides two source files for this sample:
-
M1553_MT_Monitor.c(272 lines) — the stack-based variant. Retrieves messages one at a time by pollingnaibrd_1553_MtMessageGetFromStackRaw(). -
M1553_MT_Monitor_FIFO.c(353 lines) — the FIFO-based variant. Retrieves messages in bulk using the FIFO interface, which is more efficient when the bus carries heavy traffic.
Both variants share the same initialization sequence and message filtering setup. They differ only in how captured messages are read back from the hardware during the monitoring loop.
User Input Sequence
After the board connection is established, Run_M1553_MT_Monitor() collects the remaining configuration through a series of prompts:
-
MT channel —
Get1553MTCfg()asks the user which 1553 channel to use for monitoring (default: channel 1). The available channels depend on the installed module type. -
Logical device number —
Get1553LogicalDevNum()assigns a logical device handle that the naibrd API uses to identify this 1553 session (default: device 1). -
Monitoring duration — the application prompts for how many seconds to monitor the bus (default: 5 seconds). You can run multiple monitoring cycles without restarting.
Timed Monitoring Loop
Once configuration is complete, the application enters a loop that repeats until the user quits:
-
Prompt for a duration in seconds.
-
Call
naibrd_1553_MtStart()to begin capturing bus traffic. -
Run the monitoring function (
MonitorMessages) for the specified duration, polling for and displaying captured messages. -
Call
naibrd_1553_MtStop()to halt capture. -
Prompt again — enter a new duration to monitor again, or press Q to exit.
This structure lets you observe the bus in successive windows without tearing down and reinitializing the MT session each time.
MT Role in 1553 Communication
MIL-STD-1553 defines three terminal roles. Understanding where the Monitor Terminal fits helps explain why its API surface is so much smaller than the BC or RT APIs.
BC, RT, MT Roles
The Bus Controller (BC) initiates all communication on the bus by issuing command words that direct data transfers. Remote Terminals (RTs) respond to those commands — they receive data, transmit data, or execute mode codes as instructed by the BC. The Monitor Terminal (MT) is a purely passive observer. It listens to every transaction on the bus but never transmits. Because it does not participate in the protocol, the MT cannot affect bus timing or interfere with normal BC/RT exchanges.
What MT Captures
The MT captures every transaction that passes its filter criteria. For each message, the hardware records:
-
Command words — the BC-issued command word (and a second command word for RT-to-RT transfers).
-
Status words — the RT response status for each participating terminal.
-
Data words — the payload of the transfer, up to 32 words per message.
-
Time tags — a hardware timestamp marking when the transaction occurred.
-
Block status — a status word generated by the monitoring hardware that indicates error conditions, bus selection, and message type.
When to Use MT
MT mode is the right choice when you need to observe the bus without influencing it:
-
Bus analysis — capture all traffic to understand the communication pattern between a BC and its RTs.
-
Protocol debugging — verify that command words, status words, and data payloads match expectations.
-
Traffic logging — record bus activity over time for post-processing or compliance evidence.
-
System validation — confirm that an integrated system produces the correct transactions at the correct rates.
-
Compliance testing — demonstrate that bus traffic conforms to MIL-STD-1553 requirements.
No Data Blocks or Frame Hierarchy
Unlike the BC, which organizes transmissions into frames, minor frames, and opcodes, and unlike the RT, which maps data into subaddress-based data blocks, the MT has no comparable data structures to configure. The MT workflow is: initialize the device, optionally configure filters, start monitoring, and read captured messages. This is why the MT sample is significantly shorter and simpler than the BC or RT samples.
Message Filtering
MT filtering controls which messages the hardware captures. By selectively disabling monitoring for specific RT addresses and subaddresses, you can reduce noise and focus on the traffic you care about.
Default Behavior
At power-on, the MT monitors all messages on the bus. Every transaction from every RT address across all subaddresses is captured. No filtering configuration is required to begin monitoring.
Selective Disabling
Both sample variants demonstrate filtering by disabling monitoring for RT address 1, subaddress 3. From line 148 of the stack variant:
swResult = naibrd_1553_MtMessageMonitoringDisable(DevNum, RT_DISABLE, NAI_1553_MT_FILTER_ALL, 1 << SA_DISABLE);
The parameters break down as follows:
-
RT_DISABLE(value 1) — the RT address to stop monitoring. This is the 5-bit terminal address (0-31). -
NAI_1553_MT_FILTER_ALL— the direction filter.FILTER_ALLdisables monitoring in both the receive and transmit directions for the specified RT/subaddress combination. -
1 << SA_DISABLE(value1 << 3 = 8) — a bitmask identifying the subaddress to disable. Bit N corresponds to subaddress N, so setting bit 3 disables subaddress 3.
After this call, the MT will silently ignore any transaction involving RT 1, subaddress 3, regardless of direction.
Re-enabling
To restore monitoring for a previously disabled RT/subaddress combination, call:
naibrd_1553_MtMessageMonitoringEnable(DevNum, rtAddress, directionFilter, subaddressMask);
The parameters mirror those of the disable call.
Querying Filter Status
You can check whether monitoring is currently enabled or disabled for a given RT/subaddress combination:
naibrd_1553_MtMessageMonitoringGetStatus(DevNum, rtAddress, directionFilter, &statusMask);
The returned status mask indicates which subaddresses are currently being monitored.
Direction Constants
The direction filter parameter accepts three values:
-
NAI_1553_MT_FILTER_RX— affects only receive-direction messages (BC-to-RT). -
NAI_1553_MT_FILTER_TX— affects only transmit-direction messages (RT-to-BC). -
NAI_1553_MT_FILTER_ALL— affects both directions.
Subaddress Mask
The subaddress parameter is a bitmask, not a single value. Each bit position corresponds to one subaddress (bit 0 = subaddress 0, bit 1 = subaddress 1, and so on). You can disable multiple subaddresses in a single call by setting multiple bits. For example, (1 << 3) | (1 << 7) disables subaddresses 3 and 7 simultaneously.
Practical Guidance
To reduce noise during monitoring, disable monitoring for RT addresses and subaddresses you do not care about. This is especially useful on busy buses where dozens of RTs may be active but you only need to observe a few specific transactions.
|
Important
|
Common filtering issues you may encounter:
|
Device Initialization
Both sample variants follow the same initialization sequence: open the device, initialize it in MT mode, optionally configure filters, and start monitoring. The only difference is the mode flag passed during initialization and an extra FIFO-clear step in the FIFO variant.
Opening the Device
Both variants begin by associating the card, module, and channel with a logical device number:
swResult = naibrd_1553_Open(cardIndex, module, mtchan, DevNum);
This call is identical in both variants. The logical device number (DevNum) is a handle used by all subsequent API calls to identify this 1553 session.
Initializing — Stack Variant
The stack variant initializes with a straightforward MT mode flag (line 139 of M1553_MT_Monitor.c):
swResult = naibrd_1553_Initialize(DevNum, NAI_1553_ACCESS_CARD, NAI_1553_MODE_MT, 0, 0, 0);
NAI_1553_MODE_MT puts the device into Monitor Terminal mode. The three trailing zeros are reserved parameters that are unused for MT initialization.
Initializing — FIFO Variant
The FIFO variant ORs an additional flag to enable FIFO-based message retrieval (line 140 of M1553_MT_Monitor_FIFO.c):
swResult = naibrd_1553_Initialize(DevNum, NAI_1553_ACCESS_CARD, NAI_1553_MODE_MT | NAI_1553_MESSAGE_FIFO_MODE, 0, 0, 0);
The NAI_1553_MESSAGE_FIFO_MODE flag tells the hardware to buffer captured messages in a FIFO rather than the default stack. This enables bulk retrieval during the monitoring loop.
Clearing the FIFO
The FIFO variant adds one extra step before starting each monitoring cycle. Before calling naibrd_1553_MtStart(), it clears any stale data from the FIFO (line 169 of M1553_MT_Monitor_FIFO.c):
swResult = naibrd_1553_ClearMsgFIFO(DevNum);
This ensures the monitoring loop does not process leftover messages from a previous session. The stack variant does not need this step because the stack pointer is reset implicitly.
Starting the Monitor
Both variants start MT capture with the same call:
swResult = naibrd_1553_MtStart(DevNum);
After this call returns successfully, the hardware begins capturing bus traffic according to the current filter configuration.
Comparison with BC and RT Initialization
MT initialization is notably simpler than BC or RT initialization. There is no reset sequence, no auxiliary register configuration, no data block allocation, and no frame or subaddress table setup. The entire initialization path is: open, initialize with mode flag, optionally filter, and start. This minimal setup reflects the MT’s passive role — it only needs to know which bus to listen on and which messages to capture.
|
Important
|
Common initialization issues you may encounter:
|
Message Monitoring — Stack-Based
The stack-based variant retrieves captured messages one at a time by polling the MT stack at timed intervals. This section walks through MonitorMessages() (lines 205-271 of M1553_MT_Monitor.c), which runs for a caller-specified duration and prints each decoded transaction.
Polling Loop
The monitoring loop runs on a 10ms polling interval. Each iteration calls naibrd_1553_MtMessageGetFromStackRaw() to check for a new message on the active stack. The return value indicates the result: less than 0 means an error occurred, 0 means no message is available, and greater than 0 means a message was retrieved (the value is the message size).
/* If the stack pointer has updated (new data arrived), read one message at a time */
swResult = naibrd_1553_MtMessageGetFromStackRaw(DevNum, wsBuffer, NAI_1553_MAX_MESSAGE_SIZE_MT, NAI_1553_MT_STACK_ACTIVE);
if (swResult < 0)
{
printf("Error: naibrd_1553_MtMessageGetFromStackRaw %d\n\n", swResult);
return 0;
}
Decoding
When a message is successfully retrieved (swResult > 0), the raw buffer is decoded into a structured format:
swResult = naibrd_1553_MtMessageDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);
naibrd_1553_MtMessageDecodeRaw() parses the raw word buffer into a naiDecodedMessageStructure, which provides named fields for the block status, time tag, command words, data word count, and data payload.
Message Direction
The TR (transmit/receive) bit — bit 10 (mask 0x0400) — in command word 1 determines the direction of the transfer:
if ((DecodedMsgStruct.wCommandWord1 & 0x0400) != 0x0400) /* If this is a Rx message */
{
printf("Rx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("Data:");
for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", DecodedMsgStruct.waData[i]);
}
printf("count: %d\n", count++);
printf("\n\n");
}
else
{
printf("Tx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("count: %d\n", count++);
printf("\n\n");
}
-
When the TR bit is clear (
0), this is a receive (Rx) message — the BC sent data to the RT. The application prints the full decoded message including the data payload. -
When the TR bit is set (
1), this is a transmit (Tx) message — the BC requested data from the RT. The application prints the message header fields but omits the data words.
Displayed Fields
For each captured message, the application displays:
-
Block status — a hardware-generated status word indicating error conditions, bus selection (A or B), and message type.
-
Time tag — a hardware timestamp marking when the transaction was captured.
-
Command word — the BC-issued command word that initiated the transaction.
-
Data word count — the number of data words in the transfer.
-
Data (Rx messages only) — the payload words, printed eight per line in hexadecimal.
When to Use
The stack-based approach is best suited for:
-
Simple monitoring — when you need a straightforward implementation with minimal setup.
-
Low-to-moderate traffic — when the bus traffic rate is low enough that polling at 10ms intervals does not miss messages.
-
Easy implementation — the one-message-at-a-time retrieval model is easier to understand and debug than bulk FIFO reads.
For high-traffic buses where messages arrive faster than the polling interval can service them, consider the FIFO-based variant instead.
|
Important
|
Common monitoring issues you may encounter:
|
Message Monitoring — FIFO-Based
The FIFO-based variant retrieves captured messages in bulk rather than one at a time. This section walks through MonitorMessages() (lines 214-352 of M1553_MT_Monitor_FIFO.c), which reads all available messages from the FIFO buffer in each cycle and decodes them iteratively. This approach reduces the number of API calls per monitoring cycle and is better suited to high-traffic buses where the stack-based approach may not keep up.
Bulk Retrieval
Each iteration of the monitoring loop begins by querying the FIFO for the number of available messages, then reading them all in a single call:
swResult = naibrd_1553_GetMsgFIFOCount(DevNum, &fifoCount);
if (swResult != 0)
{
printf("Error: naibrd_1553_GetMsgFIFOCount %d", swResult);
return TRUE;
}
If fifoCount is greater than zero, the application reads the entire batch into a local buffer:
swResult = naibrd_1553_ReadMsgFIFO(DevNum, fifoCount, fifoData);
This two-step pattern — count then read — retrieves all pending messages in one operation, minimizing the time spent in API calls compared to the stack variant’s one-message-at-a-time polling.
Zero Buffer
Before each bulk read, the application clears the receive buffer:
memset(fifoData, 0, sizeof(fifoData));
This prevents old data from being decoded unintentionally. Without this step, leftover data from a previous read cycle could remain in the buffer and be misinterpreted by the decoder when the current batch contains fewer messages than the previous one.
Iterative Decoding
After the bulk read, the application decodes messages one at a time from the fifoData buffer using a do-while loop. Each call to naibrd_1553_DecodeFIFOMsg() extracts one message starting at currBlockIndex and returns the index of the next message in nextBlockIndex:
do
{
swResult = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &msgStruct);
if (swResult == 0)
{
if ((msgStruct.wCommandWord1 & 0x0400) != 0x0400) /* If this is a Rx message */
{
printf("Rx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", msgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", msgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", msgStruct.wCommandWord1);
if(msgStruct.bIsCommandWord2Relevant)
printf("Command Word 2 - 0x%04X\n", msgStruct.wCommandWord2);
printf("RT Status Word: 0x%04X\n", msgStruct.wStatus1);
if (msgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", msgStruct.wStatus2);
printf("Data Word Count - 0x%04X\n", msgStruct.wDataWordCount);
printf((msgStruct.wDataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < msgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", msgStruct.waData[i]);
}
printf("count: %d\n", count++);
printf("\n\n");
}
else
{
printf("Tx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", msgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", msgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", msgStruct.wCommandWord1);
if (msgStruct.bIsCommandWord2Relevant)
printf("Command Word 2 - 0x%04X\n", msgStruct.wCommandWord2);
printf("RT Status Word: 0x%04X\n", msgStruct.wStatus1);
if (msgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", msgStruct.wStatus2);
printf("Data Word Count - 0x%04X\n", msgStruct.wDataWordCount);
printf((msgStruct.wDataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < msgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", msgStruct.waData[i]);
}
printf("count: %d\n", count++);
printf("\n\n");
}
}
else if (swResult != (uint32_t)NAI_1553_CMD_NO_MSG_TO_DECODE)
{
printf("Error: naibrd_1553_DecodeFIFOMsg %d", swResult);
return TRUE;
}
/*** IMPORTANT !!! ***/
currBlockIndex = nextBlockIndex;
nai_msDelay(1);
} while ((swResult == NAI_SUCCESS) && (time(NULL) < end));
The loop continues as long as naibrd_1553_DecodeFIFOMsg() returns NAI_SUCCESS and the monitoring duration has not expired. When there are no more messages to decode, the function returns NAI_1553_CMD_NO_MSG_TO_DECODE, which exits the loop without treating it as an error.
Block Index Traversal
The block index is the mechanism that advances the decoder through the FIFO buffer. After each successful decode, the application must update the current index:
currBlockIndex = nextBlockIndex;
This line is critical. If currBlockIndex is not advanced, the loop will decode the same message repeatedly and never progress through the buffer. The source code marks this with a prominent IMPORTANT comment for good reason.
Decoded Structure
The FIFO variant uses naiDecodedMessageStructureFIFO rather than the naiDecodedMessageStructure used by the stack variant. The FIFO structure includes additional fields for RT-to-RT transfers:
-
bIsCommandWord2Relevant— when true, the message is an RT-to-RT transfer andwCommandWord2contains the second command word. -
bIsStatus2Relevant— when true, a second RT responded to the transaction andwStatus2contains its status word. -
wStatus1— the primary RT status word, always present on a successful decode.
These fields make the FIFO structure more expressive than the stack variant’s structure, which does not expose the second command word or second status word directly.
Overflow Detection
After processing each batch of messages, the application checks whether the FIFO has overflowed:
swResult = naibrd_1553_GetMsgFIFOFullStatus(DevNum, NAI_1553_STATUS_REALTIME, &FIFOfullStatusBit);
if (swResult == NAI_SUCCESS)
{
printf("FIFO status: %d", FIFOfullStatusBit);
printf((FIFOfullStatusBit == TRUE) ? " Full\r\n" : " Not full\r\n");
}
A full FIFO means messages may have been lost because the buffer had no room for new arrivals. Monitoring this status after each read cycle lets you detect data loss and adjust your polling rate or processing strategy accordingly.
When to Use
The FIFO-based approach is best suited for:
-
High-traffic monitoring — when the bus carries heavy traffic and messages arrive faster than the stack variant can poll them individually.
-
Bulk capture — when you want to collect a batch of messages and process them together rather than one at a time.
-
Reduced API overhead — the count-then-read pattern makes fewer API calls per cycle than individual stack polls, which matters on buses with high message rates.
-
Scenarios where the stack cannot keep up — if the stack-based variant is losing messages due to overflow, switching to the FIFO variant with its bulk retrieval model may resolve the issue.
|
Important
|
Common FIFO monitoring issues you may encounter:
|
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 MT Monitoring Issues
When an MT monitor isn’t capturing messages, verify three things:
-
MT mode is initialized and started.
naibrd_1553_MtStart()must be called after initialization. Until started, the MT will not observe any bus traffic. -
Filtering hasn’t disabled the traffic you expect. By default all messages are monitored, but if
naibrd_1553_MtMessageMonitoringDisable()was called, it may have excluded the RT addresses or subaddresses you need. Usenaibrd_1553_MtMessageMonitoringGetStatus()to verify the current filter state. -
There is actually bus traffic present. MT can only capture what’s on the bus. If no BC is transmitting and no RTs are responding, MT will see nothing. Verify the bus is active with other 1553 devices.
If messages appear but data is missing or truncated, check the block status word for protocol errors. If using the FIFO variant and messages seem stale, ensure naibrd_1553_ClearMsgFIFO() is called before each monitoring session.
| Error / Symptom | Possible Causes | Suggested Resolution |
|---|---|---|
No board found or connection timeout |
Board not powered, missing configuration file, network issue |
Verify hardware and configuration. If file doesn’t exist, configure and save from board menu. |
Module not recognized as 1553 |
Selected module is not FT-series or CM with 1553 |
Verify module type at the selected slot. |
Device open or initialization failure |
Wrong card/module/channel, or device already in use |
Verify parameters. Close other applications using this channel. |
MT not started |
|
Call |
All traffic filtered out |
|
Check filter state with |
No bus traffic present |
No active BC or RTs on the bus — MT has nothing to observe |
Verify other 1553 devices are connected and operating. |
Stack overflow (stack variant) |
Messages lost — application not polling fast enough |
Increase polling rate (reduce delay) or switch to FIFO variant. |
FIFO overflow (FIFO variant) |
FIFO buffer full before application reads |
Call |
FIFO not cleared before monitoring |
Stale data from previous session decoded |
Call |
Decode error |
Raw buffer corrupted or incomplete message in stack/FIFO |
Verify message retrieval succeeded before decoding. Check return codes. |
Wrong mode flag for FIFO variant |
Initialized with |
OR the FIFO flag: |
Full Source
The complete source for both sample variants is provided below for reference. The sections above explain each part in detail.
Full Source — M1553_MT_Monitor.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai_1553_utils.h"
/* Common 1553 Sample Program include files */
#include "nai_1553_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_1553_MTMonitor.txt";
/* Function prototypes */
static bool_t Run_M1553_MT_Monitor(int32_t cardIndex, int32_t module, uint32_t modid);
static int32_t MonitorMessages(uint16_t DevNum, int32_t duration);
static const int32_t DEF_MT_CHANNEL = 1;
static const int16_t DEF_MT_DEV_NUM = 1;
#define RT_DISABLE 1
#define SA_DISABLE 3
/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_MT_Monitor is to illustrate the methods to call in the naibrd library to configure
and run the 1553 channel as a Message Monitor. If an Rx message is detected on the bus, the Rx message data will
be displayed. If a Tx message is detected, the Tx message will be displayed. This application also demonstrates
message filtering using the naibrd_1553_MtMessageMonitoringDisable() function to disable monitoring for certain
message types.
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_MT_Monitor(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_MT_Monitor(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
static bool_t Run_M1553_MT_Monitor(int32_t cardIndex, int32_t module, uint32_t modid)
{
/* Variables */
bool_t bQuit = FALSE;
int32_t mtchan;
int16_t DevNum = 0;
int32_t swResult;
bool_t bContinue = TRUE;
int32_t duration;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get Card, Module, Channel Numbers and Open a Handle */
bQuit = Get1553MTCfg(modid, DEF_MT_CHANNEL, &mtchan);
if (bQuit)
{
return bQuit;
}
/* Get Logical Device # */
bQuit = Get1553LogicalDevNum(DEF_MT_DEV_NUM, &DevNum);
if (bQuit)
{
return bQuit;
}
/* Associate Card, Module and Channel Numbers with the Logical Device # */
swResult = naibrd_1553_Open(cardIndex, module, mtchan, DevNum);
if(swResult)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Open %d", swResult);
return bQuit;
}
/* Simplex enable */
/* swResult = naibrd_1553_WriteAuxReg(DevNum, 0xF, 0x0); */
/* Initialize Device */
swResult = naibrd_1553_Initialize(DevNum,NAI_1553_ACCESS_CARD,NAI_1553_MODE_MT,0,0,0);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Initialize %d", swResult);
return bQuit;
}
/* Disable Monitoring for RT 1, SA 3 Message Types (In default power on state, all messages are monitored) */
swResult = naibrd_1553_MtMessageMonitoringDisable(DevNum, RT_DISABLE, NAI_1553_MT_FILTER_ALL, 1 << SA_DISABLE);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Initialize %d", swResult);
return bQuit;
}
while (bContinue)
{
printf("\nType duration (in seconds) to run RT or %c to quit (default: 5) : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
duration = 5;
if (inputResponseCnt > 0)
{
duration = (int)atol((const char*)inputBuffer);
}
/* Start MT */
swResult = naibrd_1553_MtStart(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_MtStart %d", swResult);
return bQuit;
}
/* Start the monitor and display any new messages */
MonitorMessages(DevNum, duration);
/* Stop MT */
swResult = naibrd_1553_MtStop(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_MtStop %d", swResult);
return bQuit;
}
}
else
bContinue = FALSE;
}
/* Free 1553 Device */
swResult = naibrd_1553_Free(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Free %d", swResult);
return bQuit;
}
return bQuit;
}
static int MonitorMessages(uint16_t DevNum, int32_t duration)
{
time_t end;
uint32_t swResult;
int32_t i;
naiDecodedMessageStructure DecodedMsgStruct;
uint16_t wsBuffer[80] = { 0x0000 };
int32_t count = 0;
end = time(NULL) + duration;
while (time(NULL) < end)
{
/* If the stack pointer has updated (new data arrived), read one message at a time */
swResult = naibrd_1553_MtMessageGetFromStackRaw(DevNum, wsBuffer, NAI_1553_MAX_MESSAGE_SIZE_MT, NAI_1553_MT_STACK_ACTIVE);
if (swResult < 0)
{
printf("Error: naibrd_1553_MtMessageGetFromStackRaw %d\n\n", swResult);
return 0;
}
else if (swResult > 0)
{
/* Decode Raw Message */
swResult = naibrd_1553_MtMessageDecodeRaw(DevNum, wsBuffer, &DecodedMsgStruct);
if (swResult < 0)
{
printf("Error: naibrd_1553_MtMessageDecodeRaw %d\n\n", swResult);
return 0;
}
if ((DecodedMsgStruct.wCommandWord1 & 0x0400) != 0x0400) /* If this is a Rx message */
{
printf("Rx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("Data:");
for (i = 0; i < DecodedMsgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", DecodedMsgStruct.waData[i]);
}
printf("count: %d\n", count++);
printf("\n\n");
}
else
{
printf("Tx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", DecodedMsgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", DecodedMsgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", DecodedMsgStruct.wCommandWord1);
printf("Data Word Count - 0x%04X\n", DecodedMsgStruct.wDataWordCount);
printf("count: %d\n", count++);
printf("\n\n");
}
}
nai_msDelay(10);
}
return 1;
}
Full Source — M1553_MT_Monitor_FIFO.c (SSK 1.x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Common Sample Program include files */
#include "include/naiapp_boardaccess_menu.h"
#include "include/naiapp_boardaccess_query.h"
#include "include/naiapp_boardaccess_access.h"
#include "include/naiapp_boardaccess_display.h"
#include "include/naiapp_boardaccess_utils.h"
#include "nai_1553_utils.h"
/* Common 1553 Sample Program include files */
#include "nai_1553_utils.h"
/* naibrd include files */
#include "nai.h"
#include "naibrd.h"
#include "functions/naibrd_1553.h"
#include "functions/naibrd_1553_assisted.h"
static const int8_t *CONFIG_FILE = (int8_t *)"default_1553_MTMonitor_FIFO.txt";
/* Function prototypes */
static bool_t Run_M1553_MT_Monitor_FIFO(int32_t cardIndex, int32_t module, uint32_t modid);
static int32_t MonitorMessages(uint16_t DevNum, int32_t duration);
static const int32_t DEF_MT_CHANNEL = 1;
static const int16_t DEF_MT_DEV_NUM = 1;
#define RT_DISABLE 1
#define SA_DISABLE 3
/**************************************************************************************************************/
/**
<summary>
The purpose of the M1553_MT_Monitor_FIFO is to illustrate the methods to call in the naibrd library to configure
and run the 1553 channel as a Message Monitor. If an Rx or TX message is detected on the bus, the received
data and message information will be displayed via message FIFO. This application also demonstrates message
filtering using the naibrd_1553_MtMessageMonitoringDisable() function to disable monitoring for certain
message types.
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_MT_Monitor_FIFO(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_MT_Monitor_FIFO(cardIndex, module, moduleID);
}
}
}
printf("\nType Q to quit or Enter key to restart application:\n");
stop = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
}
}
printf("\nType the Enter key to exit the program: ");
naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
naiapp_access_CloseAllOpenCards();
return 0;
}
static bool_t Run_M1553_MT_Monitor_FIFO(int32_t cardIndex, int32_t module, uint32_t modid)
{
/* Variables */
bool_t bQuit = FALSE;
int32_t mtchan;
int16_t DevNum = 0;
int32_t swResult;
bool_t bContinue = TRUE;
int32_t duration;
int8_t inputBuffer[80];
int32_t inputResponseCnt;
/* Get Card, Module, Channel Numbers and Open a Handle */
bQuit = Get1553MTCfg(modid, DEF_MT_CHANNEL, &mtchan);
if (bQuit)
{
return bQuit;
}
/* Get Logical Device # */
bQuit = Get1553LogicalDevNum(DEF_MT_DEV_NUM, &DevNum);
if (bQuit)
{
return bQuit;
}
/* Associate Card, Module and Channel Numbers with the Logical Device # */
swResult = naibrd_1553_Open(cardIndex, module, mtchan, DevNum);
if(swResult)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Open %d", swResult);
return bQuit;
}
/* Simplex enable */
/* swResult = naibrd_1553_WriteAuxReg(DevNum, 0xF, 0x0); */
/* Initialize Device */
swResult = naibrd_1553_Initialize(DevNum,NAI_1553_ACCESS_CARD,NAI_1553_MODE_MT | NAI_1553_MESSAGE_FIFO_MODE,0,0,0);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Initialize %d", swResult);
return bQuit;
}
/* Disable Monitoring for RT 1, SA 3 Message Types (In default power on state, all messages are monitored) */
swResult = naibrd_1553_MtMessageMonitoringDisable(DevNum, RT_DISABLE, NAI_1553_MT_FILTER_ALL, 1 << SA_DISABLE);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Initialize %d", swResult);
return bQuit;
}
while (bContinue)
{
printf("\nType duration (in seconds) to run RT or %c to quit (default: 5) : ", NAI_QUIT_CHAR);
bQuit = naiapp_query_ForQuitResponse(sizeof(inputBuffer), NAI_QUIT_CHAR, inputBuffer, &inputResponseCnt);
if (!bQuit)
{
duration = 5;
if (inputResponseCnt > 0)
{
duration = (int)atol((const char*)inputBuffer);
}
swResult = naibrd_1553_ClearMsgFIFO(DevNum);
if (swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_ClearMsgFIFO %d", swResult);
return bQuit;
}
/* Start MT */
swResult = naibrd_1553_MtStart(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_MtStart %d", swResult);
return bQuit;
}
/* Start the monitor and display any new messages */
MonitorMessages(DevNum, duration);
/* Stop MT */
swResult = naibrd_1553_MtStop(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_MtStop %d", swResult);
return bQuit;
}
}
else
bContinue = FALSE;
}
/* Free 1553 Device */
swResult = naibrd_1553_Free(DevNum);
if(swResult != 0)
{
bQuit = TRUE;
printf("Error: naibrd_1553_Free %d", swResult);
return bQuit;
}
return bQuit;
}
static int MonitorMessages(uint16_t DevNum, int32_t duration)
{
time_t end;
uint32_t swResult;
int32_t i;
naiDecodedMessageStructureFIFO msgStruct;
uint32_t fifoData[1024];
int32_t count = 0;
int32_t currBlockIndex = 0, nextBlockIndex = 0;
uint32_t fifoCount;
bool_t FIFOfullStatusBit;
end = time(NULL) + duration;
while (time(NULL) < end)
{
swResult = naibrd_1553_GetMsgFIFOCount(DevNum, &fifoCount);
if (swResult != 0)
{
printf("Error: naibrd_1553_GetMsgFIFOCount %d", swResult);
return TRUE;
}
else
{
if (fifoCount > 0)
{
currBlockIndex = 0;
/* This is necessary because otherwise, fifoData array gets used over and over without getting zero'ed out. */
/* When the array gets decoded, old data may get decoded unintentionally */
memset(fifoData, 0, sizeof(fifoData));
/* Read Message FIFO */
swResult = naibrd_1553_ReadMsgFIFO(DevNum, fifoCount, fifoData);
if (swResult != 0)
{
printf("Error: naibrd_1553_ReadMsgFIFO %d", swResult);
return TRUE;
}
else
{
/* Read Messages */
do
{
swResult = naibrd_1553_DecodeFIFOMsg(fifoData, currBlockIndex, &nextBlockIndex, &msgStruct);
if (swResult == 0)
{
if ((msgStruct.wCommandWord1 & 0x0400) != 0x0400) /* If this is a Rx message */
{
printf("Rx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", msgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", msgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", msgStruct.wCommandWord1);
if(msgStruct.bIsCommandWord2Relevant)
printf("Command Word 2 - 0x%04X\n", msgStruct.wCommandWord2);
printf("RT Status Word: 0x%04X\n", msgStruct.wStatus1);
if (msgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", msgStruct.wStatus2);
printf("Data Word Count - 0x%04X\n", msgStruct.wDataWordCount);
printf((msgStruct.wDataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < msgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", msgStruct.waData[i]);
}
printf("count: %d\n", count++);
printf("\n\n");
}
else
{
printf("Tx Msg Received\n");
printf("\n\nDecoded Message:\n\n");
printf("Block Status - 0x%04X\n", msgStruct.wBlockStatus);
printf("Time Tag - 0x%04X\n", msgStruct.wTimeTag);
printf("Command Word - 0x%04X\n", msgStruct.wCommandWord1);
if (msgStruct.bIsCommandWord2Relevant)
printf("Command Word 2 - 0x%04X\n", msgStruct.wCommandWord2);
printf("RT Status Word: 0x%04X\n", msgStruct.wStatus1);
if (msgStruct.bIsStatus2Relevant)
printf("RT Status Word 2: 0x%04X\n", msgStruct.wStatus2);
printf("Data Word Count - 0x%04X\n", msgStruct.wDataWordCount);
printf((msgStruct.wDataWordCount > 0) ? ("Data:") : (""));
for (i = 0; i < msgStruct.wDataWordCount; i++)
{
if (i % 8 == 0)
{
printf("\n");
}
printf("0x%04X ", msgStruct.waData[i]);
}
printf("count: %d\n", count++);
printf("\n\n");
}
}
else if (swResult != (uint32_t)NAI_1553_CMD_NO_MSG_TO_DECODE)
{
printf("Error: naibrd_1553_DecodeFIFOMsg %d", swResult);
return TRUE;
}
/*** IMPORTANT !!! ***/
currBlockIndex = nextBlockIndex;
nai_msDelay(1);
} while ((swResult == NAI_SUCCESS) && (time(NULL) < end));
}
swResult = naibrd_1553_GetMsgFIFOFullStatus(DevNum, NAI_1553_STATUS_REALTIME, &FIFOfullStatusBit);
if (swResult == NAI_SUCCESS)
{
printf("FIFO status: %d", FIFOfullStatusBit);
printf((FIFOfullStatusBit == TRUE) ? " Full\r\n" : " Not full\r\n");
}
else
{
printf("Error: naibrd_1553_GetMsgFIFOFullStatus %d", swResult);
return TRUE;
}
}
}
}
return 1;
}
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;
}