bkl wrote: ↑
Fri Feb 15, 2019 7:10 pm
But how does the code has to be changed if I want to access the ARMTimer of the Raspberry Pi, too?
The code has to be changed as follows:
Code: Select all
ldr r0, =mem
ldr r1, =0x101002 /* O_RDWR | O_SYNC */
mov r7, #5 /* open */
mov r4, r0 /* file descriptor */
mov r0, #0 /* kernel chooses address */
mov r1, #4096 /* map size */
mov r2, #3 /* protection */
mov r3, #1 /* shared */
ldr r5, =0x3F003 /* offset */
mov r7, #192 /* mmap2 */
/* access ARM timer via r0 */
ldr r1, [r0, #0x04] /* read CLO */
mov r0, #0 /* return code */
mov r7, #248 /* exit */
mem: .asciz "/dev/mem"
The ARM timer cannot be accessed via /dev/gpiomem, so we have to use /dev/mem. This does only work with root privileges (sudo). The offset handed over to the mmap2 system call must be 0x3F003 on the RPi 2 and 3 (0x20003 on the RPi 1 and Zero). It is expressed in 0x1000 byte sized page units. The CLO timer register can be read at offset 0x04 of the mapped memory range then.