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.
The following example illustrates
the use of __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 the following example, bit-banded
access is generated for bb.i
.
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.