MX Foundation 4
ar629_independent_mode.c
/*****************************************************************************
//
// File:
// ar629_independent_mode.c
//
// Copyright (c) MAX Technologies Inc. 1988-2015, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This demo shows how to set a basic periodic transmission in independent
// mode and set the ARINC 629 data. The transmission scenario is inspired
// of SAARU equipment.
// Acquisition is also performed with CRC verification enabled for labels
// that have a CRC.
//
// Hardware Requirements:
// - MAXT FlexMulti-629.
//
*****************************************************************************/
#include "example.h"
//#define TTL
//#define LOCAL
#define MAX_RX_RECORDS_TO_RECEIVE 1000
#define RX_BUFFER_SIZE MAX_RX_RECORDS_TO_RECEIVE*sizeof(MXF_A629_DATAREC)
#define MAX_TX_RECORDS_TO_TRANSMIT 1
#define TX_BUFFER_SIZE MAX_TX_RECORDS_TO_TRANSMIT*sizeof(MXF_A629_DATAREC)
#define NUM_Y 8
#define NUM_X 2
#define ALT_LABEL 5
#define NUM_LABEL 7
typedef struct
{
uint16 label;
uint16 lenght;
uint32 crc;
uint32 fc;
uint32 bufferIndex;
}
LABEL_INFO;
LABEL_INFO LABEL[NUM_LABEL] = {{0xFE1,8,1,1,0}, {0xFE2,14,1,1,1}, {0xFE3,14,1,1,2}, {0xFE4,14,1,1,3}, {0xFE5,14,1,1,4}, {0xFE6,14,0,0,5}, {0xFE7,14,1,1,6}};
//***************************************************************************
//
// Main()
//
//***************************************************************************
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
uint64 count=0;
HMXF_CHANNEL rxChannel=0;
HMXF_CHANNEL txChannel=0;
HMXF_BUFFER rxBuffer=0;
HMXF_BUFFER txBuffer[NUM_LABEL]={0,0,0,0,0,0,0};
MXF_A629_DATAREC *hostBuffer=NULL;
MXF_A629_DATAREC *rec629=NULL;
uint64 dev, mod, port;
uint64 index, word;
uint64 status, msgsCount, bytesCount;
uint32 minor, label;
LABEL_INFO *majorFrame[NUM_Y][NUM_X] = { {&LABEL[6], &LABEL[0]},
{0, &LABEL[4]},
{0, &LABEL[3]},
{0, &LABEL[2]},
{0, &LABEL[1]},
{0, &LABEL[4]},
{0, &LABEL[3]},
{0, &LABEL[5]} };
// Connect to services local or remote
#ifdef LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
#endif
if (rc)
{
printf("Failed to connect; rc=0x%08x", rc);
printf("\nPress a key to terminate\n");
getchar();
return 0;
}
// Initialize the server
printf("\nStarting\n");
rc = mxfSystemInit(server);
// Get the first device handle
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
if (!rc)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_A629MRT_EH, 1, &count, &module);
// Obtain the first ARINC 629 Protocol RX channel (RX logical #0)
if (!rc && count)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_A629, MXF_SCLASS_RX_CHANNEL, 1, &count, &rxChannel);
// Obtain the first ARINC 629 Protocol TX channel (TX logical #0)
if (!rc && count)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_A629, MXF_SCLASS_TX_CHANNEL, 1, &count, &txChannel);
// If module or channel not found, return an error
if(!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
// Set timebase to 64-bit nanoseconds
if (!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Get the physical port location
if (!rc)
{
rc = mxfChannelLocationGet(rxChannel, &dev, &mod, &port);
if (!rc)
printf("Acquisition Channel (RX) location=%llu.%llu.%llu\n", dev, mod, port);
}
if (!rc)
{
rc = mxfChannelLocationGet(txChannel, &dev, &mod, &port);
if (!rc)
printf("Transmitter Channel (TX) location=%llu.%llu.%llu\n", dev, mod, port);
}
// Set interface to SIM or TTL
#ifdef TTL
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_INTERFACE, VMXF_A629_MODULE_INTERFACE_TTL);
#else
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_INTERFACE, VMXF_A629_MODULE_INTERFACE_SIM);
#endif
// Allocate RX acquisition buffer
if (!rc)
rc = mxfRxAcqBufferAlloc(rxChannel, RX_BUFFER_SIZE, &rxBuffer, NULL);
// Allocate TX Periodic Update Message buffer
for(index=0; index<NUM_LABEL && !rc; index++)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(txChannel, index, TX_BUFFER_SIZE, &txBuffer[index], NULL);
// Allocate host buffer
if (!rc)
{
hostBuffer = (MXF_A629_DATAREC*)malloc(max(RX_BUFFER_SIZE, TX_BUFFER_SIZE));
if (!hostBuffer)
rc = MAXT_ERROR_MEM;
}
// Add CRC verification
for(index=0; index<NUM_LABEL && !rc; index++)
rc = mxfA629RxMsgCrcEnableSet(rxChannel, LABEL[index].label, 0, LABEL[index].crc);
// Start the acquisition process
if (!rc)
rc = mxfRxAcqModeSet(rxBuffer, MXF_RXACQ_MODE_LINEAR);
if (!rc)
{
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
if (!rc)
printf("\nAcquisition started\n\r");
}
//Disable the CID in XPP
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_XPP_CID_ENABLE, FALSE);
//Set the TI to 5 msec
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_TI, 5000000);
//Set the SG to 32
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_SG, VMXF_A629_MODULE_SG_32);
//Set the TG to 20
if(!rc)
rc = mxfAttributeUint64Set(txChannel, KMXF_A629_RT_TG, 20);
//Set the CID to 0
if(!rc)
rc = mxfAttributeUint64Set(txChannel, KMXF_A629_RT_CID, 0);
//Clear the major frame
if(!rc)
rc = mxfTxPeriodicMajorFrameClear(txChannel, 0);
// set 8 minor frames with 2 labels each
for(minor=0;minor<NUM_Y && !rc;minor++)
{
memset(minorFrame, 0, sizeof(minorFrame));
for(label=0;label<NUM_X && !rc;label++)
{
if(majorFrame[minor][label])
{
minorFrame[label].buffer = txBuffer[majorFrame[minor][label]->bufferIndex];
minorFrame[label].label = majorFrame[minor][label]->label;
minorFrame[label].cid = 0;
minorFrame[label].length = majorFrame[minor][label]->lenght;
minorFrame[label].options = (majorFrame[minor][label]->crc)?MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_CRC_ENABLE:0;
minorFrame[label].options |= MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_SYNC;
}
else
{
minorFrame[label].buffer = 0;
minorFrame[label].label = 0;
minorFrame[label].cid = 0;
minorFrame[label].length = 0;
minorFrame[label].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
}
}
rc = mxfA629TxPeriodicMajorFrameSet(txChannel, 0, minor, NUM_X, minorFrame);
}
// Add Alternate frame
if(!rc)
{
minorFrame[0].buffer = txBuffer[LABEL[ALT_LABEL].bufferIndex];
minorFrame[0].label = LABEL[ALT_LABEL].label;
minorFrame[0].cid = 0;
minorFrame[0].length = LABEL[ALT_LABEL].lenght;
minorFrame[0].options = (LABEL[ALT_LABEL].crc)?MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_CRC_ENABLE:0;
minorFrame[0].options |= MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_SYNC;
rc = mxfA629TxPeriodicMajorFrameSet(txChannel, 0, 30, 1, minorFrame);
}
// set SYNC Frame
if(!rc)
{
memset(&sync, 0, sizeof(sync));
sync.altIndex = 30;
sync.syncIndex = 0;
rc = mxfA629TxPeriodicMajorFrameSyncSet(txChannel, 0, 0, &sync);
}
//------------------------------------------------//
// Add FC
for(index=0; index<NUM_LABEL && !rc; index++)
{
fc.enable = LABEL[index].fc;
fc.position = 1;
fc.mask = 0x00f0;
fc.modulo = 1;
rc = mxfA629MsgFreshnessCounterSet(txBuffer[LABEL[index].bufferIndex], &fc);
}
//------------------------------------------------//
//--- Set default data ---//
memset(&txRec629, 0, sizeof(txRec629));
for(index=0; index<NUM_LABEL && !rc; index++)
{
txRec629.control = 0;
txRec629.repeatCount = 1;
txRec629.dataSize = 2+(LABEL[index].lenght*2);
txRec629.data[0] = 0;
for(word=1; word<=LABEL[index].lenght; word++)
txRec629.data[word] = (uint16)(0x1111*index);
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[LABEL[index].bufferIndex], 1, &txRec629);
}
//------------------------------------------------//
//Start the major frame in the Independent mode
if(!rc)
{
majorProperties.mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
majorProperties.reserved = 0;
rc = mxfA629TxPeriodicMajorFrameStart(txChannel, 0, &majorProperties);
}
//Waiting 2 seconds. Allow major frame to run a little bit.
if(!rc)
mxfSleep(2000);
//Stop the major frame
if(!rc)
rc = mxfTxPeriodicMajorFrameStop(txChannel, 0, 0);
// Stop acquisition and read data
if (!rc)
rc = mxfRxAcqStop(rxBuffer);
if (!rc)
{
rc = mxfA629RxAcqRead(rxBuffer, 0, RX_BUFFER_SIZE, &status, &msgsCount, &bytesCount, hostBuffer);
if (!rc)
{
// Display received messages
rec629 = hostBuffer;
for(index=0; index<msgsCount && !rc; index++)
{
printf(" %03llu: Timetag=%012llu, Size=%u", index, rec629->timeTag, rec629->dataSize);
if(rec629->control & MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR)
printf(" CRC error");
if(rec629->control & MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR)
printf(" Data sync error");
if(rec629->control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR|MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR))
printf(" Manchester error");
if(rec629->control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR|MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR))
printf(" Parity error");
if(rec629->control & MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR)
printf(" End of String error");
printf("\n Data=");
for(word=0; word<rec629->dataSize/2; word++)
{
printf("%04X ", rec629->data[word]);
if(!((word+1)%8) && (word+1 < rec629->dataSize/2))
printf("\n ");
}
printf("\n");
mxfA629NextDataRecordPtrGet(rec629, &rec629);
}
}
}
// Catch any previous error
if (rc)
{
char buffer[256];
rc = mxfSystemErrorStringGet(server, rc, sizeof(buffer), buffer);
printf("%s\n", buffer);
}
printf("\nTerminating\n");
// Free all buffers and terminate
if (device)
if (hostBuffer)
free(hostBuffer);
printf("\nPress enter to terminate\n");
getchar();
return rc;
}
Updated 10/23/2023