MX Foundation 4
Updating Periodic Messages

While a schedule runs, the CSDB data can be updated asynchronously by the main application using the mxfCSDBTxPeriodicUpdateMsgWrite() function.

The next example shows how to use some functions for updating a transmission buffer.

Scheduling a Single Message

The program below shows how to define a single message with mxfTxPeriodicScheduleMsgAdd() for scheduling that will be later updated while the schedule runs.

The example in the next section shows how to update the records dynamically.

csdb_buffer_threshold.c

#define BUFFER_SIZE 1*1024*1024 // 1 MiB
#define TX_MSG_LABEL 0xA0
#define TX_MSG_SI 0x1
uint32 rc;
HMXF_SCHED schedule=0;
HMXF_SCHED_MSG msgSched;
HMXF_CHANNEL txChannel;
HMXF_BUFFER txBuffer[2]={0,0};
MXF_CSDB_DATAREC *hostBuffer=NULL;
...
// Allocate host buffer
if(!rc)
{
hostBuffer = (MXF_CSDB_DATAREC *)malloc(BUFFER_SIZE);
if(!hostBuffer)
rc = MAXT_ERROR_MEM;
}
// Set the Periodic Scheduler
if(!rc)
rc = mxfTxPeriodicScheduleNew(txChannel, &schedule);
// Set scheduling values: Rate=50 ms, Phase=0 us
if(!rc)
rc = mxfTxPeriodicScheduleMsgAdd(schedule, 50000000ll, 0, &msgSched);
// Add two buffers to the message
if(!rc)
rc = mxfTxPeriodicScheduleBufferListAdd(msgSched, 2, 0, txBuffer);
// Run the schedule
if(!rc)
rc = mxfTxPeriodicScheduleRun(schedule);
// Send messages for 2 seconds
if(!rc)
{
printf("Running periodic transmission...\n\r");
mxfSleep(2000);
rc = mxfTxPeriodicScheduleFree(schedule);
}
...

Updating the buffer

The value of the CSDB data sent can be updated while a background schedule runs.

The example below shows how the mxfCSDBTxPeriodicUpdateMsgWrite() function can be used to perform the update operation.

The update loop changes every 100ms and stops after five seconds.

csdb_buffer_threshold.c

#define TX_MSG_LABEL 0xA0
#define TX_MSG_SI 0x1
#define TXALMOSTFULL 7
uint32 rc=0;
uint32 i;
MXF_CSDB_DATAREC *recPtr=hostBuffer;
static uint64 data=0;
...
// Refills the FIFO in order to produce a ramp
for(i=0; !rc && i<TXALMOSTFULL; i++)
{
// Sends a parity error on first record
recPtr->timeTag=0;
recPtr->control=(i!=0)?0:MXF_CSDB_TX_REC_CTRL_PARITY_ERROR;
recPtr->repeatCount=1;
recPtr->reserved=0;
recPtr->data[0] = TX_MSG_LABEL;
recPtr->data[1] = 0x40 | TX_MSG_SI;
recPtr->data[2] = (uint8)data;
recPtr->data[3] = (uint8)(data >> 8);
recPtr->data[4] = (uint8)data;
recPtr->data[5] = (uint8)(data >> 8);
data++;
rc = mxfCSDBNextDataRecordPtrGet(recPtr, &recPtr);
}
// Adds more data to the buffer
if(!rc)
rc = mxfCSDBTxPeriodicUpdateMsgWrite(buffer, i, hostBuffer);
...
Updated 10/23/2023