PXROS time slicing configuration
The time slicing value can be set during task creation or during runtime with use of the PxSetTimeslices() method [1]. Below, you will find examples illustrating both scenarios for reference.
Code 1. Example of time slice configuration during task creation
/* TIMESLICE (in ticks) */
#define TASK_TIMESLICE 100
PxTask_t LedClientB_Create (PxPrio_t prio, PxEvents_t events, PxMc_t memClass, PxOpool_t objPool)
{
PxTaskSpec_T task_Spec;
/* Clear task_Spec structure before it is initialized */
PxBzero ((PxUChar_t *)&task_Spec, sizeof(task_Spec));
/* Configure Task specification */
task_Spec.ts_name = (const PxChar_t *) "Task LedClientB";
task_Spec.ts_fun = LedClientB_taskFunc;
task_Spec.ts_mc = memClass;
task_Spec.ts_opool = objPool;
task_Spec.ts_privileges = TASK_PRIVILIGES;
task_Spec.ts_accessrights = THISTASK_PXACCESS;
task_Spec.ts_context = &task_Context;
task_Spec.ts_protect_region = taskAPRegions;
task_Spec.ts_timeslices = TASK_TIMESLICE;
task_Spec.ts_taskstack.stk_type = PXStackAlloc;
task_Spec.ts_taskstack.stk_size = TASK_STACKSIZE / sizeof(PxInt_t);;
task_Spec.ts_taskstack.stk_src.mc = memClass;
task_Spec.ts_inttaskstack.stk_type = PXStackAlloc;
task_Spec.ts_inttaskstack.stk_size = TASK_INTR_STACKSIZE / sizeof(PxInt_t);;
task_Spec.ts_inttaskstack.stk_src.mc = memClass;
task_Spec.ts_abortstacksize = 0;
/* Create the Task */
return PxTaskCreate (objPool,&task_Spec,prio,events);
}
Code 2. Example of timeslice configuration during runtime
void LedClientA_taskFunc (PxTask_t myID, PxMbx_t myMailbox, PxEvents_t myActEvents)
{
/* task code here */
/* Set timeslices (in ticks) */
PxSetTimeslices(50);
/* TASK MAIN LOOP
* Wait for periodic event to wake-up, and send the Event to the LedServer.
* In case of unexpected event, stop.
*/
while (1)
{
errRes = PxTaskSignalEvents (LedServerID, LEDSERVER_EV_TOGGLE_LED_0);
if (errRes != PXERR_NOERROR)
PxPanic();
}
}