Date: Wed, 6 Aug 2003 23:28:38 +0930 From: Malcolm Kay <malcolm.kay@internode.on.net> To: "J. Seth Henry" <jshamlet@comcast.net>, freebsd-questions@freebsd.org Subject: Re: FreeBSD programming question Message-ID: <200308062328.38914.malcolm.kay@internode.on.net> In-Reply-To: <1060119004.53095.25.camel@alexandria> References: <1060119004.53095.25.camel@alexandria>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200308062328.38914.malcolm.kay>