MX Foundation 4
ascb_bm.c
/*****************************************************************************
//
## File:
## ascb_bm.c
//
// Copyright (c) MAX Technologies Inc. 1988-2016, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This example demonstrates the basic usage of a ASCB bus monitor.
// It can be run with ascb_user and ascb_bc at the same time.
//
// Hardware requirements:
// - MAXT 500 series carrier with IPM-ASCB
//
*****************************************************************************/
#include "example.h"
#define MAX_TO_READ 100
struct REQUEST_INFO {
uint64 a; // request address
uint64 fc; // refresh counter
uint64 checksum; // software checksum
uint64 crc; // software crc
uint64 l; // length
};
#define NUM_REQUEST 10
const struct REQUEST_INFO requestInfo[NUM_REQUEST] = {
{0x1B,0,1,0,36},
{0x30,1,1,0,84},
{0x06,1,1,0,54},
{0x02,1,1,0,74},
{0x70,1,1,0,76},
{0x2B,1,1,0,58},
{0x23,1,1,0,238},
{0x12,1,1,0,156},
{0x1A,1,1,0,100},
{0x46,1,1,0,60} };
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device;
HMXF_MODULE module=0;
HMXF_CHANNEL channel=0;
HMXF_BUFFER acqBuf=0;
MXF_ASCB_DATAREC rec[MAX_TO_READ];
uint64 status, msgCount, byteCount;
int c;
int i;
char tmpStr[1024];
char disp[64], data[64];
uint32 index;
int doInit=1;
// Connects to services and initialize environment
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
if (rc != MAXT_SUCCESS)
{
printf("Failed to connect; rc=0x%08x", rc);
getchar();
return 0;
}
// Initializes MX Foundation library
printf("Starting ...\n");
if (!rc)
{
rc = mxfSystemInit(server);
if (rc == MAXT_ERROR_ANOTHER_PROCESS_RUNNING)
{
// if another MX Foundation application is running, only load MX-Foundation library, otherwise reset cards first
rc = mxfSystemResourcesInit(server, 0);
doInit = 0;
}
}
// Get handle of first ASCB BM channel
if (!rc)
rc = mxfChannelGet(server, MXF_CLASS_ASCB, MXF_SCLASS_BM_CHANNEL, MXF_MODULE_ALL, 0, &channel);
if (!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_USEC);
if (!rc)
rc = mxfChannelInfoGet(channel, &device, &module);
// setup
if (!rc && doInit)
{
rc = mxfAttributeUint64Set(module, KMXF_ASCB_MODULE_CLOCK_MODE, VMXF_DISABLE);
// internal loopback
if (!rc)
rc = mxfAttributeUint64Set(module, KMXF_ASCB_MODULE_TX_RX_TEST_LB, TRUE);
}
for(i=0; i<NUM_REQUEST && !rc; i++)
{
// message length error detection
rc = mxfASCBMsgLengthSet(channel, requestInfo[i].a, requestInfo[i].l);
// checksum error detection
if(!rc)
rc = mxfASCBMsgChecksumEnableSet(channel, requestInfo[i].a, requestInfo[i].checksum);
// crc error detection
if (!rc)
rc = mxfASCBMsgCrcEnableSet(channel, requestInfo[i].a, requestInfo[i].crc);
// enable the freshness counter error detection
if(!rc)
{
fc.position = 0;
fc.mask = 0x0700;
fc.enable = requestInfo[i].fc;
rc = mxfASCBMsgFreshnessCounterSet(channel, requestInfo[i].a, &fc);
}
}
// allocate buffer
if (!rc)
{
rc = mxfRxAcqBufferAlloc(channel, sizeof(rec), &acqBuf, NULL);
if(rc == MAXT_ERROR_BUFFER_ALLOCATED)
rc = mxfRxAcqBufferGet(channel, &acqBuf);
}
// Start the Acquisition
if (!rc)
rc = mxfRxAcqStart(acqBuf, 0, 0, 0);
c = 0;
// Read and display recv records (1000 times)
while((rc == MAXT_SUCCESS) && (c < 1000))
{
if (c == 0)
{
printf("| TimeTag | Control | Adrs | Data |\n");
printf("------------------------------------------------------------------------\n");
}
rc = mxfRxAcqRead(acqBuf, MAX_TO_READ, sizeof(rec), &status, &msgCount, &byteCount, rec);
if ((rc == MAXT_SUCCESS) && (msgCount != 0))
{
p = rec;
for (i = 0; i < (int)msgCount; i++)
{
/* Extracting Timetag */
printf("| %-14.14llu |", p->timeTag);
/* Extracting Control */
if (!(p->control&(MXF_ASCB_RX_REC_CTRL_HWCRC_ERROR | MXF_ASCB_RX_REC_CTRL_DATACHKSM_ERROR | MXF_ASCB_RX_REC_CTRL_DATACRC_ERROR |
MXF_ASCB_RX_REC_CTRL_FC_ERROR | MXF_ASCB_RX_REC_CTRL_FRAME_ABORT | MXF_ASCB_RX_REC_CTRL_SYNC_LOST | MXF_ASCB_RX_REC_CTRL_BYTE_COUNT_ERROR)))
printf(" %-7.9s |", " ok ");
else
printf(" %-7.9s |", " error ");
printf(" %02x |", p->data[0] & 0x00ff);
/* Extracting Data */
tmpStr[0] = '\0';
disp[0] = '\0';
for (index = 0; index < (p->dataSize + 1) / 2; index++)
{
if (index && !(index % 8)) // To display 8 data per line.
{
strcat(tmpStr, disp);
disp[0] = '\0';
strcat(tmpStr, " |\n| | ");
}
sprintf(data, "%04X", p->data[index]);
strcat(disp, data);
}
if (index)
{
if(disp[0] != '\0')
{
sprintf(data, "%-32s", disp);
strcat(tmpStr, data);
}
printf(" %s |", tmpStr);
}
printf("\n");
}
printf("------------------------------------------------------------------------\n");
}
// Avoid using all cpu resource
mxfSleep(25);
c++;
}
if(!rc)
rc = mxfRxAcqStop(acqBuf);
if(!rc)
rc = mxfRxAcqClear(acqBuf);
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");
if(acqBuf)
// Unloads MX Foundation library
rc = mxfSystemTerminate(server);
if (rc == MAXT_ERROR_ANOTHER_PROCESS_RUNNING)
// Disconnects from MX Foundation library
printf("\nPress a key to terminate\n");
getchar();
return rc;
}
Updated 10/23/2023