1 .\" $NetBSD: bits.3,v 1.3 2008/08/19 22:54:53 jnemeth Exp $
3 .\" Copyright (c) 2006 David Young. All rights reserved.
5 .\" Redistribution and use in source and binary forms, with or
6 .\" without modification, are permitted provided that the following
7 .\" conditions are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\" notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above
11 .\" copyright notice, this list of conditions and the following
12 .\" disclaimer in the documentation and/or other materials
13 .\" provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
16 .\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17 .\" THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 .\" PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
19 .\" YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 .\" TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 .\" ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 .\" POSSIBILITY OF SUCH DAMAGE.
37 .Nd "macros for preparing bitmasks and operating on bit fields"
44 .Fn __SHIFTIN "v" "mask"
45 .Fn __SHIFTOUT "v" "mask"
46 .Fn __SHIFTOUT_MASK "mask"
48 These macros prepare bitmasks, extract bitfields from words, and
49 insert bitfields into words.
52 is a span of consecutive bits defined by a bitmask, where 1s select
53 the bits in the bitfield.
55 Use __BIT and __BITS to define bitmasks:
57 .Bl -tag -width __BITS -offset indent
59 Return a bitmask with bit m set, where the least significant bit is bit 0.
61 Return a bitmask with bits
66 It does not matter whether
69 .Fa m No \*[Lt]= Fa n .
70 The least significant bit is bit 0.
77 help read and write bitfields from words:
79 .Bl -tag -width __SHIFTOUT_MASK -offset indent
80 .It Fn __SHIFTIN "v" "mask"
83 into the bitfield defined by
87 .It Fn __SHIFTOUT "v" "mask"
88 Extract and return the bitfield selected by
92 right-shifting the bits so that the rightmost selected bit is at
95 .It Fn __SHIFTOUT_MASK "mask"
96 Right-shift the bits in
98 so that the rightmost non-zero bit is at bit 0.
99 This is useful for finding the greatest unsigned value that a
103 .Fn __SHIFTOUT_MASK "m"
105 .Fn __SHIFTOUT "m" "m" .
110 * Register definitions taken from the RFMD RF3000 manual.
112 #define RF3000_GAINCTL 0x11 /* TX variable gain control */
113 #define RF3000_GAINCTL_TXVGC_MASK __BITS(7, 2)
114 #define RF3000_GAINCTL_SCRAMBLER __BIT(1)
117 * Shift the transmit power into the transmit-power field of the
118 * gain-control register and write it to the baseband processor.
120 atw_rf3000_write(sc, RF3000_GAINCTL,
121 __SHIFTIN(txpower, RF3000_GAINCTL_TXVGC_MASK));
124 * Register definitions taken from the ADMtek ADM8211 manual.
127 #define ATW_RXSTAT_OWN __BIT(31) /* 1: NIC may fill descriptor */
129 #define ATW_RXSTAT_DA1 __BIT(17) /* DA bit 1, admin'd address */
130 #define ATW_RXSTAT_DA0 __BIT(16) /* DA bit 0, group address */
131 #define ATW_RXSTAT_RXDR_MASK __BITS(15,12) /* RX data rate */
132 #define ATW_RXSTAT_FL_MASK __BITS(11,0) /* RX frame length, last
136 /* Extract the frame length from the Rx descriptor's
139 len = __SHIFTOUT(rxstat, ATW_RXSTAT_FL_MASK);
144 macros first appeared in
146 with different names and implementation.
148 macros appeared with their current names and implementation in
153 macros were written by
154 .An David Young Aq dyoung@NetBSD.org .
155 .An Matt Thomas Aq matt@NetBSD.org
156 suggested important improvements to the implementation, and
157 contributed the macro names
165 can only express 32-bit bitmasks.