scan with timeout

Fernando RUIZ CASAS (E-mail) fernando.ruiz at ctv.es
Wed Mar 27 10:31:04 UTC 2002


In my poor experience I could do this rewriting an interrupt service and
events.
Wait  events gives the timeout posibilities.
(maybe an ioctl() call to set the interupt mode)

Your device_read() waits the event setting a handle for the interrupt
notification
when the input queue is empty.
When the interrupts raise the event the device_read gets the event and
returns
the data arrived. If the event is not raised the timeout waiting the event
is enough
for your needs.

The handle is enough to maintains the mutual exclusion.
(Bizarre. Two task reading the same device).

More?

Fernando RUIZ CASAS
home:correo at fenando-ruiz.com
work:fernando.ruiz at ctv.es


-----Mensaje original-----
De: Stan [mailto:zylog at club-internet.fr]
Enviado el: miércoles, 27 de marzo de 2002 10:37
Para: rtems-users at oarcorp.com
Asunto: scan with timeout



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