MX Foundation 4
ar629_dual_xpp.c
/*****************************************************************************
//
// File:
// ar629_dual_xpp.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 use of the dual XPP feature.
//
// **** RT XPP #0 (RT0) schedule ********
//
// Label = 0x0100 | Label = 0x0200 | Label = 0x0300
// Label = 0x0101 | Label = 0x0201 |
// | Label = 0x0202 |
// | Label = 0x0203 |
// | Label = 0x0204 |
//
// **** RT XPP #1 (RT60) schedule ********
//
// Label = 0x0100 | Label = 0x0200 | Label = 0x0300
// | Label = 0x0201 | Label = 0x0301
// | Label = 0x0202 |
//
// It demonstrates how to:
//
// - Get handle to all 120 RTs channel with mxfModuleChannelAllGet().
// - Enable dual XPP with mxfAttributeUint64Set().
// - Configure TG and CID on RT #0 and RT #60 with mxfAttributeUint64Set().
// - Configure major frame on RT #0 and RT #60 with mxfA629TxPeriodicMajorFrameSet().
// - Start major frame on RT #0 and RT #60 with mxfA629TxPeriodicMajorFrameStart().
// - Stop major frame on RT #0 and RT #60 with mxfTxPeriodicMajorFrameStop().
//
// Hardware requirements:
// - MAXT FlexMulti-629.
//
*****************************************************************************/
#include "example.h"
#include <string.h>
//#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 TTL
void DisplayDataArray(uint64 recNum, MXF_A629_DATAREC* rec);
int main(void)
{
HMXF_CHANNEL ahChn[120], ahBM=0;
int iMsg,
iCnt;
MXF_A629_DATAREC aRec629[10];
MXF_A629_DATAREC *hostBuffer=NULL;
HMXF_SERVER server=0;
HMXF_BUFFER txBuffer[14]={0,0,0,0,0,0,0,0,0,0,0,0,0,0};
HMXF_BUFFER rxBuffer=0;
uint32 rc = 0;
HMXF_DEVICE device=0;
uint64 count=0, module=0, NbCh, NbBM, index, iTI=0;
uint64 status, msgsCount, bytesCount, indexBuffer;
char szBuffer[128];
// 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);
// Detects first BM
if (!rc)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_A629, MXF_SCLASS_BM_CHANNEL, 1, &NbBM, &ahBM);
// Detects all RT channels
if (!rc)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_A629, MXF_SCLASS_RT_CHANNEL, 120, &NbCh, ahChn);
// 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
// Allocates RX acquisition buffer
if (!rc)
rc = mxfRxAcqBufferAlloc(ahBM, RX_BUFFER_SIZE, &rxBuffer, NULL);
// Allocates TX Periodic Update Message buffer
for(index=0; index<8 && !rc; index++)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(ahChn[0], index, TX_BUFFER_SIZE, &txBuffer[index], NULL);
for(index=8; index<14 && !rc; index++)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(ahChn[60], index, TX_BUFFER_SIZE, &txBuffer[index], NULL);
// Allocates host buffer
if (!rc)
{
hostBuffer = (MXF_A629_DATAREC*)malloc(max(RX_BUFFER_SIZE, TX_BUFFER_SIZE));
if (!hostBuffer)
rc = MAXT_ERROR_MEM;
}
//Enable the DUAL XPP feature (global to IPack module)
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_A629_MODULE_XPP_DUAL_ENABLE, VMXF_ENABLE);
// 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");
}
while (!rc)
{
printf("\n\rPress ENTER to switch to RT #0, or 'Q' to Quit! ");
fgets(szBuffer, sizeof(szBuffer), stdin);
if (*szBuffer=='q' || *szBuffer=='Q')
rc = (uint32)-1;
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #0 -----------------------------------------//
//------------------------------------------------------------------------------//
// Stop and clear major frame on RT #0
if(!rc)
rc = mxfTxPeriodicMajorFrameStop(ahChn[0], 0, 0);
if(!rc)
rc = mxfTxPeriodicMajorFrameClear(ahChn[0], 0);
if(!rc)
rc = mxfAttributeUint64Set(ahChn[0], KMXF_A629_RT_TG, 5);
if(!rc)
rc = mxfAttributeUint64Set(ahChn[0], KMXF_A629_RT_CID, 5);
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = txBuffer[0];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x100;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length= 3;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[1];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x200;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 2;
aMsg629[iMsg].buffer = txBuffer[2];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x300;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 0, 3, aMsg629);
}
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = txBuffer[3];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x101;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[4];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x201;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 1, 2, aMsg629);
}
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].length = 0;
aMsg629[iMsg].cid = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[5];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x202;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 2, 2, aMsg629);
}
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].length = 0;
aMsg629[iMsg].cid = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[6];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x203;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 3, 2, aMsg629);
}
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].length = 0;
aMsg629[iMsg].cid = 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[7];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x204;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[0], 0, 4, 2, aMsg629);
}
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #0 DATA ------------------------------------//
//------------------------------------------------------------------------------//
if (!rc)
{
memset((char*)&Rec629, 0, sizeof(MXF_A629_DATAREC));
memset((char*)aRec629, 0, 10 * sizeof(MXF_A629_DATAREC));
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x1108;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[0], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x2208;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[3], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x3308;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[1], 1, &Rec629);
}
if (!rc)
{
p = aRec629;
for (iCnt=0; iCnt<10; iCnt++)
{
p->repeatCount = 10;
p->control = 0;
p->dataSize = 8;
p->data[1] = (uint16)iCnt; // Data = 0, 1, 2, etc
}
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[4], 10, aRec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x5508;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[5], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x6608;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[6], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x7708;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[7], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x8808;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[2], 1, &Rec629);
}
//--------------------------------------------------------------------//
//------------------------ START RT #0 -------------------------------//
//--------------------------------------------------------------------//
if (!rc)
{
// *** START RT #0 ***
iTI = 25000000;
if (!rc)
rc = mxfAttributeUint64Set(module,KMXF_A629_MODULE_TI,iTI);
}
if(!rc)
{
majorProperties.mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
majorProperties.reserved = 0;
rc = mxfA629TxPeriodicMajorFrameStart(ahChn[0], 0, &majorProperties);
}
if (!rc)
{
printf("\n\rRT #0 started.\n\r");
printf("\n\rPress ENTER to switch to RT #60, or 'Q' to Quit! ");
fgets(szBuffer, sizeof(szBuffer), stdin);
if (*szBuffer=='q' || *szBuffer=='Q')
rc = (uint32)-1;
}
// Stop and clear major frame on RT #60
if(!rc)
rc = mxfTxPeriodicMajorFrameStop(ahChn[60], 0, 0);
if(!rc)
rc = mxfTxPeriodicMajorFrameClear(ahChn[60], 0);
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #60 ----------------------------------------//
//------------------------------------------------------------------------------//
if(!rc)
rc = mxfAttributeUint64Set(ahChn[60], KMXF_A629_RT_TG, 5);
if(!rc)
rc = mxfAttributeUint64Set(ahChn[60], KMXF_A629_RT_CID, 6);
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = txBuffer[8];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x100;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length= 3;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[9];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x200;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 2;
aMsg629[iMsg].buffer = txBuffer[10];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x300;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[60], 0, 0, 3, aMsg629);
}
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length= 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[11];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x201;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
iMsg = 2;
aMsg629[iMsg].buffer = txBuffer[12];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x301;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[60], 0, 1, 3, aMsg629);
}
if (!rc)
{
iMsg = 0;
aMsg629[iMsg].buffer = 0;
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_UNUSED;
aMsg629[iMsg].label = 0;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length= 0;
iMsg = 1;
aMsg629[iMsg].buffer = txBuffer[13];
aMsg629[iMsg].options = MXF_A629_TXPERIODIC_MJRFRAME_MSG_OPT_DEFAULT;
aMsg629[iMsg].label = 0x202;
aMsg629[iMsg].cid = 0;
aMsg629[iMsg].length = 3;
rc = mxfA629TxPeriodicMajorFrameSet(ahChn[60], 0, 2, 2, aMsg629);
}
//------------------------------------------------------------------------------//
//------------------- INITIALIZE RT #60 DATA -----------------------------------//
//------------------------------------------------------------------------------//
if (!rc)
{
memset((char*)&Rec629, 0, sizeof(MXF_A629_DATAREC));
memset((char*)aRec629, 0, 10 * sizeof(MXF_A629_DATAREC));
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x1108;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[8], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x3308;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[9], 1, &Rec629);
}
if (!rc)
{
p = aRec629;
for (iCnt=0; iCnt<10; iCnt++)
{
p->repeatCount = 10;
p->control = 0;
p->dataSize = 8;
p->data[1] = (uint16)(220 + iCnt); // Data = 220, 221, 222, etc
}
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[11], 10, aRec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x5508;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[13], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x8808;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[10], 1, &Rec629);
}
if (!rc)
{
Rec629.repeatCount = 1;
Rec629.control = 0;
Rec629.dataSize = 8;
Rec629.data[1] = 0x9908;
rc = mxfA629TxPeriodicUpdateMsgWrite(txBuffer[12], 1, &Rec629);
}
//--------------------------------------------------------------------//
//------------------------ START RT #60 ------------------------------//
//--------------------------------------------------------------------//
if (!rc)
{
// With the DualXPP mode enabled, calling fct mxfA629TxPeriodicMajorFrameStart()
// on a "mirror channel" will change XPP scheduling for that
// "same Rt" without stopping or altering the ongoing scheduling.
iTI = 25000000;
if (!rc)
rc = mxfAttributeUint64Set(module,KMXF_A629_MODULE_TI,iTI);
}
if(!rc)
{
majorProperties.mode = MXF_A629_TXPERIODIC_MJRFRAME_PROPERTIES_MODE_INDEPENDENT;
majorProperties.reserved = 0;
rc = mxfA629TxPeriodicMajorFrameStart(ahChn[60], 0, &majorProperties);
}
if (!rc)
printf("\n\rRT #60 started.\n\r");
}
if (rc==-1)
rc = MAXT_SUCCESS;
//Stop RT's
if(!rc)
rc = mxfTxPeriodicMajorFrameStop(ahChn[0], 0, 0);
if(!rc)
rc = mxfTxPeriodicMajorFrameStop(ahChn[60], 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);
DisplayDataArray(msgsCount, hostBuffer);
}
if (!rc)
printf("\n\rTest done.\n\r");
else
{
char errorString[200];
if(mxfSystemErrorStringGet(server, rc, sizeof(errorString), errorString))
sprintf (errorString,"ERROR # 0x%X", rc);
printf("%s\n\r", errorString);
}
// Free all buffers and terminate
if (rxBuffer)
mxfRxAcqBufferFree(rxBuffer);
for (indexBuffer = 0; indexBuffer < 14; indexBuffer++)
{
if (txBuffer[indexBuffer])
mxfTxPeriodicUpdateMsgBufferFree(txBuffer[indexBuffer]);
}
// Unloads MX Foundation library
// Disconnects from MX Foundation library
printf("\n\rPress ENTER to terminate ");
fgets(szBuffer, sizeof(szBuffer), stdin);
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 10/23/2023