Hello folks. On our EtherCAT application, we have defined a couple low-priority tasks to handle SPI Flash writes (when demanded) and slower I2C transactions. These mostly worked initially, though slower than expected, but stopped working once we made changes to switch EtherCAT to distributed clocks (see this related thread).
For reference, here is the creation code for one of our tasks:
void NVMStartWriteTask() { Task_Params nvmTaskParams; Task_Params_init(&nvmTaskParams); nvmTaskParams.priority = 2; nvmTaskParams.stackSize = 1512; nvmWriteTaskHandle = Task_create(NVMWriteTask, &nvmTaskParams, NULL); }
Which, being a background task, is lower priority than task1.
Looking into the depths of the EtherCAT stack, it looks like tiesutils.c just runs MainLoop() and then Task_yield() repeatedly. Because the task is yielded and does not sleep for any appreciable time, I'm suspecting that now we end up going back to task1 after whatever secondary task runs, rather than having any available time for our background tasks.
Logically speaking, the foreground operations are not needed until we have SDO requests or we have another PDO/DC Sync, but I'm not sure the best/safest way to 'open up' a window for our background tasks. I think the way we have our slave code configured, PDOs are handled in a separate task, and DC pulses are handled by an interrupt, so it may be possible to slow down task1 by replacing the Task_yield() with a Task_sleep().
Is there any danger in doing this? Is there a better solution that I'm not familiar with? Any advice is recommended.