MX Foundation 4
ar629_aperiodic_mode.c
/*****************************************************************************
//
// File:
// ar629_aperiodic_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 example demonstrates the aperiodic mode functionnality.
//
// This mode allows to transmit A629 message without a major frame.
// There is some limitation of using this mode:
// - Only first RT channel can be used
// - No major frame can be used
// - This RT channel should be the only transmitter on the bus, otherwise
// collision could happen since no A629 timers (TI, SG and TG) are used
//
// Hardware requirements:
// - MAXT FlexMulti-629.
//
*****************************************************************************/
#include "example.h"
//#define LOCAL
#define TTL
#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 2
#define TX_BUFFER_SIZE MAX_TX_RECORDS_TO_TRANSMIT*sizeof(MXF_A629_DATAREC)
void DisplayDataArray(uint64 recNum, MXF_A629_DATAREC* rec);
//***************************************************************************
//
// Main()
//
//***************************************************************************
int main(void)
{
MXF_A629_DATAREC *hostBuffer=NULL;
HMXF_SERVER server=0;
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=0;
uint32 rc;
uint64 status, msgsCount, bytesCount;
uint32 length;
int i;
// Connects to services and initialize environment
#ifdef LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
#endif
// Initializes MX Foundation library
if (!rc)
{
printf("Starting ...\n");
rc = mxfSystemInit(server);
}
// Gets the first device handle
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
if (!rc)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_A629MRT_EH, 1, &count, &module);
// Obtains 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);
// Obtains 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, returns an error
if(!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
// Sets timebase to 64-bit nanoseconds
if (!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Sets 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
// Enable Aperiodic mode
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_APERIODIC_MODE, VMXF_ENABLE);
// Allocates RX acquisition buffer
if (!rc)
rc = mxfRxAcqBufferAlloc(rxChannel, RX_BUFFER_SIZE, &rxBuffer, NULL);
// Allocates one TX Aperiodic buffer
if(!rc)
rc = mxfTxAperiodicBufferAlloc(txChannel, MXF_TXAPERIODIC_PRIORITY_HIGH, TX_BUFFER_SIZE, &txBuffer, NULL);
// Allocates host buffer
if (!rc)
{
hostBuffer = (MXF_A629_DATAREC*)malloc(max(RX_BUFFER_SIZE, TX_BUFFER_SIZE));
if (!hostBuffer)
rc = MAXT_ERROR_MEM;
}
// 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");
}
// Transmits one message with two wordstrings. Label and CID are set in data[0]
if(!rc)
{
aRec629 = hostBuffer;
memset(hostBuffer, 0, TX_BUFFER_SIZE);
//Sets the lentgh of this label/CID
length = 8; //8 bytes (label + 3 data word)
aRec629->control = MXF_A629_TX_REC_CTRL_PPSYNC | MXF_A629_TX_REC_CTRL_PSYNC; // First wordstring of message must have PPSYNC and PSYNC set
aRec629->repeatCount = 1;
aRec629->dataSize = length;
aRec629->data[0] = 0x001 | (0x2 << 12); // label 1, CID 2
aRec629->data[1] = 0x1104;
aRec629->data[2] = 0x1105;
aRec629->data[3] = 0x1106;
mxfA629NextDataRecordPtrGet(aRec629, &aRec629);
//Set the lentgh of this label/CID
length = 120; //120 bytes (label + 59 data words)
aRec629->control = MXF_A629_TX_REC_CTRL_CRC; // MXF_A629_TX_REC_CTRL_CRC specifies to compute and send a CRC. It will be added after the last word.
aRec629->repeatCount = 1;
aRec629->dataSize = length;
aRec629->data[0] = 0x002 | (0x2 << 12); // label 2, CID 2
aRec629->data[1] = 0x0178;
for (i = 2; i < (int)length/2; i++)
{
aRec629->data[i] = (uint16)i;
}
rc = mxfTxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, 2, hostBuffer);
}
//------------------------------------------------//
//Waiting 1 second. Allows data to be transmitted.
mxfSleep(1000);
// Stop acquisition and read data
if (!rc)
rc = mxfRxAcqStop(rxBuffer);
if (!rc)
{
rc = mxfA629RxAcqRead(rxBuffer, 0, RX_BUFFER_SIZE, &status, &msgsCount, &bytesCount, hostBuffer);
DisplayDataArray(msgsCount, hostBuffer);
}
if(rc)
{
char errorString[200];
if(mxfSystemErrorStringGet(server, rc, sizeof(errorString), errorString))
sprintf (errorString,"ERROR # 0x%X", rc);
printf("%s\n\r", errorString);
}
printf("Terminating ...\n");
// Free all buffers and terminate
if (rxBuffer)
mxfRxAcqBufferFree(rxBuffer);
if (txBuffer)
if (hostBuffer)
free(hostBuffer);
// Unloads MX Foundation library
// Disconnects from MX Foundation library
printf("\nPress a key to terminate\n");
getchar();
return rc;
}
void DisplayDataArray(uint64 recNum, MXF_A629_DATAREC* rec)
{
uint64 iRec,
iData;
printf("\n");
for(iRec=0; iRec < recNum; iRec++)
{
printf("%03llu %010llu %02u ", iRec, p->timeTag, p->dataSize);
if(p->control & MXF_A629_RX_REC_CTRL_STRING_CRC_ERROR)
printf(" CRC error");
if(p->control & MXF_A629_RX_REC_CTRL_STRING_DATA_SYNC_ERROR)
printf(" Data sync error");
if(p->control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_MANCHESTER_ERROR|MXF_A629_RX_REC_CTRL_STRING_DATA_MANCHESTER_ERROR))
printf(" Manchester error");
if(p->control & (MXF_A629_RX_REC_CTRL_STRING_LABEL_PARITY_ERROR|MXF_A629_RX_REC_CTRL_STRING_DATA_PARITY_ERROR))
printf(" Parity error");
if(p->control & MXF_A629_RX_REC_CTRL_STRING_EOS_ERROR)
printf(" End of String error");
for(iData=0; iData < p->dataSize/2; iData++)
{
printf("%04x ", p->data[iData]);
if(!((iData+1)%8) && (iData+1 < p->dataSize/2))
printf("\n ");
}
printf("\n");
}
}
Updated 09/17/2023