MX Foundation 4
ascb_user.c
/*****************************************************************************
//
## File:
## ascb_user.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 USER.
// It can be run with ascb_bm and ascb_bc at the same time.
//
// Hardware requirements:
// - MAXT 500 series carrier with IPM-ASCB
//
*****************************************************************************/
#include "example.h"
struct RESPONSE_INFO {
uint64 a; // response address
uint64 fc; // refresh counter
uint64 checksum; // software checksum
uint64 crc; // software crc
uint64 l; // length
};
#define NUM_RESPONSE 4
const struct RESPONSE_INFO responseInfo[NUM_RESPONSE] = {
{0x1B,0,1,0,36},
{0x02,1,1,0,74},
{0x03,1,1,0,74},
{0x70,1,1,0,76} };
int main(void)
{
HMXF_SERVER server;
HMXF_DEVICE device;
HMXF_MODULE module=0;
HMXF_CHANNEL users[NUM_RESPONSE];
HMXF_BUFFER userBuf[NUM_RESPONSE][4]={0};
uint32 rc;
int i;
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 ASCB User 9B (FTIU)
if (!rc)
rc = mxfChannelGet(server, MXF_CLASS_ASCB, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 0x9B-0x80, &users[0]);
// Get handle of ASCB User 82 (SENSOR-L)
if(!rc)
rc = mxfChannelGet(server, MXF_CLASS_ASCB, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 0x82-0x80, &users[1]);
// Get handle of ASCB User 83 (SENSOR-R)
if (!rc)
rc = mxfChannelGet(server, MXF_CLASS_ASCB, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 0x83-0x80, &users[2]);
// Get handle of ASCB User F0 (DAU,1A)
if (!rc)
rc = mxfChannelGet(server, MXF_CLASS_ASCB, MXF_SCLASS_RT_CHANNEL, MXF_MODULE_ALL, 0xF0-0x80, &users[3]);
if (!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_USEC);
if (!rc)
rc = mxfChannelInfoGet(users[0], &device, &module);
// setup
if (!rc && doInit)
rc = mxfAttributeUint64Set(module, KMXF_ASCB_MODULE_CLOCK_MODE, VMXF_DISABLE);
// Configure USERS
for(i=0; i<NUM_RESPONSE && !rc; i++)
{
rc = mxfASCBUserEnableSet(users[i], FALSE);
if(!rc)
rc = mxfAttributeUint64Set(users[i], KMXF_ASCB_USER_LEFT_BUS_SELECT, VMXF_ASCB_USER_BUS_SELECT_PRIMARY);
if (!rc)
rc = mxfAttributeUint64Set(users[i], KMXF_ASCB_USER_RIGHT_BUS_SELECT, VMXF_ASCB_USER_BUS_SELECT_NONE);
// set response address for user left
if (!rc)
rc = mxfAttributeUint64Set(users[i], KMXF_ASCB_USER_LEFT_BUS_ADRS, responseInfo[i].a);
// set message length for user left
if (!rc)
rc = mxfASCBMsgLengthSet(users[i], 0, responseInfo[i].l);
// checksum for user left
if (!rc)
rc = mxfASCBMsgChecksumEnableSet(users[i], 0, responseInfo[i].checksum);
// CRC for user left
if (!rc)
rc = mxfASCBMsgCrcEnableSet(users[i], 0, responseInfo[i].crc);
// Refresh Counter for user left
if (!rc)
{
fc.position = 0;
fc.mask = 0x0700;
fc.enable = responseInfo[i].fc;
rc = mxfASCBMsgFreshnessCounterSet(users[i], 0, &fc);
}
if(!rc)
{
rc = mxfTxPeriodicUpdateMsgBufferAlloc(users[i], 0, 4096, &userBuf[i][0], NULL);
if(rc == MAXT_ERROR_BUFFER_ALLOCATED)
rc = mxfTxPeriodicUpdateMsgBufferGet(users[i], 0, &userBuf[i][0]);
if (!rc)
{
rc = mxfASCBUserBusEnableSet(users[i], 0, (responseInfo[i].a==0x70)?0:-1, userBuf[i][0]);
if(rc == MAXT_ERROR_ALREADY_ATTACHED)
{
rc = mxfASCBUserBusEnableSet(users[i], 0, (responseInfo[i].a==0x70)?0:-1, 0);
if(!rc)
rc = mxfASCBUserBusEnableSet(users[i], 0, (responseInfo[i].a==0x70)?0:-1, userBuf[i][0]);
}
}
}
if (!rc)
{
//--- Set data on the first 6 bytes (remaining bytes will be 0) ---//
//User data on the Left bus
rec.timeTag = 0;
rec.control = 0;
rec.repeatCount = 1;
rec.dataSize = 6; //6 bytes
rec.msgPhase = 0;
rec.data[0] = 0x4000;
rec.data[1] = 0x2222;
rec.data[2] = 0x3333;
//User data on the left bus
rc = mxfASCBTxPeriodicUpdateMsgWrite(userBuf[i][0], 1, &rec);
}
if(!rc)
{
if(responseInfo[i].a == 0x70) // DAU
{
rc = mxfTxPeriodicUpdateMsgBufferAlloc(users[i], 1, 4096, &userBuf[i][3], NULL);
if(rc == MAXT_ERROR_BUFFER_ALLOCATED)
rc = mxfTxPeriodicUpdateMsgBufferGet(users[i], 1, &userBuf[i][3]);
if (!rc)
{
rc = mxfASCBUserBusEnableSet(users[i], 0, 3, userBuf[i][3]);
if(rc == MAXT_ERROR_ALREADY_ATTACHED)
{
rc = mxfASCBUserBusEnableSet(users[i], 0, 3, 0);
if(!rc)
rc = mxfASCBUserBusEnableSet(users[i], 0, 3, userBuf[i][3]);
}
}
if (!rc)
{
//--- Set data on the first 6 bytes (remaining bytes will be 0) ---//
//User data on the Left bus
rec.timeTag = 0;
rec.control = 0;
rec.repeatCount = 1;
rec.dataSize = 6; //6 bytes
rec.msgPhase = 0;
rec.data[0] = 0x4000;
rec.data[1] = 0x1234;
rec.data[2] = 0x5678;
//User data on the left bus
rc = mxfASCBTxPeriodicUpdateMsgWrite(userBuf[i][3], 1, &rec);
}
}
}
// start user
if(!rc)
rc = mxfASCBUserEnableSet(users[i], TRUE);
}
// Wait a little
if(!rc)
rc = mxfSleep(5000);
// Update data
for(i=0; i<NUM_RESPONSE && !rc; i++)
{
//--- Set data on the first 6 bytes (remaining bytes will be 0) ---//
//User data on the Left bus
rec.timeTag = 0;
rec.control = 0;
rec.repeatCount = 1;
rec.dataSize = 6; //6 bytes
rec.msgPhase = 0;
rec.data[0] = 0x4000;
rec.data[1] = 0x4444;
rec.data[2] = 0x5555;
//User data on the left bus
rc = mxfASCBTxPeriodicUpdateMsgWrite(userBuf[i][0], 1, &rec);
if (!rc)
{
if (responseInfo[i].a == 0x70) // DAU
{
//User data on the Left bus
rec.timeTag = 0;
rec.control = 0;
rec.repeatCount = 1;
rec.dataSize = 6;
rec.msgPhase = 0;
rec.data[0] = 0x4000;
rec.data[1] = 0x9ABC;
rec.data[2] = 0xDEF0;
//User data on the left bus
rc = mxfASCBTxPeriodicUpdateMsgWrite(userBuf[i][3], 1, &rec);
}
}
}
// Wait a little
if (!rc)
rc = mxfSleep(5000);
for(i=0; i<NUM_RESPONSE && !rc; i++)
{
rc = mxfASCBUserEnableSet(users[i], FALSE);
if(!rc)
{
if(userBuf[i][0])
{
rc = mxfTxPeriodicUpdateMsgClear(userBuf[i][0], 0);
if(!rc)
rc = mxfTxPeriodicUpdateMsgBufferFree(userBuf[i][0]);
}
if (userBuf[i][3])
{
rc = mxfTxPeriodicUpdateMsgClear(userBuf[i][3], 0);
if (!rc)
rc = mxfTxPeriodicUpdateMsgBufferFree(userBuf[i][3]);
}
}
}
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
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