OpenCBM
i_iec.h
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 2004, 2007 Spiro Trikaliotis
8  *
9  */
10 
19 #ifndef I_CBMIEC_H
20 #define I_CBMIEC_H
21 
22 #include "iec.h"
23 
24 /* The port addresses (relative) of the parallel port */
25 
27 #define PARALLEL_DATA_OFFSET 0
28 
29 #define PARALLEL_STATUS_OFFSET 1
30 
31 #define PARALLEL_CONTROL_OFFSET 2
32 
33 #define PARALLEL_REGISTER_SPAN 3
34 
35 
36 /* lpt output lines */
37 /* this is correct for a XA1541/XM1541; a XE1541 has DATA and RESET exchanged! */
38 
39 #define PP_ATN_OUT (Pdx->IecAtnOut)
40 #define PP_CLK_OUT (Pdx->IecClkOut)
41 #define PP_DATA_OUT (Pdx->IecDataOut)
42 #define PP_RESET_OUT (Pdx->IecResetOut)
43 
44 /* additional LP control */
45 #define PP_LP_IRQ 0x10
46 #define PP_LP_BIDIR 0x20
47 
48 /* lpt input lines */
49 #define PP_ATN_IN (Pdx->IecAtnIn)
50 #define PP_CLK_IN (Pdx->IecClkIn)
51 #define PP_DATA_IN (Pdx->IecDataIn)
52 #define PP_RESET_IN (Pdx->IecResetIn)
53 
54 
55 #define PAR_PORT (Pdx->ParPortPortAddress + PARALLEL_DATA_OFFSET)
56 
58 #define IN_PORT (Pdx->ParPortPortAddress + PARALLEL_STATUS_OFFSET)
59 
61 #define OUT_PORT (Pdx->ParPortPortAddress + PARALLEL_CONTROL_OFFSET)
62 
64 #define CBMIEC_SET(_set) do { DBG_ASSERT((_set) != 0); Pdx->IecOutBits|=(_set); WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
65 
66 #define CBMIEC_RELEASE(_rel) do { DBG_ASSERT((_rel) != 0); Pdx->IecOutBits&=~(_rel); WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
67 
68 #define CBMIEC_SET_RELEASE(_set,_rel) do { DBG_ASSERT((_set) != 0); DBG_ASSERT((_rel) != 0); Pdx->IecOutBits|=(_set); Pdx->IecOutBits&=~(_rel); \
69  WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
70 
72 #define CBMIEC_ARE_OUTPUT_LINES_CORRECT() ( READ_PORT_UCHAR(OUT_PORT) == (UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits) )
73 
75 #define CBMIEC_GET(_line) (((READ_PORT_UCHAR(IN_PORT) ^ Pdx->IecInEor) & _line)==0?1:0)
76 
77 
79 typedef
80 struct IEC_TIMEOUTS
81 {
83  ULONG T_holdreset;
85  ULONG T_afterreset;
86 
89 
92 
94  ULONG T_2_Times;
95 
98 
101 
103  ULONG T_4_Times;
104 
107 
109  ULONG T_5_Times;
110 
113 
115  ULONG T_6_Times;
116 
119 
122 
125 
128 
130  ULONG T_9_Times;
131 
134 
137 
140 
143 
146 
149 
150  // sendbyte related:
151 
154 
157 
159  ULONG T_17_Times;
160 
163 
166 
169 
170 } IEC_TIMEOUTS;
171 
174 
175 #if DBG
176 
177 /* The functions DbgWp() and DbgRp() are used to intercept
178  * NDIS_WRITE_PORT() and NDIS_READ_PORT() when debugging.
179  */
180 extern VOID
181 DbgWp(IN PUCHAR Port, IN UCHAR Value);
182 
183 extern UCHAR
184 DbgRp(IN PUCHAR Port);
185 
194 extern VOID
195 cbmiec_show_port(UCHAR *s);
196 
197 /*
198  * If DBG is defined, we want to be able to monitor every
199  * READ_PORT_UCHAR and WRITE_PORT_UCHAR, so we override them
200  * here with our own functions:
201  */
202 
211 #define READ_PORT_UCHAR(_x_) DbgRp(_x_)
212 
221 #define WRITE_PORT_UCHAR(_x_, _y_) DbgWp(_x_, _y_)
222 
223 /*
224  * dump input lines
225  */
226 extern VOID
227 cbmiec_show_state(IN PDEVICE_EXTENSION Pdx, IN UCHAR *Str);
228 
229 #else /* #if DBG */
230 
232  #define cbmiec_show_state(_x_, _y_)
233 
234 #endif /* #if DBG */
235 
236 extern VOID
237 cbmiec_schedule_timeout(IN ULONG howlong); // howlong in us!
238 
239 extern VOID
240 cbmiec_udelay(IN ULONG howlong); // howlong in ms!
241 
242 extern NTSTATUS
243 cbmiec_i_raw_read(IN PDEVICE_EXTENSION Pdx, OUT UCHAR *buf, ULONG cnt, OUT ULONG *pReceived);
244 
245 extern NTSTATUS
246 cbmiec_i_raw_write(PDEVICE_EXTENSION Pdx, const UCHAR *buf, ULONG cnt, ULONG *pSent, BOOLEAN atn, BOOLEAN talk);
247 
248 extern VOID
249 cbmiec_block_irq(PDEVICE_EXTENSION Pdx);
250 
251 extern VOID
252 cbmiec_release_irq(PDEVICE_EXTENSION Pdx);
253 
254 extern LONG
255 cbmiec_i_pp_read_debounced(IN PDEVICE_EXTENSION Pdx);
256 
257 
260 typedef
261 enum cablestate_e
262 {
267 } CABLESTATE;
268 
269 extern VOID
270 cbmiec_setcablestate(PDEVICE_EXTENSION Pdx, CABLESTATE State);
271 
272 #ifdef USE_DPC
273 
274  extern VOID
275  cbmiec_dpc(IN PKDPC Dpc, IN PDEVICE_OBJECT Fdo, IN PIRP Irp, IN PVOID Context);
276 
277 #endif // #ifdef USE_DPC
278 
279 #endif /* #ifndef I_CBMIEC_H */
VOID cbmiec_udelay(IN ULONG howlong)
Wait for a timeout.
Definition: libiec/util.c:66
ULONG T_1_RECV_WAIT_CLK_LOW_DATA_READY_GRANU
= 20 us: Starting reception, granularity for the wait until CLK is low
Definition: i_iec.h:91
IEC_TIMEOUTS libiec_global_timeouts
Definition: libiec/init.c:28
enum cablestate_e CABLESTATE
@@@
Definition: cbm_driver.h:92
ULONG T_11_SEND_BEFORE_BYTE_DELAY
= 50 us: Extra wait before sending of every single byte
Definition: i_iec.h:139
ULONG T_15_SEND_BEFORE_BIT_DELAY_T_S
= 70 us: Inter-bit wait time while sending a byte
Definition: i_iec.h:153
ULONG T_10_SEND_BEFORE_1ST_BYTE
= 20 us: Extra wait before sending 1st byte
Definition: i_iec.h:136
NTSTATUS cbmiec_i_raw_write(PDEVICE_EXTENSION Pdx, const UCHAR *buf, ULONG cnt, ULONG *pSent, BOOLEAN atn, BOOLEAN talk)
Write some bytes to the IEC bus.
Definition: i_rawwrite.c:54
ULONG T_14_SEND_AT_END_DELAY
= 100 us: Extra wait after sending a block
Definition: i_iec.h:148
ULONG T_12_SEND_AFTER_BYTE_DELAY
= 100 us: Extra wait after sending every single byte
Definition: i_iec.h:142
ULONG T_17_SEND_FRAME_HANDSHAKE_T_F
= 100 us: Granularity: How long to wait for a frame handshake after sending a byte ...
Definition: i_iec.h:162
ULONG T_5_Times
x T_5, is 200: How long to wait for CLK high (=active) for every single bit
Definition: i_iec.h:109
ULONG T_16_SEND_BIT_TIME_T_V
= 20 us: How long to hold CLK low for every bit while sending
Definition: i_iec.h:156
ULONG T_17_Times
x T_17, is 20: How long to wait for a frame handshake after sending a byte
Definition: i_iec.h:159
ULONG T_9_SEND_WAIT_DEVICES_T_AT
= 10 us: Granularity: On send, how long to wait for driver to set DATA
Definition: i_iec.h:133
enum cablestate_e CABLESTATE
remember in which state the cable is currently
struct IEC_TIMEOUTS IEC_TIMEOUTS
cablestate_e
remember in which state the cable is currently
Definition: i_iec.h:260
VOID cbmiec_show_state(IN PDEVICE_EXTENSION Pdx, IN UCHAR *Str)
Dump the input lines.
Definitions for the libiec library.
ULONG T_holdreset
= 100 us: How long is a RESET being held?
Definition: i_iec.h:83
ULONG T_5_RECV_BIT_WAIT_CLK_HIGH
= 10 us: Granularity: How long to wait for CLK high (=active) for every single bit ...
Definition: i_iec.h:112
ULONG T_6_Times
x T_6, is 100: How long to wait for CLK low again (=inactive) after every single bit ...
Definition: i_iec.h:115
ULONG T_WaitForListener_Granu_T_H
= 10 us: Graunularity of wait_for_listener() polls
Definition: i_iec.h:88
ULONG T_4_Times
x T_4, is 100: Wait for CLK high after an EOI
Definition: i_iec.h:103
ULONG T_PARALLEL_BURST_READ_BYTE_HANDSHAKED
= 300ms, timeout for reading one handshaked byte with parallel burst
Definition: i_iec.h:165
ULONG T_4_RECV_WAIT_CLK_HIGH_AFTER_EOI_GRANU
= 20 us: Granularity: Wait for CLK high after an EOI
Definition: i_iec.h:106
ULONG T_2_RECV_WAIT_CLK_HIGH_T_NE
= 10 us: Granularity: How long do we wait for the data of the other site
Definition: i_iec.h:97
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
ULONG T_7_RECV_INTER_BYTE_DELAY
= 70 us: Inter-byte delay on reception
Definition: i_iec.h:121
ULONG T_3_RECV_EOI_RECOGNIZED
= 70 us: How long to set DATA to ack an EOI
Definition: i_iec.h:100
NTSTATUS cbmiec_i_raw_read(IN PDEVICE_EXTENSION Pdx, OUT UCHAR *buf, ULONG cnt, OUT ULONG *pReceived)
Read some bytes from the IEC bus.
Definition: i_rawread.c:45
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
VOID cbmiec_show_port(UCHAR *s)
show the value of parallel port lines
VOID cbmiec_block_irq(PDEVICE_EXTENSION Pdx)
Block all interrupts.
Definition: libiec/util.c:94
ULONG T_afterreset
= 5 s: How long to delay after a RESET
Definition: i_iec.h:85
ULONG T_6_RECV_BIT_WAIT_CLK_LOW
= 20 us: How long to wait for CLK low again (=inactive) after every single bit
Definition: i_iec.h:118
VOID cbmiec_setcablestate(PDEVICE_EXTENSION Pdx, CABLESTATE State)
Set the current state of the cable detection.
Definition: checkcable.c:494
ULONG T_13_SEND_TURN_AROUND_LISTENER_TALKER_T_TK
= 20 us: On listener-talker-turnaround, how long to wait until CLK is released
Definition: i_iec.h:145
UCHAR DbgRp(IN PUCHAR Port)
Read from a port address with debugging output.
ULONG T_PARALLEL_BURST_WRITE_BYTE_HANDSHAKED
= 300ms, timeout for writing one handshaked byte with parallel burst
Definition: i_iec.h:168
ULONG T_9_Times
x T_9a, is 100: On send, how long to wait for driver to set DATA
Definition: i_iec.h:130
VOID DbgWp(IN PUCHAR Port, IN UCHAR Value)
Write to a port address with debugging output.
VOID cbmiec_release_irq(PDEVICE_EXTENSION Pdx)
Release the interrupts.
Definition: libiec/util.c:118
ULONG T_8_IEC_WAIT_LONG_DELAY
= 20 us: For cbmiec_iec_wait(): Granularity (long)
Definition: i_iec.h:124
ULONG T_2_Times
x T_2 is 40
Definition: i_iec.h:94