gpioinfo.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or
  8. * without modification, are permitted (subject to the limitations
  9. * in the disclaimer below) provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer in the documentation and/or other materials
  18. * provided with the distribution.
  19. *
  20. * * Neither the name of Qualcomm Atheros nor the names of
  21. * its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written
  23. * permission.
  24. *
  25. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  26. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  27. * COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  28. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  31. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  33. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  34. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  36. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  37. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  38. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. *--------------------------------------------------------------------*/
  41. /*====================================================================*
  42. *
  43. * gpioinfo.c - print gpio Iinformation
  44. *
  45. *
  46. *--------------------------------------------------------------------*/
  47. /*====================================================================*
  48. * system header files;
  49. *--------------------------------------------------------------------*/
  50. #include <unistd.h>
  51. #include <limits.h>
  52. #include <errno.h>
  53. /*====================================================================*
  54. * custom header files;
  55. *--------------------------------------------------------------------*/
  56. #include "../tools/getoptv.h"
  57. #include "../tools/putoptv.h"
  58. #include "../tools/number.h"
  59. #include "../tools/error.h"
  60. #include "../tools/files.h"
  61. #include "../tools/types.h"
  62. /*====================================================================*
  63. * custom source files;
  64. *--------------------------------------------------------------------*/
  65. #ifndef MAKEFILE
  66. #include "../tools/getoptv.c"
  67. #include "../tools/putoptv.c"
  68. #include "../tools/version.c"
  69. #include "../tools/uintspec.c"
  70. #include "../tools/todigit.c"
  71. #include "../tools/hexstring.c"
  72. #include "../tools/hexdecode.c"
  73. #include "../tools/error.c"
  74. #endif
  75. /*====================================================================*
  76. * program constants;
  77. *--------------------------------------------------------------------*/
  78. #define TM_VERBOSE (1 << 0)
  79. #define TM_SILENCE (1 << 1)
  80. #define OFFSET 0x24BF
  81. #define LENGTH 50
  82. /*====================================================================*
  83. *
  84. * int main (int argc, char const * argv []);
  85. *
  86. *
  87. *
  88. *--------------------------------------------------------------------*/
  89. int main (int argc, char const * argv [])
  90. {
  91. static char const * optv [] =
  92. {
  93. "",
  94. "file [file] [...] [> stdout]",
  95. "print GPIO information",
  96. (char const *) (0)
  97. };
  98. #ifndef __GNUC__
  99. #pragma pack (push, 1)
  100. #endif
  101. typedef struct __packed EventBlock
  102. {
  103. uint8_t EvtPriorityId;
  104. uint8_t EvtId;
  105. uint8_t BehId [3];
  106. uint16_t ParticipatingGPIOs;
  107. uint8_t EventAttributes;
  108. uint8_t RSVD [3];
  109. }
  110. EventBlock;
  111. #ifndef __GNUC__
  112. #pragma pack (pop)
  113. #endif
  114. struct EventBlock EventBlockArray [50];
  115. file_t fd;
  116. signed c;
  117. optind = 1;
  118. while ((c = getoptv (argc, argv, optv)) != -1)
  119. {
  120. switch (c)
  121. {
  122. default:
  123. break;
  124. }
  125. }
  126. argc -= optind;
  127. argv += optind;
  128. while ((argc) && (* argv))
  129. {
  130. if ((fd = open (* argv, O_BINARY|O_RDONLY)) == -1)
  131. {
  132. error (0, errno, "Can't open %s", * argv);
  133. }
  134. else if (lseek (fd, OFFSET, SEEK_SET) != OFFSET)
  135. {
  136. error (0, errno, "Can't seek %s", * argv);
  137. close (fd);
  138. }
  139. else if (read (fd, &EventBlockArray, sizeof (EventBlockArray)) != sizeof (EventBlockArray))
  140. {
  141. error (0, errno, "Can't read %s", * argv);
  142. close (fd);
  143. }
  144. else
  145. {
  146. for (c = 0; c < LENGTH; c++)
  147. {
  148. struct EventBlock * EventBlock = (&EventBlockArray [c]);
  149. char string [10];
  150. printf ("EvtPriorityId %3d ", EventBlock->EvtPriorityId);
  151. printf ("EvtId %3d ", EventBlock->EvtId);
  152. printf ("BehId %s ", hexstring (string, sizeof (string), EventBlock->BehId, sizeof (EventBlock->BehId)));
  153. printf ("ParticipatingGPIOs %3d ", EventBlock->ParticipatingGPIOs);
  154. printf ("EventAttributes %3d ", EventBlock->EventAttributes);
  155. printf ("\n");
  156. }
  157. close (fd);
  158. }
  159. argc--;
  160. argv++;
  161. }
  162. return (0);
  163. }