/***************************************************************************** Function: DWORD TickGet(void) Summary: Obtains the current Tick value. Description: This function retrieves the current Tick value, allowing timing and measurement code to be written in a non-blocking fashion. This function retrieves the least significant 32 bits of the internal tick counter, and is useful for measuring time increments ranging from a few microseconds to a few hours. Use TickGetDiv256 or TickGetDiv64K for longer periods of time. Precondition: None Parameters: None Returns: Lower 32 bits of the current Tick value. ***************************************************************************/ DWORD TickGet(void) { DWORD dw; GetTickCopy(); ((BYTE*)&dw)[0] = vTickReading[0]; // Note: This copy must be done one ((BYTE*)&dw)[1] = vTickReading[1]; // byte at a time to prevent misaligned ((BYTE*)&dw)[2] = vTickReading[2]; // memory reads, which will reset the PIC. ((BYTE*)&dw)[3] = vTickReading[3]; return dw; }
DWORD TickGetDiv64K(void) { DWORD_VAL ret; GetTickCopy(); ret.v[0] = vTickReading[2]; // Note: This copy must be done one ret.v[1] = vTickReading[3]; // byte at a time to prevent misaligned ret.v[2] = vTickReading[4]; // memory reads, which will reset the PIC. ret.v[3] = vTickReading[5]; return ret.Val; }
int GetTickInSeconds(DWORD * Seconds, WORD * Milliseconds) { volatile DWORD S = 0; volatile DWORD m = 0; GetTickCopy(); S = *((DWORD*)&vTickReading[2]); S = S << 1; m = *((WORD*)&vTickReading[0]); m *= 1000ul; m = m / TICKS_PER_SECOND; if(m >= 1000ul){ S += 1; m -= 1000ul; } *Seconds = S; *Milliseconds = (WORD)m; return 0; }
/***************************************************************************** Function: DWORD TickGet(void) Summary: Obtains the current Tick value. Description: This function retrieves the current Tick value, allowing timing and measurement code to be written in a non-blocking fashion. This function retrieves the least significant 32 bits of the internal tick counter, and is useful for measuring time increments ranging from a few microseconds to a few hours. Use TickGetDiv256 or TickGetDiv64K for longer periods of time. Precondition: None Parameters: None Returns: Lower 32 bits of the current Tick value. ***************************************************************************/ DWORD TickGet(void) { GetTickCopy(); return *((DWORD*)&vTickReading[0]); }