MX Foundation 4
discrete_pulse_clock.c
/*****************************************************************************
//
// File:
// discrete_pulse_clock.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 pulse mode of discrete
// for transmission.
//
// Hardware requirements:
// - MAXT Flex.
//
*****************************************************************************/
#include "example.h"
#define MAX_TX_RECORDS_TO_TRANSMIT 1
#define LOCAL
int main(void)
{
uint32 rc;
HMXF_SERVER server=0;
HMXF_DEVICE device=0;
HMXF_MODULE module=0;
HMXF_CHANNEL txChannel=0;
HMXF_BUFFER txBuffer=0;
uint64 moduleCount=0;
uint64 channelCount=0;
size_t txBufferSize=0;
MXF_DISCRETE_DATAREC* txHostBuffer=0;
uint64 data;
// 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", TRUE, &server);
#endif
if(rc!=MAXT_SUCCESS)
{
printf("Failed to connect; rc=0x%08x", rc);
getchar();
return 0;
}
// Initializes MX Foundation library
if (!rc)
{
printf("Starting ...\n");
rc = mxfSystemInit(server);
}
// Gets the device handle
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
// Gets handle of first DIO_eh module
if (!rc)
rc = mxfDeviceModuleAllGet(device, MXF_MODULE_DIOFIFO_EH, 1, &moduleCount, &module);
// Gets handle of first pulse TX channel
if (!rc)
rc = mxfModuleChannelAllGet(module, MXF_CLASS_DISCRETE, MXF_SCLASS_TX_CHANNEL, 1, &channelCount, &txChannel);
// If channel not found, return an error
if(!rc && !channelCount)
rc = MAXT_ERROR_NOT_FOUND;
// Allocate buffer for tx data
if(!rc)
{
txBufferSize = MAX_TX_RECORDS_TO_TRANSMIT*sizeof(MXF_DISCRETE_DATAREC);
// Allocates TX Aperiodic static buffer for HIGH priority queue
rc=mxfTxAperiodicBufferAlloc(txChannel, MXF_TXAPERIODIC_PRIORITY_HIGH, txBufferSize, &txBuffer, NULL);
// Host buffer allocation
if(!rc)
{
txHostBuffer = (MXF_DISCRETE_DATAREC*) calloc(1, txBufferSize);
if(!txHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Sets timebase to RTC nsec
if(!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
if(!rc)
{
// Prepares records
rec = txHostBuffer;
for(data=0; data<MAX_TX_RECORDS_TO_TRANSMIT; data++)
{
rec->timeTag = 0;
rec->control = MXF_DISCRETE_TX_REC_CTRL_PULSE_START;
rec->repeatCount = 0; // forever
rec->data = 0x0000;
rec->edge = 0x0003;
rec->highDuration = (uint32)(20000000); //LEDs 0 and 1 stay on for 200 msec
rec->lowDuration = (uint32)(10000000); //LEDs 0 and 1 stay off for 100 msec
}
}
if(!rc)
{
printf("Transmitting ...\n");
rc = mxfDiscreteTxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, MAX_TX_RECORDS_TO_TRANSMIT, txHostBuffer);
}
if(!rc)
{
mxfSleep(10000);
}
// Stop pulse
if(!rc)
{
// Prepares record
rec = txHostBuffer;
rec->timeTag = 0;
rec->control = 0;
rec->repeatCount = 1;
rec->data = 0x0000;
rec->edge = 0x0003;
rec->highDuration = 0;
rec->lowDuration = 0;
rc = mxfDiscreteTxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, 1, txHostBuffer);
}
// Frees device and host buffers
if(txBuffer)
if(txHostBuffer)
free(txHostBuffer);
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");
// Unloads MX Foundation library
// Disconnects from MX Foundation library
printf("\nPress a key to terminate\n");
getchar();
return rc;
}
Updated 10/23/2023