OpenCBM
ppread.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,2008-2009 Spiro Trikaliotis
9  *
10  */
11 
22 #include <wdm.h>
23 #include "cbm_driver.h"
24 #include "i_iec.h"
25 
26 
38 LONG
39 cbmiec_i_pp_read_debounced(IN PDEVICE_EXTENSION Pdx)
40 {
41  int returnValue=-1, returnValue2, returnValue3, timeoutCount=0;
42 
43  FUNC_ENTER();
44 
45  returnValue3 = READ_PORT_UCHAR(PAR_PORT);
46  returnValue2 = ~returnValue3; // ensure to read once more
47 
48  do {
49  if (++timeoutCount >= 8)
50  {
51  DBG_PRINT((DBG_PREFIX "Triple-Debounce TIMEOUT: 0x%02x, 0x%02x, 0x%02x (%d)",
52  returnValue, returnValue2, returnValue3, timeoutCount));
53  break;
54  }
55  returnValue = returnValue2;
56  returnValue2 = returnValue3;
57  returnValue3 = READ_PORT_UCHAR(PAR_PORT);
58  } while ((returnValue != returnValue2) || (returnValue != returnValue3));
59 
60  FUNC_LEAVE_LONG(returnValue);
61 }
62 
78 NTSTATUS
79 cbmiec_pp_read(IN PDEVICE_EXTENSION Pdx, OUT UCHAR *Return)
80 {
81  LONG returnValue = -1;
82  NTSTATUS ntStatus = STATUS_NO_DATA_DETECTED;
83 
84  FUNC_ENTER();
85 
86  if (!(Pdx->IecOutBits & PP_LP_BIDIR))
87  {
90  }
91 
92  returnValue = cbmiec_i_pp_read_debounced(Pdx);
93 
94  if (returnValue >= 0)
95  {
96  *Return = (UCHAR) returnValue;
97  ntStatus = STATUS_SUCCESS;
98  }
99 
100  FUNC_LEAVE_NTSTATUS(ntStatus);
101 }
#define FUNC_LEAVE_LONG(_xxx)
Definition: debug.h:372
#define PAR_PORT
Definition: i_iec.h:55
#define CBMIEC_SET(_set)
Definition: i_iec.h:64
NTSTATUS cbmiec_pp_read(IN PDEVICE_EXTENSION Pdx, OUT UCHAR *Return)
Read a byte from the X[M|A]P1541 cable.
Definition: ppread.c:79
Internal functions and definitions of the libiec library.
#define PP_LP_BIDIR
Bit for setting set bidirectional mode of the LPT.
Definition: i_iec.h:46
LONG cbmiec_i_pp_read_debounced(IN PDEVICE_EXTENSION Pdx)
Read a byte from the X[M|A]P1541 cable. Make sure to debounce it.
Definition: ppread.c:39
#define WRITE_PORT_UCHAR(_x_, _y_)
WRITE_PORT_UCHAR replacement for debugging.
Definition: i_iec.h:221
#define FUNC_ENTER()
Definition: debug.h:347
Definitions for the opencbm driver.
#define DBG_PREFIX
Definition: debug.h:320
#define DBG_PRINT(_xxx)
Definition: debug.h:403
#define READ_PORT_UCHAR(_x_)
READ_PORT_UCHAR replacement for debugging.
Definition: i_iec.h:211