/* * ======== TimestampProvider_get64 ======== * This API has different implementations based on whether we're using a * dedicated timer or sharing the Clock timer. * If we're sharing the Clock timer, we have to multiply the Clock tick count * by the Clock tick period. If we have a dedicate timer, the timer period is * 2^32, so we can just use the MOD->hi tick count as the upper 32-bits of the * timestamp. */ Void TimestampProvider_get64(Types_Timestamp64 *result) { UInt key; /* * If we're sharing the Clock timer, get the timestamp by using the Clock * tick count. */ if (TimestampProvider_useClockTimer) { UInt64 timestamp; /* * Disable interrupts so that the Clock tick count doesn't change if * the timer expires while we are reading it. */ key = Hwi_disable(); /* * timestamp = (clock ticks) x (tick period) + (current timer count) * The 'getExpiredCounts' API retrieves the current Timer count and * also accounts for timer rollover. */ timestamp = (UInt64) Clock_getTicks() * Timer_getPeriod(MOD->timer) + Timer_getExpiredCounts(MOD->timer); Hwi_restore(key); /* * Copy the value into the result structure. * * The 28x is little endian, so it stores the 16-bit words * in reverse order. For example, the value * 0xFEDCBA9876543210 * Is stored as: * Address Value * 0x0 0x3210 * 0x1 0x7654 * 0x2 0xBA98 * 0x3 0xFEDC * * To retrieve the lower 32 bits, simply cast the value as a UInt32. * To retrieve the upper 32 bits, cast the address of 'timestamp' as a * pointer to a UInt32, increment the pointer by 1, then retrieve the * value at that address. */ result->lo = (UInt32) timestamp; result->hi = *(((UInt32 *) ×tamp) + 1); } /* If we have a dedicated timer... */ else { /* Disable interrupts while reading the tick count and timer value. */ key = Hwi_disable(); /* Use the tick counter as the upper 32-bits. */ result->hi = MOD->hi; /* * Get the timer value as the lower 32-bits. This API will also take * timer rollover into account and add 1 to result->hi if necessary. */ Timer_getExpiredCounts64(MOD->timer, result); Hwi_restore(key); } }
/* * ======== Timer_getExpiredCounts ======== */ UInt32 Timer_getExpiredCounts(Timer_Object *obj) { return (Timer_getExpiredCounts64(obj)); }