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 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_RX_MSG Specific message available in the queue.
MXF_ASYNCEVENT_COND_RX_ERROR Receive errors on the RX port.
MXF_ASYNCEVENT_COND_RXACQ_BUFFER_THRESHOLD Acquisition buffer threshold exceeded.

csdb_rx_event_handler.c
csdb_buffer_threshold.c
The function below illustrates how to define an asynchronous callback handler for trapping CSDB RX conditions.

uint32 asyncEventHandler(HMXF_ASYNCEVENT asyncEvent, void *param)
{
uint64 i, maxCount=64, pendingCount;
uint32 rc;
// Build 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:
{
...
break;
}
case MXF_ASYNCEVENT_COND_RX_MSG:
{
...
break;
}
case MXF_ASYNCEVENT_COND_RX_ERROR:
{
...
break;
}
}
}
return rc;
}

Registering Conditions

csdb_rx_event_handler.c
csdb_buffer_threshold.c

In the example below a condition handler is defined to monitor conditions, and a CSDB RX acquisition channel is started to receive data.

#define BUFFER_SIZE 4096 // 4KB
#define LABEL 0x9
#define SI 0
HMXF_SERVER server;
HMXF_CHANNEL rxChannel;
HMXF_ASYNCEVENT asyncEvent=0;
MXF_ASYNCEVENT_CONDITION asyncEventInfo[2];
MXF_CSDB_DATAREC *hostBuffer=NULL;
...
// Allocate host buffer
if(!rc)
{
hostBuffer = (MXF_CSDB_DATAREC *)malloc(BUFFER_SIZE);
if(!hostBuffer)
rc = MAXT_ERROR_MEM;
}
// Sets the event handler
if(!rc)
rc = mxfAsyncEventHandlerInit(server, &asyncEventHandler, hostBuffer, &asyncEvent);
// Sets the RX async event conditions
if(!rc)
{
asyncEventInfo[0].condID = MXF_ASYNCEVENT_COND_RX_MSG;
asyncEventInfo[0].condition.rxMsg.channel = rxChannel;
asyncEventInfo[1].condID = MXF_ASYNCEVENT_COND_RX_ERROR;
asyncEventInfo[1].condition.rxErr.channel = rxChannel;
rc = mxfAsyncEventConditionsSet(asyncEvent, TRUE, 2, &asyncEventInfo[0]);
}
// Monitor a specific label/si
if (!rc)
{
msgid.label = LABEL;
msgid.sdi = SI;
msgid.reserved[0] = 0;
msgid.reserved[1] = 0;
rc = mxfCSDBAsyncEventRxMsgSelectSet(asyncEvent, rxChannel, MXF_MSG_SELECT_ADD, 1, &msgid);
}
...
// Terminate async event handler
if(!rc)
rc = mxfAsyncEventConditionsSet(asyncEvent, FALSE, 2, asyncEventInfo);
if(!rc)
if(hostBuffer)
free(hostBuffer);
...
Updated 10/23/2023