From owner-freebsd-questions@FreeBSD.ORG Wed Aug 6 06:58:44 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D9FC637B401 for ; Wed, 6 Aug 2003 06:58:44 -0700 (PDT) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8D14843FA3 for ; Wed, 6 Aug 2003 06:58:43 -0700 (PDT) (envelope-from malcolm.kay@internode.on.net) Received: from smtp1.adl2.internode.on.net (localhost [127.0.0.1]) h76DwfRH054824 for ; Wed, 6 Aug 2003 23:28:41 +0930 (CST) Received: (from mailnull@localhost)h76DwfWe054820 for ; Wed, 6 Aug 2003 23:28:41 +0930 (CST) X-Authentication-Warning: smtp1.adl2.internode.on.net: mailnull set sender to using -f Received: from beta.home (ppp55-166.lns1.adl2.internode.on.net [150.101.55.166]) by localhost (8.12.9/8.12.9+MIMEDefang) with ESMTP id h76DwdRH054815; Wed, 06 Aug 2003 23:28:41 +0930 Content-Type: text/plain; charset="iso-8859-1" From: Malcolm Kay Organization: At home To: "J. Seth Henry" , freebsd-questions@freebsd.org Date: Wed, 6 Aug 2003 23:28:38 +0930 User-Agent: KMail/1.4.3 References: <1060119004.53095.25.camel@alexandria> In-Reply-To: <1060119004.53095.25.camel@alexandria> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200308062328.38914.malcolm.kay@internode.on.net> X-Streamed-Recipients: X-Proc-As: freebsd-questions X-Scanned-By: MIMEDefang 2.33 (www . roaringpenguin . com / mimedefang) Subject: Re: FreeBSD programming question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Aug 2003 13:58:45 -0000 On Wed, 6 Aug 2003 07:00, J. Seth Henry wrote: > Not sure if this is the right list or not, but I could really use some > pointers. > > How can I code trap serial port interrupts in my C program? > For any modern hosted system interrupt trapping and servicing is in the=20 province of the system -- it should not be a userland activity. > For example, I want to read values from a serial device every > user-specified number of seconds, calculate some stuff and then sit for > a while. Should the serial device decide it wants to send some data > unsolicited, I would like to enter an interrupt service routine, handle > the communication, and then return to the previous loop. There are a number of techniques which may or may not suit your needs; it is not too clear just what you are trying to do. Generally the system will provide some buffering of input so it is not us= ually important that your code processes each character immediately on arrival. In many cases using placing the select(2) system call in a loop will meet= the=20 needs. In more difficult cases you may need to look at threading pthread(3) or=20 forking fork(2) or vfork(2) > > I can get the loop going by using sleep(n), but I don't know how to > write the ISR in C, and (additionally) make it such that it will run on > any *nix like platform. You might be able to do something at system level by adding your driver t= o the=20 kernel possibly as a kernel module. This is not generally the way to go i= f=20 userland alternatives work and it certainly will be very operating system= and=20 platform specific possibly even requiring significant editing from one OS= =20 version to the next. > > Any pointers, HOWTO's, or examples would be greatly appreciated! > > Thanks, > Seth > Malcolm Kay