KISS Data Aquisition and Control System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.2 KiB

  1. /*
  2. *
  3. * PRU Debug Program - UIO routines
  4. * (c) Copyright 2011,2013 by Arctica Technologies
  5. * Written by Steven Anderson
  6. *
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <unistd.h>
  11. #include <sys/types.h>
  12. #include <dirent.h>
  13. #include <string.h>
  14. #include "uio.h"
  15. // get UIO devices and put into structure
  16. int uio_getprussfile(char *devname)
  17. {
  18. DIR *d;
  19. struct dirent *dent;
  20. char fn[UIO_MAX_UIO_FILEPATH];
  21. FILE *fd;
  22. char s_name[UIO_MAX_DEV_NAME];
  23. // clear user buffer
  24. devname[0] = 0;
  25. // open directory /dev and scan for uio* files
  26. d = opendir("/dev");
  27. // read in first entry
  28. dent = readdir(d);
  29. // scan the entries
  30. while (dent != NULL) {
  31. // determine if this is a uio* file
  32. if (dent->d_name[0] == 'u' && dent->d_name[1] == 'i' && dent->d_name[2] == 'o' && devname[0] == 0) {
  33. // get uio device name and version
  34. sprintf(fn, "/sys/class/uio/%s/name", dent->d_name);
  35. fd = fopen (fn, "r");
  36. fgets(s_name, UIO_MAX_DEV_NAME, fd);
  37. s_name[strlen(s_name)-1] = 0;
  38. if (!strncmp(s_name, "pruss", 5)) {
  39. sprintf(devname, "/dev/%s", dent->d_name);
  40. }
  41. fclose(fd);
  42. }
  43. // read next directory entry
  44. dent = readdir(d);
  45. }
  46. // close directory handle
  47. closedir(d);
  48. return 0;
  49. }