MX Foundation 4
Aperiodic Transmit Service

The BC allows the user to send aperiodic messages that are inserted into the current minor frame message on a one shot basis or just sent when the major frame is stopped. Two types of messages are supported: low priority and high priority. One FIFO per priority is used to send a message to the BC. Each message may be sent now or on the specified time tag. When a time tag is used, the message will be sent on or after this time tag. Refer to the mxfMIL1553TxAperiodicWrite() function.

A delay before sending the aperiodic commands can be set by using the MXF_MIL1553_DATAREC.service.txAperiodic.delay field.

MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD event condition can be registered so a callback handler can be automatically called when the number of messages of a buffer falls below a determined threshold.

Major frame stopped

Low and high priority FIFO may be used if the major frame is stopped. With the now option, all messages in the high priority queue will be transmitted before the low priority ones. With the time tag option, the next high priority message will be sent first only if the time tag is before or equal to the next low priority message.

#define FRAME_RATE 20000000 //20 msec
#define ALMOST_FULL 20
#define ALMOST_EMPTY 10
uint32 rc;
HMXF_SERVER server;
HMXF_CHANNEL bc;
HMXF_BUFFER bcBufferTx=0;
HMXF_ASYNCEVENT asyncEvent=0;
uint32 txBufferSize;
MXF_MIL1553_DATAREC* txBuffer=NULL;
...
// Allocates enough buffer for at least ALMOST_FULL tx data
if(!rc)
{
txBufferSize = ALMOST_FULL * sizeof(MXF_MIL1553_DATAREC);
// Flex1553 allocation
rc = mxfTxAperiodicBufferAlloc(bc, MXF_TXAPERIODIC_PRIORITY_LOW, txBufferSize, &bcBufferTx, NULL);
// Host allocation
if(!rc)
{
txBuffer = (MXF_MIL1553_DATAREC*)malloc(txBufferSize);
if(!txBuffer)
rc = MAXT_ERROR_MEM;
}
}
// Configures aperiodic asynchronous event condition
if(!rc)
rc = mxfAsyncEventHandlerInit(server, &txHandler, txBuffer, &asyncEvent);
if(!rc)
{
condition.reserved = 0;
condition.condID = MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD;
rc = mxfAsyncEventConditionsSet(asyncEvent, TRUE, 1, &condition);
}
...
// Disables asynchronous event condition
if(!rc)
rc = mxfAsyncEventConditionsSet(asyncEvent, FALSE, 1, &condition);
if(!rc)
// Clears aperiodic buffer
if(!rc)
rc = mxfTxAperiodicClear(bcBufferTx, 0);
...
uint32 txHandler(HMXF_ASYNCEVENT asyncEvent, void* param)
{
uint32 rc;
uint64 count;
// get asynchronous event information
rc = mxfAsyncEventPendingGet(asyncEvent, 1, &count, &pendingInfo);
if(!rc && count)
{
if(pendingInfo.condID == MXF_ASYNCEVENT_COND_TXAPERIODIC_BUFFER_THRESHOLD)
{
uint64 cmd;
// Send commands until it reaches almost full threshold
txRec1553 = (MXF_MIL1553_DATAREC *)param;
for(cmd=0; cmd<pendingInfo.condition.txAperiodicBufferThreshold.almostFull-1; cmd++)
{
memset(txRec1553, 0, sizeof(MXF_MIL1553_DATAREC));
// send two commands in simulated major frame
if(cmd % 2)
{
txRec1553->timeTag = startTime + 1000000; // 1 msec after other command
txRec1553->repeatCount = 1;
txRec1553->dataSize = 10; //10 bytes (command + 4 words)
mxfMIL1553CommandCompose(0, 3, MXF_MIL1553_MSGTYPE_RX, 4, &txRec1553->data[0]);
txRec1553->data[1] = 0x0000;
txRec1553->data[2] = 0x1111;
txRec1553->data[3] = 0x2222;
txRec1553->data[4] = 0x3333;
}
else
{
startTime += FRAME_RATE; // one FRAME_RATE after the first command
txRec1553->timeTag = startTime;
txRec1553->repeatCount = 1;
txRec1553->dataSize = 10; //10 bytes (command + 4 words)
mxfMIL1553CommandCompose(0, 5, MXF_MIL1553_MSGTYPE_RX, 4, &txRec1553->data[0]);
txRec1553->data[1] = 0x3333;
txRec1553->data[2] = 0x2222;
txRec1553->data[3] = 0x1111;
txRec1553->data[4] = 0x0000;
}
mxfMIL1553NextDataRecordPtrGet(txRec1553, &txRec1553);
}
// Sends commands
rc = mxfMIL1553TxAperiodicWrite(pendingInfo.condition.txAperiodicBufferThreshold.buffer, MXF_TXAPERIODIC_FLAG_USE_RECORD_ABSOLUTE_TIME, 0, cmd, (MXF_MIL1553_DATAREC *)param);
}
}
return rc;
}

mil1553_aperiodic.c

Major frame started

High priority

Aperiodic message(s) are executed upon the completion of the current message when transmitted NOW or when the time tag has been reached. Then, the aperiodic message(s) are sent by the BC. The BC then returns to the current minor frame message.

Low priority

Aperiodic messages will be sent at the end of the current minor frame, if there is a gap before the transmission of the next minor frame. If not, the BC will retry to send the message at the end of the next minor frame. This process will be repeated until the message is executed.

mil1553_aperiodic_frame.c

Updated 10/23/2023