psgraph.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * psgraph.c - print PIB prescaler graph;
  11. *
  12. * Contributor(s):
  13. * Charles Maier <cmaier@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 "../plc/plc.h"
  31. #include "../pib/pib.h"
  32. /*====================================================================*
  33. * custom source files;
  34. *--------------------------------------------------------------------*/
  35. #ifndef MAKEFILE
  36. #include "../tools/getoptv.c"
  37. #include "../tools/putoptv.c"
  38. #include "../tools/version.c"
  39. #include "../tools/uintspec.c"
  40. #include "../tools/todigit.c"
  41. #include "../tools/error.c"
  42. #endif
  43. #ifndef MAKEFILE
  44. #include "../pib/pibscalers.c"
  45. #endif
  46. /*====================================================================*
  47. * program constants;
  48. *--------------------------------------------------------------------*/
  49. #define PSGRAPH_VERBOSE (1 << 0)
  50. #define PSGRAPH_SILENCE (1 << 1)
  51. /*====================================================================*
  52. *
  53. * void int6x00Prescalers (struct _file_ * pib, unsigned scale);
  54. *
  55. *--------------------------------------------------------------------*/
  56. static void int6x00Prescalers (struct _file_ * pib, unsigned scale)
  57. {
  58. unsigned index = 0;
  59. if (lseek (pib->file, INT_PRESCALER_OFFSET, SEEK_SET) != INT_PRESCALER_OFFSET)
  60. {
  61. error (1, errno, "Can't seek %s", pib->name);
  62. }
  63. for (index = 0; index < INT_PRESCALER_LENGTH; index++)
  64. {
  65. uint32_t value;
  66. if (read (pib->file, & value, sizeof (value)) != sizeof (value))
  67. {
  68. error (1, errno, "can't read %s", pib->name);
  69. }
  70. printf (" %6.3f %04d %6d ", INDEX_TO_FREQ (index), index, value);
  71. while (value > scale)
  72. {
  73. printf ("#");
  74. value -= scale;
  75. }
  76. printf ("\n");
  77. }
  78. return;
  79. }
  80. /*====================================================================*
  81. *
  82. * int main (int argc, char const * argv []);
  83. *
  84. *--------------------------------------------------------------------*/
  85. int main (int argc, char const * argv [])
  86. {
  87. static char const * optv [] =
  88. {
  89. "s:",
  90. "file [> stdout]",
  91. "print PIB prescaler graph",
  92. "s n\tscale",
  93. (char const *) (0)
  94. };
  95. struct _file_ pib;
  96. unsigned count = 0;
  97. unsigned scale = 10;
  98. signed c;
  99. optind = 1;
  100. while (~ (c = getoptv (argc, argv, optv)))
  101. {
  102. switch (c)
  103. {
  104. case 's':
  105. scale = (unsigned) (uintspec (optarg, 1, UCHAR_MAX));
  106. break;
  107. default:
  108. break;
  109. }
  110. }
  111. argc -= optind;
  112. argv += optind;
  113. if (argc > 1)
  114. {
  115. error (1, ENOTSUP, "Only one file is permitted");
  116. }
  117. if ((argc) && (* argv))
  118. {
  119. pib.name = * argv;
  120. if ((pib.file = open (pib.name, O_BINARY | O_RDONLY)) == - 1)
  121. {
  122. error (1, errno, "Can't open %s", pib.name);
  123. }
  124. count = pibscalers (& pib);
  125. if (count == AMP_CARRIERS)
  126. {
  127. error (1, ENOTSUP, "AR7x00 PIB Format");
  128. }
  129. else if (count == INT_CARRIERS)
  130. {
  131. int6x00Prescalers (& pib, scale);
  132. }
  133. else
  134. {
  135. error (1, ENOTSUP, "Unknown PIB Format");
  136. }
  137. close (pib.file);
  138. }
  139. return (0);
  140. }