gpioinfo.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * gpioinfo.c - print gpio Iinformation
  11. *
  12. * Contributor(s):
  13. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  14. *
  15. *--------------------------------------------------------------------*/
  16. /*====================================================================*
  17. * system header files;
  18. *--------------------------------------------------------------------*/
  19. #include <unistd.h>
  20. #include <limits.h>
  21. #include <errno.h>
  22. /*====================================================================*
  23. * custom header files;
  24. *--------------------------------------------------------------------*/
  25. #include "../tools/getoptv.h"
  26. #include "../tools/putoptv.h"
  27. #include "../tools/number.h"
  28. #include "../tools/error.h"
  29. #include "../tools/files.h"
  30. #include "../tools/types.h"
  31. /*====================================================================*
  32. * custom source files;
  33. *--------------------------------------------------------------------*/
  34. #ifndef MAKEFILE
  35. #include "../tools/getoptv.c"
  36. #include "../tools/putoptv.c"
  37. #include "../tools/version.c"
  38. #include "../tools/uintspec.c"
  39. #include "../tools/todigit.c"
  40. #include "../tools/hexstring.c"
  41. #include "../tools/hexdecode.c"
  42. #include "../tools/error.c"
  43. #endif
  44. /*====================================================================*
  45. * program constants;
  46. *--------------------------------------------------------------------*/
  47. #define TM_VERBOSE (1 << 0)
  48. #define TM_SILENCE (1 << 1)
  49. #define OFFSET 0x24BF
  50. #define LENGTH 50
  51. /*====================================================================*
  52. *
  53. * int main (int argc, char const * argv []);
  54. *
  55. *--------------------------------------------------------------------*/
  56. int main (int argc, char const * argv [])
  57. {
  58. static char const * optv [] =
  59. {
  60. "",
  61. "file [file] [...] [> stdout]",
  62. "print GPIO information",
  63. (char const *) (0)
  64. };
  65. #ifndef __GNUC__
  66. #pragma pack (push, 1)
  67. #endif
  68. typedef struct __packed EventBlock
  69. {
  70. uint8_t EvtPriorityId;
  71. uint8_t EvtId;
  72. uint8_t BehId [3];
  73. uint16_t ParticipatingGPIOs;
  74. uint8_t EventAttributes;
  75. uint8_t RSVD [3];
  76. }
  77. EventBlock;
  78. #ifndef __GNUC__
  79. #pragma pack (pop)
  80. #endif
  81. struct EventBlock EventBlockArray [50];
  82. file_t fd;
  83. signed c;
  84. optind = 1;
  85. while (~ (c = getoptv (argc, argv, optv)))
  86. {
  87. switch (c)
  88. {
  89. default:
  90. break;
  91. }
  92. }
  93. argc -= optind;
  94. argv += optind;
  95. while ((argc) && (* argv))
  96. {
  97. if ((fd = open (* argv, O_BINARY | O_RDONLY)) == - 1)
  98. {
  99. error (0, errno, "Can't open %s", * argv);
  100. }
  101. else if (lseek (fd, OFFSET, SEEK_SET) != OFFSET)
  102. {
  103. error (0, errno, "Can't seek %s", * argv);
  104. close (fd);
  105. }
  106. else if (read (fd, & EventBlockArray, sizeof (EventBlockArray)) != sizeof (EventBlockArray))
  107. {
  108. error (0, errno, "Can't read %s", * argv);
  109. close (fd);
  110. }
  111. else
  112. {
  113. for (c = 0; c < LENGTH; c++)
  114. {
  115. struct EventBlock * EventBlock = (& EventBlockArray [c]);
  116. char string [10];
  117. printf ("EvtPriorityId %3d ", EventBlock->EvtPriorityId);
  118. printf ("EvtId %3d ", EventBlock->EvtId);
  119. printf ("BehId %s ", hexstring (string, sizeof (string), EventBlock->BehId, sizeof (EventBlock->BehId)));
  120. printf ("ParticipatingGPIOs %3d ", EventBlock->ParticipatingGPIOs);
  121. printf ("EventAttributes %3d ", EventBlock->EventAttributes);
  122. printf ("\n");
  123. }
  124. close (fd);
  125. }
  126. argc--;
  127. argv++;
  128. }
  129. return (0);
  130. }