예제 #1
0
파일: devtty.c 프로젝트: chettrick/uzics
/*
 * This tty interrupt routine checks to see if the uart receiver
 * actually caused the interrupt.  If so it adds the character to
 * the tty input queue, echoing and processing backspace and carriage
 * return.  If the queue contains a full line, it wakes up anything
 * waiting on it.  If it is totally full, it beeps at the user.
 */
int
tty_int(void)
{
	char c;
	int found;
	char oc;

	found = 0;
again:
	if ((in(0x72) & 0x81) != 0x81)
		return (found);
	c = (in(0x73) & 0x7f);

	if (c == 0x1a)			/* ^Z */
		idump();		/* For debugging. */

	if (c == '\003')		/* ^C */
		sendsig(NULL, SIGINT);
	else if (c == '\017')		/* ^O */
		flshflag = !flshflag;
	else if (c == '\023')		/* ^S */
		stopflag = 1;
	else if (c == '\021') {		/* ^Q */
		stopflag = 0;
		wakeup(&stopflag);
	} else if (c == '\b') {
		if (uninsq(&ttyinq, &oc)) {
			if (oc == '\n') {
				/* Don't erase past newline. */
				insq(&ttyinq, oc);
			} else {
				_putc('\b');
				_putc(' ');
				_putc('\b');
			}
		}
	} else {
		if ((c == '\r') || (c == '\n')) {
			c = '\n';
			_putc('\r');
		}

		if (insq(&ttyinq, c))
			_putc(c);
		else
			_putc('\007');	/* Beep if no more room. */
	}

	if ((c == '\n') || (c == '\004'))	/* ^D */
		wakeup(&ttyinq);

	found = 1;
	goto again;	/* Loop until the uart has no data ready. */
}
void main()
{
	int ele,ch;
	struct queue q;
	q.f=q.r=q.count=0;
	while(true)
	{
		system("cls");
		printf("1. Insert\n2. Delete\n3. Display\n4. Exit\n\nEnter Choice : ");
		scanf("%d",&ch);
		switch(ch)
		{
		case 1:printf("Enter Element To Insert : ");
			scanf("%d",&ele);
			insq(&q,ele);
			break;
		case 2:delq(&q);
			break;
		case 3:display(&q);
			break;
		case 4:exit(0);
			break;
		default:printf("Invalid Selection");
		}
		getch();
	}
}
예제 #3
0
파일: tty.c 프로젝트: jfernand/FUZIX
void pty_putc_wait(uint8_t minor, char c)
{
	struct s_queue q = &ptyq[minor + PTY_OFFSET + PTY_PAIR];
	/* tty output queue to pty */
	insq(q, c);
	wakeup(q);
}
예제 #4
0
/* put an rtp packet in queue. It is called by rtp_parse()*/
void rtp_putq(queue_t *q, mblk_t *mp)
{
	mblk_t *tmp;
	rtp_header_t *rtp=(rtp_header_t*)mp->b_rptr,*tmprtp;
	/* insert message block by increasing time stamp order : the last (at the bottom)
		message of the queue is the newest*/
	ortp_debug("rtp_putq(): Enqueuing packet with ts=%i and seq=%i",rtp->timestamp,rtp->seq_number);
	
	if (qempty(q)) {
		putq(q,mp);
		return;
	}
	tmp=qlast(q);
	/* we look at the queue from bottom to top, because enqueued packets have a better chance
	to be enqueued at the bottom, since there are surely newer */
	while (!qend(q,tmp))
	{
		tmprtp=(rtp_header_t*)tmp->b_rptr;
		ortp_debug("rtp_putq(): Seeing packet with seq=%i",tmprtp->seq_number);
		
 		if (rtp->seq_number == tmprtp->seq_number)
 		{
 			/* this is a duplicated packet. Don't queue it */
 			ortp_debug("rtp_putq: duplicated message.");
 			freemsg(mp);
 			return;
		}else if (RTP_SEQ_IS_GREATER(rtp->seq_number,tmprtp->seq_number)){
			
			insq(q,tmp->b_next,mp);
			return;
 		}
		tmp=tmp->b_prev;
	}
	/* this packet is the oldest, it has to be 
	placed on top of the queue */
	insq(q,qfirst(q),mp);
	
}
예제 #5
0
파일: tty.c 프로젝트: jfernand/FUZIX
int tty_inproc(uint8_t minor, unsigned char c)
{
	unsigned char oc;
	struct termios *td;
	struct s_queue *q = &ttyinq[minor];
	int canon;
	uint16_t pgrp = tty_pgrp[minor];
	uint8_t wr;

	td = &ttydata[minor];
	canon = td->c_lflag & ICANON;

	if (td->c_iflag & ISTRIP)
		c &= 0x7f;	/* Strip off parity */
	if (canon && !c)
		return 1;	/* Simply quit if Null character */

#ifdef CONFIG_IDUMP
	if (c == 0x1a)		/* ^Z */
		idump();	/*   (For debugging) */
#endif
#ifdef CONFIG_MONITOR
	if (c == 0x01)		/* ^A */
		trap_monitor();
#endif

	if (c == '\r' && (td->c_iflag & ICRNL))
		c = '\n';
	if (c == '\n' && (td->c_iflag & INLCR))
		c = '\r';

	if (td->c_lflag & ISIG) {
		if (c == td->c_cc[VINTR]) {	/* ^C */
			sgrpsig(pgrp, SIGINT);
			clrq(q);
			stopflag[minor] = flshflag[minor] = false;
			return 1;
		} else if (c == td->c_cc[VQUIT]) {	/* ^\ */
			sgrpsig(pgrp, SIGQUIT);
			clrq(q);
			stopflag[minor] = flshflag[minor] = false;
			return 1;
		}
	}
	if (c == td->c_cc[VDISCARD]) {	/* ^O */
		flshflag[minor] = !flshflag[minor];
		return 1;
	}
	if (td->c_iflag & IXON) {
		if (c == td->c_cc[VSTOP]) {	/* ^S */
			stopflag[minor] = true;
			return 1;
		}
		if (c == td->c_cc[VSTART]) {	/* ^Q */
			stopflag[minor] = false;
			wakeup(&stopflag[minor]);
			return 1;
		}
	}
	if (canon) {
		if (c == td->c_cc[VERASE]) {
			if (uninsq(q, &oc)) {
				if (oc == '\n' || oc == td->c_cc[VEOL])
					insq(q, oc);	/* Don't erase past nl */
				else if (td->c_lflag & ECHOE)
					tty_erase(minor);
				return 1;
			} else if (c == td->c_cc[VKILL]) {
				while (uninsq(q, &oc)) {
					if (oc == '\n'
					    || oc == td->c_cc[VEOL]) {
						insq(q, oc);	/* Don't erase past nl */
						break;
					}
					if (td->c_lflag & ECHOK)
						tty_erase(minor);
				}
				return 1;
			}
		}
	}

	/* All modes come here */
	if (c == '\n') {
		if ((td->c_oflag & OPOST | ONLCR) == OPOST | ONLCR)
			tty_echo(minor, '\r');
	}

	wr = insq(q, c);
	if (wr)
		tty_echo(minor, c);
	else if (minor < PTY_OFFSET)
		tty_putc_wait(minor, '\007');	/* Beep if no more room */

	if (!canon || c == td->c_cc[VEOL] || c == '\n'
	    || c == td->c_cc[VEOF])
		wakeup(q);
	return wr;
}
예제 #6
0
/* Queue a character to the input device */
void queue_input(uint8_t c)
{
    insq(&kqueue, c);
    wakeup(&kqueue);
}
예제 #7
0
파일: tty.c 프로젝트: aralbrec/FUZIX
/* This routine processes a character in response to an interrupt.  It
 * adds the character to the tty input queue, echoing and processing
 * backspace and carriage return.  If the queue contains a full line,
 * it wakes up anything waiting on it.  If it is totally full, it beeps
 * at the user.
 * UZI180 - This routine is called from the raw Hardware read routine,
 * either interrupt or polled, to process the input character.  HFB
 */
int tty_inproc(uint8_t minor, unsigned char c)
{
	unsigned char oc;
	int canon;
	uint8_t wr;
	struct tty *t = &ttydata[minor];
	struct s_queue *q = &ttyinq[minor];

	canon = t->termios.c_lflag & ICANON;

	if (t->termios.c_iflag & ISTRIP)
		c &= 0x7f;	/* Strip off parity */
	if (canon && !c)
		return 1;	/* Simply quit if Null character */

#ifdef CONFIG_IDUMP
	if (c == 0x1a)		/* ^Z */
		idump();	/*   (For debugging) */
#endif
#ifdef CONFIG_MONITOR
	if (c == 0x01)		/* ^A */
		trap_monitor();
#endif

	if (c == '\r' && (t->termios.c_iflag & ICRNL))
		c = '\n';
	if (c == '\n' && (t->termios.c_iflag & INLCR))
		c = '\r';

	if (t->termios.c_lflag & ISIG) {
		if (c == t->termios.c_cc[VINTR]) {	/* ^C */
		        wr = SIGINT;
			goto sigout;
		} else if (c == t->termios.c_cc[VQUIT]) {	/* ^\ */
		        wr = SIGQUIT;
sigout:
			sgrpsig(t->pgrp, wr);
			clrq(q);
			t->flag &= ~(TTYF_STOP | TTYF_DISCARD);
			return 1;
		}
	}
	if (c == t->termios.c_cc[VDISCARD]) {	/* ^O */
	        t->flag ^= TTYF_DISCARD;
		return 1;
	}
	if (t->termios.c_iflag & IXON) {
		if (c == t->termios.c_cc[VSTOP]) {	/* ^S */
		        t->flag |= TTYF_STOP;
			return 1;
		}
		if (c == t->termios.c_cc[VSTART]) {	/* ^Q */
		        t->flag &= ~TTYF_STOP;
			wakeup(&t->flag);
			return 1;
		}
	}
	if (canon) {
		if (c == t->termios.c_cc[VERASE]) {
		        wr = ECHOE;
		        goto eraseout;
		} else if (c == t->termios.c_cc[VKILL]) {
		        wr = ECHOK;
		        goto eraseout;
		}
	}

	/* All modes come here */
	if (c == '\n') {
		if ((t->termios.c_oflag & (OPOST | ONLCR)) == (OPOST | ONLCR))
			tty_echo(minor, '\r');
	}

	wr = insq(q, c);
	if (wr)
		tty_echo(minor, c);
	else
		tty_putc(minor, '\007');	/* Beep if no more room */

	if (!canon || c == t->termios.c_cc[VEOL] || c == '\n'
	    || c == t->termios.c_cc[VEOF])
		wakeup(q);
	return wr;

eraseout:
	while (uninsq(q, &oc)) {
		if (oc == '\n' || oc == t->termios.c_cc[VEOL]) {
			insq(q, oc);	/* Don't erase past nl */
			break;
		}
		if (t->termios.c_lflag & wr)
			tty_erase(minor);
                if (wr == ECHOE)
                        break;
	}
	return 1;
}