Subject: CVS commit: src/sys
To: None <source-changes@NetBSD.org>
From: David Young <dyoung@netbsd.org>
List: source-changes
Date: 03/08/2006 00:24:06
Module Name: src
Committed By: dyoung
Date: Wed Mar 8 00:24:06 UTC 2006
Modified Files:
src/sys/arch/i386/pci: geode.c geodereg.h
src/sys/dev/ic: atw.c atwreg.h atwvar.h max2820reg.h rtw.c rtwphy.c
rtwphyio.c rtwreg.h sa2400reg.h si4136reg.h
src/sys/lib/libkern: libkern.h
Log Message:
Move my bit-twiddling macros to libkern.h from my drivers, where
I had duplicated them. Improve the macros' names. Simplify their
implementation.
A brief description of each macro is below.
BIT(n): Return a bitmask with bit m set, where the least
significant bit is bit 0.
BITS(m, n): Return a bitmask with bits m through n, inclusive,
set. It does not matter whether m>n or m<=n.
The least significant bit is bit 0.
A "bitfield" is a span of consecutive bits defined by a
bitmask, where 1s select the bits in the bitfield. SHIFTIN,
SHIFTOUT, and SHIFTOUT_MASK help read and write bitfields
from device registers.
SHIFTIN(v, mask): Left-shift bits `v' into the bitfield
defined by `mask', and return them. No
side-effects.
SHIFTOUT(v, mask): Extract and return the bitfield selected
by `mask' from `v', right-shifting the
bits so that the rightmost selected bit
is at bit 0. No side-effects.
SHIFTOUT_MASK(mask): Right-shift the bits in `mask' so that
the rightmost non-zero bit is at bit
0. This is useful for finding the
greatest unsigned value that a bitfield
can hold. No side-effects. Note that
SHIFTOUT_MASK(m) = SHIFTOUT(m, m).
Examples:
/*
* Register definitions taken from the RFMD RF3000 manual.
*/
#define RF3000_GAINCTL 0x11 /* TX variable gain control */
#define RF3000_GAINCTL_TXVGC_MASK BITS(7, 2)
#define RF3000_GAINCTL_SCRAMBLER BIT(1)
/*
* Shift the transmit power into the transmit-power field of the
* gain-control register and write it to the baseband processor.
*/
atw_rf3000_write(sc, RF3000_GAINCTL,
SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));
/*
* Register definitions taken from the ADMtek ADM8211 manual.
*
*/
#define ATW_RXSTAT_OWN BIT(31) /* 1: NIC may fill descriptor */
/* ... */
#define ATW_RXSTAT_DA1 BIT(17) /* DA bit 1, admin'd address */
#define ATW_RXSTAT_DA0 BIT(16) /* DA bit 0, group address */
#define ATW_RXSTAT_RXDR_MASK BITS(15,12) /* RX data rate */
#define ATW_RXSTAT_FL_MASK BITS(11,0) /* RX frame length, last
* descriptor only
*/
/* Extract the frame length from the Rx descriptor's
* status field.
*/
len = SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
To generate a diff of this commit:
cvs rdiff -r1.4 -r1.5 src/sys/arch/i386/pci/geode.c \
src/sys/arch/i386/pci/geodereg.h
cvs rdiff -r1.109 -r1.110 src/sys/dev/ic/atw.c
cvs rdiff -r1.12 -r1.13 src/sys/dev/ic/atwreg.h
cvs rdiff -r1.19 -r1.20 src/sys/dev/ic/atwvar.h
cvs rdiff -r1.3 -r1.4 src/sys/dev/ic/max2820reg.h
cvs rdiff -r1.67 -r1.68 src/sys/dev/ic/rtw.c
cvs rdiff -r1.8 -r1.9 src/sys/dev/ic/rtwphy.c
cvs rdiff -r1.10 -r1.11 src/sys/dev/ic/rtwphyio.c
cvs rdiff -r1.16 -r1.17 src/sys/dev/ic/rtwreg.h
cvs rdiff -r1.4 -r1.5 src/sys/dev/ic/sa2400reg.h
cvs rdiff -r1.2 -r1.3 src/sys/dev/ic/si4136reg.h
cvs rdiff -r1.55 -r1.56 src/sys/lib/libkern/libkern.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.