[riot-devel] bitfeilds

Juergen Stuber juergen at jstuber.net
Sun Oct 30 10:55:35 CET 2016

On Fri, 28 Oct 2016 10:03:17 +0200
Juergen Stuber <juergen at jstuber.net> wrote:
> When you use shift and mask you usually do a single access for
> all fields of a register.

Note that you shouldn't do it in two assignments
(I'm seeing this in cpu/stm32l1/periph/gpio.c):

    port &= ~mask;
    port |= (new_value << shift);

This will result in bigger code and the first assignment will write a
spurious value to the register, which might cause problems.

    port = (port & ~mask) | (new_value << shift);

is better. Or

    port = (port & ~mask)
         | (new_value1 << shift1)
         | (new_valueN << shiftN);

for multiple fields.


Jürgen Stuber <juergen at jstuber.net>
1B78 A579 E159 2A85 67BB  1314 C083 224B 0F9C DA21
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.riot-os.org/pipermail/devel/attachments/20161030/e3e781b0/attachment.sig>

More information about the devel mailing list