Hardware Reference
In-Depth Information
A program could determine this as well, by using the sysconf(2) system call:
#include <unistd.h>
...
long sz = sysconf(_SC_PAGESIZE);
Protection
The third mmap(2) argument is supplied with the flags PROT_READ and PROT_WRITE .
This indicates that the application wants both read and write access to the memory-
mapped region.
Flags
The flags argument is supplied with the value MAP_SHARED . This permits nonexclusive
access to the underlying mapping.
File Descriptor
This argument supplies the underlying opened file to be mapped into memory. In this
case, we map a region of physical ARM memory into our application by using the opened
device driver node /dev/mem .
Offset
This last argument specifies the location in physical memory where we want to start our
access. For the GPIO registers, it is the address 0x20200000.
Return Value
The return value, when successful, will be an application address that points to the
physical memory region we asked for. The application programmer need not be
concerned with what this address is, except to save and use it for access.
The return value is also used for indicating failure, so this should be checked and
handled:
if ( (long) map == -1L ) {
perror("mmap(/dev/mem)");
exit(1);
}
The returned address (pointer) map is cast to a long integer and compared to -1L .
This is the magic value that indicates that an error occurred. The error code is found in
errno .
 
Search WWH ::




Custom Search