How to write to shared memory from host?

Discussion about Parallella (and Epiphany) Software Development

Moderators: amylaar, jeremybennett, simoncook

How to write to shared memory from host?

Postby etim » Mon Oct 12, 2015 8:59 pm

The following code on the host gives the runtime error: "./run.sh: line 11: 4478 Segmentation fault ./pnn_encoder.elf 0 0 4 4 0x12345678". What am I doing wrong?

Code: Select all
  e_mem_t mbuf;
  int rc;
  unsigned count;
  count = 0;
  // const unsigned ShmSize = 128; // bytes
  const char ShmName[] = "hello_shared_memory";  // I think this is just a key to the shared memory location
  ////////////////////////////////////////////////////// 
  // 2. Allocate a buffer in shared external memory for message passing from eCore to host.
  //////////////////////////////////////////////////////
  rc = e_shm_alloc(&mbuf, ShmName, sizeof(unsigned));
  if (rc != E_OK){
    printf("e_shm_alloc was not OK! Trying e_shm_attach.");
    rc = e_shm_attach(&mbuf, ShmName);
  }
  if (rc != E_OK) {
    fprintf(stderr, "Failed to allocate shared memory. Error is %d\n", strerror(errno));
    return EXIT_FAILURE;
  }
  e_write((void*)&mbuf, count, 0, 0, NULL, sizeof(unsigned)); // it works as well without specifying a row and column (docs say they are ignored)
etim
 
Posts: 22
Joined: Sat Jun 27, 2015 6:08 pm

Re: How to write to shared memory from host?

Postby sebraa » Wed Oct 14, 2015 12:12 pm

Try the following:
Code: Select all
#define SHM_OFFSET 0x01000000

int main()
{
    /* .... */
    e_mem_t emem;
    e_alloc(&emem, SHM_OFFSET, sizeof(ShmType));
    /* ... */
}


The second parameter of e_alloc() is the offset inside the shared memory. In my case, 16 MB above the SHM base, which matches the default linker scripts.
sebraa
 
Posts: 495
Joined: Mon Jul 21, 2014 7:54 pm


Return to Programming Q & A

Who is online

Users browsing this forum: Google [Bot] and 6 guests

cron