n_r3964.h 5.1 KB

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