[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

BOUNCE rtl@rtlinux.org: Approval required: Non-member submissionfrom [Denis RICHARD <dri@sxb.bsf.alcatel.fr>] (fwd)



>From owner-rtl Wed Jun 13 06:25:09 2001
Received: from mel.alcatel.fr (mel.alcatel.fr [212.208.74.132])
	by hq.fsmlabs.com (8.11.2/8.11.2) with ESMTP id f5DCP8b08322
	for <rtl@fsmlabs.com>; Wed, 13 Jun 2001 06:25:08 -0600
Received: from aifhs2.alcatel.fr (mailhub.alcatel.fr [155.132.180.80])
        by mel.alcatel.fr (ALCANET/SMTP) with ESMTP id MAA20765
        for <rtl@fsmlabs.com>; Wed, 13 Jun 2001 12:57:13 +0200
Received: from bsf.alcatel.fr (mail.dit.sxb.bsf.alcatel.fr [155.132.20.1])
        by aifhs2.alcatel.fr (ALCANET/SMTP2) with ESMTP id OAA03704
        for <rtl@fsmlabs.com>; Wed, 13 Jun 2001 14:18:54 +0200 (MET DST)
Received: from mail (mail-bsf-alcatel-fr.dit.sxb.bsf.alcatel.fr [155.132.205.91])
	by bsf.alcatel.fr (8.8.8+Sun/8.9.3) with ESMTP id OAA18988
	for <rtl@fsmlabs.com>; Wed, 13 Jun 2001 14:17:59 +0200 (MET DST)
Received: from lion (lion [172.25.48.221]) 
	by mail (8.8.8+Sun/) with ESMTP id OAA18982;
	Wed, 13 Jun 2001 14:17:58 +0200 (MET DST)
Received: from sxb.bsf.alcatel.fr by lion (8.8.8+Sun/ABS1.5) id OAA28525; Wed, 13 Jun 2001 14:17:55 +0200 (MET DST)
Sender: dri@sxb.bsf.alcatel.fr
Message-ID: <3B2759F2.98E106D@sxb.bsf.alcatel.fr>
Date: Wed, 13 Jun 2001 14:17:55 +0200
From: Denis RICHARD <dri@sxb.bsf.alcatel.fr>
X-Mailer: Mozilla 4.7 [en] (X11; I; SunOS 5.6 sun4u)
X-Accept-Language: en
MIME-Version: 1.0
To: Jochen@Jochen-Kuepper.de, rtl@fsmlabs.com
CC: Yves LUDWIG <Yves.Ludwig@sxb.bsf.alcatel.fr>,
   Denis RICHARD <Denis.Richard@sxb.bsf.alcatel.fr>
Subject: Bug in rt_com-0.5.3.
Content-Type: multipart/mixed;
 boundary="------------EE32B8A48509A1AE18DDCCB8"

This is a multi-part message in MIME format.
--------------EE32B8A48509A1AE18DDCCB8
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi all,

I found a bug in rt_com-0.5.3.

To verify free space remaining in a buffer (input or output), the
indexes
head and tail are compared. But when the buffer is full (head == tail),
it is considered as empty. It cannot do the difference between a full
and
an empty buffer.

To solve that, I added a counter (used) in the rt_buf_struct structure,
which count the numbers of characters in the buffer.

Attach the diff file.

Denis



--------------EE32B8A48509A1AE18DDCCB8
Content-Type: text/plain; charset=us-ascii;
 name="rt_com.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="rt_com.diff"

*** rt_com.c	Wed Jun 13 13:30:38 2001
--- ../rt_com-0.5.3.ori/rt_com.c	Fri May  5 19:37:13 2000
***************
*** 77,83 ****
   *                    a standard rt_com you can set used=1. */
  struct rt_com_struct rt_com_table[ RT_COM_CNT ] =
  {
!     { 0, RT_COM_BASE_BAUD, 0x3f8, 4, RT_COM_STD_COM_FLAG, rt_com0_isr, 0x02, 0x01 },  /* ttyS0 - COM1 */
      { 0, RT_COM_BASE_BAUD, 0x2f8, 3, RT_COM_STD_COM_FLAG, rt_com1_isr, 0, 0 }   /* ttyS1 - COM2 */
  };
  
--- 77,83 ----
   *                    a standard rt_com you can set used=1. */
  struct rt_com_struct rt_com_table[ RT_COM_CNT ] =
  {
!     { 0, RT_COM_BASE_BAUD, 0x3f8, 4, RT_COM_STD_COM_FLAG, rt_com0_isr, 0, 0 },  /* ttyS0 - COM1 */
      { 0, RT_COM_BASE_BAUD, 0x2f8, 3, RT_COM_STD_COM_FLAG, rt_com1_isr, 0, 0 }   /* ttyS1 - COM2 */
  };
  
***************
*** 87,94 ****
  /** Remaining free space of buffer
   *
   * @return amount of free space remaining in a buffer (input or output) */
! #define rt_com_buff_free( b ) \
!         ( RT_COM_BUF_SIZ - (b)->used )
  
  
  
--- 87,94 ----
  /** Remaining free space of buffer
   *
   * @return amount of free space remaining in a buffer (input or output) */
! #define rt_com_buff_free( head, tail ) \
!         ( RT_COM_BUF_SIZ - ( ( head - tail ) & ( RT_COM_BUF_SIZ - 1 ) ) )
  
  
  
***************
*** 140,146 ****
  	struct rt_com_struct *p = &( rt_com_table[ com ] );
  	struct rt_buf_struct *b = &( p->obuf );
  	if( p->used > 0 )
! 	    return( rt_com_buff_free( b ) );
      }
      return( -1 );
  }
--- 140,146 ----
  	struct rt_com_struct *p = &( rt_com_table[ com ] );
  	struct rt_buf_struct *b = &( p->obuf );
  	if( p->used > 0 )
! 	    return( rt_com_buff_free( b->head, b->tail ) );
      }
      return( -1 );
  }
***************
*** 163,169 ****
  	if( p->used > 0 ) {
  	    rt_com_irq_off( state );
  	    b->tail = b->head;
- 	    b->used = 0;
  	    if( RT_COM_FIFO_TRIGGER > 0)
  		rt_com_enable_fifo(p->port, RT_COM_FIFO_TRIGGER, 0x02); 
  	    rt_com_irq_on( state );
--- 163,168 ----
***************
*** 197,203 ****
  	    p->ier &= ~0x02;
  	    outb ( p->ier, p->port+RT_COM_IER);
  	    b->tail = b->head;
- 	    b->used = 0;
  	    if ( RT_COM_FIFO_TRIGGER > 0)
  		rt_com_enable_fifo( p->port, RT_COM_FIFO_TRIGGER, 0x04 ); 
  	    rt_com_irq_on( state );
--- 196,201 ----
***************
*** 335,341 ****
  		b->buf[ b->head++ ] = *data++;
  		/* if( head == RT_COM_BUF_SIZ ), wrap head to the first buffer element */
  		b->head &= ( RT_COM_BUF_SIZ - 1 );
- 		b->used++;
  	    }
  	    p->ier |= 0x02;
  	    outb( p->ier, p->port + RT_COM_IER );
--- 333,338 ----
***************
*** 365,379 ****
  	long state;
  	if( p->used > 0) {
  	    rt_com_irq_off( state );
! 	    while( ( b->used ) && ( --cnt >= 0 ) ) {
  		done++;
  		*ptr++ = b->buf[ b->tail++ ];
  		b->tail &= ( RT_COM_BUF_SIZ - 1 );
- 		b->used--;
  	    }
  	    rt_com_irq_on( state );
  	    if( ( p->mode & 0x02 )
! 		&& ( rt_com_buff_free( b ) > RT_COM_BUF_HI ) ) {
  		/* if hardware flow and enough free space on input buffer
  		   then set RTS */
  		p->mcr |= 0x02;
--- 362,375 ----
  	long state;
  	if( p->used > 0) {
  	    rt_com_irq_off( state );
! 	    while( ( b->head != b->tail ) && ( --cnt >= 0 ) ) {
  		done++;
  		*ptr++ = b->buf[ b->tail++ ];
  		b->tail &= ( RT_COM_BUF_SIZ - 1 );
  	    }
  	    rt_com_irq_on( state );
  	    if( ( p->mode & 0x02 )
! 		&& ( rt_com_buff_free( b->head, b->tail ) > RT_COM_BUF_HI ) ) {
  		/* if hardware flow and enough free space on input buffer
  		   then set RTS */
  		p->mcr |= 0x02;
***************
*** 397,406 ****
  static inline int rt_com_irq_get( struct rt_com_struct *p, unsigned char *c )
  {
      struct rt_buf_struct *b = &( p->obuf );
!     if( b->used ) {
  	*c = b->buf[ b->tail++ ];
  	b->tail &= ( RT_COM_BUF_SIZ - 1 );
- 	b->used--;
  	return( 1 );
      }
      return( 0 );
--- 393,401 ----
  static inline int rt_com_irq_get( struct rt_com_struct *p, unsigned char *c )
  {
      struct rt_buf_struct *b = &( p->obuf );
!     if( b->head != b->tail ) {
  	*c = b->buf[ b->tail++ ];
  	b->tail &= ( RT_COM_BUF_SIZ - 1 );
  	return( 1 );
      }
      return( 0 );
***************
*** 420,426 ****
      struct rt_buf_struct *b = &( p->ibuf );
      b->buf[ b->head++ ] = ch;
      b->head &= ( RT_COM_BUF_SIZ - 1 );
-     b->used++;
  }
  
  
--- 415,420 ----
***************
*** 489,495 ****
  	};
  		
  	/* controls on buffer full and RTS clear on hardware flow control */
! 	buff = rt_com_buff_free( b );
  	if (buff < RT_COM_BUF_FULL) p->error = RT_COM_BUFFER_FULL;
  	if( ( p->mode & 0x02 ) && ( buff < RT_COM_BUF_LOW ) ) {
  	    p->mcr &= ~0x02;
--- 483,489 ----
  	};
  		
  	/* controls on buffer full and RTS clear on hardware flow control */
! 	buff = rt_com_buff_free( b->head, b->tail );
  	if (buff < RT_COM_BUF_FULL) p->error = RT_COM_BUFFER_FULL;
  	if( ( p->mode & 0x02 ) && ( buff < RT_COM_BUF_LOW ) ) {
  	    p->mcr &= ~0x02;
*** rt_comP.h	Wed Jun 13 13:31:01 2001
--- ../rt_com-0.5.3.ori/rt_comP.h	Wed May  3 01:14:11 2000
***************
*** 100,106 ****
  struct rt_buf_struct{
      int  head;
      int  tail;
-     int	 used;	
      char buf[ RT_COM_BUF_SIZ ];
  };
  
--- 100,105 ----

--------------EE32B8A48509A1AE18DDCCB8--

----- End of forwarded message from owner-rtl@fsmlabs.com -----