home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / wkermit.zip / asiports.h < prev    next >
C/C++ Source or Header  |  1985-11-11  |  12KB  |  334 lines

  1. /*  asiports.h
  2. *
  3. *  Defines and parameter structures for Async I/O Ports.
  4. *
  5. *  The Greenleaf Comm Library - Copyright (C) 1984 Greenleaf Software Inc.
  6. *
  7. *  USAGE - INCLUDE IN MAIN PROGRAM ONLY WHEN USING ASYNC FUNCTIONS
  8. */
  9. #define MAX_ASPORTS 8    /* maximum number of ports - may be changed */
  10. #define N_ASPORTS 2    /* actual number of ports in the system */
  11. #define max_asbuf_len 32000  /* max buffer size - user selectable */
  12.  
  13. /*    F L A G S
  14. *
  15. *  These should be considered read-only by all applications.  Use macros
  16. *  provided below to read individual bits.  Use asierst() to reset alert,
  17. *  linerr, modchg, and chkerr bits.  Applications should NOT write to other
  18. *  bits as the interrupts and other functions depend on these.
  19. */
  20. struct AS_FLAGS {
  21.   unsigned alert :  1;        /* alert when 1     */
  22.   unsigned rxempty: 1;        /* Rx Buffer Empty    */
  23.   unsigned rxfull:  1;        /* Rx Buffer Full    */
  24.   unsigned txempty: 1;        /* Tx Buffer Empty    */
  25.   unsigned txfull:  1;        /* Tx Buffer Full    */
  26.   unsigned linerr:  1;        /* line error        */
  27.   unsigned modchg:  1;        /* modem status change    */
  28.   unsigned chkerr:  1;        /* checksum error    */
  29.   unsigned xchrun:  1;        /* transmit interrupts are running */
  30.   unsigned rchrun:  1;        /* receive interrupts are running */
  31.   unsigned igalert: 1;        /* ignore alert     */
  32.   unsigned igcts:   1;        /* ignore CTS        */
  33.   unsigned igdsr:   1;        /* ignore DTR        */
  34.   unsigned igcd:    1;        /* ignore carrier detect CD */
  35.   unsigned igmstat: 1;        /* ignore modem status changes */
  36.   unsigned igrcver: 1;        /* ignore receive errors */
  37.   };
  38.  
  39. /*  L I N E   S T A T U S   B I T S
  40. *
  41. *   These are set by the interrupts and status functions.  asilrst()
  42. *   resets the static portion.
  43. *
  44. *   Use the macros (below) to test individual bits.
  45. */
  46. struct AS_LSTAT {        /* First 8 are dynamic    */
  47.   unsigned dready:  1;        /* Rx data ready    */
  48.   unsigned overrun: 1;        /* Overrun Error    */
  49.   unsigned parerr:  1;        /* Parity Error     */
  50.   unsigned framerr: 1;        /* Framing Error    */
  51.   unsigned breakdet:1;        /* Break Signal Detect    */
  52.   unsigned txhempty:1;        /* Tx Holding Reg Empty */
  53.   unsigned txsempty:1;        /* Tx Shift Reg Empty    */
  54.   unsigned timeout: 1;        /* Timeout (not used)    */
  55.   unsigned sdready: 1;    /* the next 8 are STATIC repeat */
  56.   unsigned soverrun:1;    /*  of the last 8 bits        */
  57.   unsigned sparerr:  1;
  58.   unsigned sframerr: 1;
  59.   unsigned sbreakdet:1;
  60.   unsigned stxhempty:1;
  61.   unsigned stxsempty:1;
  62.   unsigned stimeout: 1;
  63.   };
  64.  
  65. /*  M O D E M    S T A T U S   B I T S
  66. *
  67. *   These are set by the interrupts and status functions.  asimrst() resets
  68. *   the static portion.
  69. *
  70. *   Use macros (below) to read individual bits.
  71. */
  72. struct AS_MSTAT {    /* first 8 are dynamic    */
  73.   unsigned dcts:    1;    /* delta CTS        */
  74.   unsigned ddsr:    1;    /* delta DSR        */
  75.   unsigned teri:    1;    /* trailing edge of RI    */
  76.   unsigned drlsd:   1;    /* delta CD        */
  77.   unsigned cts:     1;    /* CTS            */
  78.   unsigned dsr:     1;    /* DSR            */
  79.   unsigned ri:        1;    /* RI            */
  80.   unsigned rlsd:    1;    /* CD            */
  81.   unsigned sdcts:   1;    /* the next 8 are static */
  82.   unsigned sddsr:   1;    /*  repeats of last 8    */
  83.   unsigned steri:   1;
  84.   unsigned sdrlsd:  1;
  85.   unsigned scts:    1;
  86.   unsigned sdsr:    1;
  87.   unsigned sri:     1;
  88.   unsigned srlsd:   1;
  89.   };
  90.  
  91. /*  P A R A M E T E R    S T R U C T U R E
  92. *
  93. *  This holds parameters used by all functions and interrupt routines.
  94. *  asisetup() establishes the values for these;  applications should NOT
  95. *  write to this structure at any time.  Use asixrst() to reset the receiver
  96. *  counter (.xmcount).
  97. */
  98. struct ASITABLE {
  99.     int port;    /* port number 0...    */
  100.     int intnum;    /* interrupt no. ...    */
  101.    unsigned ioaddr;    /* base address of 8250 */
  102.    unsigned flags;    /* major status flags    */
  103.    unsigned lstat;    /* line status        */
  104.    unsigned mstat;    /* modem status     */
  105.     int mode;
  106.    unsigned rseg;    /* Rx Buffer segment    */
  107.    unsigned rbob;    /* Beginning of Buf (Rx)*/
  108.    unsigned rpi;    /* Pointer In        (Rx)*/
  109.    unsigned rpo;    /* Pointer Out        (Rx)*/
  110.    int        rsize;    /* size of Rx queue    */
  111.    int        rfree;    /* free space in Rx queue */
  112.    unsigned tseg;    /* Tx Buffer segment    */
  113.    unsigned tbob;    /* Beginning of Buf (Tx)*/
  114.    unsigned tpi;    /* Pointer In        (Tx)*/
  115.    unsigned tpo;    /* Pointer Out        (Tx)*/
  116.    int        tsize;    /* size of Tx queue    */
  117.    int        tcnt;    /* number of bytes in Tx queue */
  118.    int        xmcount;    /* count/is rx active    */
  119.    unsigned chkflag;    /* flags for check characters */
  120.    char     chkchr0;    /* Check character 0    */
  121.    char     chkchr1;    /* Check character 1    */
  122.    char     chkchr2;    /* Check character 2    */
  123.    unsigned irq8259;    /* Interrupt # in 8259 (com0 = 4) */
  124.    unsigned port8259;    /* I/O Address of 8259 */
  125.    char not_used[15];    /* Pad to 64 bytes    */
  126.    };
  127.  
  128. /*
  129. *  Structure for Local Parameters for XMODEM functions.
  130. */
  131. struct XMBUF {
  132.   int xblocknum;
  133.   char first;
  134.   int xstatus;
  135.   };
  136.  
  137. /*
  138. *  The next two declarations must be exactly as stated.
  139. *
  140. */
  141. int n_asi_ports = N_ASPORTS;
  142. struct ASITABLE asi_parms[ N_ASPORTS ];
  143. char *loc_asi_parms;
  144.  
  145. /*
  146. *  Define I/O Addresses for Intel 8250 UART devices.  These are addresses of
  147. *  the base of a register array.  The first two are declared as COM1 and COM2.
  148. *
  149. *  These values will be transferred into the structures by "asisetup".
  150. */
  151. unsigned as_port[MAX_ASPORTS] = { 0x3f8,0x2f8,0,0,0,0,0,0 };
  152.  
  153. /*
  154. *  Define Interrupt Numbers.  For COM1 and COM2 the conventional ones
  155. *  are used.  The rest are just unassigned numbers.
  156. */
  157. int as_intnums[MAX_ASPORTS] = { 12,11,0,0,0,0,0,0 };
  158.  
  159. /*
  160.  * Define Port Numbers for the 8259, COM1 and COM2 are 33, add
  161.  * addresses here for additional 8259's
  162.  */
  163. int as_8259ports[MAX_ASPORTS] = { 33,33,0,0,0,0,0,0};
  164.  
  165. /*
  166.  * Define IRQ number for 8259 COM1 = 4, COM2 = 3, add additional
  167.  * ones as necessary.
  168.  */
  169. int as_8259irq[MAX_ASPORTS] = {4,3,0,0,0,0,0,0};
  170.  
  171. /*
  172. *  The next variable, when set to 1 in an assignment statement, will
  173. *  make the time constants below valid.  When set to 0, however, NO
  174. *  DELAY is taken except for character ready or Tx Buffer Empty.
  175. *  In this mode ( _as_wcts = 0 ), communication with certain modems
  176. *  such as the Hayes series can be managed when CTS is not high - e.g.
  177. *  before a call is established, or when DSR is not high.
  178. */
  179. int _as_wcts;
  180.  
  181. /*
  182. *  Time Constants for timeout on polled write (asputc).  A call to asputc
  183. *  will first read the status - if the Tx Buffer is empty the character
  184. *  will be written and the function will exit.    If it is not empty, the
  185. *  function will enter a loop in which status is repeatedly read and
  186. *  checked for Tx Buffer Empty so that when it goes empty, the character
  187. *  will be written.  This delay, then, must assure that a full character
  188. *  may be transmitted at the worst-case baud rate.
  189. *
  190. *  Time Constant:  Each loop is approx. 1 millisec. in the IBM PC and XT.
  191. *
  192. *  At 300 baud and 8 data bits, 1 stop bit, odd or even parity,
  193. *  one character requires about 33 millisec. to transmit.  Therefore
  194. *  TC must be at least 35.
  195. *
  196. *  Baud Rate        Minimum Time Constant Recommended
  197. *    110            95
  198. *    150            70
  199. *    300            35
  200. *    600            17
  201. *    1200            9
  202. *    2400            5
  203. *    4800            2
  204. *    9600            1
  205. *
  206. *  NOTE:  The maximum value is 255; only 8 bits are significant.
  207. *
  208. *  These timeouts do NOT apply to interrupt mode, e.g. asiputc.
  209. */
  210. int as_wtime[MAX_ASPORTS] = { 95,95,95,95,95,95,95,95 };
  211.  
  212. /*  Time Constants for READ (polled mode only)
  213.  *
  214.  *  These operate to allow the asgetc function to dally before returning,
  215.  *  hence waiting until the Receiver Data Buffer has been filled with a
  216.  *  character.    For applications which do NOT want to wait, this time
  217.  *  constant may be 0 in which case the function asgetc will return -1
  218.  *  if no character is available.  Alternatively, the time constants may
  219.  *  be set to similar values as above for WRITE operations.
  220.  */
  221. int as_rtime[MAX_ASPORTS] = { 0,0,0,0,0,0,0,0 };
  222.  
  223. /*
  224. *  Macros to define status and flag bits.
  225. */
  226. /*  T E S T   IF RECEIVER DETECTED A PARTICULAR CHECK CHARACTER
  227. *
  228. *  Use these in conjunction with asirchk().
  229. */
  230. #define ischk2(x)    (asi_parms[x].chkflag&256)?1:0
  231. #define ischk1(x)    (asi_parms[x].chkflag&128)?1:0
  232. #define ischk0(x)    (asi_parms[x].chkflag&64)?1:0
  233.  
  234. /*  F L A G   B I T   T E S T S
  235. *
  236. *  These just test flag bits.  The first 8 are for  general applications,
  237. *  the next 8 are provided for completeness and to test when the system
  238. *  has been told to ignore certain conditions.    Never write into these.
  239. */
  240. #define isalert(x)   (asi_parms[x].flags&1)?1:0
  241. #define isrxempty(x) (asi_parms[x].flags&2)?1:0
  242. #define isrxfull(x)  (asi_parms[x].flags&4)?1:0
  243. #define istxempty(x) (asi_parms[x].flags&8)?1:0
  244. #define istxfull(x)  (asi_parms[x].flags&16)?1:0
  245. #define islnerr(x)   (asi_parms[x].flags&32)?1:0
  246. #define ismderr(x)   (asi_parms[x].flags&64)?1:0
  247. #define isckerr(x)   (asi_parms[x].flags&128)?1:0
  248. #define isxchrun(x)  (asi_parms[x].flags&256)?1:0
  249. #define isrchrun(x)  (asi_parms[x].flags&512)?1:0
  250. #define isigalert(x) (asi_parms[x].flags&1024)?1:0
  251. #define isigcts(x)   (asi_parms[x].flags&2048)?1:0
  252. #define isigdtr(x)   (asi_parms[x].flags&4096)?1:0
  253. #define isigcd(x)    (asi_parms[x].flags&8192)?1:0
  254. #define isigmstat(x) (asi_parms[x].flags&16384)?1:0
  255. #define isigrcver(x) (asi_parms[x].flags&32768)?1:0
  256.  
  257. /* Return DYNAMIC Line Status */
  258. #define isdatardy(x)   (asi_parms[x].lstat&1)?1:0  /* DATA READY    */
  259. #define isoverrun(x)   (asi_parms[x].lstat&2)?1:0  /* OVERRUN ERROR */
  260. #define isparityerr(x) (asi_parms[x].lstat&4)?1:0  /* PARITY ERROR  */
  261. #define isframerr(x)   (asi_parms[x].lstat&8)?1:0  /* FRAMING ERROR */
  262. #define isbreak(x)     (asi_parms[x].lstat&16)?1:0 /* BREAK DETECT  */
  263. #define ishrempty(x)   (asi_parms[x].lstat&32)?1:0 /* TX HOLDING REG */
  264. #define issrempty(x)   (asi_parms[x].lstat&64)?1:0 /* TX SHIFT REG  */
  265. #define istimeout(x)   (asi_parms[x].lstat&128)?1:0 /* NOT USED     */
  266.  
  267. /* Return STATIC Line Status */
  268. #define issdatardy(x)    (asi_parms[x].lstat&256)?1:0
  269. #define issoverrun(x)    (asi_parms[x].lstat&512)?1:0
  270. #define issparityerr(x) (asi_parms[x].lstat&1024)?1:0
  271. #define issframerr(x)    (asi_parms[x].lstat&2048)?1:0
  272. #define issbreak(x)    (asi_parms[x].lstat&4096)?1:0
  273. #define isshrempty(x)    (asi_parms[x].lstat&8192)?1:0
  274. #define isssrempty(x)    (asi_parms[x].lstat&0x4000)?1:0
  275. #define isstimeout(x)    (asi_parms[x].lstat&0x8000)?1:0
  276.  
  277.  
  278. /* Return DYNAMIC Modem Status */
  279. #define ischgcts(x)    (asi_parms[x].mstat&1)?1:0
  280. #define ischgdsr(x)    (asi_parms[x].mstat&2)?1:0
  281. #define ischgri(x)     (asi_parms[x].mstat&4)?1:0
  282. #define ischgcd(x)     (asi_parms[x].mstat&8)?1:0
  283. #define iscts(x)   (asi_parms[x].mstat&16)?1:0
  284. #define isdsr(x)   (asi_parms[x].mstat&32)?1:0
  285. #define isri(x)    (asi_parms[x].mstat&64)?1:0
  286. #define iscd(x)    (asi_parms[x].mstat&128)?1:0
  287.  
  288. /* Return STATIC Modem Status */
  289. #define isschgcts(x)    (asi_parms[x].mstat&256)?1:0
  290. #define isschgdsr(x)    (asi_parms[x].mstat&512)?1:0
  291. #define isschgri(x)    (asi_parms[x].mstat&1024)?1:0
  292. #define isschgcd(x)    (asi_parms[x].mstat&2048)?1:0
  293. #define isscts(x)   (asi_parms[x].mstat&4096)?1:0
  294. #define issdsr(x)   (asi_parms[x].mstat&8192)?1:0
  295. #define issri(x)    (asi_parms[x].mstat&0x4000)?1:0
  296. #define isscd(x)    (asi_parms[x].mstat&0x8000)?1:0
  297.  
  298. /* Boolean:  Has receiver gotten one or more characters ? */
  299. #define isxmrxing(x)  (asi_parms[x].xmcount>0)?1:0
  300.  
  301. /* Boolean:  Has receiver gotten a specified number of characters ? */
  302. #define isxmrxcnt(x,y) (asi_parms[x].xmcount>=y)?1:0
  303.  
  304.  
  305. /*  Misc. definitions
  306. */
  307. #define ASIN 1
  308. #define ASOUT 2
  309. #define ASINOUT 3
  310. #define ASCIINONE 1
  311. #define ASCIIXM 5
  312. #define BINARYNONE 2
  313. #define BINARYXM 6
  314.  
  315. /*  ASCII Protocol Characters
  316. */
  317. #define NUL 0
  318. #define SOH 1
  319. #define STX 2
  320. #define ETX 3
  321. #define EOT 4
  322. #define ACK 6
  323. #define DLE 0x10
  324. #define DC1 0x11
  325. #define DC2 0x12
  326. #define DC3 0x13
  327. #define DC4 0x14
  328. #define NAK 0x15
  329. #define ETB 0x17
  330. #define XON 0x11
  331. #define XOFF 0x13
  332.  
  333.  
  334.