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_THRESHOLD Acquisition buffer threshold exceeded.


Example

The example below shows how an acquisition threshold condition is defined.

discrete_event_handler.c

uint32 eventHandler(HMXF_HANDLE asyncEvent, void* param);
{
MXF_ASYNCEVENT_INFO pendingInfo;
uint64 count;
uint32 rc;
rc = mxfAsyncEventPendingGet(asyncEvent, 1, &count, &pendingInfo);
if(!rc && count)
{
if(pendingInfo.condID == MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD)
{
...
}
}
return rc;
}

The main function used to define the handler is shown below.

typedef struct
{
uint64 rxBufferSize;
MXF_DISCRETE_DATAREC* rxHostBuffer;
FILE* fp;
}
EVENT_INFO;
void main()
{
HMXF_SERVER server;
HMXF_CHANNEL channel;
EVENT_INFO eventInfo;
HMXF_ASYNCEVENT asyncEvent;
HMXF_BUFFER bufferRx=0;
...
memset(&eventInfo, 0, sizeof(eventInfo));
// Allocate 10KB buffer for rx data
if(!rc)
{
eventInfo.rxBufferSize = 10*1024;
// Flex1553 allocation
rc = mxfRxAcqBufferAlloc(rx, eventInfo.rxBufferSize, &bufferRx, NULL);
// Host allocation
if(!rc)
{
eventInfo.rxHostBuffer = (MXF_DISCRETE_DATAREC*)malloc((size_t)eventInfo.rxBufferSize);
if(!eventInfo.rxHostBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Configure acquisition asynchronous event condition
if(!rc)
{
eventInfo.fp = fopen("discrete_log.txt", "w+t");
rc = mxfAsyncEventHandlerInit(server, &eventHandler, &eventInfo, &asyncEvent);
}
if(!rc)
{
condition.reserved = 0;
condition.condID = MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD;
condition.condition.rxAcqBufferThreshold.buffer = bufferRx;
rc = mxfAsyncEventConditionsSet(asyncEvent, TRUE, 1, &condition);
}
// Start acquisition
if(!rc)
rc = mxfRxAcqStart(bufferRx, MXF_RXACQ_FLAG_DEFAULT, 0, 0);
...
// Stop acquisition
if(!rc)
rc = mxfRxAcqStop(bufferRx);
// Disable asynchronous event condition
if(!rc)
rc = mxfAsyncEventConditionsSet(asyncEvent, FALSE, 1, &condition);
if(!rc)
rc = mxfAsyncEventHandlerTerminate(asyncEvent);
...
}

–>

Updated 10/23/2023