/*** io_ports.h - defs & decls for lower level bit I/O routines written and copyright October 1994 Wim Lewis, wiml@{netcom,omnigroup}.com distribution & re-use ok as long as you use this power wisely and only for good, never for evil */ #ifndef IO_PORTS_H #define IO_PORTS_H #define COM1 0x3F8 #define COM2 0x2F8 #define COM3 0x3E8 #define COM4 0x2E8 #define MCR 4 #define MSR 6 /*** *** Stuff in io_ports.c ***/ void open_io(void); /* open /dev/port */ void close_io(void); /* close /dev/port */ unsigned char in_byte(int); /* read one byte */ void out_byte(int, unsigned char); /* write one byte */ extern int dev_port_fd; /* the fd used to talk to the kernel */ /* Note: Bit masks for using the status (base+1) and ctl (base+2) ports can be found in /usr/include/linux/lp.h under Linux. Be sure to use the LP_Pwhatever constants and *not* the LP_whatever constants (which are for the device driver's status word, not the hardware's). */ /*** *** Stuff in lp_io.c ***/ /* This allows simple buffering of the bit changes to a line printer port */ struct lp_io { int base; /* base I/O address */ /* Most recently written/read values */ unsigned last[7]; /* was 3 */ /* Desired values */ unsigned wanted[7]; /* was 3 */ }; void lpb_flush(struct lp_io *); /* write out all buffered changes */ void lpb_refresh(struct lp_io *); /* read in current values */ /* These two functions use "bit indicators" encoded into an int; see the bitmasks below. */ int lpb_test(struct lp_io *, int); void lpb_write(struct lp_io *, int, int); /* Bit indicators are encoded into ints and are passed to the set, reset, & test macros. Note that BI_TYPE is the offset from the parallel port base I/O address. NOTE: the serial port uses three bits (8 registers). */ #define BI_OFFSET 000007 /* Bit offset within the word */ #define BI_DATA 000000 /* Data bit? */ #define BI_STAT 000010 /* Status bit? */ #define BI_CTL 000020 /* Control bit? */ #define BI_TYPE 000070 /* Mask for DATA/CTL/STAT etc. */ #define BI_TYPE_SHIFT 3 #define BI_INVERSE 000100 /* Negative logic */ enum { lpc_eof=0, lpc_number=1, lpc_bits=2, lpc_abits=4 }; /* Associats a name with a bit indicator. */ struct lp_name { char *name; char lptype; int *value; }; /* read a fileful of name-indicator pairs */ int lpb_cfg_read(const char *, int, struct lp_name *); void lpb_dump_names(int, struct lp_name *); #endif /* IO_PORTS_H */