1 /* r3964 linediscipline for linux
3 * -----------------------------------------------------------
5 * Philips Automation Projects
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.
16 * Revision 1.3 2001/03/18 13:02:24 dwmw2
17 * Fix timer usage, use spinlocks properly.
19 * Revision 1.2 2001/03/18 12:53:15 dwmw2
20 * Merge changes in 2.4.2
22 * Revision 1.1.1.1 1998/10/13 16:43:14 dwmw2
23 * This'll screw the version control
25 * Revision 1.6 1998/09/30 00:40:38 dwmw2
26 * Updated to use kernel's N_R3964 if available
28 * Revision 1.4 1998/04/02 20:29:44 lhaag
29 * select, blocking, ...
31 * Revision 1.3 1998/02/12 18:58:43 root
32 * fixed some memory leaks
33 * calculation of checksum characters
35 * Revision 1.2 1998/02/07 13:03:17 root
38 * Revision 1.1 1998/02/06 19:19:43 root
44 #ifndef __LINUX_N_R3964_H__
45 #define __LINUX_N_R3964_H__
47 /* line disciplines for r3964 protocol */
48 #include <asm/termios.h>
52 * Common ascii handshake characters:
61 * Timeouts (msecs/10 msecs per timer interrupt):
64 #define R3964_TO_QVZ 550/10
65 #define R3964_TO_ZVZ 220/10
66 #define R3964_TO_NO_BUF 400/10
67 #define R3964_NO_TX_ROOM 100/10
68 #define R3964_TO_RX_PANIC 4000/10
69 #define R3964_MAX_RETRIES 5
77 #define R3964_ENABLE_SIGNALS 0x5301
78 #define R3964_SETPRIORITY 0x5302
79 #define R3964_USE_BCC 0x5303
80 #define R3964_READ_TELEGRAM 0x5304
82 /* Options for R3964_SETPRIORITY */
83 #define R3964_MASTER 0
86 /* Options for R3964_ENABLE_SIGNALS */
87 #define R3964_SIG_ACK 0x0001
88 #define R3964_SIG_DATA 0x0002
89 #define R3964_SIG_ALL 0x000f
90 #define R3964_SIG_NONE 0x0000
91 #define R3964_USE_SIGIO 0x1000
94 * r3964 operation states:
99 R3964_TX_REQUEST, R3964_TRANSMITTING,
100 R3964_WAIT_ZVZ_BEFORE_TX_RETRY, R3964_WAIT_FOR_TX_ACK,
101 R3964_WAIT_FOR_RX_BUF,
102 R3964_RECEIVING, R3964_WAIT_FOR_BCC, R3964_WAIT_FOR_RX_REPEAT
106 * All open file-handles are 'clients' and are stored in a linked list:
109 struct r3964_message;
111 struct r3964_client_info {
114 unsigned int sig_flags;
116 struct r3964_client_info *next;
118 struct r3964_message *first_msg;
119 struct r3964_message *last_msg;
120 struct r3964_block_header *next_block_to_read;
127 /* types for msg_id: */
128 enum {R3964_MSG_ACK=1, R3964_MSG_DATA };
130 #define R3964_MAX_MSG_COUNT 32
132 /* error codes for client messages */
133 #define R3964_OK 0 /* no error. */
134 #define R3964_TX_FAIL -1 /* transmission error, block NOT sent */
135 #define R3964_OVERFLOW -2 /* msg queue overflow */
137 /* the client gets this struct when calling read(fd,...): */
138 struct r3964_client_message {
144 #define R3964_MTU 256
149 struct r3964_block_header;
151 /* internal version of client_message: */
152 struct r3964_message {
156 struct r3964_block_header *block;
157 struct r3964_message *next;
161 * Header of received block in rx_buf/tx_buf:
164 struct r3964_block_header
166 unsigned int length; /* length in chars without header */
167 unsigned char *data; /* usually data is located
168 immediately behind this struct */
169 unsigned int locks; /* only used in rx_buffer */
171 struct r3964_block_header *next;
172 struct r3964_client_info *owner; /* =NULL in rx_buffer */
176 * If rx_buf hasn't enough space to store R3964_MTU chars,
177 * we will reject all incoming STX-requests by sending NAK.
180 #define RX_BUF_SIZE 4000
181 #define TX_BUF_SIZE 4000
182 #define R3964_MAX_BLOCKS_IN_RX_QUEUE 100
184 #define R3964_PARITY 0x0001
185 #define R3964_FRAME 0x0002
186 #define R3964_OVERRUN 0x0004
187 #define R3964_UNKNOWN 0x0008
188 #define R3964_BREAK 0x0010
189 #define R3964_CHECKSUM 0x0020
190 #define R3964_ERROR 0x003f
191 #define R3964_BCC 0x4000
192 #define R3964_DEBUG 0x8000
197 struct tty_struct *tty;
198 unsigned char priority;
199 unsigned char *rx_buf; /* ring buffer */
200 unsigned char *tx_buf;
202 wait_queue_head_t read_wait;
203 //struct wait_queue *read_wait;
205 struct r3964_block_header *rx_first;
206 struct r3964_block_header *rx_last;
207 struct r3964_block_header *tx_first;
208 struct r3964_block_header *tx_last;
209 unsigned int tx_position;
210 unsigned int rx_position;
211 unsigned char last_rx;
213 unsigned int blocks_in_rx_queue;
216 struct r3964_client_info *firstClient;
220 struct timer_list tmr;