CRpi
A library for rpi with intefaces to: gpio, pwm, dma
Macros | Functions | Variables
addressing.h File Reference

Provides helper macros for address management. More...

#include <stdint.h>

Go to the source code of this file.

Macros

#define PERIPHERAL_BASE_ADDR_PHYS_RPI2   0x3f000000
 Physical base address of the peripherals memory area on the raspberry 2.
 
#define PERIPHERAL_BASE_ADDR_PHYS_RPI1   0x20000000
 Physical base address of the peripherals memory area on the raspberry 1.
 
#define PERIPHERAL_BASE_ADDR_BUS   0x7e000000
 Bus base address of the peripherals memory area.
 
#define TO_PHYS_MEM(addr)   (addr & ~0xc0000000)
 Converts physical memory from any alias to alias 0 memory. So it works to convert bus memory to physical memory.
 
#define PERIPHERAL_PHYS_TO_BUS_ADDR(addr)   (addr - PERIPHERAL_BASE_ADDR_PHYS_RPI2 + PERIPHERAL_BASE_ADDR_BUS)
 Converts a peripheral's physical address to it's bus address.
 

Functions

int addrVirtToPhys (void *virtAddr, uintptr_t *physAddrRet)
 Gets the physical address corresponding to the provided virtual address. More...
 

Variables

uintptr_t peripheralsBaseAddressPhys
 Physical base address of the peripherals memory area.
 

Detailed Description

Provides helper macros for address management.

See the documentation at "BCM 2835 ARM Peripherals" pag 4 and following.

In the BCM 2835 (also BCM2836 and BCM2837) there are three different addressing modes, so we have:

Virtual addresses span on the whole address space (0x0-0xffffffff) Physical addresses from 0x0 to 0x3fffffff (1GB) Bus addresses on the whole address space (0x0-0xffffffff)

In bus addressing the RPI memory is mapped at different addresses in different ways. These areas are called aliases:

Peripherals are mapped to physical memory at address 0x20000000 in rpi1 and 0x3f000000 in rpi2 and rpi3. And so are also mapped to bus address in the various aliases.

Function Documentation

int addrVirtToPhys ( void *  virtAddr,
uintptr_t *  physAddrRet 
)

Gets the physical address corresponding to the provided virtual address.

Parameters
virtAddrThe virtuall address to convert
physAddrRetThe physical address is rturned here
Returns
0 for success, negative for error, 1 if the virtual address isn't in ram