Recently, I have started working on embedded system (and I don't have any prior knowledge about it), trying to gain some knowledge in this field. I am working with Raspberry-pi. I am doing bare-metal programming, without any OS. I was reading the data-sheet of bcm2835 and got to know that
Peripherals (at physical address 0x20000000 on) are mapped into the kernel virtual address space starting at address 0xF2000000.
Now, I would like to know that if I can assign any kernel virtual address to a pointer and perform standard pointer operation on it. Like
uint32_t *p = (uint32_t*)0xF20203000; //PCM Base address
p[1] = 1; // This should be (0xF20203000 + 0x0004) = 0xF20203004
uint32_t value = p[1];
I have seen many code samples for raspberry-pi but the problem is they all are using mmap() function of Linux. Till now, I am doing it in assembly: (Code taken from http://wiki.osdev.org/ARM_RaspberryPi_Tutorial_C#Writing_a_kernel_in_C)
static inline void mmio_write(uint32_t reg, uint32_t data) {
uint32_t *ptr = (uint32_t*)reg;
asm volatile("str %[data], [%[reg]]" : : [reg]"r"(ptr), [data]"r"(data));
}
static inline uint32_t mmio_read(uint32_t reg) {
uint32_t *ptr = (uint32_t*)reg;
uint32_t data;
asm volatile("ldr %[data], [%[reg]]" : [data]"=r"(data) : [reg]"r"(ptr));
return data;
}
And if the above operation using pointers can be performed then will it actually write to physical address? What will be the trade-off?