MX Foundation 4
Asynchronous Events

An application can register condition(s) to be monitored by the receive firmware.

When a callback handler is defined, the condition(s) are reported to the application asynchronously from the firmware to the handler.

The way to define an handler is as follows:

After this registration, the application can read acquisition data as usual and/or received asynchronous events through the callback handler.

The receive queue can also be read from the callback handler if necessary.

List of conditions

The event conditions that can be monitored are as follows:

Condition Description
MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD Acquisition buffer threshold exceeded.
MXF_ASYNCEVENT_COND_RX_ERROR Receive errors on the RX port.
MXF_ASYNCEVENT_COND_RX_MSG Specific message available in the buffer.

Example

ar708_event_handler.c
ar708_buffer_threshold.c

In the example below a condition handler is defined for monitoring MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD condition and ARINC 708 RX acquisition channel started for receiving data.

uint32 asyncEventHandler(HMXF_ASYNCEVENT asyncEvent, void *param)
{
HMXF_CHANNEL channel;
uint64 i, maxCount=64, pendingCount, status;
uint32 rc=MAXT_SUCCESS;
uint64 dev, mod, port;
// Builds the list of pending events to process
rc = mxfAsyncEventPendingGet(asyncEvent, maxCount, &pendingCount, pendingList);
for (i=0; i < pendingCount && !rc; i++)
{
switch ( pendingList[i].condID )
{
case MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD:
{
MXF_A708_DATAREC *recPtr=rec708;
HMXF_BUFFER buffer;
uint64 status;
uint64 msgCount, byteCount;
uint32 iData;
uint64 msg;
uint32 rc=MAXT_SUCCESS;
buffer = pendingList[i].condition.rxAcqBufferThreshold.buffer;
// The buffer is almost full, we should then read the data with mxfA708RxAcqRead().
rc = mxfA708RxAcqRead(buffer, 0, BUFFER_SIZE, &status, &msgCount, &byteCount, rec708);
for (msg=0; msg<msgsCount && !rc; msg++)
{
printf("%03llu %010llu 0x%08x %02u ", msg, recPtr->timeTag, recPtr->control, recPtr->dataSize);
for(iData=0; iData < recPtr->dataSize/2; iData++)
{
printf("%04x", recPtr->data[iData]);
if(!((iData+1)%8) && (iData+1 < recPtr->dataSize/2))
printf("\n ");
}
printf("\n");
rc = mxfA708NextDataRecordPtrGet(recPtr, &recPtr);
}
break;
}
case MXF_ASYNCEVENT_COND_RX_ERROR:
// A receive error was detected
channel = pendingList[i].condition.rxErr.channel;
status = pendingList[i].condition.rxErr.status;
rc = mxfChannelLocationGet(channel, &dev, &mod, &port);
if(!rc)
printf("Status 0x%08llx received on channel %llu.%llu.%llu\n", status, dev, mod, port);
break;
default:
printf("Unknown condID 0x%llx)", pendingList[i].condID);
break;
}
}
return rc;
}
#define BUFFER_SIZE 1*1024*1024 // 1 MB
int main()
{
HMXF_SERVER server;
MXF_ASYNCEVENT_CONDITION asyncEventInfo[2];
HMXF_ASYNCEVENT asyncEvent=0;
MXF_A708_DATAREC *hostBuffer=NULL;
uint64 count;
uint32 rc=0;
...
// Allocates host buffer
if(!rc)
{
hostBuffer = (MXF_A708_DATAREC *)malloc(BUFFER_SIZE);
if(!hostBuffer)
rc = MAXT_ERROR_MEM;
}
if (!rc)
// Registers the callback handler service function
rc = mxfAsyncEventHandlerInit(server, asyncEventHandler, hostBuffer, &asyncEvent);
memset(&asyncEventInfo, 0, sizeof(asyncEventInfo));
// Acquisition threshold; the callback gets called when the receive FIFO is
// almost full >=4 until it gets to < 1 word (almost empty).
asyncEventInfo[0].condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
asyncEventInfo[0].condition.rxAcqBufferThreshold.buffer=buffer;
// Receive message in error; the callback gets called when a data word in error is detected
asyncEventInfo[1].condID = MXF_ASYNCEVENT_COND_RX_ERROR;
asyncEventInfo[1].condition.rxErr.channel = channel;
// Enables Acquisition threshold interrupt
if (!rc)
rc = mxfAsyncEventConditionsSet(asyncEvent, TRUE, 2, asyncEventInfo);
...
if (!rc)
rc = mxfAsyncEventConditionsSet(asyncEvent, FALSE, 2, asyncEventInfo);
if (!rc)
if (hostBuffer)
free(hostBuffer);
...
}
Updated 10/23/2023