n_r3964.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* r3964 linediscipline for linux
  2. *
  3. * -----------------------------------------------------------
  4. * Copyright by
  5. * Philips Automation Projects
  6. * Kassel (Germany)
  7. * http://www.pap-philips.de
  8. * -----------------------------------------------------------
  9. * This software may be used and distributed according to the terms of
  10. * the GNU General Public License, incorporated herein by reference.
  11. *
  12. * Author:
  13. * L. Haag
  14. *
  15. * $Log: r3964.h,v $
  16. * Revision 1.3 2001/03/18 13:02:24 dwmw2
  17. * Fix timer usage, use spinlocks properly.
  18. *
  19. * Revision 1.2 2001/03/18 12:53:15 dwmw2
  20. * Merge changes in 2.4.2
  21. *
  22. * Revision 1.1.1.1 1998/10/13 16:43:14 dwmw2
  23. * This'll screw the version control
  24. *
  25. * Revision 1.6 1998/09/30 00:40:38 dwmw2
  26. * Updated to use kernel's N_R3964 if available
  27. *
  28. * Revision 1.4 1998/04/02 20:29:44 lhaag
  29. * select, blocking, ...
  30. *
  31. * Revision 1.3 1998/02/12 18:58:43 root
  32. * fixed some memory leaks
  33. * calculation of checksum characters
  34. *
  35. * Revision 1.2 1998/02/07 13:03:17 root
  36. * ioctl read_telegram
  37. *
  38. * Revision 1.1 1998/02/06 19:19:43 root
  39. * Initial revision
  40. *
  41. *
  42. */
  43. #ifndef __LINUX_N_R3964_H__
  44. #define __LINUX_N_R3964_H__
  45. /* line disciplines for r3964 protocol */
  46. #include <asm/termios.h>
  47. #ifdef __KERNEL__
  48. /*
  49. * Common ascii handshake characters:
  50. */
  51. #define STX 0x02
  52. #define ETX 0x03
  53. #define DLE 0x10
  54. #define NAK 0x15
  55. /*
  56. * Timeouts (msecs/10 msecs per timer interrupt):
  57. */
  58. #define R3964_TO_QVZ 550/10
  59. #define R3964_TO_ZVZ 220/10
  60. #define R3964_TO_NO_BUF 400/10
  61. #define R3964_NO_TX_ROOM 100/10
  62. #define R3964_TO_RX_PANIC 4000/10
  63. #define R3964_MAX_RETRIES 5
  64. #endif
  65. /*
  66. * Ioctl-commands
  67. */
  68. #define R3964_ENABLE_SIGNALS 0x5301
  69. #define R3964_SETPRIORITY 0x5302
  70. #define R3964_USE_BCC 0x5303
  71. #define R3964_READ_TELEGRAM 0x5304
  72. /* Options for R3964_SETPRIORITY */
  73. #define R3964_MASTER 0
  74. #define R3964_SLAVE 1
  75. /* Options for R3964_ENABLE_SIGNALS */
  76. #define R3964_SIG_ACK 0x0001
  77. #define R3964_SIG_DATA 0x0002
  78. #define R3964_SIG_ALL 0x000f
  79. #define R3964_SIG_NONE 0x0000
  80. #define R3964_USE_SIGIO 0x1000
  81. /*
  82. * r3964 operation states:
  83. */
  84. #ifdef __KERNEL__
  85. enum { R3964_IDLE,
  86. R3964_TX_REQUEST, R3964_TRANSMITTING,
  87. R3964_WAIT_ZVZ_BEFORE_TX_RETRY, R3964_WAIT_FOR_TX_ACK,
  88. R3964_WAIT_FOR_RX_BUF,
  89. R3964_RECEIVING, R3964_WAIT_FOR_BCC, R3964_WAIT_FOR_RX_REPEAT
  90. };
  91. /*
  92. * All open file-handles are 'clients' and are stored in a linked list:
  93. */
  94. struct r3964_message;
  95. struct r3964_client_info {
  96. spinlock_t lock;
  97. pid_t pid;
  98. unsigned int sig_flags;
  99. struct r3964_client_info *next;
  100. struct r3964_message *first_msg;
  101. struct r3964_message *last_msg;
  102. struct r3964_block_header *next_block_to_read;
  103. int msg_count;
  104. };
  105. #endif
  106. /* types for msg_id: */
  107. enum {R3964_MSG_ACK=1, R3964_MSG_DATA };
  108. #define R3964_MAX_MSG_COUNT 32
  109. /* error codes for client messages */
  110. #define R3964_OK 0 /* no error. */
  111. #define R3964_TX_FAIL -1 /* transmission error, block NOT sent */
  112. #define R3964_OVERFLOW -2 /* msg queue overflow */
  113. /* the client gets this struct when calling read(fd,...): */
  114. struct r3964_client_message {
  115. int msg_id;
  116. int arg;
  117. int error_code;
  118. };
  119. #define R3964_MTU 256
  120. #ifdef __KERNEL__
  121. struct r3964_block_header;
  122. /* internal version of client_message: */
  123. struct r3964_message {
  124. int msg_id;
  125. int arg;
  126. int error_code;
  127. struct r3964_block_header *block;
  128. struct r3964_message *next;
  129. };
  130. /*
  131. * Header of received block in rx_buf/tx_buf:
  132. */
  133. struct r3964_block_header
  134. {
  135. unsigned int length; /* length in chars without header */
  136. unsigned char *data; /* usually data is located
  137. immediately behind this struct */
  138. unsigned int locks; /* only used in rx_buffer */
  139. struct r3964_block_header *next;
  140. struct r3964_client_info *owner; /* =NULL in rx_buffer */
  141. };
  142. /*
  143. * If rx_buf hasn't enough space to store R3964_MTU chars,
  144. * we will reject all incoming STX-requests by sending NAK.
  145. */
  146. #define RX_BUF_SIZE 4000
  147. #define TX_BUF_SIZE 4000
  148. #define R3964_MAX_BLOCKS_IN_RX_QUEUE 100
  149. #define R3964_PARITY 0x0001
  150. #define R3964_FRAME 0x0002
  151. #define R3964_OVERRUN 0x0004
  152. #define R3964_UNKNOWN 0x0008
  153. #define R3964_BREAK 0x0010
  154. #define R3964_CHECKSUM 0x0020
  155. #define R3964_ERROR 0x003f
  156. #define R3964_BCC 0x4000
  157. #define R3964_DEBUG 0x8000
  158. struct r3964_info {
  159. spinlock_t lock;
  160. struct tty_struct *tty;
  161. unsigned char priority;
  162. unsigned char *rx_buf; /* ring buffer */
  163. unsigned char *tx_buf;
  164. wait_queue_head_t read_wait;
  165. //struct wait_queue *read_wait;
  166. struct r3964_block_header *rx_first;
  167. struct r3964_block_header *rx_last;
  168. struct r3964_block_header *tx_first;
  169. struct r3964_block_header *tx_last;
  170. unsigned int tx_position;
  171. unsigned int rx_position;
  172. unsigned char last_rx;
  173. unsigned char bcc;
  174. unsigned int blocks_in_rx_queue;
  175. struct r3964_client_info *firstClient;
  176. unsigned int state;
  177. unsigned int flags;
  178. struct timer_list tmr;
  179. int nRetry;
  180. };
  181. #endif
  182. #endif