📄 timer.c
字号:
/******************************************************************************
* FileName: timer.c - Time and Date.
*
* SanDisk Host Developer's Toolkit
*
* Copyright (c) 1997 - 1999 SanDisk Corporation
* All rights reserved.
*
******************************************************************************/
/* timer.c - Timer service routines for run-time drivers.
*
* These routines provide executive services for the run-time drivers
* running on a PC with no executive kernel. Equivalent services should
* be provided by the kernel environment, replacing these.
*
* The following functions must be provided
*
* SDVOID oem_getsysdate() - Date and time information
* ULONG platform_get_ticks() - Return the current system tick count
* ULONG platform_ticks_per_second() - Return the tick period
*
*/
#include <windows.h>
#include <winbase.h>
#include "oem.h"
#define TICKS_PER_SECOND 18
ULONG delayTime = 0L;
DWORD CurMSec;
/* ======================= Timer management functions ===================== */
/****************************************************************************
** Name: PLATFORM_TICK_P_SECOND - Get current tick per second (USER SUPPLIED)
**
** Summary:
**
** #include "oem.h"
**
** platform_tick_p_second(SDVOID)
**
** Description:
** Provide a way to get the number of ticks per second.
** The default is 18 ticks per second for INTEL platform
** and 60 ticks per second for other platforms.
**
**
** NOTE: Be sure to retain the property of returning its argument. The
** package depends on it.
**
** Entries:
** None
**
** Returns
** The ticks per second.
**
**
*****************************************************************************/
ULONG platform_ticks_p_second(SDVOID) /*__fn__*/
{
return(TICKS_PER_SECOND);
}
/****************************************************************************
** Name: PLATFORM_DELAYMS - delay in certain time (USER SUPPLIED)
**
** Summary:
**
** #include "oem.h"
**
** platform_delayms(SDVOID)
**
** Description:
** Wait for a certain time requested by the user
**
** Entries:
** sleep The granularity in miliseconds
**
** Returns
** None.
**
** Example:
** #include "oem.h"
**
** Note:
** The calculation of the ticks at a given delay time in millisecond is:
** one tick in millisecond = 1000 millisecond / TICKS_PER_SECOND
** no. ticks = (delay time in millisecond) / (onetick in millisecond)
**
*****************************************************************************/
SDVOID platform_delayms(COUNT delay_millis) /*__fn__*/
{
ULONG tticks, tcurr;
tcurr = platform_get_ticks();
tticks = tcurr + (ULONG)(delay_millis / (1000 / TICKS_PER_SECOND));
/* Wait for awhile */
while (tcurr <= tticks)
{
if (tcurr > platform_get_ticks())
{
tticks = 1L + platform_get_ticks();
}
tcurr = platform_get_ticks();
}
}
/****************************************************************************
** Name: PLATFORM_GET_TICKS - Get current timer tick (USER SUPPLIED)
**
** Summary:
**
** #include "oem.h"
**
** platform_get_ticks(SDVOID)
**
** Description:
** Provide a way to get the current timer tick.
**
** Entries:
** None
**
** Returns
** The granularity timer ticks.
**
** Example:
** #include "oem.h"
**
**
*****************************************************************************/
ULONG platform_get_ticks(SDVOID) /*__fn__*/
{
ULONG myTicks;
ULONG WorkTicks;
WorkTicks=GetTickCount();
myTicks=WorkTicks;
/*Since this code was originally developed on a PC with the old 55ms
timer, even a delay of 1ms was potentially 55ms. Delays used in the
code issued via OS_WAIT(n) may need a 55ms tick. You can try playing
with values in the following loop if necessary -- or remove the
loop entirely if everything is working*/
while(myTicks <= WorkTicks + 3)
myTicks=GetTickCount();
return(myTicks);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -