/****************************************************************************** ** Function: CFE_PSP_GetTime() ** ** Purpose: Gets the value of the time from the hardware using the PPC ** time base register ** ** ** Arguments: LocalTime - where the time is returned through ******************************************************************************/ void CFE_PSP_GetTime( OS_time_t *LocalTime) { UINT32 tbu; UINT32 tbl; unsigned long long tb; vxTimeBaseGet(&tbu, &tbl); /* reassemble 64-bit count */ tb = ((unsigned long long)tbu << 32) | (unsigned long long) tbl; /* convert to seconds and microseconds using only integer computations */ LocalTime->seconds = tb / CFE_PSP_TIMER_TICKS_PER_SECOND; LocalTime->microsecs = ((tb % CFE_PSP_TIMER_TICKS_PER_SECOND) * 1000000 / CFE_PSP_TIMER_TICKS_PER_SECOND); /* could compute seconds.fraction_of_sec to better than 1 us * resolution as follows, but CFS time is based on sec, usec. Also, if the * time functions are called by an ISR, floating point is not allowed */ /* double sec = tb * CFE_PSP_TIMER_PERIOD; OS_printf("sec: %f\n", sec); */ /* OS_printf("tb: 0x%016llX tb: %llu tbu: 0x%08X tbl: 0x%08X\n", tb, tb, tbu, tbl); OS_printf("sec: %u usec: %u\n", LocalTime->seconds, LocalTime->microsecs); OS_printf("-------------\n"); */ }/* end CFE_PSP_GetLocalTime */
/*---------------------------------------------------------------------------- * getFutureTime - get a time in usec in the future * * used with checkTime() * * Used where we want a a timeout but with out giving up control * as would a taskDelay() might do. * * Simple example * * unsigned long ftop,fbot; * * // what time will it be 10 ms from now * getFutureTime(10000,&ftop,&fbot); * while(!ready) * { * testBit(4); * // now avoid a hung system incase bit 4 never changes we add this * // will test for 10msec then the time will be up and we will break out * if (checkTime(ftop,fbot) == 1) * break; // times up break out of loop * } * * * * *----------------------------------------------------------------------------*/ void getFutureTime(unsigned int usec, unsigned int *top, unsigned int *bot ) { /* for 405 @ 200 MHz */ unsigned int advtime; advtime = usec * (sysTimerClkFreq / 1000000); vxTimeBaseGet(top,bot); *bot += advtime; }
/* * marksysclk() - return the value of system count up timer, * for high percision time measurements */ long long marksysclk() { union { long long lword; int word[2]; } test; vxTimeBaseGet(&(test.word[0]),&(test.word[1])); return(test.lword); }
static int gto_timestamp_get (uint32 *up, uint32 *low,uint32 *freq) { /* * GTO platform ensures that the CCB operates at 400MHz * The CCB frequency is divided by 8 before being fed to the timebase * So, the frequency is 50MHz (counter granularity is 20ns) */ *freq = 50000000; vxTimeBaseGet(up,low); return OK; }
/*---------------------------------------------------------------------------- * checkTime * check to see if the time given has past * return 0 if not past * return 1 if time has past * see above for usage example *----------------------------------------------------------------------------*/ checkTime(unsigned int top, unsigned int bot ) { unsigned int ptop, pbot; vxTimeBaseGet(&ptop,&pbot); /* present time top is greater than the given time then time is up */ if (top < ptop) return(1); /* time has past */ /* present time bot is greater than the given time then time is up */ if ( bot <= pbot) return(1); /* time has past */ /* time is not up */ return(0); }
/****************************************************************************** ** Function: CFE_PSP_Get_Timebase() ** ** Purpose: ** Provides a common interface to system timebase. This routine ** is in the BSP because it is sometimes implemented in hardware and ** sometimes taken care of by the RTOS. ** ** Arguments: ** ** Return: ** Timebase register value */ void CFE_PSP_Get_Timebase(uint32 *Tbu, uint32* Tbl) { vxTimeBaseGet((UINT32 *)Tbu, (UINT32 *)Tbl); }