From owner-freebsd-hackers Fri Mar 2 10: 3:12 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from mail.matriplex.com (ns1.matriplex.com [208.131.42.8]) by hub.freebsd.org (Postfix) with ESMTP id 87BBE37B718 for ; Fri, 2 Mar 2001 10:03:07 -0800 (PST) (envelope-from rh@matriplex.com) Received: from mail.matriplex.com (mail.matriplex.com [208.131.42.9]) by mail.matriplex.com (8.9.2/8.9.2) with ESMTP id KAA48413; Fri, 2 Mar 2001 10:02:47 -0800 (PST) (envelope-from rh@matriplex.com) Date: Fri, 2 Mar 2001 10:02:47 -0800 (PST) From: Richard Hodges To: Dmitry Dicky Cc: freebsd-hackers@FreeBSD.ORG Subject: Re: stupid device driver question In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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