Hi
I’m developing a KMDF driver, I would like to know what is the BKM for
Hardware Pin Polling with timeout (I don’t have interrupts on those
Hardware pins), I will explain what I need to do, it is something like this:
Poll Pin 1 Until High || if PollingTime > 50ms Error!
Write Data to HW.
Poll Pin 2 Until Low || if PollingTime > 100ms Error!
Write Read to HW.
For NOW, I’m doing it with WHILE loop and KTIMER (For timeout using
KeReadStateTimer() ) I’m doing something like that:
status = FALSE;
while((status = KeReadStateTimer(&timer)) == FALSE)
{
val = HwReadReg(Reg1);
if (Val & Pin1)
break;
}
if (status == TRUE)
{
ERROR();
}
P.S. i know that it is bad coding 
Thanks in advance.
–
Oren
KeQueryInterruptTime or KeQueryTickCount. Use KeQueryTimeIncrement to get
the granularity.
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-299220-
xxxxx@lists.osr.com] On Behalf Of Oren Weil
Sent: Monday, September 03, 2007 3:34 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] BKM for Hardware Polling with timeout
Hi
I’m developing a KMDF driver, I would like to know what is the BKM for
Hardware Pin Polling with timeout (I don’t have interrupts on those
Hardware pins), I will explain what I need to do, it is something like
this:
Poll Pin 1 Until High || if PollingTime > 50ms Error!
Write Data to HW.
Poll Pin 2 Until Low || if PollingTime > 100ms Error!
Write Read to HW.
For NOW, I’m doing it with WHILE loop and KTIMER (For timeout using
KeReadStateTimer() ) I’m doing something like that:
status = FALSE;
while((status = KeReadStateTimer(&timer)) == FALSE)
{
val = HwReadReg(Reg1);
if (Val & Pin1)
break;
}
if (status == TRUE)
{
ERROR();
}
P.S. i know that it is bad coding 
Thanks in advance.
–
Oren
NTDEV is sponsored by OSR
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer
Thanks,
but it is ok that I’m polling the pin using a loop?
Mark Roddy wrote:
KeQueryInterruptTime or KeQueryTickCount. Use KeQueryTimeIncrement to get
the granularity.
> -----Original Message-----
> From: xxxxx@lists.osr.com [mailto:bounce-299220-
> xxxxx@lists.osr.com] On Behalf Of Oren Weil
> Sent: Monday, September 03, 2007 3:34 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] BKM for Hardware Polling with timeout
>
> Hi
> I’m developing a KMDF driver, I would like to know what is the BKM for
> Hardware Pin Polling with timeout (I don’t have interrupts on those
> Hardware pins), I will explain what I need to do, it is something like
> this:
>
> Poll Pin 1 Until High || if PollingTime > 50ms Error!
> Write Data to HW.
> Poll Pin 2 Until Low || if PollingTime > 100ms Error!
> Write Read to HW.
>
> For NOW, I’m doing it with WHILE loop and KTIMER (For timeout using
> KeReadStateTimer() ) I’m doing something like that:
>
> status = FALSE;
> while((status = KeReadStateTimer(&timer)) == FALSE)
> {
> val = HwReadReg(Reg1);
> if (Val & Pin1)
> break;
> }
>
> if (status == TRUE)
> {
> ERROR();
> }
>
> P.S. i know that it is bad coding 
>
> Thanks in advance.
>
> –
> Oren
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
–
Oren Weil
Hi Oren,
I once used the following code to poll with a time-out:
retries = 0;
KeStallExecutionProcessor(INTERVAL);
while (condition is false)
{
KeStallExecutionProcessor(INTERVAL);
if (retries < MAX_RETRIES)
{
retries++;
}
else
{
return FALSE; //timeout
}
}
I don’t know if this code is less efficient than working with a timer, but it sure did its job.
Kurt
> I don’t know if this code is less efficient than working with a timer, but it sure did its job.
Sure … , but depending on your INTERVAL , MAX_RETRIES values and where you call that code , you may strangle the OS to death. I
hope you don’t have used this code in a worldwide spread driver …
C.
----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Tuesday, September 04, 2007 9:38 AM
Subject: RE:[ntdev] BKM for Hardware Polling with timeout
> Hi Oren,
>
> I once used the following code to poll with a time-out:
> retries = 0;
> KeStallExecutionProcessor(INTERVAL);
> while (condition is false)
> {
> KeStallExecutionProcessor(INTERVAL);
> if (retries < MAX_RETRIES)
> {
> retries++;
> }
> else
> {
> return FALSE; //timeout
> }
> }
>
> I don’t know if this code is less efficient than working with a timer, but it sure did its job.
>
> Kurt
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
I use KeDelayExecutionThread in an interrupt loop that polls for dma
completions in a chip that cannot interrupt, and it works fine. The time
interval goes in units of 100 ns, which is ok for my purposes. I may be
wrong, but I believe that KeStallExecutionProcessor does a busy wait, so,
it’s not clear whether it should be used for longer waits.
Alberto.
----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Tuesday, September 04, 2007 3:38 AM
Subject: RE:[ntdev] BKM for Hardware Polling with timeout
> Hi Oren,
>
> I once used the following code to poll with a time-out:
> retries = 0;
> KeStallExecutionProcessor(INTERVAL);
> while (condition is false)
> {
> KeStallExecutionProcessor(INTERVAL);
> if (retries < MAX_RETRIES)
> {
> retries++;
> }
> else
> {
> return FALSE; //timeout
> }
> }
>
> I don’t know if this code is less efficient than working with a timer, but
> it sure did its job.
>
> Kurt
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
Oren Weil wrote:
I’m developing a KMDF driver, I would like to know what is the BKM for
Hardware Pin Polling with timeout (I don’t have interrupts on those
Hardware pins), I will explain what I need to do, it is something like this:
Poll Pin 1 Until High || if PollingTime > 50ms Error!
Write Data to HW.
Poll Pin 2 Until Low || if PollingTime > 100ms Error!
Write Read to HW.
For NOW, I’m doing it with WHILE loop and KTIMER (For timeout using
KeReadStateTimer() ) I’m doing something like that:
status = FALSE;
while((status = KeReadStateTimer(&timer)) == FALSE)
{
val = HwReadReg(Reg1);
if (Val & Pin1)
break;
}
if (status == TRUE)
{
ERROR();
}
P.S. i know that it is bad coding 
Polling like this for tens or hundreds of milliseconds is not
acceptable. Create a periodic timer that runs every millisecond, or
every couple of milliseconds. In the timer callback, figure out the
hardware state, and take the next action. You can keep a countdown
value that tells you when is too long.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
how can still poll hardware pin without strangle the OS to death?
Christiaan Ghijselinck wrote:
> I don’t know if this code is less efficient than working with a timer,
> but it sure did its job.
Sure … , but depending on your INTERVAL , MAX_RETRIES values and
where you call that code , you may strangle the OS to death. I hope you
don’t have used this code in a worldwide spread driver …
C.
----- Original Message ----- From:
> To: “Windows System Software Devs Interest List”
> Sent: Tuesday, September 04, 2007 9:38 AM
> Subject: RE:[ntdev] BKM for Hardware Polling with timeout
>
>
>> Hi Oren,
>>
>> I once used the following code to poll with a time-out:
>> retries = 0;
>> KeStallExecutionProcessor(INTERVAL);
>> while (condition is false)
>> {
>> KeStallExecutionProcessor(INTERVAL);
>> if (retries < MAX_RETRIES)
>> {
>> retries++;
>> }
>> else
>> {
>> return FALSE; //timeout
>> }
>> }
>>
>> I don’t know if this code is less efficient than working with a timer,
>> but it sure did its job.
>>
>> Kurt
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>
–
Oren Weil
Thanks for the answer.
let say that I need to implement it in IOCTL and there is a flow that I
need to perform (that include checking pins and setting/clearing
hardware pins) to send the command and to received the answer,
with timer callbacks I need to build a complex Stats Machine, no?
Tim Roberts wrote:
Oren Weil wrote:
> I’m developing a KMDF driver, I would like to know what is the BKM for
> Hardware Pin Polling with timeout (I don’t have interrupts on those
> Hardware pins), I will explain what I need to do, it is something like this:
>
> Poll Pin 1 Until High || if PollingTime > 50ms Error!
> Write Data to HW.
> Poll Pin 2 Until Low || if PollingTime > 100ms Error!
> Write Read to HW.
>
> For NOW, I’m doing it with WHILE loop and KTIMER (For timeout using
> KeReadStateTimer() ) I’m doing something like that:
>
> status = FALSE;
> while((status = KeReadStateTimer(&timer)) == FALSE)
> {
> val = HwReadReg(Reg1);
> if (Val & Pin1)
> break;
> }
>
> if (status == TRUE)
> {
> ERROR();
> }
>
> P.S. i know that it is bad coding 
>
Polling like this for tens or hundreds of milliseconds is not
acceptable. Create a periodic timer that runs every millisecond, or
every couple of milliseconds. In the timer callback, figure out the
hardware state, and take the next action. You can keep a countdown
value that tells you when is too long.
–
Oren Weil
Oren Weil wrote:
how can still poll hardware pin without strangle the OS to death?
Use KeDelayExecutionThread instead of KeStallExecutionProcessor.
KeDelay goes into a friendly wait state, whereas KeStall is a tight CPU
loop.
Or, you can use a timer, as I suggested.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Oren Weil wrote:
Thanks for the answer.
let say that I need to implement it in IOCTL and there is a flow that I
need to perform (that include checking pins and setting/clearing
hardware pins) to send the command and to received the answer,
with timer callbacks I need to build a complex Stats Machine, no?
Well, I doubt that it would be a “complex” state machine, although I
don’t know your hardware. In the long run, there’s little difference
between using a timer callback and using straight-line flow with
KeDelayExecutionThread, as long as the application doesn’t want to use
overlapped I/O.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
Use a timer as Tim suggested.
Or I know, how about you replace your hardware designer with someone who has
heard of this new thing called interrupts
Just a joke…not a flame.
Bill M.
“Oren Weil” wrote in message news:xxxxx@ntdev…
> how can still poll hardware pin without strangle the OS to death?
>
>
> Christiaan Ghijselinck wrote:
>>
>>> I don’t know if this code is less efficient than working with a timer,
>>> but it sure did its job.
>>
>> Sure … , but depending on your INTERVAL , MAX_RETRIES values and
>> where you call that code , you may strangle the OS to death. I hope you
>> don’t have used this code in a worldwide spread driver …
>>
>> C.
>>
>> ----- Original Message ----- From:
>> To: “Windows System Software Devs Interest List”
>> Sent: Tuesday, September 04, 2007 9:38 AM
>> Subject: RE:[ntdev] BKM for Hardware Polling with timeout
>>
>>
>>> Hi Oren,
>>>
>>> I once used the following code to poll with a time-out:
>>> retries = 0;
>>> KeStallExecutionProcessor(INTERVAL);
>>> while (condition is false)
>>> {
>>> KeStallExecutionProcessor(INTERVAL);
>>> if (retries < MAX_RETRIES)
>>> {
>>> retries++;
>>> }
>>> else
>>> {
>>> return FALSE; //timeout
>>> }
>>> }
>>>
>>> I don’t know if this code is less efficient than working with a timer,
>>> but it sure did its job.
>>>
>>> Kurt
>>>
>>> —
>>> NTDEV is sponsored by OSR
>>>
>>> For our schedule of WDF, WDM, debugging and other seminars visit:
>>> http://www.osr.com/seminars
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
>
> –
> Oren Weil
>