MX Foundation 4
flexdac_relative_timing.c
/*****************************************************************************
//
// File:
// flexdac_relative_timing.c
//
// Copyright (c) MAX Technologies Inc. 1988-2022, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the configuration of a FlexDAC module and perform relative
// timing record transmission on 8 single-ended channels and 8 differential channels.
//
// Hardware requirements:
// - MAXT FlexMAX with FlexDAC
//
*****************************************************************************/
#include "example.h"
#define MAX_ANALOG_CHN_NUM 24
#define MAX_REC 10
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_MODULE module=0;
HMXF_CHANNEL txChn[MAX_ANALOG_CHN_NUM];
HMXF_BUFFER txBuffer;
MXF_FLEXANALOG_DATAREC recANALOG[MAX_REC];
int iPort, iRec;
uint64 count, txMask, index;
uint64 mask=0x0000000000FF00FFULL;
// Connect to services and initialize environment
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
if (rc != MAXT_SUCCESS)
{
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 a handle to 24 Analog FlexDAC channel
if (!rc)
rc = mxfChannelAllGet(server, MXF_CLASS_FLEXANALOG, MXF_SCLASS_TX_CHANNEL, MXF_MODULE_ALL, MAX_ANALOG_CHN_NUM, &count, txChn);
// If channel not found, return an error
if (!rc && !count)
rc = MAXT_ERROR_NOT_FOUND;
if (!rc)
rc = mxfChannelInfoGet(txChn[0], NULL, &module);
// Set time base
if(!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_USEC);
// Set the output range of the first 8 to +/-10V single-ended and 16-23 to 10V differential
for(iPort=0; iPort<MAX_ANALOG_CHN_NUM && !rc; iPort++)
{
if(iPort < 8) // single-ended
{
rc = mxfAttributeUint64Set(txChn[iPort], KMXF_FLEXDAC_CHN_OUTPUT_RANGE, VMXF_FLEXDAC_CHN_OUTPUT_RANGE_SE_BIPOLAR_10V);
}
else // differential
{
// In differential, only positive pin is used to set attribute
if(!(iPort & 0x8))
rc = mxfAttributeUint64Set(txChn[iPort], KMXF_FLEXDAC_CHN_OUTPUT_RANGE, VMXF_FLEXDAC_CHN_OUTPUT_RANGE_DIFF_BIPOLAR_10V);
}
}
// Set the channel selection to 8 single-ended and 8 differential
if(!rc)
rc = mxfAttributeUint64Set(module, KMXF_FLEXDAC_MODULE_CHN_SELECTION, mask);
// Allocate TX aperiodic buffer
if(!rc)
rc = mxfTxAperiodicBufferAlloc(module, MXF_TXAPERIODIC_PRIORITY_NORMAL, sizeof(recANALOG), &txBuffer, NULL);
// Transmit loop
if(!rc)
{
p = recANALOG;
for (iRec=0; !rc && iRec<MAX_REC; iRec++)
{
p->timeTag = iRec*1000000; // 1 sec
p->control = 0;
p->repeatCount = 1;
p->reserved = 0;
p->dataSize = 32; // 2 bytes each
p->dataMask = mask; // update all channels
txMask = mask;
index = 0;
iPort = 0;
while(txMask && !rc)
{
if(txMask & 0x1)
{
rc = mxfFlexDacDataConvert(txChn[iPort], (float)iRec, &p->data[index]);
index++;
}
iPort++;
txMask >>= 1;
}
}
if(!rc)
rc = mxfFlexAnalogTxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_USE_RECORD_RELATIVE_TIME, 0, MAX_REC, recANALOG);
}
// Wait a little
if(!rc)
mxfSleep(10000);
if (rc)
{
char buffer[256];
if (mxfSystemErrorStringGet(server, rc, sizeof(buffer), buffer))
sprintf(buffer, "ERROR # 0x%08X", rc);
printf("%s\n\r", buffer);
}
// Terminate
printf("\nPress enter to terminate\n");
getchar();
return rc;
}
Updated 10/23/2023