Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Dec 2002 12:55:07 +0100
From:      Daniel Lang <langd-freebsd-hackers@leo.org>
To:        freebsd-hackers@freebsd.org
Subject:   more kernel programming style questions
Message-ID:  <20021213115507.GE84493@atrbg11.informatik.tu-muenchen.de>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021213115507.GE84493>