OpenCBM
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
i_iec.h File Reference

Internal functions and definitions of the libiec library. More...

#include "iec.h"

Go to the source code of this file.

Data Structures

struct  IEC_TIMEOUTS
 

Macros

#define PARALLEL_DATA_OFFSET   0
 
#define PARALLEL_STATUS_OFFSET   1
 
#define PARALLEL_CONTROL_OFFSET   2
 
#define PARALLEL_REGISTER_SPAN   3
 
#define PP_ATN_OUT   (Pdx->IecAtnOut)
 The ATN OUT bit.
 
#define PP_CLK_OUT   (Pdx->IecClkOut)
 The CLOCK OUT bit.
 
#define PP_DATA_OUT   (Pdx->IecDataOut)
 The DATA OUT bit.
 
#define PP_RESET_OUT   (Pdx->IecResetOut)
 The RESET OUT bit.
 
#define PP_LP_IRQ   0x10
 Bit for allowing interrupts of the LPT.
 
#define PP_LP_BIDIR   0x20
 Bit for setting set bidirectional mode of the LPT.
 
#define PP_ATN_IN   (Pdx->IecAtnIn)
 The ATN IN bit.
 
#define PP_CLK_IN   (Pdx->IecClkIn)
 The CLOCK IN bit.
 
#define PP_DATA_IN   (Pdx->IecDataIn)
 The DATA IN bit.
 
#define PP_RESET_IN   (Pdx->IecResetIn)
 The RESET IN bit.
 
#define PAR_PORT   (Pdx->ParPortPortAddress + PARALLEL_DATA_OFFSET)
 
#define IN_PORT   (Pdx->ParPortPortAddress + PARALLEL_STATUS_OFFSET)
 
#define OUT_PORT   (Pdx->ParPortPortAddress + PARALLEL_CONTROL_OFFSET)
 
#define CBMIEC_SET(_set)   do { DBG_ASSERT((_set) != 0); Pdx->IecOutBits|=(_set); WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
 
#define CBMIEC_RELEASE(_rel)   do { DBG_ASSERT((_rel) != 0); Pdx->IecOutBits&=~(_rel); WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
 
#define CBMIEC_SET_RELEASE(_set, _rel)
 
#define CBMIEC_ARE_OUTPUT_LINES_CORRECT()   ( READ_PORT_UCHAR(OUT_PORT) == (UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits) )
 
#define CBMIEC_GET(_line)   (((READ_PORT_UCHAR(IN_PORT) ^ Pdx->IecInEor) & _line)==0?1:0)
 
#define READ_PORT_UCHAR(_x_)   DbgRp(_x_)
 READ_PORT_UCHAR replacement for debugging. More...
 
#define WRITE_PORT_UCHAR(_x_, _y_)   DbgWp(_x_, _y_)
 WRITE_PORT_UCHAR replacement for debugging. More...
 

Typedefs

typedef struct IEC_TIMEOUTS IEC_TIMEOUTS
 
typedef enum cablestate_e CABLESTATE
 remember in which state the cable is currently
 

Enumerations

enum  cablestate_e { CABLESTATE_UNKNOWN, CABLESTATE_ERROR_OCCURRED, CABLESTATE_TESTED, CABLESTATE_SUCCESSFULLY_USED }
 remember in which state the cable is currently More...
 

Functions

VOID DbgWp (IN PUCHAR Port, IN UCHAR Value)
 Write to a port address with debugging output. More...
 
UCHAR DbgRp (IN PUCHAR Port)
 Read from a port address with debugging output. More...
 
VOID cbmiec_show_port (UCHAR *s)
 show the value of parallel port lines More...
 
VOID cbmiec_show_state (IN PDEVICE_EXTENSION Pdx, IN UCHAR *Str)
 Dump the input lines. More...
 
VOID cbmiec_schedule_timeout (IN ULONG howlong)
 Schedule a timeout. More...
 
VOID cbmiec_udelay (IN ULONG howlong)
 Wait for a timeout. More...
 
NTSTATUS cbmiec_i_raw_read (IN PDEVICE_EXTENSION Pdx, OUT UCHAR *buf, ULONG cnt, OUT ULONG *pReceived)
 Read some bytes from the IEC bus. More...
 
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. More...
 
VOID cbmiec_block_irq (PDEVICE_EXTENSION Pdx)
 Block all interrupts. More...
 
VOID cbmiec_release_irq (PDEVICE_EXTENSION Pdx)
 Release the interrupts. More...
 
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. More...
 
VOID cbmiec_setcablestate (PDEVICE_EXTENSION Pdx, CABLESTATE State)
 Set the current state of the cable detection.
 

Variables

IEC_TIMEOUTS libiec_global_timeouts
 

Detailed Description

Internal functions and definitions of the libiec library.



Author
Spiro Trikaliotis

Definition in file i_iec.h.

Macro Definition Documentation

#define CBMIEC_ARE_OUTPUT_LINES_CORRECT ( )    ( READ_PORT_UCHAR(OUT_PORT) == (UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits) )

for the "hibernate workaround": Find out if the status of the control lines is like it should be

Definition at line 72 of file i_iec.h.

Referenced by cbmiec_is_cable_state_wrong().

#define CBMIEC_GET (   _line)    (((READ_PORT_UCHAR(IN_PORT) ^ Pdx->IecInEor) & _line)==0?1:0)
#define CBMIEC_RELEASE (   _rel)    do { DBG_ASSERT((_rel) != 0); Pdx->IecOutBits&=~(_rel); WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
#define CBMIEC_SET (   _set)    do { DBG_ASSERT((_set) != 0); Pdx->IecOutBits|=(_set); WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
#define CBMIEC_SET_RELEASE (   _set,
  _rel 
)
Value:
do { DBG_ASSERT((_set) != 0); DBG_ASSERT((_rel) != 0); Pdx->IecOutBits|=(_set); Pdx->IecOutBits&=~(_rel); \
WRITE_PORT_UCHAR(OUT_PORT,(UCHAR)(Pdx->IecOutEor ^ Pdx->IecOutBits)); } while (0)
#define OUT_PORT
Definition: i_iec.h:61
#define DBG_ASSERT(_xxx)
Definition: debug.h:401
#define WRITE_PORT_UCHAR(_x_, _y_)
WRITE_PORT_UCHAR replacement for debugging.
Definition: i_iec.h:221

set and release an output line on the parallel port (simultaneously)

Definition at line 68 of file i_iec.h.

Referenced by cbmiec_iec_setrelease(), and cbmiec_send_byte().

#define IN_PORT   (Pdx->ParPortPortAddress + PARALLEL_STATUS_OFFSET)

Get the address of the parallel port STATUS register (= the port for input) out of the Pdx info

Definition at line 58 of file i_iec.h.

Referenced by cbmiec_iec_dbg_read(), cbmiec_iec_poll(), cbmiec_iec_wait(), and cbmiec_interrupt().

#define OUT_PORT   (Pdx->ParPortPortAddress + PARALLEL_CONTROL_OFFSET)

Get the address of the parallel port CONTROL register (= the port for output) out of the Pdx info

Definition at line 61 of file i_iec.h.

Referenced by cbmiec_checkcable(), and cbmiec_iec_dbg_write().

#define PAR_PORT   (Pdx->ParPortPortAddress + PARALLEL_DATA_OFFSET)

Get the address of the parallel port DATA register out of the Pdx info

Definition at line 55 of file i_iec.h.

Referenced by cbmiec_i_pp_read_debounced(), cbmiec_pp_read(), and cbmiec_pp_write().

#define PARALLEL_CONTROL_OFFSET   2

the CONTROL register is located here

Definition at line 31 of file i_iec.h.

#define PARALLEL_DATA_OFFSET   0

the DATA register is located here

Definition at line 27 of file i_iec.h.

#define PARALLEL_REGISTER_SPAN   3

the count of port addresses the parallel port occupies

Definition at line 33 of file i_iec.h.

#define PARALLEL_STATUS_OFFSET   1

the STATUS register is located here

Definition at line 29 of file i_iec.h.

#define READ_PORT_UCHAR (   _x_)    DbgRp(_x_)

READ_PORT_UCHAR replacement for debugging.

Parameters
<em>x</em>the port number to read
Returns
The current value on that port

Definition at line 211 of file i_iec.h.

Referenced by cbmiec_checkcable(), cbmiec_i_pp_read_debounced(), cbmiec_iec_dbg_read(), cbmiec_iec_poll(), cbmiec_iec_wait(), cbmiec_interrupt(), cbmiec_show_port(), cbmiec_test_irq(), DbgRp(), ParPortSetModeWdm(), and ParPortUnsetModeWdm().

#define WRITE_PORT_UCHAR (   _x_,
  _y_ 
)    DbgWp(_x_, _y_)

WRITE_PORT_UCHAR replacement for debugging.

Parameters
<em>x</em>the port number to read
<em>y</em>the value to put into that port number

Definition at line 221 of file i_iec.h.

Referenced by cbmiec_iec_dbg_write(), cbmiec_pp_read(), cbmiec_pp_write(), cbmiec_test_irq(), DbgWp(), and ParPortSetModeNt4().

Typedef Documentation

typedef struct IEC_TIMEOUTS IEC_TIMEOUTS

The various timeouts of the IEC bus protocol

Enumeration Type Documentation

remember in which state the cable is currently

Enumerator
CABLESTATE_UNKNOWN 

not tested yet

CABLESTATE_ERROR_OCCURRED 

cable has been tested, but a transfer ended with an error

CABLESTATE_TESTED 

tested, but not used yet

CABLESTATE_SUCCESSFULLY_USED 

tested and successfully used

Definition at line 260 of file i_iec.h.

Function Documentation

VOID cbmiec_block_irq ( PDEVICE_EXTENSION  Pdx)

Block all interrupts.

This function blocks all interrupt, thus that we cannot be interrupted while executing some critical things.

This should not be used for big time periods.

Definition at line 94 of file libiec/util.c.

References CLI(), DBG_ASSERT, DBGDO, FUNC_ENTER, and FUNC_LEAVE.

Referenced by cbmiec_i_raw_read(), cbmiec_i_raw_write(), cbmiec_send_byte(), and cbmiec_wait_for_listener().

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.

This function reads a byte from the parallel portion of the X[M|A]P1541 cable. The lines are debounced.

Parameters
PdxPointer to the device extension.
Returns
The read value, or -1 if debouncing failed.

Definition at line 39 of file ppread.c.

References DBG_PREFIX, DBG_PRINT, FUNC_ENTER, FUNC_LEAVE_LONG, PAR_PORT, and READ_PORT_UCHAR.

Referenced by cbmiec_pp_read().

NTSTATUS cbmiec_i_raw_read ( IN PDEVICE_EXTENSION  Pdx,
OUT UCHAR *  Buffer,
ULONG  Count,
OUT ULONG *  Received 
)
NTSTATUS cbmiec_i_raw_write ( PDEVICE_EXTENSION  Pdx,
const UCHAR *  Buffer,
ULONG  Count,
ULONG *  Sent,
BOOLEAN  Atn,
BOOLEAN  Talk 
)

Write some bytes to the IEC bus.

Parameters
PdxPointer to the device extension.
BufferPointer to a buffer where the read bytes are written to.
CountMaximum number of characters to read from the bus.
SentPointer to the variable which will hold the number of written bytes.
AtnIf true: Sent the bytes with set ATN; else, with released ATN
TalkIf true: A talk command is to be sent (some special care has to be taken at the end of the transmission).
Returns
If the routine succeeds, it returns STATUS_SUCCESS. Otherwise, it returns one of the error status values.

ATN is released on return of this routine

Definition at line 54 of file i_rawwrite.c.

References CABLESTATE_ERROR_OCCURRED, CABLESTATE_SUCCESSFULLY_USED, cbmiec_block_irq(), cbmiec_checkcable(), CBMIEC_GET, CBMIEC_RELEASE, cbmiec_release_irq(), cbmiec_schedule_timeout(), cbmiec_send_byte(), CBMIEC_SET, cbmiec_setcablestate(), cbmiec_udelay(), cbmiec_wait_for_listener(), DBG_ASSERT, DBG_ERROR, DBG_PREFIX, DBG_SUCCESS, DebugNtStatus(), FUNC_ENTER, libiec_global_timeouts, PERF_EVENT_WRITE_BYTE, PERF_EVENT_WRITE_BYTE_NO, PP_ATN_OUT, PP_CLK_IN, PP_CLK_OUT, PP_DATA_IN, PP_DATA_OUT, QueueShouldCancelCurrentIrp(), IEC_TIMEOUTS::T_10_SEND_BEFORE_1ST_BYTE, IEC_TIMEOUTS::T_11_SEND_BEFORE_BYTE_DELAY, IEC_TIMEOUTS::T_12_SEND_AFTER_BYTE_DELAY, IEC_TIMEOUTS::T_14_SEND_AT_END_DELAY, IEC_TIMEOUTS::T_9_SEND_WAIT_DEVICES_T_AT, and IEC_TIMEOUTS::T_9_Times.

Referenced by cbmiec_close(), cbmiec_listen(), cbmiec_open(), cbmiec_raw_write(), cbmiec_talk(), cbmiec_unlisten(), and cbmiec_untalk().

VOID cbmiec_release_irq ( PDEVICE_EXTENSION  Pdx)

Release the interrupts.

This function releases all interrupt, undoing a previous cbmiec_block_irq() call.

Definition at line 118 of file libiec/util.c.

References DBG_ASSERT, DBGDO, FUNC_ENTER, FUNC_LEAVE, and STI().

Referenced by cbmiec_i_raw_read(), cbmiec_i_raw_write(), cbmiec_send_byte(), and cbmiec_wait_for_listener().

VOID cbmiec_schedule_timeout ( IN ULONG  Howlong)

Schedule a timeout.

This function schedules a timeout. Scheduling means that other threads have the opportunity to use the processor while we're waiting.

Parameters
HowlongHow long to wait (in us)

Definition at line 34 of file libiec/util.c.

References FUNC_ENTER, and FUNC_LEAVE.

Referenced by cbmiec_check_device(), cbmiec_i_raw_read(), cbmiec_i_raw_write(), cbmiec_iec_wait(), cbmiec_reset(), cbmiec_wait_for_drives_ready(), and cbmiec_wait_for_listener().

VOID cbmiec_show_port ( UCHAR *  s)

show the value of parallel port lines

cbmiec_show_port() is used to show the value of the parallel port lines if needed for debugging

Parameters
s@@\xrefitem todo 162.
VOID cbmiec_show_state ( IN PDEVICE_EXTENSION  Pdx,
IN UCHAR *  Str 
)

Dump the input lines.

Parameters
PdxPointer to the device extension of the driver.
StrCaller-supplied pointer to a string to output before the values.

Definition at line 111 of file sys/libiec/debug.c.

References CBMIEC_GET, DBG_ASSERT, DBG_PREFIX, DBG_SUCCESS, FUNC_DEF, PP_ATN_IN, PP_CLK_IN, and PP_DATA_IN.

VOID cbmiec_udelay ( IN ULONG  Howlong)

Wait for a timeout.

This function waits for a timeout. Waiting means that we want to have an exact timing, so don't give away the processor.

Parameters
HowlongHow long to wait (in us)

Definition at line 66 of file libiec/util.c.

Referenced by cbmiec_i_raw_read(), cbmiec_i_raw_write(), cbmiec_iec_wait(), cbmiec_parallel_burst_read(), cbmiec_parallel_burst_write(), cbmiec_send_byte(), and cbmiec_test_irq().

UCHAR DbgRp ( IN PUCHAR  Port)

Read from a port address with debugging output.

Parameters
PortThe port address to be written.
Returns
The read value.

Definition at line 85 of file sys/libiec/debug.c.

References cbmiec_show_port(), DBG_PREFIX, FUNC_DEF, and READ_PORT_UCHAR.

VOID DbgWp ( IN PUCHAR  Port,
IN UCHAR  Value 
)

Write to a port address with debugging output.

Parameters
PortThe port address to be written.
ValueThe value to be written.

Definition at line 63 of file sys/libiec/debug.c.

References cbmiec_show_port(), DBG_PREFIX, FUNC_DEF, and WRITE_PORT_UCHAR.

Variable Documentation

IEC_TIMEOUTS libiec_global_timeouts