MX Foundation 4
Asynchronous Events

An application can register condition(s) to be monitored by the 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 a handler is as follows:

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

The receive buffer 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. Read enough records from the buffer to go below the almost empty threshold to clear the event.

Example

ar717_buffer_threshold.c
In the example below an async event handler is defined to monitor MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD condition and ARINC 717 RX acquisition channel is started to receive data.

uint32 asyncEventHandler(HMXF_ASYNCEVENT asyncEvent, void* param)
{
uint64 maxCount=64, pendingCount;
uint64 i;
uint32 rc;
// Gets the list of pending events to process
rc = mxfAsyncEventPendingGet(asyncEvent, maxCount, &pendingCount, pendingList);
for (i=0; !rc && i<pendingCount; i++)
{
switch(pendingList[i].condID)
{
case MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD:
// An almost empty condition was detected...
writeMsgs(pendingList[i].condition.txAperiodicBufferThreshold.buffer, (MXF_A717_DATAREC *)param);
break;
case MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD:
// An almost full condition was detected...
readAcquisition(pendingList[i].condition.rxAcqBufferThreshold.buffer, (MXF_A717_DATAREC *)param);
break;
default:
printf("Unknown condID 0x%llx)", pendingList[i].condID);
break;
}
}
return rc;
}
uint32 readAcquisition(HMXF_BUFFER rxBuffer, MXF_A717_DATAREC *rxHostBuffer)
{
uint64 status, msgsCount, bytesCount;
uint64 word, data;
uint32 rc;
size_t bufferSize = (RXALMOSTFULL*sizeof(MXF_A717_DATAREC));
// Reads and display records
rc = mxfA717RxAcqRead(rxBuffer, 0, bufferSize, &status, &msgsCount, &bytesCount, rxHostBuffer);
if(!rc)
printf("String received count = %llu \n", msgsCount);
if(!rc)
{
// Displays received strings
recPtr = rxHostBuffer;
for(data=0; data<msgsCount && !rc; data++)
{
printf("\n%02llu: Timetag=%012llu, Size=%u words\n", data, recPtr->timeTag, (recPtr->dataSize)/2);
for(word=0; word < SUBFRAMESIZE ; word++)
printf("%03X ", recPtr->data[word]);
printf("\n");
mxfA717NextDataRecordPtrGet(recPtr, &recPtr);
}
}
if(rc)
printf("Acquisition read failed; rc=0x%08x\n", rc);
return rc;
}



Asynchronous main logic for registering a condition handler and add conditions to be monitored.

#define TXALMOSTFULL 7
#define TXALMOSTEMPTY 3
#define RXALMOSTFULL 5
#define RXALMOSTEMPTY 2
uint32 rc;
HMXF_SERVER server;
HMXF_CHANNEL rxChannel;
HMXF_ASYNCEVENT asyncEvent;
HMXF_BUFFER rxBuffer;
size_t bufferSize;
MXF_A717_DATAREC *hostBuffer;
MXF_ASYNCEVENT_CONDITION RXasyncEventInfo;
...
// Allocates host buffer
bufferSize = (TXALMOSTFULL*sizeof(MXF_A717_DATAREC));
if(!rc)
{
hostBuffer = (MXF_A717_DATAREC *)malloc(bufferSize);
if(!hostBuffer)
rc = MAXT_ERROR_MEM;
}
// Sets the event handler
if(!rc)
rc = mxfAsyncEventHandlerInit(server, &asyncEventHandler, hostBuffer, &asyncEvent);
// Allocates RX acquisition buffer
if(!rc)
rc = mxfRxAcqBufferAlloc(rxChannel, bufferSize, &rxBuffer, NULL);
// Sets the RX async event condition
if(!rc)
{
memset(&RXasyncEventInfo, 0, sizeof(RXasyncEventInfo));
RXasyncEventInfo.condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
RXasyncEventInfo.condition.rxAcqBufferThreshold.buffer = rxBuffer;
RXasyncEventInfo.condition.rxAcqBufferThreshold.almostFull = RXALMOSTFULL;
RXasyncEventInfo.condition.rxAcqBufferThreshold.almostEmpty = RXALMOSTEMPTY;
rc = mxfAsyncEventConditionsSet(asyncEvent, TRUE, 1, &RXasyncEventInfo);
}
// Sets acquisition mode
if(!rc)
rc = mxfRxAcqModeSet(rxBuffer, MXF_RXACQ_MODE_LINEAR);
// Starts acquisition
if(!rc)
rc = mxfRxAcqStart(rxBuffer, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
...
// Stops acquisition
if(!rc)
rc = mxfRxAcqStop(rxBuffer);
// Terminates async event handler
if(!rc)
rc = mxfAsyncEventConditionsSet(asyncEvent, FALSE, 1, &RXasyncEventInfo);
if(!rc)
...
Updated 10/23/2023