Dear Simon Glass, In message <banlktingfrorjd3w7rwqzu80kotfov0...@mail.gmail.com> you wrote: > > > Looking closer, the "FIELD_VAL" macro alone will probably not suffice, > > as you need both shift directions, like that: > > > > #define FIELD_SHIFT 16 > > #define FIELD_MASK 0xF > > > > > > #define FIELD_BITS(x) (x << 16) > > #define FIELD_MASK FIELD_BITS(0xF) > > #define FIELD_VAL(x) ((x & FIELD_MASK) >> 16) > > Hi Wolfgang, > > I think you have FIELD_MASK being two meanings: the un-shifted or > 'raw' mask, and the shifted mask. So perhaps:
My intention was to have only the real mask, i. e. what you need to apply to the register data (in your language the shifted mask). > #define FIELD_SHIFT 16 > #define FIELD_RAWMASK 0xF This is never really needed - you only use it once. > When you have a lot of these definitions in a row you have mentally > check the bit width of the mask: Yes, this is one of the disadvantages of thinking in bit fields and one reason why I never write code like that. I mentioned this before - I consider it error prone [like most other "clever" tricks that "make life easy" and allow you to stop thinking]. > Is the above correct, or do fields overlap or not cover fully? All this is possible. There may be overlapping definitions, and there may be reserved bits that need special handling. There may even be bits that cannot simply be re-writeen as we read them, but that must always be written as zeroes or ones. I never claimed that these "bit field" juggling was a clever idea. It works for some cases, and causes major pita for others. 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: w...@denx.de In an organization, each person rises to the level of his own incom- petency - The Peter Principle _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot