home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / sercom / cfunct.c < prev    next >
Encoding:
Text File  |  1986-06-18  |  3.1 KB  |  76 lines

  1. /*------------------------------ CFUNCT.C --------------------------------*/
  2. int mstat;                             /* modem status                     */
  3. int lstat;                             /* line status                      */
  4. int comerror;                          /* error number                     */
  5.  
  6. #define PARITY 1
  7. #define FRAME 2
  8. #define BREAK 3
  9.  
  10. #define COMBASE 0x03F8                 /* 0x02F8 for COM2                  */
  11.  
  12. #define TXREG   COMBASE                /* Transmit reg                     */
  13. #define RXREG   COMBASE                /* Receive reg                      */
  14. #define INTID   COMBASE + 2            /* Interrupt ID reg                 */
  15. #define LINSTAT COMBASE + 5            /* Line Status Reg                  */
  16. #define MODSTAT COMBASE + 6            /* Modem Status Reg                 */
  17.  
  18. typedef struct {
  19.    int count;                          /* number of chars now in the buffer*/
  20.    int start;                          /* offset of next character to take */
  21.    int size;                           /* size of the buffer               */
  22.    char *buffer;                       /* Address of the buffer            */
  23. } RING;
  24.  
  25. RING ibuf;                             /* input buffer                     */
  26. RING obuf;                             /* output buffer                    */
  27.  
  28. extern void putbuf();                  /* See Figure 16.11                 */
  29. extern int getbuf();                   /* See Figure 16.11                 */
  30.  
  31. /*-------------------------------------------------------------------------*/
  32. void cfunct()
  33. {
  34. int intnr, ch;
  35.  
  36.    for (;;) {                          /* until no more ints               */
  37.  
  38.       intnr = inp(INTID);              /* Interrupt ID                     */
  39.  
  40.       if (intnr & 1) {                 /* no interrupt pending             */
  41.          return;
  42.       }
  43.  
  44.       switch (intnr) {
  45.  
  46.          case(0):                      /* Modem status                     */
  47.             mstat = inp(MODSTAT);      /* Read the status                  */
  48.             break;
  49.  
  50.          case(2):                      /* Ready to transmit                */
  51.             if (getbuf(&obuf, &ch))    /* If we have one to send           */
  52.                outp(TXREG, ch);        /* send it                          */
  53.             break;
  54.  
  55.          case(4):                      /* Received Data                    */
  56.             ch = inp(RXREG);           /* read the char                    */
  57.             putbuf(&ibuf, ch);         /* save it in buffer                */
  58.             break;
  59.  
  60.          case(6):                      /* Line Status                      */
  61.             lstat = inp(LINSTAT);
  62.             if (lstat & 4)             /* Parity error                     */
  63.                comerror = PARITY;
  64.             else if (lstat & 8)        /* Framing eror                     */
  65.                comerror = FRAME;
  66.             else if (lstat & 16)       /* Break Interrupt                  */
  67.                comerror = BREAK;
  68.             break;
  69.       }
  70.    }
  71. }
  72. /*-------------------------------------------------------------------------*/
  73.  
  74.  
  75.  
  76.