从硬件芯片的数据表中,
Peripherals (at physical address 0x20000000 on) are mapped into the kernel virtual
address
space starting at address 0xF2000000. Thus a peripheral advertised here at bus address
0x7Ennnnnn is available in the ARM kenel at virtual address 0xF2nnnnnn.
然后从示例代码中,
#define BCM2835_PERI_BASE 0x20000000
我认为程序员应该处理虚拟地址,物理地址隐藏在后面。MMU 隐藏了物理地址较小的一面,使虚拟地址变大。最终用户/程序员将处理虚拟地址。
但是从上面看,示例代码显然使用了物理地址,为什么?
示例代码
#define BCM2835_PERI_BASE 0x20000000
#define GPIO_PADS (BCM2708_PERI_BASE + 0x00100000)
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x00101000)
#define GPIO_BASE (BCM2708_PERI_BASE + 0x00200000)
#define GPIO_TIMER (BCM2708_PERI_BASE + 0x0000B000)
#define GPIO_PWM (BCM2708_PERI_BASE + 0x0020C000)
static volatile uint32_t *pads ;
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;