PRU Shared Memory - C programming

Hello everyone,

I am a newbie when it concerns embedded Linux/BBB and I’ve been having some difficulties about shared memory access.
Using the main processor, I could perfectly read/write data into shared memory (I want to share them with the PRUs).

And when it comes to PRU, I cannot access shmemory (maybe my code to map the registers is not working - I am coding in C).
Has anyone tried to write and read shared memory in PRU code?

Thanks!

Hello everyone,

I am a newbie when it concerns embedded Linux/BBB and I’ve been having some difficulties about shared memory access.
Using the main processor, I could perfectly read/write data into shared memory (I want to share them with the PRUs).

And when it comes to PRU, I cannot access shmemory (maybe my code to map the registers is not working - I am coding in C).
Has anyone tried to write and read shared memory in PRU code?

I’d recommend looking at the source code for the http://beaglelogic.net and PRU Speak projects.

i’m using pru0

/* host c code */

#include <stdio.h>
#include <stdlib.h>

#include <prussdrv.h>
#include <pruss_intc_mapping.h>

#define PRU_NUM 0
#define AM33XX

int main (int argc, char **argv)
{
unsigned int ret;
tpruss_intc_initdata pruss_intc_initdata = PRUSS_INTC_INITDATA;

/* Initialize the PRU */
prussdrv_init ();

/* Open PRU Interrupt */
ret = prussdrv_open(PRU_EVTOUT_0);
if (ret) {
printf(“prussdrv_open open failed\n”);
return (ret);
}

prussdrv_map_prumem (PRUSS0_SHARED_DATARAM, &prudata);
/* some macros from prussdrv.h
#define PRUSS0_PRU0_DATARAM 0
#define PRUSS0_PRU1_DATARAM 1
#define PRUSS0_PRU0_IRAM 2
#define PRUSS0_PRU1_IRAM 3
#define PRUSS0_SHARED_DATARAM 4 */








pru0data_int = (unsigned int ) prudata; / (pru0data_int) memory location to send data to pru0 from host code */
*(pru0data_int) = 1;

/* Get the interrupt initialized */
prussdrv_pruintc_init(&pruss_intc_initdata);

/* Execute example on PRU */
prussdrv_exec_program (PRU_NUM, “./text.bin”);

/* Wait until PRU0 has finished execution */
prussdrv_pru_wait_event (PRU_EVTOUT_0);
prussdrv_pru_clear_event (PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);

/* Disable PRU and close memory mapping*/
prussdrv_pru_disable (PRU_NUM);
prussdrv_exit ();

return(0);
}

/* pru code */

.origin 0
.entrypoint START

#define PRU_EVTOUT_0 3
//#define USER_DELAY 50

START:
MOV r0, 0x00000000
LBBO r4, r0, 0, 4 /* read data from host code /
/
do some more stuff */
END:
MOV r31.b0, 35
HALT

please not the change in pru code for shared memory access
/* pru code */

.origin 0
.entrypoint START

#define PRU_EVTOUT_0 3
//#define USER_DELAY 50

START:
MOV r0, 0x00010000 /* 0x00000000 for own data memory, 0x00002000 for other pru data memory /
LBBO r4, r0, 0, 4 /
read data from host code /
/
do some more stuff */
END:
MOV r31.b0, 35
HALT
0x00010000