public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Wolfgang Denk <wd@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/5] Tegra2: Add bitfield access macros
Date: Tue, 07 Jun 2011 12:06:23 +0200	[thread overview]
Message-ID: <20110607100623.01E351EA347@gemini.denx.de> (raw)
In-Reply-To: <BANLkTi=+pqk=UQY_=NoXcMabBDm845xcEw@mail.gmail.com>

Dear Simon Glass,

In message <BANLkTi=+pqk=UQY_=NoXcMabBDm845xcEw@mail.gmail.com> you wrote:
> 
> >> #define clrsetfield_le32(bitfield, addr, value) =A0...
> >>
> >> Then caller can define these in a header file:
> >>
> >> #define FIELD_MASK 0xf0000
> >> #define FIELD_SHIFT 16
> >>
> >> And use this macro to set the bitfield to 6, for example:
> >>
> >> clrsetfield_le32(FIELD, &my_device->ctrl, 6)
> >>
> >> (this will simply shift the value left 16 bits and apply the supplied ma=
> sk)
> >>
> >> This captures the essence of bitfields, in that we are abstracting the
> >> field under a single name. The change would just add this macro to the
> >> io.h header file.
> >
> > Sorry, I fail to understand how you envision to use this, and how it
> > would be different from =A0clrsetbits*() ?
> 
> For example this allows us to replace:
> 
> clrsetbits_le(&my_device->ctrl, 0xf << 16, 6 << 16)
> 
> with:
> 
> clrsetfield_le32(FIELD, &my_device->ctrl, 6)
> 
> So the two identical shifts are avoided, and the forming of the mask
> is done once in the define.

If you really insist:

	#define FIELD_VAL(x)	(x << 16)
	#define FIELD_MASK	FIELD_VAL(0xF)

	clrsetbits_le32(&my_device->ctrl, FIELD_MASK, FIELD_VAL(6));

In practical use cases, you will probablu not use magg numbers like
'6' anyway, and define symbolic names for this anyway, so this would
be:

	clrsetbits_le32(&my_device->ctrl, FIELD_MASK, FIELD_VAL_FOO);

or similar.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
News is what a chap who doesn't care much  about  anything  wants  to
read. And it's only news until he's read it. After that it's dead.
                           - Evelyn Waugh _Scoop_ (1938) bk. 1, ch. 5

  reply	other threads:[~2011-06-07 10:06 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-02  0:14 [U-Boot] [PATCH 0/5] Add bitfields, clock and pinmux functions to simplify code Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 1/5] Tegra2: Add bitfield access macros Simon Glass
2011-06-06 18:50   ` Wolfgang Denk
2011-06-07  0:38     ` Simon Glass
2011-06-07  6:28       ` Wolfgang Denk
2011-06-07  6:46         ` Simon Glass
2011-06-07 10:06           ` Wolfgang Denk [this message]
2011-06-07 15:06             ` Mike Frysinger
2011-06-07 15:12             ` Simon Glass
2011-06-07 15:51               ` Wolfgang Denk
2011-06-07 20:00               ` Wolfgang Denk
2011-06-08  7:37                 ` Detlev Zundel
2011-06-08 16:10                 ` Simon Glass
2011-06-08 19:21                   ` Wolfgang Denk
2011-06-08 19:48                     ` Simon Glass
2011-06-08 20:46                       ` Wolfgang Denk
2011-06-02  0:14 ` [U-Boot] [PATCH 2/5] Tegra2: Add microsecond timer functions Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 3/5] Tegra2: Add more clock support Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 4/5] Tegra2: add additional pin multiplexing features Simon Glass
2011-06-02  0:14 ` [U-Boot] [PATCH 5/5] Tegra2: Use clock and pinmux functions to simplify code Simon Glass
2011-06-06 18:59 ` [U-Boot] [PATCH 0/5] Add bitfields, " Wolfgang Denk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110607100623.01E351EA347@gemini.denx.de \
    --to=wd@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox