scan with timeout

Stan zylog at club-internet.fr
Wed Mar 27 09:36:53 UTC 2002


Hi,

I should like all input operation (read...scan...) return on timeout.
What are best way for that ?

This code you seem good ?
In fact, the first call to the function scan return on timeout, but not the
following.
An idea?

/**********************************************************************/
/* transfer character from the buffer */
char inbyte(int minor, int* timeout) {
  register char a;
  register int length;

  while ((char *)(((int)rcv[minor].in+1) & ((int)BUFFER_LENGTH-1))==
rcv[minor].out){
    if(*timeout) (*timeout)--; else return '\0';
    rtems_task_wake_after(1);
  }
  a=*(char *)((int)rcv[minor].offset+(int)rcv[minor].out);
  rcv[minor].out= (char *)(((int)rcv[minor].out+1) &
((int)BUFFER_LENGTH-1));
  length = (BUFFER_LENGTH -1) & (
    ( ((int)rcv[minor].out <= (int)rcv[minor].in) ? 0 : BUFFER_LENGTH) -
(int)rcv[minor].out
    + (int)rcv[minor].in + 1);

  if ((params[minor].mode & MODE_RTSCTS) && length < RTS_START_SIZE)
StartRemoteTx(minor);

  return (a);
}


rtems_device_driver console_read(
  rtems_device_major_number major,
  rtems_device_minor_number minor,
  void *arg
)
{


  rtems_libio_rw_args_t *rw_args;
  char *buffer;
  int maximum;
  int count = 0;
  volatile int timeout;

  rw_args = (rtems_libio_rw_args_t *) arg;

  buffer = rw_args->buffer;
  maximum = rw_args->count;


  for (count = 0; count < maximum; count++) {
    timeout = 100*60;  /* 100*60*5 = 5 minutes */
    buffer[ count ] = (char) inbyte(minor, &timeout);
    if(timeout==0) break;
    if ( params[minor].mode & MODE_CANON && (buffer[ count ] == '\n' ||
buffer[ count ] == '\r')){
        if ( params[minor].mode &  MODE_ADD_LF ) buffer[ count]  = '\n';
        count++;
        break;
    }
  }

  rw_args->bytes_moved = count;
  return (count >= 0) ? RTEMS_SUCCESSFUL : RTEMS_UNSATISFIED;

}
/***************************************************************************
*/


thanks.

        Stan .






More information about the users mailing list