vsta

Check-in [57a7c9b100]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Get SLIP working a little better. Clean up CVS warnings.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:57a7c9b1000853002df9d733d5384c3bf52c09eb34844394909126d0d071949e
User & Date: vandys 2002-01-04 18:00:04
Context
2002-01-10
09:56
No such opcode as "pushb"... it's actually a "pushl". check-in: f221206067 user: vandys tags: master, trunk
2002-01-04
18:00
Get SLIP working a little better. Clean up CVS warnings. check-in: 57a7c9b100 user: vandys tags: master, trunk
17:58
Use named for calloc()'s parameters, as I can never remember which is which here, either (see comment for tcsetattr() :->). check-in: 8e0db21cd7 user: vandys tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to vsta/src/srv/ka9q/vsta_io.c.

42
43
44
45
46
47
48

49
50
51

52
53
54
55
56
57
58
59
...
145
146
147
148
149
150
151
152
153
154
155
156
157

158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
...
261
262
263
264
265
266
267

268
269
270
271
272
273
274
...
334
335
336
337
338
339
340
341
342
343
344
345
346

347
348
349
350
351
352
353
354
355
356
357
...
360
361
362
363
364
365
366
367
368
369


370
371
372
373
374
375
376
/*
 * Per async port state
 */
static struct asy {
	char *a_tty;		/* Port accessed */
	port_t a_txport,	/* Open ports to this name */
		a_rxport;

	char *a_txbuf;		/* When active, buffer being sent */
	int a_txcnt;		/*  ...size */
	char *a_rxbuf;		/* Receive buffer */

	int a_hd, a_tl;		/* Head/tail of rx FIFO */
	pid_t a_txpid,		/* Thread serving this port (tx) */
		a_rxpid;	/*   ...rx */
} asy[ASY_MAX];

/*
 * ioinit()
 *	Called at startup time to set up console I/O
................................................................................
 * asy_rx_daemon()
 *	Thread to watch for incoming bytes, and queue them
 */
static void
asy_rx_daemon(struct asy *ap)
{
	struct msg m;
	int cnt;

	for (;;) {
		/*
		 * See how much we can pull in this time
		 */

		if (ap->a_hd >= ap->a_tl) {
			cnt = BUFLEN - ap->a_hd;
		} else {
			cnt = (ap->a_tl - ap->a_hd);
		}
		if (cnt <= 1) {
			__msleep(10);
			continue;
		}
		cnt -= 1;

		/*
		 * Do the receive
		 */
		m.m_op = FS_READ | M_READ;
		m.m_arg = m.m_buflen = cnt;
		m.m_arg1 = 0;
................................................................................

		/*
		 * Transmit it
		 */
		m.m_op = FS_WRITE;
		m.m_arg = m.m_buflen = ap->a_txcnt;
		m.m_arg1 = 0;
		m.m_buf = ap->a_txbuf;
		m.m_nseg = 1;
		(void)msg_send(ap->a_txport, &m);

		/*
		 * Flag completion
		 */
		ap->a_txbuf = 0;
................................................................................
	/* 
	 * Set to default parameters
	 */
	(void)wstat(p, "baud=9600\n");
	(void)wstat(p, "databits=8\n");
	(void)wstat(p, "stopbits=1\n");
	(void)wstat(p, "parity=none\n");


	/*
	 * Initialize tty, launch threads
	 */
	ap->a_txport = clone(p);
	ap->a_rxbuf = malloc(BUFLEN);
	ap->a_rxpid = tfork(asy_rx_daemon, (ulong)ap);
................................................................................
 *
 * Returns count of characters read
 */
int16
asy_recv(int16 dev, char *buf, int cnt)
{
	struct asy *ap = &asy[dev];
	int avail;

	/*
	 * Take the lesser of how much is there and how much
	 * they want.
	 */

	if (ap->a_hd < ap->a_tl) {
		avail = BUFLEN - ap->a_tl;
	} else {
		avail = ap->a_hd - ap->a_tl;
	}
	if (avail > cnt) {
		avail = cnt;
	}
	if (avail <= 0) {
		return(0);
	}
................................................................................
	 * Copy it out
	 */
	bcopy(ap->a_rxbuf + ap->a_tl, buf, avail);

	/*
	 * Update state
	 */
	ap->a_tl += avail;
	if (ap->a_tl >= BUFLEN) {
		ap->a_tl = 0;


	}

	return(avail);
}

/*
 * asy_ioctl()







>
|


>
|







 







|





>
|


|

|



<







 







|







 







>







 







|





>
|


|







 







|
|

>
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
...
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

170
171
172
173
174
175
176
...
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
...
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
...
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
 * Per async port state
 */
static struct asy {
	char *a_tty;		/* Port accessed */
	port_t a_txport,	/* Open ports to this name */
		a_rxport;
	char volatile *
		a_txbuf;	/* When active, buffer being sent */
	int a_txcnt;		/*  ...size */
	char *a_rxbuf;		/* Receive buffer */
	volatile int
		a_hd, a_tl;	/* Head/tail of rx FIFO */
	pid_t a_txpid,		/* Thread serving this port (tx) */
		a_rxpid;	/*   ...rx */
} asy[ASY_MAX];

/*
 * ioinit()
 *	Called at startup time to set up console I/O
................................................................................
 * asy_rx_daemon()
 *	Thread to watch for incoming bytes, and queue them
 */
static void
asy_rx_daemon(struct asy *ap)
{
	struct msg m;
	int cnt, tl;

	for (;;) {
		/*
		 * See how much we can pull in this time
		 */
		tl = ap->a_tl;
		if (ap->a_hd >= tl) {
			cnt = BUFLEN - ap->a_hd;
		} else {
			cnt = (tl - ap->a_hd) - 1;
		}
		if (cnt <= 0) {
			__msleep(10);
			continue;
		}


		/*
		 * Do the receive
		 */
		m.m_op = FS_READ | M_READ;
		m.m_arg = m.m_buflen = cnt;
		m.m_arg1 = 0;
................................................................................

		/*
		 * Transmit it
		 */
		m.m_op = FS_WRITE;
		m.m_arg = m.m_buflen = ap->a_txcnt;
		m.m_arg1 = 0;
		m.m_buf = (char *)ap->a_txbuf;
		m.m_nseg = 1;
		(void)msg_send(ap->a_txport, &m);

		/*
		 * Flag completion
		 */
		ap->a_txbuf = 0;
................................................................................
	/* 
	 * Set to default parameters
	 */
	(void)wstat(p, "baud=9600\n");
	(void)wstat(p, "databits=8\n");
	(void)wstat(p, "stopbits=1\n");
	(void)wstat(p, "parity=none\n");
	(void)wstat(p, "onlcr=0\n");

	/*
	 * Initialize tty, launch threads
	 */
	ap->a_txport = clone(p);
	ap->a_rxbuf = malloc(BUFLEN);
	ap->a_rxpid = tfork(asy_rx_daemon, (ulong)ap);
................................................................................
 *
 * Returns count of characters read
 */
int16
asy_recv(int16 dev, char *buf, int cnt)
{
	struct asy *ap = &asy[dev];
	int x, avail;

	/*
	 * Take the lesser of how much is there and how much
	 * they want.
	 */
	x = ap->a_hd;
	if (x < ap->a_tl) {
		avail = BUFLEN - ap->a_tl;
	} else {
		avail = x - ap->a_tl;
	}
	if (avail > cnt) {
		avail = cnt;
	}
	if (avail <= 0) {
		return(0);
	}
................................................................................
	 * Copy it out
	 */
	bcopy(ap->a_rxbuf + ap->a_tl, buf, avail);

	/*
	 * Update state
	 */
	x = ap->a_tl + avail;
	if (x >= BUFLEN) {
		ap->a_tl = 0;
	} else {
		ap->a_tl = x;
	}

	return(avail);
}

/*
 * asy_ioctl()