AMP with Raspberry Pi: Step 4 - Shared memory for Inter-Process Communication

To establish a simple IPC I will write from Linux to a memory address used by bare-metal app.
+Linux mmap() can access beyond the assigned memory (lower 512Mb imposed by boot args) and devmem is mmap() based, so I'll use it.

First, create a variable in the bare-metal app:
Edit armc-03.c and add a global variable:

volatile char delay=0x54;

also change the delay loops in order to use it:

for(tim = 0; tim < delay * 10000; tim++)

Compile armc-03.c and link (upper 512MB starts from 0x20000000)

gcc -c armc-03.c -o arm-03.o
ld -Ttext 0x20000000 arm-03.o -o up-metal2.elf
objcopy up-metal2.elf -O binary up-metal2.img

Place the obtained binary in memory (0x20000000)
root@minibian:~/code#./loadmetal up-metal2.img

Write to Core 3 mailbox 3 the start address (0x20000000)
./devmem 0x400000bc w 0x20000000

Blink starts, with blink speed managed by the "delay" variable.

To determine "delay" memory address look at elf symbol table:

nm up-metal2.elf

200000ac B __bss_end__
200000ac B _bss_end__
200000a1 D __bss_start
200000a1 D __bss_start__
200000a0 D __data_start
200000a0 D delay
200000a1 D _edata
200000ac B _end
200000ac B __end__
200000a8 B gpio
20000000 T main
00080000 N _stack
         U _start
200000a4 B tim

The global (volatile) "delay" variable is located at 0x200000a0
If we read it we get the coded value (0x54)

./devmem 0x200000a0 b

Or we can change it in order to change blink speed:

./devmem 0x200000a0 b 0x0a

+ volatile is needed to avoid compiler optimizations (our program never changes "delay" value, so a posible optimization is to make it a constant).

No hay comentarios:

Publicar un comentario