Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Mar 2001 10:02:47 -0800 (PST)
From:      Richard Hodges <rh@matriplex.com>
To:        Dmitry Dicky <diwil@eis.ru>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: stupid device driver question
Message-ID:  <Pine.BSF.4.10.10103020956490.48242-100000@mail.matriplex.com>
In-Reply-To: <XFMail.010302180256.diwil@eis.ru>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 2 Mar 2001, Dmitry Dicky wrote:

> Hi fellows,
> 
> I'm writing some device driver which should pass some data to the user
> space.
> 
> The part of the device read routine looks as follows:
> 
> ----------------------------------
> int
> dev_read(dev_t dev, struct uio *uio, int ioflag)
> {
>     int err = 0;
> /* ... */
>     amnt = MIN(uio->uio_resid, cntw);
> /* Wait here until data available .... how? */
>     err = uiomove(buf2, amnt, uio);
>     if (err != 0) {
>         return(err);
>     }
>     
>     memset(buf2, 0, amnt);
>     cntw -= amnt;
>     return 0;
> }
> -------------------------------------
> User application hands on read(2).
> 
> But buf2 being filled upon some event and 'dev_read' should
> wait until data in buf2 available.
> 
> So, the question is:
> How can I hang dev_read, issue some signal and then continue uiomove(9)
> data to the user space?

How about something like:

  int  timeout;

  timeout = hz;  /* fail if nothing in one second */

  while(timeout && (NOTREADY)) 
    if(tsleep(softc, PRIBIO, "mydev", 1))
      timeout--;
  if(NOTREADY)
    return(EIO); /* or whatever... */
  uiomove(...)

Then in your interrupt service routine:

  wakeup(softc);

Hope this helps!

-Richard 

-------------------------------------------
   Richard Hodges   | Matriplex, inc.
   Product Manager  | 769 Basque Way
  rh@matriplex.com  | Carson City, NV 89706
    775-886-6477    | www.matriplex.com 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.10.10103020956490.48242-100000>