home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1067 / fas.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-28  |  13.3 KB  |  390 lines

  1. /* This file contains various defines for the FAS async driver.
  2.    If you change anything here you have to recompile the driver module.
  3. */
  4.  
  5. #ident    "@(#)fas.h    2.06"
  6.  
  7. #include <sys/param.h>
  8. #include <sys/types.h>
  9. #include <sys/signal.h>
  10. #include <sys/buf.h>
  11. #include <sys/iobuf.h>
  12. #include <sys/dir.h>
  13. #include <sys/user.h>
  14. #include <sys/errno.h>
  15. #include <sys/tty.h>
  16. #include <sys/conf.h>
  17. #include <sys/sysinfo.h>
  18. #include <sys/file.h>
  19. #include <sys/termio.h>
  20. #include <sys/ioctl.h>
  21. #include <macros.h>
  22.  
  23. #if defined (TRUE)
  24. #undef TRUE
  25. #endif
  26. #define    TRUE    (1)
  27.  
  28. #if defined (FALSE)
  29. #undef FALSE
  30. #endif
  31. #define FALSE    (0)
  32.  
  33. /* Uncomment the following line if you need init8250. DosMerge needs
  34.    this function, but only if you link the kernel without the original
  35.    asy driver.
  36. */
  37. /* #define NEED_INIT8250    /* */
  38.  
  39. /* Uncomment the following line if you need asyputchar and asygetchar.
  40.    Bell Tech needs these.  uPort has them burried in the kd device.
  41. */
  42. /* #define NEED_PUT_GETCHAR    /* */
  43.  
  44. /* Initial line control register.  Value will only be meaningful for
  45.    asyputchar and asygetchar and they are only meaningful if
  46.    NEED_PUT_GETCHAR is defined.
  47. */
  48. #define    INITIAL_LINE_CONTROL    LC_WORDLEN_8
  49.  
  50. /* Initial baud rate.  Value will only be meaningful for
  51.    asyputchar and asygetchar and they are only meaningful if
  52.    NEED_PUT_GETCHAR is defined.
  53. */
  54. #define INITIAL_BAUD_RATE    (BAUD_BASE/9600)
  55.  
  56. /* Initial modem control register.  This should probably not have to
  57.    be touched.  It is here because some terminals used as the console
  58.    require one or more of the modem signals set. It is only meaningful
  59.    for asyputchar and asygetchar and they are only meaningful if
  60.    NEED_PUT_GETCHAR is defined.
  61. */
  62. #define INITIAL_MDM_CONTROL    0
  63.  
  64. /****************************************************/
  65. /* Nothing past this line should have to be changed */
  66. /****************************************************/
  67.  
  68. #define NUM_INT_VECTORS    16    /* sixteen vectors possible but only
  69.                    the first eight are normally used
  70.                 */
  71.  
  72. #define MAX_UNITS    16    /* we will only use that many units */
  73.  
  74. /* Miscellaneous Constants */
  75.  
  76. #define BAUD_BASE    (1843200 / 16)    /* 115200 bps */
  77. #define HANGUP_DELAY    ((HZ) / 4)    /* 250 msec */
  78. #define HANGUP_TIME    (HZ)        /* 1 sec */
  79. #define BREAK_TIME    ((HZ) / 4)    /* 250 msec */
  80. #define ADAPT_TIME    ((HZ) * 2)    /* 2 sec */
  81. #define    RECV_BUFF_SIZE    5000        /* receiver ring buffer size (MAX) */
  82. #define SW_LOW_WATER    2500    /* 50% MAX    sw flow control */
  83. #define SW_HIGH_WATER    4000    /* 80% MAX     trigger levels */
  84. #define HW_LOW_WATER    4500    /* MAX - 500    hw flow control */
  85. #define HW_HIGH_WATER    4900    /* MAX - 100     trigger levels */
  86. #define XMIT_BUFF_SIZE    2500        /* transmitter ring buffer size */
  87.  
  88.  
  89. /* Here are the modem control flags for the fas_modem array in space.c.
  90.    They are arranged in three 8-bit masks which are combined to a 32-bit
  91.    word. Each of these 32-bit words represents one entry in the fas_modem
  92.    array.
  93.  
  94.    The lowest byte is used as a mask to manipulate the modem control
  95.    register for modem enable. Use the MC_* macros to build the mask.
  96.  
  97.    The second lowest byte is used to mask signals from the modem status
  98.    register that will be used as the carrier detect signal. Use the MS_*
  99.    macros to build the mask and shift them 8 bits to the left. If you use
  100.    more than one signal, carrier is considered on only when all signals
  101.    are on.
  102.  
  103.    The second highes byte is used to mask signals from the modem status
  104.    register that will be used as the unblock signal. Use the MS_* macros
  105.    to build the mask and shift them 16 bits to the left. If you use more
  106.    than one signal, unblock occurs only when all signals are on.
  107.  
  108.    The highest byte is reserved for future use.
  109.  
  110.    Here are some useful macros for the space.c file. You may create your
  111.    own macros if you have some special requirements not met by the
  112.    predefined ones.
  113. */
  114.  
  115. /* modem enable (chose one) */
  116. #define EN_RTS            MC_SET_RTS    /* RTS enables modem */
  117. #define EN_DTR            MC_SET_DTR    /* DTR enables modem */
  118. #define EN_RTS_AND_DTR        (MC_SET_RTS | MC_SET_DTR)
  119.  
  120. /* carrier detect signal (chose one) */
  121. #define CA_DCD            (MS_DCD_PRESENT << 8) /* DCD is carr. detect */
  122. #define CA_CTS            (MS_CTS_PRESENT << 8) /* CTS is carr. detect */
  123. #define CA_DSR            (MS_DSR_PRESENT << 8) /* DSR is carr. detect */
  124.  
  125. /* unblock signal (chose one) */
  126. #define UB_DCD            (MS_DCD_PRESENT << 16)    /* DCD is unblock */
  127. #define UB_RING            (MS_RING_PRESENT << 16)    /* RING is unblock */
  128.  
  129.  
  130. /* Here are the hardware handshake flags for the fas_flow array in space.c.
  131.    They are arranged in three 8-bit masks which are combined to a 32-bit
  132.    word. Each of these 32-bit words represents one entry in the fas_flow
  133.    array.
  134.  
  135.    The lowest byte is used as a mask to manipulate the modem control
  136.    register for input flow control. Use the MC_* macros to build the mask.
  137.  
  138.    The second lowest byte is used to mask signals from the modem status
  139.    register that will be used for output flow control. Use the MS_* macros
  140.    to build the mask and shift them 8 bits to the left. If you use more
  141.    than one signal, output is allowed only when all signals are on.
  142.  
  143.    The second highest byte is used to mask signals from the modem status
  144.    register that will be used to enable the output flow control selected
  145.    by the second lowest byte. Use the MS_* macros to build the mask and
  146.    shift them 16 bits to the left. If you use more than one signal, output
  147.    flow control is enabled only when all signals are on.
  148.  
  149.    The highest byte is reserved for future use.
  150.  
  151.    Here are some useful macros for the space.c file. You may create your
  152.    own macros if you have some special requirements not met by the
  153.    predefined ones.
  154. */
  155.  
  156. /* input flow control (chose one) */
  157. #define HI_RTS            MC_SET_RTS    /* RTS input flow ctrl */
  158. #define HI_DTR            MC_SET_DTR    /* DTR input flow ctrl */
  159. #define HI_RTS_AND_DTR        (MC_SET_RTS | MC_SET_DTR)
  160.  
  161. /* output flow control (chose one) */
  162. #define HO_CTS            (MS_CTS_PRESENT << 8) /* CTS output flow ctrl */
  163. #define HO_DSR            (MS_DSR_PRESENT << 8) /* DSR output flow ctrl */
  164. #define HO_CTS_AND_DSR        ((MS_CTS_PRESENT | MS_DSR_PRESENT) << 8)
  165. #define HO_CTS_ON_DSR        ((MS_CTS_PRESENT << 8) | (MS_DSR_PRESENT << 16))
  166. #define HO_CTS_ON_DSR_AND_DCD    ((MS_CTS_PRESENT << 8) \
  167.                 | ((MS_DSR_PRESENT | MS_DCD_PRESENT) << 16))
  168.  
  169.  
  170. /* define the local open flags */
  171.  
  172. #define OS_DEVICE_CLOSED    0x0000
  173. #define OS_OPEN_FOR_DIALOUT    0x0001
  174. #define OS_OPEN_FOR_GETTY    0x0002
  175. #define OS_WAIT_OPEN        0x0004
  176. #define OS_NO_DIALOUT        0x0008
  177. #define OS_CHECK_CARR_ON_OPEN    0x0010
  178. #define OS_FAKE_CARR_ON        0x0020
  179. #define OS_UNBLOCK_ENABLE    0x0040
  180. #define OS_CLOCAL        0x0080
  181. #define OS_HW_HANDSHAKE        0x0100
  182. #define OS_EXCLUSIVE_OPEN    0x0200    /* SYSV 3.2 Xenix compatibility */
  183.  
  184. #define OS_OPEN_STATES        (OS_OPEN_FOR_DIALOUT | OS_OPEN_FOR_GETTY)
  185. #define OS_TEST_MASK        (OS_OPEN_FOR_DIALOUT | OS_NO_DIALOUT \
  186.                 | OS_CHECK_CARR_ON_OPEN | OS_FAKE_CARR_ON \
  187.                 | OS_UNBLOCK_ENABLE | OS_CLOCAL \
  188.                 | OS_HW_HANDSHAKE | OS_EXCLUSIVE_OPEN)
  189.  
  190. /* define the device status flags */
  191.  
  192. #define DF_DEVICE_CONFIGURED    0x0001    /* device is configured */
  193. #define DF_DEVICE_HAS_FIFO    0x0002    /* it's an NS16550 */
  194. #define DF_DEVICE_OPEN        0x0004    /* physical device is open */
  195. #define DF_DEVICE_LOCKED    0x0008    /* physical device locked */
  196. #define DF_MODEM_ENABLED    0x0010    /* modem enabled */
  197. #define DF_SWO_STOPPED        0x0020    /* output stopped by sw flow control */
  198. #define DF_SWI_STOPPED        0x0040    /* input stopped by sw flow control */
  199. #define DF_SW_FC_REQ        0x0080    /* sw input flow control request */
  200. #define    DF_HWO_STOPPED        0x0100    /* output stopped by hw handshake */
  201. #define DF_HWI_STOPPED        0x0200    /* input stopped by hw handshake */
  202. #define DF_XMIT_DISABLED    0x0400    /* transmitter is disabled */
  203. #define DF_XMIT_BUSY        0x0800    /* transmitter is busy */
  204. #define DF_DO_HANGUP        0x1000    /* delayed hangup request */
  205. #define DF_DO_BREAK        0x2000    /* delayed break request */
  206. #define DF_GUARD_TIMEOUT    0x4000    /* protect last char from corruption */
  207. #define DF_ADAPT_TIMEOUT    0x8000    /* transmitter was used recently */
  208.  
  209. /* define an easy way to refenence the absolute port addresses */
  210.  
  211. #define RCV_DATA_PORT        (fip->uart_port_0)
  212. #define XMT_DATA_PORT        (fip->uart_port_0)
  213. #define INT_ENABLE_PORT        (fip->uart_port_1)
  214. #define INT_ID_PORT        (fip->uart_port_2)
  215. #define FIFO_CTL_PORT        (fip->uart_port_2)
  216. #define LINE_CTL_PORT        (fip->uart_port_3)
  217. #define MDM_CTL_PORT        (fip->uart_port_4)
  218. #define LINE_STATUS_PORT    (fip->uart_port_5)
  219. #define MDM_STATUS_PORT        (fip->uart_port_6)
  220. #define DIVISOR_LSB_PORT    (fip->uart_port_0)
  221. #define DIVISOR_MSB_PORT    (fip->uart_port_1)
  222. #define INT_ACK_PORT        (fip->int_ack_port)
  223.  
  224. /* modem control port */
  225.  
  226. #define MC_SET_DTR        0x01
  227. #define MC_SET_RTS        0x02
  228. #define MC_SET_OUT1        0x04
  229. #define MC_SET_OUT2        0x08    /* tristates int line when false */
  230. #define MC_SET_LOOPBACK        0x10
  231.  
  232. /* modem status port */
  233.  
  234. #define MS_CTS_PRESENT        0x10
  235. #define MS_DSR_PRESENT        0x20
  236. #define MS_RING_PRESENT        0x40
  237. #define MS_DCD_PRESENT        0x80
  238.  
  239. #define MS_ANY_PRESENT    (MS_CTS_PRESENT | MS_DSR_PRESENT | MS_RING_PRESENT \
  240.                 | MS_DCD_PRESENT)
  241.  
  242. /* interrupt enable port */
  243.  
  244. #define IE_NONE                0x00
  245. #define    IE_RECV_DATA_AVAILABLE        0x01
  246. #define    IE_XMIT_HOLDING_BUFFER_EMPTY    0x02
  247. #define IE_LINE_STATUS            0x04
  248. #define IE_MODEM_STATUS            0x08
  249.  
  250. #define IE_INIT_MODE    (IE_RECV_DATA_AVAILABLE | IE_XMIT_HOLDING_BUFFER_EMPTY \
  251.             | IE_LINE_STATUS | IE_MODEM_STATUS)
  252.  
  253. /* interrupt id port */
  254.  
  255. #define II_NO_INTS_PENDING    0x01
  256. #define II_CODE_MASK        0x07
  257. #define II_MODEM_STATE        0x00
  258. #define II_XMTD_CHAR        0x02
  259. #define II_RCVD_CHAR        0x04
  260. #define II_RCV_ERROR        0x06
  261. #define II_FIFO_TIMEOUT        0x08
  262. #define II_FIFO_ENABLED        0xC0
  263.  
  264. /* line control port */
  265.  
  266. #define    LC_WORDLEN_MASK        0x03
  267. #define    LC_WORDLEN_5        0x00
  268. #define    LC_WORDLEN_6        0x01
  269. #define    LC_WORDLEN_7        0x02
  270. #define    LC_WORDLEN_8        0x03
  271. #define LC_STOPBITS_LONG    0x04
  272. #define LC_ENABLE_PARITY    0x08
  273. #define LC_EVEN_PARITY        0x10
  274. #define LC_STICK_PARITY        0x20
  275. #define LC_SET_BREAK_LEVEL    0x40
  276. #define LC_ENABLE_DIVISOR    0x80
  277.  
  278. /* line status port */
  279.  
  280. #define LS_RCV_AVAIL        0x01
  281. #define LS_OVERRUN        0x02
  282. #define LS_PARITY_ERROR        0x04
  283. #define LS_FRAMING_ERROR    0x08
  284. #define LS_BREAK_DETECTED    0x10
  285. #define LS_XMIT_AVAIL        0x20
  286. #define LS_XMIT_COMPLETE    0x40
  287. #define LS_ERROR_IN_FIFO    0x80    /* NS16550 only */
  288.  
  289. #define LS_RCV_INT    (LS_RCV_AVAIL | LS_OVERRUN | LS_PARITY_ERROR \
  290.             | LS_FRAMING_ERROR | LS_BREAK_DETECTED)
  291.  
  292. /* fifo control port (NS16550 only) */
  293.  
  294. #define    FIFO_ENABLE    0x01
  295. #define    FIFO_CLR_RECV    0x02
  296. #define    FIFO_CLR_XMIT    0x04
  297. #define    FIFO_START_DMA    0x08
  298. #define FIFO_SIZE_1    0x00
  299. #define FIFO_SIZE_4    0x40
  300. #define FIFO_SIZE_8    0x80
  301. #define FIFO_SIZE_14    0xC0
  302. #define FIFO_SIZE_MASK    0xC0
  303.  
  304. #define STANDARD_FIFO_CLEAR    0
  305. #define STANDARD_FIFO_SETUP    (FIFO_SIZE_8 | FIFO_ENABLE)
  306. #define STANDARD_FIFO_INIT    (STANDARD_FIFO_SETUP | FIFO_CLR_RECV \
  307.                 | FIFO_CLR_XMIT)
  308.  
  309. #define INPUT_FIFO_SIZE        16
  310. #define OUTPUT_FIFO_SIZE    16
  311.  
  312.  
  313. /* This structure contains everything one would like to know about
  314.    an open device.  There is one of these for each physical unit.
  315.  
  316.    We use several unions to eliminate most integer type conversions
  317.    at run-time. The standard UNIX V 3.X/386 C compiler forces all
  318.    operands in expressions and all function parameters to type int.
  319.    To save some time, with the means of unions we deliver type int
  320.    at the proper locations while dealing with the original type
  321.    wherever int would be slower.
  322.  
  323.    This is highly compiler implementation specific. But for the sake
  324.    of speed the end justifies the means.
  325. */
  326.  
  327. struct    fas_info
  328. {
  329.     struct    tty    *tty;    /* the tty structure */
  330.     struct    fas_info *prev_int_user;/* link to previous fas_info struct */
  331.     struct    fas_info *next_int_user;/* link to next fas_info struct */
  332.     uint    vec;        /* interrupt vector for this struct */
  333.     uint    iflag;        /* current terminal input flags */
  334.     uint    cflag;        /* current terminal hardware control flags */
  335.     union {            /* flags about the device */
  336.         ushort    s;
  337.         uint    i;
  338.     } device_flags;
  339.     uint    o_state;    /* current open state */
  340.     uint    po_state;    /* previous open state */
  341.     union {            /* modem control masks */
  342.         struct {
  343.             unchar    en;    /* mask for modem enable */
  344.             unchar    ca;    /* mask for carrier detect */
  345.             unchar    ub;    /* mask for unblock signal */
  346.         } m;
  347.         uint    i;
  348.     } modem;
  349.     union {            /* hardware flow control masks */
  350.         struct {
  351.             unchar    ic;    /* control mask for inp. flow ctrl */
  352.             unchar    oc;    /* control mask for outp. flow ctrl */
  353.             unchar    oe;    /* enable mask for outp. flow ctrl */
  354.         } m;
  355.         uint    i;
  356.     } flow;
  357.     uint    msr;        /* modem status register value */
  358.     union {            /* modem control register value */
  359.         unchar    c;
  360.         uint    i;
  361.     } mcr;
  362.     union {            /* line control register value */
  363.         unchar    c;
  364.         uint    i;
  365.     } lcr;
  366.     union {            /* interrupt enable register value */
  367.         unchar    c;
  368.         uint    i;
  369.     } ier;
  370.     uint    timeout_idx;    /* timeout index for untimeout () */
  371.     uint    uart_port_0;    /* uart port 0 address */
  372.     uint    uart_port_1;    /* uart port 1 address */
  373.     uint    uart_port_2;    /* uart port 2 address */
  374.     uint    uart_port_3;    /* uart port 3 address */
  375.     uint    uart_port_4;    /* uart port 4 address */
  376.     uint    uart_port_5;    /* uart port 5 address */
  377.     uint    uart_port_6;    /* uart port 6 address */
  378.     uint    int_ack_port;    /* int ack port address */
  379.     uint    int_ack;    /* int ack value */
  380.     uint    recv_ring_cnt;    /* receiver ring buffer counter */
  381.     unchar    *recv_ring_put_ptr;    /* recv ring buf put ptr */
  382.     unchar    *recv_ring_take_ptr;    /* recv ring buf take ptr */
  383.     uint    xmit_ring_size;    /* transmitter ring buffer size */
  384.     uint    xmit_ring_cnt;    /* transmitter ring buffer counter */
  385.     unchar    *xmit_ring_put_ptr;    /* xmit ring buf put ptr */
  386.     unchar    *xmit_ring_take_ptr;    /* xmit ring buf take ptr */
  387.     unchar    recv_buffer [RECV_BUFF_SIZE];    /* recv ring buf */
  388.     unchar    xmit_buffer [XMIT_BUFF_SIZE];    /* xmit ring buf */
  389. };
  390.