Control and change the tasking and scheduling of the MLC/XLC system and the user application.
Using the task lib, it is possible to hook your task into the real-time task scheduler of the target system. Of course, this only makes sense if your program runs on the same target as the device you are connected to. Using the TaskLib when connecting via MLPI over Ethernet is possible, but the timing of the methods is non-deterministic. But when running with your app on the target, you can make sure that your task is one of the first tasks to get scheduled, when for example new data has arrived on the sercos bus. To do this, you have to increase the task priority of your task using mlpiTaskSetCurrentPriority and then you may want to wait for a given system event using mlpiTaskWaitForEvent.
- Attention
- Your task is scheduled with the same rights as every other (system) task in a fully native real-time environment! So special care is needed, when running your task at higher priority levels. Your task will block any task with a lower priority level as long as it is running. Programming an infinite loop will most likely look up your system (a system watchdog will stop your system). If you have never programmed a real-time system, then please have a look at the manual of your operating system and read about the mechanics of a real-time scheduler!
Here is some example code:
{
printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
return result;
}
unsigned long cycleCounter = 0;
bool bRunning = true;
do {
printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
break;
}
cycleCounter++;
if (cycleCounter>1000)
bRunning = false;
}while (bRunning);
printf("\ncall of MLPI function failed with 0x%08x!", (unsigned)result);
return result;
}
}
Here is another example which shows how to start our function on a VxWorks target. For more information about the usage of task on VxWorks, please have a look at the VxWorks Reference help regarding the taskLib functionality.
taskSpawn("ExampleTask", 100, VX_FP_TASK, 0x200000, (FUNCPTR)&taskFunc, connection, 0, 0, 0, 0, 0, 0, 0, 0, 0);
- Note
- The TaskLib functions trace their debug information mainly into the module MLPI_TASK_LIB and in addition into the module MLPI_BASE_MODULES. For further information, see also the detailed description of the library TraceLib and the notes about Using the Trace for debugging.