Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Problem in alt_find_dev

I've got a DMA component in my system named "/dev/dma". I copied code from the Memtest template so it should work. However, calling alt_dma_txchan_open("/dev/dma") fails. I traced down into the library code and found that alt_find_dev was performing a memcmp on the name. If I manually change the number of bytes to compare, then memcmp will pass otherwise it fails. Any ideas if I'm doing something wrong?


alt_dev* alt_find_dev(const char* name, alt_llist* llist)
{
  alt_dev* next = (alt_dev*) llist->next;
  alt_32 len;
  // change this line to pass
  len  = strlen(name) + 1; // fails
  len = strlen(name); // passes
  while (next != (alt_dev*) llist)
  {
    if (!memcmp (next->name, name, len))
    {
      /* match found */
      return next;
    }
    next = (alt_dev*) next->llist.next;
  }
  return NULL;
}

5 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Are you sure that your component device name is really "/dev/dma" and not something like "/dev/dma_0" or something else?

    To be sure you can include system.h in your source file and use the constant defined there instead of hard coding "/dev/dma". The constant should have a name like DMA_NAME or something close.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I was actually using the defined name from system.h, but I modified my post to make it clear what I was doing.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    The only reason I can see for the failure is that the two strings (the one that you provide as device name and tho one declared in the system) are equal on the first 8 characters but differ on the ninth: yours has a 0 indicating an end of string, and the one in the system has something else, indicating that the string is longer.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    A recompile of the hardware and software solved the problem, with no indication of what the problem might have been.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    --- Quote Start ---

    A recompile of the hardware and software solved the problem, with no indication of what the problem might have been.

    --- Quote End ---

    i had the same pb,

    i simply add a counter to limit the cycle, when the counter reaches max times, return

    null. and pb solved. dont need to recompile the system.

    if you look carefully,i'ts the llist.next who block the program. .next remains always the same address, that's why it turns into a infinity cycle.