MX Foundation 4
hfce_tx_error_injection.c
/*****************************************************************************
//
// File:
// hfce_tx_error_injection.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 usage of HFCE channel class
// for transmission and reception with an error injection in transmission.
//
// Hardware requirements:
// - 500 series carrier with IPM-HFCE
// - loopback between TX0 and RX0
//
*****************************************************************************/
#include "example.h"
#define MAX_TX_RECORDS_TO_TRANSMIT 8
#define LOOPBACK
#define LABEL 0xCD10
#define PAYLOAD_SIZE 6
void DisplayDataArray(uint64 recNum, MXF_HFCE_DATAREC* rec);
int main(void)
{
uint32 rc;
HMXF_SERVER server=0;
HMXF_CHANNEL rxChannel=0;
HMXF_CHANNEL txChannel=0;
HMXF_BUFFER rxBuffer=0;
HMXF_BUFFER txBuffer=0;
size_t txBufferSize=0;
size_t rxBufferSize=0;
MXF_HFCE_DATAREC* rxHostBuffer=0;
MXF_HFCE_DATAREC* txHostBuffer=0;
uint64 rxAcqStatus=0;
uint64 msgCount=0;
uint64 byteCount=0;
uint64 data;
uint64 word;
// Connects to services and initialize environment
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
// Initializes MX Foundation library
if (!rc)
{
printf("Starting ...\n");
rc = mxfSystemInit(server);
}
// Gets handle of first HFCE RX channel
if(!rc)
rc = mxfChannelGet(server, MXF_CLASS_HFCE, MXF_SCLASS_RX_CHANNEL, MXF_MODULE_ALL, 0, &rxChannel);
// Gets handle of first HFCE TX channel
if (!rc)
rc = mxfChannelGet(server, MXF_CLASS_HFCE, MXF_SCLASS_TX_CHANNEL, MXF_MODULE_ALL, 0, &txChannel);
// Sets speed
if (!rc)
rc = mxfAttributeUint64Set(rxChannel, KMXF_HFCE_SPEED, 400000);
if(!rc)
rc = mxfAttributeUint64Set(txChannel, KMXF_HFCE_SPEED, 400000);
// Sets interframe idle pattern
if (!rc)
rc = mxfAttributeUint64Set(txChannel, KMXF_HFCE_TX_INTERFRAME_TIME_FILL, VMXF_HFCE_TX_INTERFRAME_TIME_FILL_IDLE_PATTERN);
// Enables loopback
#ifdef LOOPBACK
if(!rc)
rc = mxfAttributeUint64Set(rxChannel, KMXF_HFCE_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Allocates buffer for tx data
if(!rc)
{
txBufferSize = MAX_TX_RECORDS_TO_TRANSMIT*sizeof(MXF_HFCE_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_HFCE_DATAREC*) calloc(1, txBufferSize);
if(!txHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Allocates buffer for RX data
if(!rc)
{
rxBufferSize = 4*1024;
// Allocates RX acquisition static buffer
rc=mxfRxAcqBufferAlloc(rxChannel, rxBufferSize, &rxBuffer, NULL);
// Host buffer allocation
if(!rc)
{
rxHostBuffer = (MXF_HFCE_DATAREC*) calloc(1, rxBufferSize);
if(!rxHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Sets timebase to RTC nsec
if(!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_NSEC);
// Starts acquisition
if(!rc)
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
if(!rc)
{
rec = txHostBuffer;
//Prepares records to send for basic transmission/reception test with an error injection in transmission for the 3rd record
for(data=0; data<MAX_TX_RECORDS_TO_TRANSMIT; data++)
{
rec->timeTag = 0;
rec->control = (data != 2)?0:MXF_HFCE_TX_REC_CTRL_FCS_ERROR;
rec->repeatCount = 1;
rec->dataSize = (PAYLOAD_SIZE+2)*2;
rec->reserved = 0;
rec->data[0] = LABEL;
rec->data[1] = PAYLOAD_SIZE;
for(word=0; word < PAYLOAD_SIZE; word++)
{
rec->data[word+2] = (uint16)(0x1111*1);
}
rc = mxfHFCENextDataRecordPtrGet(rec, &rec);
}
}
//if (!rc)
// DisplayDataArray(MAX_TX_RECORDS_TO_TRANSMIT, txHostBuffer);
if(!rc)
{
printf("Transmitting ...\n");
// Transmits strings on relative record time
rc = mxfHFCETxAperiodicWrite(txBuffer, MXF_TXAPERIODIC_FLAG_DEFAULT, 0, MAX_TX_RECORDS_TO_TRANSMIT, txHostBuffer);
}
if(!rc)
mxfSleep(1000);
if(!rc)
{
printf("Receiving ...\n");
// Reads rx buffer
rc = mxfHFCERxAcqRead(rxBuffer, 0, rxBufferSize, &rxAcqStatus, &msgCount, &byteCount, rxHostBuffer);
}
if(!rc)
printf("String received count = %"PRIu64" \n", msgCount);
if(!rc)
{
// Displays received strings
DisplayDataArray(msgCount, rxHostBuffer);
}
// Stops acquisition
if(!rc)
rc = mxfRxAcqStop(rxBuffer);
// Frees device and host buffers
if(txBuffer)
if(rxBuffer)
mxfRxAcqBufferFree(rxBuffer);
if(txHostBuffer)
free(txHostBuffer);
if(rxHostBuffer)
free(rxHostBuffer);
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;
}
void DisplayDataArray(uint64 recNum, MXF_HFCE_DATAREC* rec)
{
uint64 iRec,
iData;
printf("\n");
for(iRec=0; iRec < recNum; iRec++)
{
printf("%03"PRIu64" %010"PRIu64" 0x%08x %04u ", iRec, p->timeTag, p->control, p->dataSize);
for(iData=0; iData < p->dataSize/2; iData++)
{
if((p->dataSize % 2) == 0)
printf("%04x ", p->data[iData]);
else
printf("%02x %02x ", (uint8)p->data[iData], (uint8)(p->data[iData]>>8));
if(!((iData+1)%8) && (iData+1 < p->dataSize/2))
printf("\n ");
}
printf("\n");
if(p->control & MXF_HFCE_RX_REC_CTRL_DECODING_ERROR)
printf("Decoding error ");
if(p->control & MXF_HFCE_RX_REC_CTRL_FCS_ERROR)
printf("FCS error ");
if(p->control & MXF_HFCE_RX_REC_CTRL_LENGTH_ERROR)
printf("Frame Size error ");
printf("\n");
}
}
Updated 10/23/2023