I have the following code to read rt memory from ethercat at each 2ms. switch (event_type)
{
case common::scheduler::SchedEventType::SCHED_EVENT_TICK:
// Call real-time method here
if (m_finalStateMachineState == FinalStateMachineState::SCHED_OPERATING)
{
runSharedMemUser();
}
return common::scheduler::SchedEventResponse::SCHED_EVENT_RESP_OKAY;
(...)
(...)
(...)
void Callable::runSharedMemUser()
{
comm::datalayer::DlResult result;
// // ----------------------- Write flatbuffer Output memory -----------------------
result = outputMemUser->beginAccess(inData, revisionOut);
if (result == comm::datalayer::DlResult::DL_RT_NOTOPEN)
{
outputMemUser->endAccess();
return;
}
if (STATUS_FAILED(result))
{
TRACE_ERR("ERROR Accessing output memory failed with: %s", result.toString());
return;
}
size_t size = 0;
if (comm::datalayer::STATUS_FAILED(outputMemUser->getSize(size)))
{
TRACE_ERR("WARNING Can't read output memory size");
return;
}
else
{
if (isFirstRun1) {
outDataRead = new uint8_t[size];
memcpy(outDataRead, inData, size);
isFirstRun1 = false;
}else{
delete[] outDataRead;
outDataRead = new uint8_t[size];
memcpy(outDataRead, inData, size);
}
}
outputMemUser->endAccess();
// ----------------------- Write flatbuffer Input memory -----------------------
result = inputMemUser->beginAccess(inData, revisionIn);
if (result == comm::datalayer::DlResult::DL_RT_NOTOPEN)
{
inputMemUser->endAccess();
return;
}
if (STATUS_FAILED(result))
{
TRACE_ERR("ERROR Accessing input memory failed with: %s", result.toString());
return;
}
size = 0;
if (comm::datalayer::STATUS_FAILED(inputMemUser->getSize(size)))
{
TRACE_ERR("WARNING Can't read input memory size");
return;
}
else
{
if (isFirstRun2)
{
inDataRead = new uint8_t[size];
memcpy(inDataRead, inData, size);
isFirstRun2 = false;
}else{
delete[] inDataRead;
inDataRead = new uint8_t[size];
memcpy(inDataRead, inData, size);
}
}
inputMemUser->endAccess();
TRACE_INFO("runSharedMemUser");
} The average running time is good, but sometimes it takes more than 2ms and I have a scheduler error. Can someone give me some help to try to solve this?
... View more