/* asiports.h * * Defines and parameter structures for Async I/O Ports. * * The Greenleaf Comm Library - Copyright (C) 1984 Greenleaf Software Inc. * * USAGE - INCLUDE IN MAIN PROGRAM ONLY WHEN USING ASYNC FUNCTIONS */ #define MAX_ASPORTS 8 /* maximum number of ports - may be changed */ #define N_ASPORTS 2 /* actual number of ports in the system */ #define max_asbuf_len 32000 /* max buffer size - user selectable */ /* F L A G S * * These should be considered read-only by all applications. Use macros * provided below to read individual bits. Use asierst() to reset alert, * linerr, modchg, and chkerr bits. Applications should NOT write to other * bits as the interrupts and other functions depend on these. */ struct AS_FLAGS { unsigned alert : 1; /* alert when 1 */ unsigned rxempty: 1; /* Rx Buffer Empty */ unsigned rxfull: 1; /* Rx Buffer Full */ unsigned txempty: 1; /* Tx Buffer Empty */ unsigned txfull: 1; /* Tx Buffer Full */ unsigned linerr: 1; /* line error */ unsigned modchg: 1; /* modem status change */ unsigned chkerr: 1; /* checksum error */ unsigned xchrun: 1; /* transmit interrupts are running */ unsigned rchrun: 1; /* receive interrupts are running */ unsigned igalert: 1; /* ignore alert */ unsigned igcts: 1; /* ignore CTS */ unsigned igdsr: 1; /* ignore DTR */ unsigned igcd: 1; /* ignore carrier detect CD */ unsigned igmstat: 1; /* ignore modem status changes */ unsigned igrcver: 1; /* ignore receive errors */ }; /* L I N E S T A T U S B I T S * * These are set by the interrupts and status functions. asilrst() * resets the static portion. * * Use the macros (below) to test individual bits. */ struct AS_LSTAT { /* First 8 are dynamic */ unsigned dready: 1; /* Rx data ready */ unsigned overrun: 1; /* Overrun Error */ unsigned parerr: 1; /* Parity Error */ unsigned framerr: 1; /* Framing Error */ unsigned breakdet:1; /* Break Signal Detect */ unsigned txhempty:1; /* Tx Holding Reg Empty */ unsigned txsempty:1; /* Tx Shift Reg Empty */ unsigned timeout: 1; /* Timeout (not used) */ unsigned sdready: 1; /* the next 8 are STATIC repeat */ unsigned soverrun:1; /* of the last 8 bits */ unsigned sparerr: 1; unsigned sframerr: 1; unsigned sbreakdet:1; unsigned stxhempty:1; unsigned stxsempty:1; unsigned stimeout: 1; }; /* M O D E M S T A T U S B I T S * * These are set by the interrupts and status functions. asimrst() resets * the static portion. * * Use macros (below) to read individual bits. */ struct AS_MSTAT { /* first 8 are dynamic */ unsigned dcts: 1; /* delta CTS */ unsigned ddsr: 1; /* delta DSR */ unsigned teri: 1; /* trailing edge of RI */ unsigned drlsd: 1; /* delta CD */ unsigned cts: 1; /* CTS */ unsigned dsr: 1; /* DSR */ unsigned ri: 1; /* RI */ unsigned rlsd: 1; /* CD */ unsigned sdcts: 1; /* the next 8 are static */ unsigned sddsr: 1; /* repeats of last 8 */ unsigned steri: 1; unsigned sdrlsd: 1; unsigned scts: 1; unsigned sdsr: 1; unsigned sri: 1; unsigned srlsd: 1; }; /* P A R A M E T E R S T R U C T U R E * * This holds parameters used by all functions and interrupt routines. * asisetup() establishes the values for these; applications should NOT * write to this structure at any time. Use asixrst() to reset the receiver * counter (.xmcount). */ struct ASITABLE { int port; /* port number 0... */ int intnum; /* interrupt no. ... */ unsigned ioaddr; /* base address of 8250 */ unsigned flags; /* major status flags */ unsigned lstat; /* line status */ unsigned mstat; /* modem status */ int mode; unsigned rseg; /* Rx Buffer segment */ unsigned rbob; /* Beginning of Buf (Rx)*/ unsigned rpi; /* Pointer In (Rx)*/ unsigned rpo; /* Pointer Out (Rx)*/ int rsize; /* size of Rx queue */ int rfree; /* free space in Rx queue */ unsigned tseg; /* Tx Buffer segment */ unsigned tbob; /* Beginning of Buf (Tx)*/ unsigned tpi; /* Pointer In (Tx)*/ unsigned tpo; /* Pointer Out (Tx)*/ int tsize; /* size of Tx queue */ int tcnt; /* number of bytes in Tx queue */ int xmcount; /* count/is rx active */ unsigned chkflag; /* flags for check characters */ char chkchr0; /* Check character 0 */ char chkchr1; /* Check character 1 */ char chkchr2; /* Check character 2 */ unsigned irq8259; /* Interrupt # in 8259 (com0 = 4) */ unsigned port8259; /* I/O Address of 8259 */ char not_used[15]; /* Pad to 64 bytes */ }; /* * Structure for Local Parameters for XMODEM functions. */ struct XMBUF { int xblocknum; char first; int xstatus; }; /* * The next two declarations must be exactly as stated. * */ int n_asi_ports = N_ASPORTS; struct ASITABLE asi_parms[ N_ASPORTS ]; char *loc_asi_parms; /* * Define I/O Addresses for Intel 8250 UART devices. These are addresses of * the base of a register array. The first two are declared as COM1 and COM2. * * These values will be transferred into the structures by "asisetup". */ unsigned as_port[MAX_ASPORTS] = { 0x3f8,0x2f8,0,0,0,0,0,0 }; /* * Define Interrupt Numbers. For COM1 and COM2 the conventional ones * are used. The rest are just unassigned numbers. */ int as_intnums[MAX_ASPORTS] = { 12,11,0,0,0,0,0,0 }; /* * Define Port Numbers for the 8259, COM1 and COM2 are 33, add * addresses here for additional 8259's */ int as_8259ports[MAX_ASPORTS] = { 33,33,0,0,0,0,0,0}; /* * Define IRQ number for 8259 COM1 = 4, COM2 = 3, add additional * ones as necessary. */ int as_8259irq[MAX_ASPORTS] = {4,3,0,0,0,0,0,0}; /* * The next variable, when set to 1 in an assignment statement, will * make the time constants below valid. When set to 0, however, NO * DELAY is taken except for character ready or Tx Buffer Empty. * In this mode ( _as_wcts = 0 ), communication with certain modems * such as the Hayes series can be managed when CTS is not high - e.g. * before a call is established, or when DSR is not high. */ int _as_wcts; /* * Time Constants for timeout on polled write (asputc). A call to asputc * will first read the status - if the Tx Buffer is empty the character * will be written and the function will exit. If it is not empty, the * function will enter a loop in which status is repeatedly read and * checked for Tx Buffer Empty so that when it goes empty, the character * will be written. This delay, then, must assure that a full character * may be transmitted at the worst-case baud rate. * * Time Constant: Each loop is approx. 1 millisec. in the IBM PC and XT. * * At 300 baud and 8 data bits, 1 stop bit, odd or even parity, * one character requires about 33 millisec. to transmit. Therefore * TC must be at least 35. * * Baud Rate Minimum Time Constant Recommended * 110 95 * 150 70 * 300 35 * 600 17 * 1200 9 * 2400 5 * 4800 2 * 9600 1 * * NOTE: The maximum value is 255; only 8 bits are significant. * * These timeouts do NOT apply to interrupt mode, e.g. asiputc. */ int as_wtime[MAX_ASPORTS] = { 95,95,95,95,95,95,95,95 }; /* Time Constants for READ (polled mode only) * * These operate to allow the asgetc function to dally before returning, * hence waiting until the Receiver Data Buffer has been filled with a * character. For applications which do NOT want to wait, this time * constant may be 0 in which case the function asgetc will return -1 * if no character is available. Alternatively, the time constants may * be set to similar values as above for WRITE operations. */ int as_rtime[MAX_ASPORTS] = { 0,0,0,0,0,0,0,0 }; /* * Macros to define status and flag bits. */ /* T E S T IF RECEIVER DETECTED A PARTICULAR CHECK CHARACTER * * Use these in conjunction with asirchk(). */ #define ischk2(x) (asi_parms[x].chkflag&256)?1:0 #define ischk1(x) (asi_parms[x].chkflag&128)?1:0 #define ischk0(x) (asi_parms[x].chkflag&64)?1:0 /* F L A G B I T T E S T S * * These just test flag bits. The first 8 are for general applications, * the next 8 are provided for completeness and to test when the system * has been told to ignore certain conditions. Never write into these. */ #define isalert(x) (asi_parms[x].flags&1)?1:0 #define isrxempty(x) (asi_parms[x].flags&2)?1:0 #define isrxfull(x) (asi_parms[x].flags&4)?1:0 #define istxempty(x) (asi_parms[x].flags&8)?1:0 #define istxfull(x) (asi_parms[x].flags&16)?1:0 #define islnerr(x) (asi_parms[x].flags&32)?1:0 #define ismderr(x) (asi_parms[x].flags&64)?1:0 #define isckerr(x) (asi_parms[x].flags&128)?1:0 #define isxchrun(x) (asi_parms[x].flags&256)?1:0 #define isrchrun(x) (asi_parms[x].flags&512)?1:0 #define isigalert(x) (asi_parms[x].flags&1024)?1:0 #define isigcts(x) (asi_parms[x].flags&2048)?1:0 #define isigdtr(x) (asi_parms[x].flags&4096)?1:0 #define isigcd(x) (asi_parms[x].flags&8192)?1:0 #define isigmstat(x) (asi_parms[x].flags&16384)?1:0 #define isigrcver(x) (asi_parms[x].flags&32768)?1:0 /* Return DYNAMIC Line Status */ #define isdatardy(x) (asi_parms[x].lstat&1)?1:0 /* DATA READY */ #define isoverrun(x) (asi_parms[x].lstat&2)?1:0 /* OVERRUN ERROR */ #define isparityerr(x) (asi_parms[x].lstat&4)?1:0 /* PARITY ERROR */ #define isframerr(x) (asi_parms[x].lstat&8)?1:0 /* FRAMING ERROR */ #define isbreak(x) (asi_parms[x].lstat&16)?1:0 /* BREAK DETECT */ #define ishrempty(x) (asi_parms[x].lstat&32)?1:0 /* TX HOLDING REG */ #define issrempty(x) (asi_parms[x].lstat&64)?1:0 /* TX SHIFT REG */ #define istimeout(x) (asi_parms[x].lstat&128)?1:0 /* NOT USED */ /* Return STATIC Line Status */ #define issdatardy(x) (asi_parms[x].lstat&256)?1:0 #define issoverrun(x) (asi_parms[x].lstat&512)?1:0 #define issparityerr(x) (asi_parms[x].lstat&1024)?1:0 #define issframerr(x) (asi_parms[x].lstat&2048)?1:0 #define issbreak(x) (asi_parms[x].lstat&4096)?1:0 #define isshrempty(x) (asi_parms[x].lstat&8192)?1:0 #define isssrempty(x) (asi_parms[x].lstat&0x4000)?1:0 #define isstimeout(x) (asi_parms[x].lstat&0x8000)?1:0 /* Return DYNAMIC Modem Status */ #define ischgcts(x) (asi_parms[x].mstat&1)?1:0 #define ischgdsr(x) (asi_parms[x].mstat&2)?1:0 #define ischgri(x) (asi_parms[x].mstat&4)?1:0 #define ischgcd(x) (asi_parms[x].mstat&8)?1:0 #define iscts(x) (asi_parms[x].mstat&16)?1:0 #define isdsr(x) (asi_parms[x].mstat&32)?1:0 #define isri(x) (asi_parms[x].mstat&64)?1:0 #define iscd(x) (asi_parms[x].mstat&128)?1:0 /* Return STATIC Modem Status */ #define isschgcts(x) (asi_parms[x].mstat&256)?1:0 #define isschgdsr(x) (asi_parms[x].mstat&512)?1:0 #define isschgri(x) (asi_parms[x].mstat&1024)?1:0 #define isschgcd(x) (asi_parms[x].mstat&2048)?1:0 #define isscts(x) (asi_parms[x].mstat&4096)?1:0 #define issdsr(x) (asi_parms[x].mstat&8192)?1:0 #define issri(x) (asi_parms[x].mstat&0x4000)?1:0 #define isscd(x) (asi_parms[x].mstat&0x8000)?1:0 /* Boolean: Has receiver gotten one or more characters ? */ #define isxmrxing(x) (asi_parms[x].xmcount>0)?1:0 /* Boolean: Has receiver gotten a specified number of characters ? */ #define isxmrxcnt(x,y) (asi_parms[x].xmcount>=y)?1:0 /* Misc. definitions */ #define ASIN 1 #define ASOUT 2 #define ASINOUT 3 #define ASCIINONE 1 #define ASCIIXM 5 #define BINARYNONE 2 #define BINARYXM 6 /* ASCII Protocol Characters */ #define NUL 0 #define SOH 1 #define STX 2 #define ETX 3 #define EOT 4 #define ACK 6 #define DLE 0x10 #define DC1 0x11 #define DC2 0x12 #define DC3 0x13 #define DC4 0x14 #define NAK 0x15 #define ETB 0x17 #define XON 0x11 #define XOFF 0x13