From owner-freebsd-hackers Fri Dec 13 3:55:11 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C532537B401 for ; Fri, 13 Dec 2002 03:55:09 -0800 (PST) Received: from mailout.informatik.tu-muenchen.de (mailout.informatik.tu-muenchen.de [131.159.0.5]) by mx1.FreeBSD.org (Postfix) with ESMTP id C207843EDA for ; Fri, 13 Dec 2002 03:55:08 -0800 (PST) (envelope-from langd@informatik.tu-muenchen.de) Received: from mailrelay1.informatik.tu-muenchen.de (mailrelay1.informatik.tu-muenchen.de [131.159.254.5]) by mailout.informatik.tu-muenchen.de (Postfix) with ESMTP id 0A59261EB for ; Fri, 13 Dec 2002 12:55:08 +0100 (MET) Received: from atrbg11.informatik.tu-muenchen.de (atrbg11.informatik.tu-muenchen.de [131.159.42.129]) by mailrelay1.informatik.tu-muenchen.de (Postfix) with ESMTP id E8F017942 for ; Fri, 13 Dec 2002 12:55:07 +0100 (MET) Received: by atrbg11.informatik.tu-muenchen.de (Postfix, from userid 20455) id A188913691; Fri, 13 Dec 2002 12:55:07 +0100 (CET) Date: Fri, 13 Dec 2002 12:55:07 +0100 From: Daniel Lang To: freebsd-hackers@freebsd.org Subject: more kernel programming style questions Message-ID: <20021213115507.GE84493@atrbg11.informatik.tu-muenchen.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Geek: GCS/CC d-- s: a- C++$ UBS++++$ P+++$ L- E-(---) W+++(--) N++ o K w--- O? M? V? PS+(++) PE--(+) Y+ PGP+ t++ 5+++ X R+(-) tv+ b+ DI++ D++ G++ e+++ h---(-) r++>+++ y+ User-Agent: Mutt/1.5.1i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Hi, now I've come across another style problem. The MOXA hardware of course maintains a structure for each channel. I have details about the size and offsets for each field, belonging to a channel. What would be the most sensible way, to access them? I can come up, with two possiblities: use #define'd address offsets and macros, like #define MOXA_CHN_RX_POINTER 0x02 #define MOXA_CHN_TX_POINTER 0x04 ... #define MOXA_CHN_FUNC_CODE 0x30 ... and then create a macro like: #define Chn_Rx_Pointer(x) Base_Channel_Addr(x) + MOXA_CHN_RX_POINTER with Base_Channel_Addr() yielding the base address of the specified channel. (ok very naive coded, but the principle is clear). The other possibility would be, to define a struct, that maps the fields and just assign a pointer of that type to the base-address: struct channel { u_int16_t rx_pointer; u_int16_t tx_pointer; [..] u_int16_t func_code; } The problem with this is a bit, that there are gaps between some fields, and that there are fields, that are explicitily marked as not to be used. To map the structure, I would need to enter padding fields. I thing the second way is more reasonable, and it also seems to be used in other drivers, but the first one also does not seem to be uncommon. Advice is appreciated. Thanks, Daniel -- IRCnet: Mr-Spock - "I hear that, if you play the WindowsXP CD backwards, you get a Satanic message!" - "That's nothing. If you play it forward, it installs WindowsXP!" Daniel Lang * dl@leo.org * +49 89 289 18532 * http://www.leo.org/~dl/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message