Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

libiec/util.c

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or
00003  *  modify it under the terms of the GNU General Public License
00004  *  as published by the Free Software Foundation; either version
00005  *  2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 1999-2004 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
00008  *  Copyright 2001-2004 Spiro Trikaliotis
00009  *
00010  */
00011 
00021 #include <wdm.h>
00022 #include "cbm_driver.h"
00023 #include "i_iec.h"
00024 
00034 VOID
00035 cbmiec_schedule_timeout(IN ULONG Howlong)
00036 {
00037     LARGE_INTEGER li;
00038     NTSTATUS ntStatus;
00039     KTIMER cbmTimer;
00040 
00041     FUNC_ENTER();
00042 
00043     // Note: The following timer is NEVER fired! We just use it
00044     //       to allow a KeWaitForSingleObject()-determined timeout!
00045 
00046     KeInitializeTimer (&cbmTimer);
00047 
00048     li.QuadPart  = - (LONG) Howlong;
00049     li.QuadPart *= 10i64;
00050 
00051     ntStatus = KeWaitForSingleObject(&cbmTimer, UserRequest,
00052                   KernelMode, FALSE, &li);
00053 
00054     FUNC_LEAVE();
00055 }
00056 
00066 VOID
00067 cbmiec_udelay(IN ULONG Howlong)
00068 {
00069     LARGE_INTEGER li;
00070     NTSTATUS ntStatus;
00071 
00072     FUNC_ENTER();
00073 
00074 #if 1
00075     KeStallExecutionProcessor(Howlong);
00076 #else
00077     li.QuadPart  = - (LONG) Howlong;
00078     li.QuadPart *= 10i64;
00079 
00080     ntStatus = KeDelayExecutionThread(KernelMode, FALSE, &li);
00081 #endif
00082 
00083     FUNC_LEAVE();
00084 }
00085 
00086 
00094 VOID
00095 cbmiec_block_irq(PDEVICE_EXTENSION Pdx)
00096 {
00097     KIRQL irql; // do not use Irql directly, but only indirectly,
00098                 // as suggested by Doron Holan at
00099                 // http://blogs.msdn.com/doronh/archive/2006/03/08/546934.aspx
00100 
00101     FUNC_ENTER();
00102 
00103     DBGDO(DBG_ASSERT(InterlockedIncrement(&Pdx->IecBlockIrqUsageCount)==1));
00104 
00105     KeRaiseIrql(HIGH_LEVEL, &irql);
00106     Pdx->IecBlockIrqPreviousIrql = irql;
00107 
00108     CLI();
00109 
00110     FUNC_LEAVE();
00111 }
00112 
00118 VOID
00119 cbmiec_release_irq(PDEVICE_EXTENSION Pdx)
00120 {
00121     FUNC_ENTER();
00122 
00123     STI();
00124 
00125     KeLowerIrql(Pdx->IecBlockIrqPreviousIrql);
00126 
00127     DBGDO(DBG_ASSERT(InterlockedDecrement(&Pdx->IecBlockIrqUsageCount)==0));
00128 
00129     FUNC_LEAVE();
00130 }

Generated on Sun Apr 30 18:46:00 2006 for opencbm by  doxygen 1.4.2