OpenCBM
wait.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 1999-2004 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8  * Copyright 2001-2004 Spiro Trikaliotis
9  *
10  */
11 
22 #include <wdm.h>
23 #include "cbm_driver.h"
24 #include "i_iec.h"
25 
44 NTSTATUS
45 cbmiec_iec_wait(IN PDEVICE_EXTENSION Pdx, IN UCHAR Line, IN UCHAR State, OUT PUCHAR Result)
46 {
47  NTSTATUS ntStatus;
48  UCHAR mask;
49  ULONG i;
50 
51  FUNC_ENTER();
52 
53  FUNC_PARAM((DBG_PREFIX "line = 0x%02x, state = 0x%02x", Line, State));
54 
55  // Find the correct mask for the line which has to be tested
56 
57  switch (Line)
58  {
59  case IEC_LINE_DATA:
60  mask = PP_DATA_IN;
61  break;
62 
63  case IEC_LINE_CLOCK:
64  mask = PP_CLK_IN;
65  break;
66 
67  case IEC_LINE_ATN:
68  mask = PP_ATN_IN;
69  break;
70 
71  default:
72  FUNC_LEAVE_NTSTATUS_CONST(STATUS_INVALID_PARAMETER);
73  }
74 
75  // For which state do we have to wait: Set (= mask) or unset
76 
77  State = State ? mask : 0;
78 
79  i = 0;
80 
81  while ((READ_PORT_UCHAR(IN_PORT) & mask) == State)
82  {
83  if(i >= 20)
84  {
86 
87  if (QueueShouldCancelCurrentIrp(&Pdx->IrpQueue))
88  {
89  FUNC_LEAVE_NTSTATUS_CONST(STATUS_TIMEOUT);
90  }
91  }
92  else
93  {
94  i++;
96  }
97  }
98 
99  ntStatus = cbmiec_iec_poll(Pdx, Result);
100  FUNC_LEAVE_NTSTATUS(ntStatus);
101 }
VOID cbmiec_udelay(IN ULONG howlong)
Wait for a timeout.
Definition: libiec/util.c:66
IEC_TIMEOUTS libiec_global_timeouts
Definition: libiec/init.c:28
NTSTATUS cbmiec_iec_wait(IN PDEVICE_EXTENSION Pdx, IN UCHAR Line, IN UCHAR State, OUT PUCHAR Result)
Wait for a line to have a specific value.
Definition: wait.c:45
#define PP_CLK_IN
The CLOCK IN bit.
Definition: i_iec.h:50
BOOLEAN QueueShouldCancelCurrentIrp(PQUEUE Queue)
Should the current IRP be cancelled?
Definition: queue.c:1041
Internal functions and definitions of the libiec library.
#define IN_PORT
Definition: i_iec.h:58
VOID cbmiec_schedule_timeout(IN ULONG howlong)
Schedule a timeout.
Definition: libiec/util.c:34
ULONG T_8_IEC_WAIT_SHORT_DELAY
= 10 us: For cbmiec_iec_wait(): Granularity (short)
Definition: i_iec.h:127
#define PP_DATA_IN
The DATA IN bit.
Definition: i_iec.h:51
#define IEC_LINE_DATA
Definition: cbmioctl.h:74
#define FUNC_ENTER()
Definition: debug.h:347
#define FUNC_PARAM(_xxx)
Definition: debug.h:351
#define PP_ATN_IN
The ATN IN bit.
Definition: i_iec.h:49
Definitions for the opencbm driver.
#define DBG_PREFIX
Definition: debug.h:320
NTSTATUS cbmiec_iec_poll(IN PDEVICE_EXTENSION Pdx, OUT PUCHAR Result)
Polls the status of the lines on the IEC bus.
Definition: poll.c:39
#define IEC_LINE_ATN
Definition: cbmioctl.h:78
#define IEC_LINE_CLOCK
Definition: cbmioctl.h:76
ULONG T_8_IEC_WAIT_LONG_DELAY
= 20 us: For cbmiec_iec_wait(): Granularity (long)
Definition: i_iec.h:124
#define READ_PORT_UCHAR(_x_)
READ_PORT_UCHAR replacement for debugging.
Definition: i_iec.h:211