Hardware Reference
In-Depth Information
Volatile
The last section of this initialization code for GPIO assigns the address map to another
variable, ugpio , as follows:
ugpio = (volatile unsigned
)map;
The value ugpio was defined earlier in the program:
static volatile unsigned
ugpio = 0;
There are two things noteworthy about this:
int (32 bits on the Pi).
The data type is an unsigned
The pointed-to data is marked as
volatile.
Since the Pis registers are 32 bits in size, it is often more convenient to access them
as 32-bit words. The unsigned data type is perfect for this. But be careful with offsets in
conjunction with this pointer, since they will be word offsets rather than byte offsets.
The volatile keyword tells the compiler not to optimize access to memory through
the pointer variable. Imagine code that reads a peripheral register and reads the same
register again later, to see whether an event has occurred. An optimizing compiler might
say to itself, “I already have this value in CPU register R, so I'll just use that since it is
faster.” But the effect of this code is that it will never see a bit change in the peripheral's
register because that data was not fetched back into a CPU register. The volatile
keyword forces the compiler to retrieve the value even though it would be faster to use the
value still found in a register.
Virtual Memory
In the previous section, you looked at how to access physical memory in an application,
provided that you had the rights to do so (root or setuid ). The Broadcom Corporation
PDF manual “BCM2835 ARM Peripherals,” page 5, also shows a virtual memory layout
on the right. This should not be confused with the physical memory layout that you
examined earlier. Virtual memory can be accessed through /dev/kmem driver node using
mmap(2) , but we won't be needing that in this topic.
Final Thoughts on SDRAM
Some parameters such as Buffers impact the performance of Raspbian Linux on the Pi.
From our comparison, we saw that the Model A seems to use about half of the buffering
available to the Model B Rev 2.0 Pi. This is reasonable when limited memory has to be
divided between operating system and application use.
Another performance area related to memory is how much SDRAM is dedicated
to GPU use. This parameter is examined in Chapter 2 of Raspberry Pi System Software
Reference (Apress, 2014).
 
Search WWH ::




Custom Search