MX Foundation 4
mil1553_bm_mx3.c
/*****************************************************************************
//
## File:
## mil1553_bm_mx3.c
//
// Copyright (c) MAX Technologies Inc. 1988-2015, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the basic usage of MIL-STD-1553 bus monitor.
//
// Hardware requirements:
// - MAXT 400 series carrier with MIL-STD-1553 Channel Class compliant
// IPM module
//
*****************************************************************************/
#include <mx-api/mx-base/mxbase.h>
#include <mx-api/mx-gen/mxgen.h>
#include <mx-api/mx-mon/mxmon.h>
#include <mx-api/mx-class/mxmilstd1553.h>
#include <memory.h>
int main(void)
{
uint32 rc;
uint16 appCount;
HCHANNEL bm=0;
DATAREC_MILSTD1553 rxRec1553[32];
uint32 msgCount;
uint32 rxRec;
uint32 loop=0;
uint32 address;
uint32 subAddress;
uint32 wordCount;
uint32 data;
MSGINFO_MILSTD1553 msgInfo;
char errorString[200];
int card, mod, port;
// Initialize MX Foundation library
rc = mxLibraryLoad();
if(!rc)
{
rc = mxApplicationCount(0, &appCount);
if(!rc)
{
// if other MX Foundation application running, only load MX-Foundation library, otherwise reset cards first
printf("Starting ... %s\n", appCount > 0 ? "(Other Applications Running)" : "");
if(appCount == 1)
{
mxCardsReset(0);
mxLibraryUnload();
rc = mxLibraryLoad();
}
}
}
// Get handle of first Flex1553 MIL-STD-1553 Bus monitor channel
if(!rc)
rc = mxChannelGet(CHN_CLASS_MILSTD1553, mMX_SCLASS_BM_CHN, MX_IPMTYPE_ALL, 0, &bm);
// Diplay BM channel location
rc = mxChannelLocationGet(bm, &card, &mod, &port);
if (!rc)
printf("BM location is Device:%d Module:%d Port:%d\n", card, mod, port);
// Set timebase to RTC usec 64-bit
if(!rc)
rc = mxTimeBaseSet(MX_TIME_BASE_CARD_USEC_64BITS, 0);
// Start BM acquisition
if(!rc)
{
printf("Starting BM\n\r");
rc = mxAcqStart(bm, 0, 0, mACQ_DEFAULT_START_FLAGS);
}
// Read and display received messages
if(!rc)
{
do
{
rc = mxAcqRecordRead(bm, 10, rxRec1553, &msgCount);
for(rxRec=0; rxRec<msgCount && !rc; rxRec++)
{
rc = mxMsgDecompose(bm, MX_MSGINFO_RECTYPE_ACQ, &rxRec1553[rxRec], 1, 0, &msgInfo);
if(!rc)
{
address = MXMILSTD1553_COMMAND_ADRS_GET(rxRec1553[rxRec].awData[0]);
subAddress = MXMILSTD1553_COMMAND_SUBADRS_GET(rxRec1553[rxRec].awData[0]);
wordCount = MXMILSTD1553_COMMAND_WORDCNT_GET(rxRec1553[rxRec].awData[0]);
if(!rc)
{
printf("\n\r%010u:\t", rxRec1553[rxRec].dwTimetag);
switch(msgInfo.wMsgType)
{
case MXMILSTD1553_MSGINFO_TYPE_BCRT:
printf("BC to RT%u SA%u WC%u (0x%04x)\n\r", address, subAddress, wordCount, rxRec1553[rxRec].awData[0]);
printf("\t\tBC data:");
for(data=0; data<msgInfo.wDataWordCnt; data++)
{
if(data && !(data%4))
printf("\n\r\t\t\t");
printf(" 0x%04x", rxRec1553->awData[msgInfo.wDataIdx + data]);
}
printf("\n\r");
if(msgInfo.awStsIdx[0] != 0xffff)
printf("\t\tRT status: 0x%04x\n\r", rxRec1553[rxRec].awData[msgInfo.awStsIdx[0]]);
break;
case MXMILSTD1553_MSGINFO_TYPE_RTBC:
printf("\n\r%010u:\t", rxRec1553[rxRec].dwTimetag);
printf("RT%u SA%u WC%u to BC (0x%04x)\n\r", address, subAddress, wordCount, rxRec1553[rxRec].awData[0]);
if(msgInfo.awStsIdx[0] != 0xffff)
{
printf("\t\tRT status: 0x%04x\n\r", rxRec1553[rxRec].awData[msgInfo.awStsIdx[0]]);
printf("\t\tRT data:");
for(data=0; data<msgInfo.wDataWordCnt; data++)
{
if(data && !(data%4))
printf("\n\r\t\t\t");
printf(" 0x%04x", rxRec1553->awData[msgInfo.wDataIdx + data]);
}
printf("\n\r");
}
break;
case MXMILSTD1553_MSGINFO_TYPE_MODECODE_TXDATA:
printf("BC Mode Command %u to RT%u SA%u (0x%04x)\n\r", wordCount, address, subAddress, rxRec1553[rxRec].awData[0]);
if(msgInfo.awStsIdx[0] != 0xffff)
{
printf("\t\tRT status: 0x%04x\n\r", rxRec1553[rxRec].awData[msgInfo.awStsIdx[0]]);
printf("\t\tRT data: 0x%04x\n\r", rxRec1553[rxRec].awData[msgInfo.wDataIdx]);
}
break;
}
}
}
}
mxTimerYield(500);
loop++;
}while(loop < 300);
}
// Stop acquisition
if(!rc)
{
printf("Stopping BM\n\r");
rc = mxAcqStop(bm);
}
if(rc)
{
mxErrorStringGet(0, rc, sizeof(errorString), errorString);
printf("%s\n\r", errorString);
}
// Unload MX Foundation library
rc = mxApplicationCount(0, &appCount);
if(!rc)
{
// if other MX Foundation application running, only unload MX-Foundation library, otherwise reset cards first
if(appCount > 1)
mxLibraryUnload();
else
{
mxCardsReset(0);
mxLibraryUnload();
}
}
return rc;
}
Updated 03/30/2022