n_r3964.h 5.2 KB

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