__attribute__((bitband)) is a type attribute
that gives you efficient atomic access to single-bit values in SRAM
and Peripheral regions of the memory architecture. It is possible
to set or clear a single bit directly with a single memory access
in certain memory regions, rather than having to use the traditional
read, modify, write approach. It is also possible to read a single
bit directly rather than having to use the traditional read then
shift and mask operation. Example 10 illustrates the use of __attribute__((bitband)).
Example 10. Using __attribute__((bitband))
typedef struct {
int i : 1;
int j : 2;
int k : 3;
} BB __attribute__((bitband));
BB bb __attribute__((at(0x20000004));
void foo(void)
{
bb.i = 1;
}
For peripherals that are sensitive to the memory access width,
byte, halfword, and word stores or loads to the alias space are
generated for char, short, and int types
of bitfields of bit-banded structs respectively.
In Example 11, bit-banded
access is generated for bb.i.
Example 11. Bitfield bit-band access
typedef struct {
char i : 1;
int j : 2;
int k : 3;
} BB __attribute__((bitband));
BB bb __attribute__((at(0x20000004)));
void foo()
{
bb.i = 1;
}
If you do not use __attribute__((at())) to
place the bit-banded variable in the bit-band region, you must relocate
it using another method. You can do this by either using an appropriate scatter-loading
description file or by using the --rw_base linker
command-line option. See the Linker Reference for
more information.
Restrictions
The following restrictions apply:
This
type attribute can only be used with struct. Any union
type or other aggregate type with a union as a member cannot be
bit-banded.
Members of structs cannot be bit-banded individually.
Bit-banded accesses are only generated for single-bit
bitfields.
Bit-banded accesses are not generated for const objects,
pointers, and local objects.
Bit-banding is only available on some processors.
For example, the Cortex-M3 and Cortex-M4 processors.
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.