zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:2182回复:12

请假大侠:在驱动程序里如何控制延时时间?

楼主#
更多 发布于:2004-07-28 22:48

 我希望驱动程序里面能够循环中查询外部状态和时间,条件满足则执行,每次查询状态的时间最好能比较精确的控制吗?或在vc里有没有现成的延时函数可以调用?谢谢!

最新喜欢:

shahlynnshahly...
AllenZh
驱动老牛
驱动老牛
  • 注册日期2001-08-19
  • 最后登录2015-11-27
  • 粉丝19
  • 关注10
  • 积分1316分
  • 威望2387点
  • 贡献值7点
  • 好评度321点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-07-29 11:58
VC 应用程序中Sleep
内核中KeDelayExecutionThread
如果需要更精确的,使用KeQuerySystemTime来自己写个Delay函数。



________________________________________________________

回答的好请给分
1,承接Windows下驱动/应用开发 2,本人原创虚拟鼠标/键盘,触摸屏,虚拟显卡,Mirror驱动,XP无盘的SCSI虚拟磁盘驱动等 3,windows下有尝技术服务(包括BUG调试,员工培训等) 欢迎深圳和海外企业联系.msn:mfczmh@sina.com
zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-07-29 13:41
我不是很明白用KeQuerySystemTime来自己写个Delay函数,能具体的讲一下吗?有例程更好。多谢回答!只要回答就给分。
AllenZh
驱动老牛
驱动老牛
  • 注册日期2001-08-19
  • 最后登录2015-11-27
  • 粉丝19
  • 关注10
  • 积分1316分
  • 威望2387点
  • 贡献值7点
  • 好评度321点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-07-29 15:38
KeDelayExecutionThread精度可能不够,
你可循环调用KeQuerySystemTime,

void Delay(ULONG xMs)
{
  LARGE_INTEGER    llStart ;
  LARGE_INTEGER    llEnd ;
  LARGE_INTEGER    llFreq ;

   llFreq = llFreq*xMs/1000 ;
   KeQueryPerformanceCounter(&llFreq )
   KeQuerySystemTime(&llStart) ;
   do
       KeQuerySystemTime(&llEnd) ;
   while((llEnd-llStart)<llFreq) ;
}
1,承接Windows下驱动/应用开发 2,本人原创虚拟鼠标/键盘,触摸屏,虚拟显卡,Mirror驱动,XP无盘的SCSI虚拟磁盘驱动等 3,windows下有尝技术服务(包括BUG调试,员工培训等) 欢迎深圳和海外企业联系.msn:mfczmh@sina.com
zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2004-07-29 15:54
多谢回答!我的msdn有点问题,KeQueryPerformanceCounter(&llFreq )
KeQuerySystemTime(&llStart) 这两个函数是包含在哪个头文件里的?xMs,llStart , llEnd ,llFreq 各表示什么意思啊?多谢多谢!
zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2004-07-29 15:56
给分按钮不见了,该怎么给分啊?
AllenZh
驱动老牛
驱动老牛
  • 注册日期2001-08-19
  • 最后登录2015-11-27
  • 粉丝19
  • 关注10
  • 积分1316分
  • 威望2387点
  • 贡献值7点
  • 好评度321点
  • 原创分0分
  • 专家分0分
6楼#
发布于:2004-07-29 15:58
多谢回答!我的msdn有点问题,KeQueryPerformanceCounter(&llFreq )
KeQuerySystemTime(&llStart) 这两个函数是包含在哪个头文件里的?xMs,llStart , llEnd ,llFreq 各表示什么意思啊?多谢多谢!
 


KeQueryPerformanceCounter
LARGE_INTEGER
  KeQueryPerformanceCounter(
  IN PLARGE_INTEGER  PerformanceFrequency  OPTIONAL
  );
KeQueryPerformanceCounter provides the finest grained running count available in the system.

Parameters
PerformanceFrequency
Specifies an optional pointer to a variable that is to receive the performance counter frequency.
Include
wdm.h or ntddk.h

Return Value
KeQueryPerformanceCounter returns the performance counter value in units of ticks.

Comments
KeQueryPerformanceCounter always returns a 64-bit integer representing the number of ticks. Accumulating the count begins when the system is booted. The count is in ticks; the frequency is reported by PerformanceFrequency if this optional parameter is supplied.

The resolution of the timer used to accumulate the current count can be obtained by specifying PerformanceFrequency. For example, if the returned PerformanceFrequency is 2 million, each tick is 1/2 millionth of a second. Each 1/x millionth increment of the count corresponds to one second of elapsed time.

KeQueryPerformanceCounter is intended for time-stamping packets or for computing performance and capacity measurements. It is not intended for measuring elapsed time, for computing stalls or waits, or for iterations.

Use this routine as infrequently as possible. Depending on the platform, KeQueryPerformanceCounter can disable system-wide interrupts for a minimal interval. Consequently, calling this routine frequently or repeatedly, as in an iteration, defeats its purpose of returning very fine-grained, running time-stamp information. Calling this routine too frequently can degrade I/O performance for the calling driver and for the system as a whole.

Callers of KeQueryPerformanceCounter can be running at any IRQL.



KeQuerySystemTime
VOID
  KeQuerySystemTime(
  OUT PLARGE_INTEGER  CurrentTime
  );
KeQuerySystemTime obtains the current system time.

Parameters
CurrentTime
Pointer to the current time on return from KeQuerySystemTime.
Include
wdm.h or ntddk.h

Comments
System time is a count of 100-nanosecond intervals since January 1, 1601. System time is typically updated approximately every ten milliseconds. This value is computed for the GMT time zone. To adjust this value for the local time zone use ExSystemTimeToLocalTime.

Callers of KeQuerySystemTime can be running at any IRQL.


你几个是临时变量,用来确定时间用的。


________________________________________________________

回答的好请给分

1,承接Windows下驱动/应用开发 2,本人原创虚拟鼠标/键盘,触摸屏,虚拟显卡,Mirror驱动,XP无盘的SCSI虚拟磁盘驱动等 3,windows下有尝技术服务(包括BUG调试,员工培训等) 欢迎深圳和海外企业联系.msn:mfczmh@sina.com
AllenZh
驱动老牛
驱动老牛
  • 注册日期2001-08-19
  • 最后登录2015-11-27
  • 粉丝19
  • 关注10
  • 积分1316分
  • 威望2387点
  • 贡献值7点
  • 好评度321点
  • 原创分0分
  • 专家分0分
7楼#
发布于:2004-07-29 15:59
给分按钮不见了,该怎么给分啊?

在楼顶,嘿嘿


________________________________________________________

回答的好请给分

1,承接Windows下驱动/应用开发 2,本人原创虚拟鼠标/键盘,触摸屏,虚拟显卡,Mirror驱动,XP无盘的SCSI虚拟磁盘驱动等 3,windows下有尝技术服务(包括BUG调试,员工培训等) 欢迎深圳和海外企业联系.msn:mfczmh@sina.com
zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
8楼#
发布于:2004-07-29 16:04
多谢多谢!但楼顶好像也没有,改分和给分的都没有了
zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
9楼#
发布于:2004-07-30 17:19
AllenZh,再问一个问题:我把头文件包含进来了,编译时却提示"No such file or directory",还需要什么设置吗?谢谢!

(改分和给分的都没有了,该怎么给分呢?)
AllenZh
驱动老牛
驱动老牛
  • 注册日期2001-08-19
  • 最后登录2015-11-27
  • 粉丝19
  • 关注10
  • 积分1316分
  • 威望2387点
  • 贡献值7点
  • 好评度321点
  • 原创分0分
  • 专家分0分
10楼#
发布于:2004-07-30 20:52
你怎么包含的?
使用
extern "C"
{
#include "xxx.h"
}
实一下(因为我不知道你的工程是NT方式还是WDM方式的)
不同的问题最好放在不同主题中,因为这样查看起来比较方便。




________________________________________________________

回答的好请给分
1,承接Windows下驱动/应用开发 2,本人原创虚拟鼠标/键盘,触摸屏,虚拟显卡,Mirror驱动,XP无盘的SCSI虚拟磁盘驱动等 3,windows下有尝技术服务(包括BUG调试,员工培训等) 欢迎深圳和海外企业联系.msn:mfczmh@sina.com
zsh_7769
驱动小牛
驱动小牛
  • 注册日期2004-04-15
  • 最后登录2005-12-06
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
11楼#
发布于:2004-07-30 21:57
AllenZh,我的工程是WDM方式的,我原本是直接包含那个头文件,现在我按照你说的那样包含,但还是不行,还增加了一个错误"error C2059: syntax error : 'string'",不知道是什么问题?
sean198148
驱动牛犊
驱动牛犊
  • 注册日期2003-01-22
  • 最后登录2014-10-08
  • 粉丝0
  • 关注0
  • 积分44分
  • 威望26点
  • 贡献值0点
  • 好评度3点
  • 原创分0分
  • 专家分0分
12楼#
发布于:2004-07-31 11:51
我不是很明白用KeQuerySystemTime来自己写个Delay函数,能具体的讲一下吗?有例程更好。多谢回答!只要回答就给分。
 

ddk的文档里面推荐用KeQueryTickCount和KeQueryTimeIncrement
函数来计算延时.
游客

返回顶部