diff -uNr rt_com-0.5.4/Makefile patched/Makefile --- rt_com-0.5.4/Makefile Mon Dec 4 04:36:24 2000 +++ patched/Makefile Tue May 8 15:56:36 2001 @@ -16,7 +16,7 @@ OBJS = rt_com.o # rt_com_posix.o currently broken ;-( -VERSION = 0.5.4 +VERSION = 0.5.5pre1 CFLAGS += -D$(SYSTEM) -DVERSION=\"$(VERSION)\" diff -uNr rt_com-0.5.4/rt_com.c patched/rt_com.c --- rt_com-0.5.4/rt_com.c Wed Nov 15 14:48:50 2000 +++ patched/rt_com.c Tue May 8 16:12:39 2001 @@ -86,9 +86,12 @@ /** Remaining free space of buffer * - * @return amount of free space remaining in a buffer (input or output) */ + * @return amount of free space remaining in a buffer (input or output) + * + * Note that, although the buffer is RT_COM_BUF_SIZ bytes long, it can + * only hold RT_COM_BUF_SIZ - 1 bytes. */ #define rt_com_buff_free( head, tail ) \ - ( RT_COM_BUF_SIZ - ( ( head - tail ) & ( RT_COM_BUF_SIZ - 1 ) ) ) + ( RT_COM_BUF_SIZ - 1 - ( ( head - tail ) & ( RT_COM_BUF_SIZ - 1 ) ) ) @@ -470,6 +473,7 @@ int buff,t; char loop = 4; char toFifo = 16; + int rxd_bytes = 0; do { /* get available data from port */ @@ -479,6 +483,7 @@ while( RT_COM_DATA_READY & sta ) { data = inb( B + RT_COM_RXB ); rt_com_irq_put( p, data ); + rxd_bytes = 1; sta = inb( B + RT_COM_LSR ); if( 0x1e & sta ) p->error = sta & 0x1e; @@ -515,6 +520,12 @@ /* Note: why is it done at most 4 times ? */ } while( 1 != ( ( inb( B + RT_COM_IIR ) & 0x0f ) ) && ( --loop > 0 ) ); + if (rxd_bytes) { + /* We received 1+ bytes. If user requested a callback, invoke it. */ + if (p->callback) + (*(p->callback)) (com); + } + #if defined RTLINUX_V1 || defined RTAI return; #else @@ -568,6 +579,7 @@ inb( base + RT_COM_MSR ); p->error = 0; //!! init. last error code + p->callback = 0; if( 0 == baud ) { /* return */ @@ -596,6 +608,38 @@ } +/** Optional callback function. + * + * If the user supplies a callback function, it is called whenever + * characters are received. + * + * *** NOTE *** The callback function is called in the context of the + * interrupt handler! + * + * @param com Port to use; corresponding to internal numbering scheme. + * @param fn Callback function (0 = de-register callback function). + * @return Pointer to previously-installed callback function. + * + * @author James Puttick + * @version 2000/02/08 */ +IRQ_CALLBACK_FN rt_com_set_callback (unsigned int com, IRQ_CALLBACK_FN fn) +{ + struct rt_com_struct *p; + IRQ_CALLBACK_FN + old_fn; + + if( com >= RT_COM_CNT ) + return( 0 ); + + p = &( rt_com_table[ com ] ); + + old_fn = p->callback; + p->callback = fn; + + return( old_fn ); +} + + /** Port and irq setting for a specified COM. * * This must run in standard Linux context ! @@ -619,21 +663,22 @@ p->port = port; if( 0 != irq ) p->irq = irq; - p->used = 1; if( -EBUSY == check_region( p->port, 8 ) ) { return( -EBUSY ); } request_region( p->port, 8, "rt_com" ); rt_com_request_irq( p->irq, p->isr ); rt_com_setup( com, 0, 0, 0, 0 ); + p->used = 1; } else { if( 0 > port ) { rt_com_setup( com, 0, 0, 0, 0 ); rt_com_free_irq( p->irq ); release_region( p->port, 8 ); p->used = 0; - } else + } else { return( -EBUSY ); + } } } return( 0 ); @@ -676,7 +721,7 @@ for( j=0; jused ) { - free_RTirq( p->irq ); + rt_com_free_irq( p->irq ); release_region( p->port, 8 ); } } diff -uNr rt_com-0.5.4/rt_com.h patched/rt_com.h --- rt_com-0.5.4/rt_com.h Thu May 4 19:11:57 2000 +++ patched/rt_com.h Tue May 8 15:34:42 2001 @@ -29,6 +29,8 @@ #define RT_COM_H +typedef void (*IRQ_CALLBACK_FN) (unsigned int com_port); + extern void cleanup_module( void ); extern int init_module( void ); @@ -45,6 +47,8 @@ extern int rt_com_read( unsigned int, char *, int ); /* set up port */ extern int rt_com_setup( unsigned int, int, unsigned int, unsigned int, unsigned int ); +/* set call-back function for when data rx'd */ +extern IRQ_CALLBACK_FN rt_com_set_callback (unsigned int com, IRQ_CALLBACK_FN fn); /* port & irq setting for a specified com */ extern int rt_com_set_param( unsigned int com, int port, int irq ); /* set functioning mode */ diff -uNr rt_com-0.5.4/rt_comP.h patched/rt_comP.h --- rt_com-0.5.4/rt_comP.h Tue May 2 19:14:11 2000 +++ patched/rt_comP.h Tue May 8 15:33:50 2001 @@ -129,6 +129,7 @@ int type; int ier; /* copy of chip register */ int mcr; /* copy of the MCR internal register */ + IRQ_CALLBACK_FN callback; /* called when chars rx'd */ struct rt_buf_struct ibuf; struct rt_buf_struct obuf; };