From owner-freebsd-questions@FreeBSD.ORG Wed Jun 11 23:30:07 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 0E97637B401 for ; Wed, 11 Jun 2003 23:30:07 -0700 (PDT) Received: from mail11.ispronet.com (mail11.is-pronet.com [195.15.52.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id A62CF43FDD for ; Wed, 11 Jun 2003 23:30:05 -0700 (PDT) (envelope-from bernard.dugas@is-production.com) Received: from is-production.com (unknown [81.28.194.61]) by mail11.ispronet.com (Postfix) with ESMTP id EDF224A382; Thu, 12 Jun 2003 08:30:03 +0200 (CEST) Message-ID: <3EE79ED4.93DB9224@is-production.com> Date: Wed, 11 Jun 2003 23:27:49 +0200 From: Bernard Dugas Organization: ISProduction X-Mailer: Mozilla 4.75 [fr] (WinNT; U) X-Accept-Language: fr,en MIME-Version: 1.0 To: Malcolm Kay References: <20030609175804.043AA37B405@hub.freebsd.org> <3EE65F83.9A1890FA@is-production.com> <200306112123.47587.malcolm.kay@internode.on.net> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit cc: freebsd-questions@freebsd.org Subject: Re: how to talk to the serial and parallel ports through a C 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: Thu, 12 Jun 2003 06:30:07 -0000 Hello, Malcolm Kay a écrit : > The i/o space in FreeBSD is normally reserved for management > by the kernel. In my opinion this makes it a real hosted OS rather > than some mickey mouse thing. This is why i'm using FreeBSD :-) > However if a process run by root opens /dev/io then while it is > held open the process can make direct access to i/o ports. Nice > for experimenting with software, but for production it is better to > write a kernel module for special driver requirements. > > Are you sure the standard serial driver interfaces are not suitable > for your needs -- they are very flexible. Not sure, but i'm using the serial port only to read and write electrical values, to command power relays. On mickey systems, serial drivers are far to complicated for that. Did anybody write a simple kernel module doing just that ? #include #include void getComValues(int adr,unsigned char *p_TxdS3, unsigned char *p_DtrS4,unsigned char *p_RtsS7, unsigned char *p_CtsE8,unsigned char *p_DsrE6, unsigned char *p_RiE9,unsigned char *p_DcdE1) { unsigned char val3,val4,val6; val3=inb(adr+3); *p_TxdS3=(val3&64)>>6 ; //récupère le bit 6 val4=inb(adr+4); *p_DtrS4=val4&1 ; //récupère le bit 0 *p_RtsS7=(val4&2)>>1 ; //récupère le bit 1 val6=inb(adr+6); *p_CtsE8=(val6&16)>>4 ; //récupère le bit 4 *p_DsrE6=(val6&32)>>5 ; //récupère le bit 5 *p_RiE9=(val6&64)>>6 ; //récupère le bit 6 *p_DcdE1=(val6&128)>>7 ; //récupère le bit 7 } void setComValues(int adr,unsigned char c_TxdS3,unsigned char TxdS3, unsigned char c_DtrS4, unsigned char DtrS4, unsigned char c_RtsS7, unsigned char RtsS7) { unsigned char pmask3,pmask4,nmask3,nmask4,nnTxdS3,nnDtrS4,nnRtsS7; // Quand c_x est faux, la variable x n'est pas modifiée. //Le OU du pmask est utile quand x est à 1 //Le ET du nmask est utile quand x est à 0 //On fait les 2 opérations à la fois pour éviter une combinatoire //conditionnelle. //Il faut formatter x au cas où il serait strictment supérieur //à 1 //Attention ! ~1=254 alors que !1=0 if(c_TxdS3) { nnTxdS3=!TxdS3; TxdS3=!nnTxdS3; //décalage de TxdS3 en bit 6 pmask3=TxdS3<<6; nmask3=~(nnTxdS3<<6); //on modifie seulement le(s) bit(s) modifié(s) de la valeur //lue immédiatement avant, pour limiter les risques de modification //intermédiaire. outb(((inb(adr+3)|pmask3)&nmask3),adr+3); } //on ne touche pas au registre +3 si c_TxdS3 est faux if(c_DtrS4 || c_RtsS7) { if(c_DtrS4) { nnDtrS4=!DtrS4; DtrS4=!nnDtrS4; } else { //les 2 variables à 0 ne modifient aucun masque nnDtrS4=0; DtrS4=0; } if(c_RtsS7) { nnRtsS7=!RtsS7; RtsS7=!nnRtsS7; } else { //les 2 variables à 0 ne modifient aucun masque RtsS7=0; nnRtsS7=0; } //décalage de RtsS7 en bit 1 pmask4=DtrS4|(RtsS7<<1); nmask4=~(nnDtrS4|(nnRtsS7<<1)); //on modifie seulement le(s) bit(s) modifié(s) de la valeur //lue immédiatement avant, pour limiter les risques de modification //intermédiaire. outb(((inb(adr+4)|pmask4)&nmask4),adr+4); } } Best regards, -- __________ Bernard DUGAS ________________________________________ | | | Technoparc Pays de Gex mailto:bernard.dugas@is-production.com | | 30 Rue Auguste Piccard Tel.: +33 450 205 105 | | FR 01630 St Genis Pouilly Fax : +33 450 205 106 | |_________________________________________________________________|