MX Foundation 4
ar429_periodic.c
/*******************************************************************************
//
// File:
// arinc429_periodic.c
//
// Copyright (c) MAX Technologies Inc. 1988-2019, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// This demo shows how to set a basic periodic transmission with the
// scheduler and update the ARINC data.
//
// Hardware Requirements:
// - MAXT FM429, FM664 or series 500 carrier with IPM-429/IPM-MULTI with A429 option installed on IP1
// - Loopback between first TX and RX ARINC 429 channels.
//
*******************************************************************************/
#include "example.h"
#define LOOPBACK
#define LOCAL
#define BUFFER_SIZE 4096 // 4KB
#define TX_MSG_LABEL 5
#define TX_MSG_SDI 0
uint32 RX429ReadAcquisitionData(HMXF_BUFFER rxBuffer, MXF_A429_DATAREC * rec429);
uint32 TX429PeriodicScheduling(HMXF_CHANNEL txChannel, HMXF_BUFFER txBuffer, MXF_A429_DATAREC* rec429);
/***************************************************************************************************************/
// Main
/***************************************************************************************************************/
int main(void)
{
uint32 rc;
HMXF_SERVER server;
HMXF_DEVICE device = 0;
HMXF_MODULE module = 0;
HMXF_CHANNEL rxChannel = 0;
HMXF_CHANNEL txChannel = 0;
HMXF_BUFFER rxBuffer = 0;
HMXF_BUFFER txBuffer = 0;
MXF_A429_DATAREC* rec429 = NULL;
uint64 dev, mod, port;
// Connect to services local or remote
#ifdef LOCAL
rc = mxfServerConnect("0.0.0.0", "", "", FALSE, &server);
#else
rc = mxfServerConnect("192.168.0.1", "admin", "admin", FALSE, &server);
#endif
if (rc)
{
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 the first device handle
if (!rc)
rc = mxfSystemDeviceGet(server, 0, &device);
// Get module #1 handle (module 429)
if (!rc)
rc = mxfDeviceModuleGet(device, 1, &module);
// Obtain channel #0 ( 429 TX channel)
if (!rc)
rc = mxfModuleChannelGet(module, 0, &txChannel);
// Obtain channel #8 ( 429 RX channel)
if (!rc)
rc = mxfModuleChannelGet(module, 8, &rxChannel);
// Set timebase to 64-bit microseconds
if (!rc)
rc = mxfSystemTimeBaseSet(server, MXF_TIMEBASE_DEVICE_USEC);
// Get the physical port location
if (!rc)
{
rc = mxfChannelLocationGet(rxChannel, &dev, &mod, &port);
if (!rc)
printf("Acquisition Channel (RX) location=%llu.%llu.%llu\n", dev, mod, port);
}
if (!rc)
{
rc = mxfChannelLocationGet(txChannel, &dev, &mod, &port);
if (!rc)
printf("Transmitter Channel (TX) location=%llu.%llu.%llu\n", dev, mod, port);
}
//Activate loopback before transmission and reception
#ifdef LOOPBACK
if (!rc)
rc = mxfAttributeUint64Set(rxChannel, KMXF_A429_TX_RX_TEST_LB, VMXF_ENABLE);
#endif
// Allocate RX acquisition buffer
if (!rc)
rc = mxfRxAcqBufferAlloc(rxChannel, BUFFER_SIZE, &rxBuffer, NULL);
// Allocate TX Periodic Update buffer
if (!rc)
rc = mxfTxPeriodicUpdateMsgBufferAlloc(txChannel, TX_MSG_LABEL, BUFFER_SIZE, &txBuffer, NULL);
// Allocate host buffer
if (!rc)
{
rec429 = (MXF_A429_DATAREC*)malloc(BUFFER_SIZE);
if (!rec429)
rc = MAXT_ERROR_MEM;
}
// Start the acquisition process
if (!rc)
rc = mxfRxAcqModeSet(rxBuffer, MXF_RXACQ_MODE_LINEAR);
if (!rc)
{
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
if (!rc)
printf("\nAcquisition started\n\r");
}
// Start 429 data transmission
if (!rc)
{
rc = TX429PeriodicScheduling(txChannel, txBuffer, rec429);
if (!rc)
{
// Read 429 data in acquisition buffer
rc = RX429ReadAcquisitionData(rxBuffer, rec429);
if (!rc)
{
uint64 status;
// Check Rx status
rc = mxfChannelRxStatusGet(rxChannel, &status);
if (!rc && status)
{
if (status & MXF_RX_STATUS_OVERFLOW)
printf("Rx overflow\n\r");
}
}
}
}
// Stop and flush unread data
if (!rc)
rc = mxfRxAcqStop(rxBuffer);
if (!rc)
{
rc = mxfRxAcqClear(rxBuffer);
if (!rc)
printf("\nAcquisition stopped\n\r");
}
// Catch any previous error
if (rc)
{
char buffer[256];
rc = mxfSystemErrorStringGet(server, rc, sizeof(buffer), buffer);
printf("%s\n", buffer);
}
printf("\nTerminating\n");
// Free all buffers and terminate
if (rxBuffer)
mxfRxAcqBufferFree(rxBuffer);
if (txBuffer)
if (rec429)
free(rec429);
printf("\nPress enter to terminate\n");
getchar();
return rc;
}
/***************************************************************************************************************/
// RX429ReadAcquisitionData
/***************************************************************************************************************/
uint32 RX429ReadAcquisitionData(HMXF_BUFFER rxBuffer, MXF_A429_DATAREC* rec429)
{
MXF_A429_DATAREC* recPtr = rec429;
uint64 status, msgsCount, bytesCount;
uint64 label, sdi, data, ssm, parity;
uint64 j;
uint32 rc;
// Read and display records
rc = mxfA429RxAcqRead(rxBuffer, 0, BUFFER_SIZE, &status, &msgsCount, &bytesCount, rec429);
for (j = 0; j < msgsCount && !rc; j++)
{
rc = mxfA429ArwDecompose(recPtr->data, &label, &sdi, &data, &ssm, &parity);
if (!rc)
{
printf("%02llu: Timetag %llu - ARINC word=[%03llo,%lld,%05llX,%lld,%s]\n",
j, recPtr->timeTag, label, sdi, data, ssm, (parity == VMXF_A429_PARITY_ODD) ? "ODD" : "EVEN");
if (!rc)
rc = mxfA429NextDataRecordPtrGet(recPtr, &recPtr);
}
}
return rc;
}
/***************************************************************************************************************/
// TX429PeriodicScheduling
/***************************************************************************************************************/
uint32 TX429PeriodicScheduling(HMXF_CHANNEL txChannel, HMXF_BUFFER txBuffer, MXF_A429_DATAREC* rec429)
{
HMXF_SCHED schedule;
HMXF_SCHED_MSG msg = 0;
uint64 label, sdi, data, ssm, parity;
uint32 rc;
// Set the A429 records and create the schedule
// Create the periodic scheduler
rc = mxfTxPeriodicScheduleNew(txChannel, &schedule);
// Set scheduling values: Rate=100 ms (.1sec), Phase=0 us
if (!rc)
rc = mxfTxPeriodicScheduleMsgAdd(schedule, 100000LL, 0, &msg);
// Define the number of buffer for the list and link to it
if (!rc)
rc = mxfTxPeriodicScheduleBufferListAdd(msg, 1, 0, &txBuffer);
// Set record for the buffer: ARINC 429 LABEL=005, SDI=0
if (!rc)
{
rec429->timeTag = 0;
rec429->control = 0;
rec429->repeatCount = 1;
rec429->reserved = 0;
label = TX_MSG_LABEL;
sdi = TX_MSG_SDI;
data = 0x7fe;
parity = VMXF_A429_PARITY_ODD;
ssm = 1;
rc = mxfA429ArwCompose(label, sdi, data, ssm, parity, &rec429->data);
if (!rc)
rc = mxfA429TxPeriodicUpdateMsgWrite(txBuffer, 1, rec429);
}
// Run the scheduler, update records
if (!rc)
{
printf("Running periodic transmission, please wait...\n\r");
// Run the schedule now
rc = mxfTxPeriodicScheduleRun(schedule);
}
// Wait 10 seconds
if (!rc)
{
uint64 status;
int loop=0;
do
{
mxfSleep(1000);
// Check Tx status
rc = mxfChannelTxStatusGet(txChannel, &status);
if (!rc && status)
{
if (status & MXF_TX_STATUS_OVERLOAD)
printf("Tx overload\n\r");
if (status & MXF_TX_STATUS_TIMING_LOST)
printf("Tx timing lost\n\r");
if (status & MXF_TX_STATUS_OVERFLOW)
printf("Tx overflow\n\r");
}
loop++;
}while(!rc && (loop<10));
}
if (!rc)
printf("\n\rTransmission stopped\n\r");
return rc;
}
Updated 10/23/2023