/* ********************************************************************************************************* * TASK SWITCH HOOK ********************************************************************************************************* */ void OSTaskSwHook (void) { INT32U time; TASK_USER_DATA *puser; time = PC_ElapsedStop(0); /* This task is done */ PC_ElapsedStart(0); /* Start for next task */ puser = OSTCBCur->OSTCBExtPtr; /* Point to used data */ if (puser != (TASK_USER_DATA *)0) { puser->TaskCtr++; /* Increment task counter */ puser->TaskExecTime = (INT16U) time; /* Update the task's execution time */ puser->TaskTotExecTime += time; /* Update the task's total execution time */ } }
/* ********************************************************************************************************* * ELAPSED TIME INITIALIZATION * * Description : This function initialize the elapsed time module by determining how long the START and * STOP functions take to execute. In other words, this function calibrates this module * to account for the processing time of the START and STOP functions. * Needs to be called only once before any of the timers is started with PC_ElapsedStart(). * * Arguments : None. * * Returns : None. ********************************************************************************************************* */ void PC_ElapsedInit(void) { static BOOLEAN initDone=FALSE; int i; if (initDone) return; printf("INFO: Please wait - timer calibration may take up to 4 secs\n"); for (i=0; i < 4; i++) { PC_frequency += countsPerSecond(); } PC_frequency = PC_frequency >> 2; PC_ElapsedOverhead = 0; // Measure the overhead of PC_ElapsedStart PC_ElapsedStart(0); // ... and PC_ElapsedStop PC_ElapsedOverhead = (INT16U) PC_ElapsedStop(0); initDone=TRUE; }
//allows us to measure the execution time of each task, //keeps track of how often each task executes //and accumulates total execution times of each task //****OSTaskSwHook() is called when UCOSII switches from a low priority task to a higher priority task void OSTaskSwHook (void) { INT16U time; TASK_USER_DATA *puser; time = PC_ElapsedStop(); /* This task is done */ PC_ElapsedStart(); /* Start for next task */ //global pointer OSTCBCur points to the TCB of the current task //that's the last second paramter in OSTaskCreateExt() puser = OSTCBCur->OSTCBExtPtr; /* Point to used data */ //check if the pointer is not NULL //the two default tasks: idle task and statistic task do not contain a TCB externsion pointer if (puser != (TASK_USER_DATA *)0) { //calculate how many times this task being called puser->TaskCtr++; /* Increment task counter */ puser->TaskExecTime = time; /* Update the task's execution time */ puser->TaskTotExecTime += time; /* Update the task's total execution time */ } }
/* ********************************************************************************************************* * ELAPSED TIME INITIALIZATION * * Description : This function initialize the elapsed time module by determining how long the START and * STOP functions take to execute. In other words, this function calibrates this module * to account for the processing time of the START and STOP functions. * * Arguments : None. * * Returns : None. ********************************************************************************************************* */ void PC_ElapsedInit(void) { PC_ElapsedOverhead = 0; PC_ElapsedStart(); PC_ElapsedOverhead = PC_ElapsedStop(); }