rs232 support

This commit is contained in:
Philip Homburg 2005-07-29 15:22:58 +00:00
parent 2471939f7d
commit a93faca75f
5 changed files with 69 additions and 29 deletions

View File

@ -133,9 +133,9 @@ int scode;
} }
/*===========================================================================* /*===========================================================================*
* kbd_hw_int * * kbd_interrupt *
*===========================================================================*/ *===========================================================================*/
PUBLIC void do_interrupt(m_ptr) PUBLIC void kbd_interrupt(m_ptr)
message *m_ptr; message *m_ptr;
{ {
/* A keyboard interrupt has occurred. Process it. */ /* A keyboard interrupt has occurred. Process it. */
@ -406,6 +406,7 @@ tty_t *tp;
panic("TTY", "Couldn't set keyboard IRQ policy", i); panic("TTY", "Couldn't set keyboard IRQ policy", i);
if ((i=sys_irqenable(&irq_hook_id)) != OK) if ((i=sys_irqenable(&irq_hook_id)) != OK)
panic("TTY", "Couldn't enable keyboard IRQs", i); panic("TTY", "Couldn't enable keyboard IRQs", i);
kbd_irq_set |= (1 << KEYBOARD_IRQ);
} }
} }

View File

@ -226,6 +226,7 @@ typedef struct rs232 {
unsigned parity_errors; unsigned parity_errors;
unsigned break_interrupts; unsigned break_interrupts;
int irq; /* irq for this line */
int irq_hook_id; /* interrupt hook */ int irq_hook_id; /* interrupt hook */
char ibuf[RS_IBUFSIZE]; /* input buffer */ char ibuf[RS_IBUFSIZE]; /* input buffer */
@ -249,21 +250,21 @@ PRIVATE port_t addr_8250[] = {
}; };
#endif #endif
FORWARD _PROTOTYPE( int rs232_handler, (message *m) );
FORWARD _PROTOTYPE( void in_int, (rs232_t *rs) ); FORWARD _PROTOTYPE( void in_int, (rs232_t *rs) );
FORWARD _PROTOTYPE( void line_int, (rs232_t *rs) ); FORWARD _PROTOTYPE( void line_int, (rs232_t *rs) );
FORWARD _PROTOTYPE( void modem_int, (rs232_t *rs) ); FORWARD _PROTOTYPE( void modem_int, (rs232_t *rs) );
FORWARD _PROTOTYPE( int rs_write, (tty_t *tp, int try) ); FORWARD _PROTOTYPE( int rs_write, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void rs_echo, (tty_t *tp, int c) ); FORWARD _PROTOTYPE( void rs_echo, (tty_t *tp, int c) );
FORWARD _PROTOTYPE( void rs_ioctl, (tty_t *tp) ); FORWARD _PROTOTYPE( int rs_ioctl, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void rs_config, (rs232_t *rs) ); FORWARD _PROTOTYPE( void rs_config, (rs232_t *rs) );
FORWARD _PROTOTYPE( int rs_read, (tty_t *tp, int try) ); FORWARD _PROTOTYPE( int rs_read, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void rs_icancel, (tty_t *tp) ); FORWARD _PROTOTYPE( int rs_icancel, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void rs_ocancel, (tty_t *tp) ); FORWARD _PROTOTYPE( int rs_ocancel, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void rs_ostart, (rs232_t *rs) ); FORWARD _PROTOTYPE( void rs_ostart, (rs232_t *rs) );
FORWARD _PROTOTYPE( void rs_break, (tty_t *tp) ); FORWARD _PROTOTYPE( int rs_break, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void rs_close, (tty_t *tp) ); FORWARD _PROTOTYPE( int rs_close, (tty_t *tp, int try) );
FORWARD _PROTOTYPE( void out_int, (rs232_t *rs) ); FORWARD _PROTOTYPE( void out_int, (rs232_t *rs) );
FORWARD _PROTOTYPE( void rs232_handler, (rs232_t *rs) );
/* XXX */ /* XXX */
PRIVATE void lock(void) {} PRIVATE void lock(void) {}
@ -282,7 +283,7 @@ PRIVATE int my_inb(port_t port)
/*==========================================================================* /*==========================================================================*
* rs_write * * rs_write *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_write(tp, try) PRIVATE int rs_write(tp, try)
register tty_t *tp; register tty_t *tp;
int try; int try;
{ {
@ -387,13 +388,15 @@ int c; /* character to echo */
/*==========================================================================* /*==========================================================================*
* rs_ioctl * * rs_ioctl *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_ioctl(tp) PRIVATE int rs_ioctl(tp, dummy)
tty_t *tp; /* which TTY */ tty_t *tp; /* which TTY */
int dummy;
{ {
/* Reconfigure the line as soon as the output has drained. */ /* Reconfigure the line as soon as the output has drained. */
rs232_t *rs = tp->tty_priv; rs232_t *rs = tp->tty_priv;
rs->drain = TRUE; rs->drain = TRUE;
return 0; /* dummy */
} }
@ -580,6 +583,7 @@ tty_t *tp; /* which TTY */
/* Enable interrupts for both interrupt controller and device. */ /* Enable interrupts for both interrupt controller and device. */
irq = (line & 1) == 0 ? RS232_IRQ : SECONDARY_IRQ; irq = (line & 1) == 0 ? RS232_IRQ : SECONDARY_IRQ;
rs->irq = irq;
if(sys_irqsetpolicy(irq, IRQ_REENABLE, &rs->irq_hook_id) != OK) { if(sys_irqsetpolicy(irq, IRQ_REENABLE, &rs->irq_hook_id) != OK) {
printf("RS232: Couldn't obtain hook for irq %d\n", irq); printf("RS232: Couldn't obtain hook for irq %d\n", irq);
} else { } else {
@ -588,6 +592,8 @@ tty_t *tp; /* which TTY */
} }
} }
rs_irq_set |= (1 << irq);
sys_outb(rs->int_enab_port, IE_LINE_STATUS_CHANGE | IE_MODEM_STATUS_CHANGE sys_outb(rs->int_enab_port, IE_LINE_STATUS_CHANGE | IE_MODEM_STATUS_CHANGE
| IE_RECEIVER_READY | IE_TRANSMITTER_READY); | IE_RECEIVER_READY | IE_TRANSMITTER_READY);
#else /* MACHINE == ATARI */ #else /* MACHINE == ATARI */
@ -617,14 +623,35 @@ tty_t *tp; /* which TTY */
/* Tell external device we are ready. */ /* Tell external device we are ready. */
istart(rs); istart(rs);
}
/*==========================================================================*
* rs_interrupt *
*==========================================================================*/
PUBLIC void rs_interrupt(m)
message *m; /* which TTY */
{
unsigned long irq_set;
int i;
rs232_t *rs;
irq_set= m->NOTIFY_ARG;
for (i= 0, rs = rs_lines; i<NR_RS_LINES; i++, rs++)
{
if (irq_set & (1 << rs->irq))
rs232_handler(rs);
}
} }
/*==========================================================================* /*==========================================================================*
* rs_icancel * * rs_icancel *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_icancel(tp) PRIVATE int rs_icancel(tp, dummy)
tty_t *tp; /* which TTY */ tty_t *tp; /* which TTY */
int dummy;
{ {
/* Cancel waiting input. */ /* Cancel waiting input. */
rs232_t *rs = tp->tty_priv; rs232_t *rs = tp->tty_priv;
@ -634,14 +661,17 @@ tty_t *tp; /* which TTY */
rs->itail = rs->ihead; rs->itail = rs->ihead;
istart(rs); istart(rs);
unlock(); unlock();
return 0; /* dummy */
} }
/*==========================================================================* /*==========================================================================*
* rs_ocancel * * rs_ocancel *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_ocancel(tp) PRIVATE int rs_ocancel(tp, dummy)
tty_t *tp; /* which TTY */ tty_t *tp; /* which TTY */
int dummy;
{ {
/* Cancel pending output. */ /* Cancel pending output. */
rs232_t *rs = tp->tty_priv; rs232_t *rs = tp->tty_priv;
@ -651,13 +681,15 @@ tty_t *tp; /* which TTY */
rs->ocount = 0; rs->ocount = 0;
rs->otail = rs->ohead; rs->otail = rs->ohead;
unlock(); unlock();
return 0; /* dummy */
} }
/*==========================================================================* /*==========================================================================*
* rs_read * * rs_read *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_read(tp, try) PRIVATE int rs_read(tp, try)
tty_t *tp; /* which tty */ tty_t *tp; /* which tty */
int try; int try;
{ {
@ -718,8 +750,9 @@ rs232_t *rs; /* which rs line */
/*==========================================================================* /*==========================================================================*
* rs_break * * rs_break *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_break(tp) PRIVATE int rs_break(tp, dummy)
tty_t *tp; /* which tty */ tty_t *tp; /* which tty */
int dummy;
{ {
/* Generate a break condition by setting the BREAK bit for 0.4 sec. */ /* Generate a break condition by setting the BREAK bit for 0.4 sec. */
rs232_t *rs = tp->tty_priv; rs232_t *rs = tp->tty_priv;
@ -731,21 +764,25 @@ tty_t *tp; /* which tty */
/* milli_delay(400); */ /* ouch */ /* milli_delay(400); */ /* ouch */
printf("RS232 break\n"); printf("RS232 break\n");
sys_outb(rs->line_ctl_port, line_controls); sys_outb(rs->line_ctl_port, line_controls);
return 0; /* dummy */
} }
/*==========================================================================* /*==========================================================================*
* rs_close * * rs_close *
*==========================================================================*/ *==========================================================================*/
PRIVATE void rs_close(tp) PRIVATE int rs_close(tp, dummy)
tty_t *tp; /* which tty */ tty_t *tp; /* which tty */
int dummy;
{ {
/* The line is closed; optionally hang up. */ /* The line is closed; optionally hang up. */
rs232_t *rs = tp->tty_priv; rs232_t *rs = tp->tty_priv;
int r;
if (tp->tty_termios.c_cflag & HUPCL) { if (tp->tty_termios.c_cflag & HUPCL) {
sys_outb(rs->modem_ctl_port, MC_OUT2 | MC_RTS); sys_outb(rs->modem_ctl_port, MC_OUT2 | MC_RTS);
} }
return 0; /* dummy */
} }
@ -755,19 +792,11 @@ tty_t *tp; /* which tty */
/*==========================================================================* /*==========================================================================*
* rs232_handler * * rs232_handler *
*==========================================================================*/ *==========================================================================*/
PRIVATE int rs232_handler(m) PRIVATE void rs232_handler(rs)
message *m; struct rs232 *rs;
{ {
/* Interrupt hander for RS232. */ /* Interrupt hander for RS232. */
/* XXX */
#if DEAD_CODE
register rs232_t *rs = structof(rs232_t, hook, hook);
#else
/* XXX */
register rs232_t *rs = NULL;
#endif
while (TRUE) { while (TRUE) {
int v; int v;
/* Loop to pick up ALL pending interrupts for device. /* Loop to pick up ALL pending interrupts for device.
@ -790,7 +819,7 @@ message *m;
line_int(rs); line_int(rs);
continue; continue;
} }
return(1); /* reenable serial interrupt */ return;
} }
} }
#endif /* MACHINE == IBM_PC */ #endif /* MACHINE == IBM_PC */

View File

@ -76,6 +76,9 @@
extern int irq_hook_id; extern int irq_hook_id;
unsigned long kbd_irq_set = 0;
unsigned long rs_irq_set = 0;
/* Address of a tty structure. */ /* Address of a tty structure. */
#define tty_addr(line) (&tty_table[line]) #define tty_addr(line) (&tty_table[line])
@ -204,7 +207,10 @@ PUBLIC void main(void)
expire_timers(); /* run watchdogs of expired timers */ expire_timers(); /* run watchdogs of expired timers */
continue; /* contine to check for events */ continue; /* contine to check for events */
case HARD_INT: { /* hardware interrupt notification */ case HARD_INT: { /* hardware interrupt notification */
do_interrupt(&tty_mess);/* fetch chars from keyboard */ if (tty_mess.NOTIFY_ARG & kbd_irq_set)
kbd_interrupt(&tty_mess);/* fetch chars from keyboard */
if (tty_mess.NOTIFY_ARG & rs_irq_set)
rs_interrupt(&tty_mess);/* serial I/O */
expire_timers(); /* run watchdogs of expired timers */ expire_timers(); /* run watchdogs of expired timers */
continue; /* contine to check for events */ continue; /* contine to check for events */
} }

View File

@ -84,6 +84,9 @@ extern tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
extern int ccurrent; /* currently visible console */ extern int ccurrent; /* currently visible console */
extern int irq_hook_id; /* hook id for keyboard irq */ extern int irq_hook_id; /* hook id for keyboard irq */
extern unsigned long kbd_irq_set;
extern unsigned long rs_irq_set;
/* Values for the fields. */ /* Values for the fields. */
#define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */ #define NOT_ESCAPED 0 /* previous character is not LNEXT (^V) */
#define ESCAPED 1 /* previous character was LNEXT (^V) */ #define ESCAPED 1 /* previous character was LNEXT (^V) */
@ -129,6 +132,7 @@ _PROTOTYPE( int select_retry, (struct tty *tp) );
/* rs232.c */ /* rs232.c */
_PROTOTYPE( void rs_init, (struct tty *tp) ); _PROTOTYPE( void rs_init, (struct tty *tp) );
_PROTOTYPE( void rs_interrupt, (message *m) );
#if (CHIP == INTEL) #if (CHIP == INTEL)
/* console.c */ /* console.c */
@ -146,7 +150,7 @@ _PROTOTYPE( void kb_init, (struct tty *tp) );
_PROTOTYPE( int kbd_loadmap, (message *m) ); _PROTOTYPE( int kbd_loadmap, (message *m) );
_PROTOTYPE( void do_panic_dumps, (message *m) ); _PROTOTYPE( void do_panic_dumps, (message *m) );
_PROTOTYPE( void do_fkey_ctl, (message *m) ); _PROTOTYPE( void do_fkey_ctl, (message *m) );
_PROTOTYPE( void do_interrupt, (message *m) ); _PROTOTYPE( void kbd_interrupt, (message *m) );
/* pty.c */ /* pty.c */
_PROTOTYPE( void do_pty, (struct tty *tp, message *m_ptr) ); _PROTOTYPE( void do_pty, (struct tty *tp, message *m_ptr) );

View File

@ -112,7 +112,7 @@
* system can handle. * system can handle.
*/ */
#define NR_CONS 4 /* # system consoles (1 to 8) */ #define NR_CONS 4 /* # system consoles (1 to 8) */
#define NR_RS_LINES 0 /* # rs232 terminals (0 to 4) */ #define NR_RS_LINES 4 /* # rs232 terminals (0 to 4) */
#define NR_PTYS 32 /* # pseudo terminals (0 to 64) */ #define NR_PTYS 32 /* # pseudo terminals (0 to 64) */