prussdrv.c

I'm an absolute beginner in the field of pru. I was wondering what actually takes place when a bin file is loaded into the instruction memory of a pru. I looked through the prussdrv.c in am335x_pru_package file where application loader api functions are located.
https://github.com/beagleboard/am335x_pru_package/blob/master/pru_sw/app_loader/interface/prussdrv.c

My question is in
int prussdrv_pru_write_memory (unsigned int pru_ram_id, unsigned int wordoffset, unsigned int *memarea, unsigned int bytelength);
function scope

wordlength = (bytelength + 3) >> 2; //Adjust length as multiple of 4 bytes

for (i = 0; i < wordlength; i++) {
*(pruramarea + i + wordoffset) = *(memarea + i);
    }
    return wordlength;

why wordoffset is added to pruramarea which holds the the address of the instruction memory.but according to this guide

http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader_API_Guide

wordoffset is the offset from *memarea and I think wordoffset is to be added to memarea instead , otherwise we are missing some parts of the instruction memory.

My other question is why pru instruction memory is said to be 8kB But according to the trm pru global memory section the instruction memory is just 4k

I'm an absolute beginner in the field of pru. I was wondering what actually takes place when a bin file is loaded into the instruction memory of a pru. I looked through the prussdrv.c in am335x_pru_package file where application loader api functions are located.
https://github.com/beagleboard/am335x_pru_package/blob/master/pru_sw/app_loader/interface/prussdrv.c

My question is in
int prussdrv_pru_write_memory (unsigned int pru_ram_id, unsigned int wordoffset, unsigned int *memarea, unsigned int bytelength);
function scope

wordlength = (bytelength + 3) >> 2; //Adjust length as multiple of 4 bytes

for (i = 0; i < wordlength; i++) {
*(pruramarea + i + wordoffset) = *(memarea + i);
    }
    return wordlength;

why wordoffset is added to pruramarea which holds the the address of the instruction memory.but according to this guide

http://processors.wiki.ti.com/index.php/PRU_Linux_Application_Loader_API_Guide

wordoffset is the offset from *memarea and I think wordoffset is to be added to memarea instead , otherwise we are missing some parts of the instruction memory.

It looks like the documentation is unclear (or wrong). The offset is
the offset into the mapped memory region (pruramarea, selected by what
you pass as the pru_ram_id parameter) where the memory buffer
specified by memarea & bytelength will be copied.

When in doubt, trust the code! :slight_smile:

My other question is why pru instruction memory is said to be 8kB But according to the trm pru global memory section the instruction memory is just 4k

Which TRM? The TRMs I have for the AM335x refer to 8KB instruction
memory for each PRU core, but there are several versions of the PRU
floating around in different SoC's.