psgraph.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. * psgraph.c - print PIB prescaler graph;
  44. *
  45. *
  46. * Contributor(s):
  47. * Charles Maier
  48. *
  49. *--------------------------------------------------------------------*/
  50. /*====================================================================*
  51. * system header files;
  52. *--------------------------------------------------------------------*/
  53. #include <unistd.h>
  54. #include <limits.h>
  55. #include <errno.h>
  56. /*====================================================================*
  57. * custom header files;
  58. *--------------------------------------------------------------------*/
  59. #include "../tools/getoptv.h"
  60. #include "../tools/putoptv.h"
  61. #include "../tools/number.h"
  62. #include "../tools/error.h"
  63. #include "../tools/files.h"
  64. #include "../plc/plc.h"
  65. #include "../pib/pib.h"
  66. /*====================================================================*
  67. * custom source files;
  68. *--------------------------------------------------------------------*/
  69. #ifndef MAKEFILE
  70. #include "../tools/getoptv.c"
  71. #include "../tools/putoptv.c"
  72. #include "../tools/version.c"
  73. #include "../tools/uintspec.c"
  74. #include "../tools/todigit.c"
  75. #include "../tools/error.c"
  76. #endif
  77. #ifndef MAKEFILE
  78. #include "../pib/pibscalers.c"
  79. #endif
  80. /*====================================================================*
  81. * program constants;
  82. *--------------------------------------------------------------------*/
  83. #define PSGRAPH_VERBOSE (1 << 0)
  84. #define PSGRAPH_SILENCE (1 << 1)
  85. /*====================================================================*
  86. *
  87. * void int6x00Prescalers (struct _file_ * pib, unsigned scale);
  88. *
  89. *
  90. *--------------------------------------------------------------------*/
  91. static void int6x00Prescalers (struct _file_ * pib, unsigned scale)
  92. {
  93. unsigned index = 0;
  94. if (lseek (pib->file, INT_PRESCALER_OFFSET, SEEK_SET) != INT_PRESCALER_OFFSET)
  95. {
  96. error (1, errno, "Can't seek %s", pib->name);
  97. }
  98. for (index = 0; index < INT_PRESCALER_LENGTH; index++)
  99. {
  100. uint32_t value;
  101. if (read (pib->file, &value, sizeof (value)) != sizeof (value))
  102. {
  103. error (1, errno, "can't read %s", pib->name);
  104. }
  105. printf (" %6.3f %04d %6d ", INDEX_TO_FREQ (index), index, value);
  106. while (value > scale)
  107. {
  108. printf ("#");
  109. value -= scale;
  110. }
  111. printf ("\n");
  112. }
  113. return;
  114. }
  115. /*====================================================================*
  116. *
  117. * void qca7x00Prescalers (struct _file_ * pib, unsigned scale);
  118. *
  119. *--------------------------------------------------------------------*/
  120. static void qca7x00Prescalers (struct _file_ * pib, unsigned scale)
  121. {
  122. unsigned index = 0;
  123. if (lseek (pib->file, QCA_PRESCALER_OFFSET, SEEK_SET) != QCA_PRESCALER_OFFSET)
  124. {
  125. error (1, errno, FILE_CANTSEEK, pib->name);
  126. }
  127. for (index = 0; index < QCA_PRESCALER_LENGTH; index++)
  128. {
  129. byte value;
  130. if (read (pib->file, &value, sizeof (value)) != sizeof (value))
  131. {
  132. error (1, errno, "can't read %s", pib->name);
  133. }
  134. printf (" %6.3f %04d %6d ", INDEX_TO_FREQ (index), index, value);
  135. while (value > scale)
  136. {
  137. printf ("#");
  138. value -= scale;
  139. }
  140. printf ("\n");
  141. }
  142. return;
  143. }
  144. /*====================================================================*
  145. *
  146. * int main (int argc, char const * argv []);
  147. *
  148. *
  149. *
  150. *--------------------------------------------------------------------*/
  151. int main (int argc, char const * argv [])
  152. {
  153. static char const * optv [] =
  154. {
  155. "s:",
  156. "file [> stdout]",
  157. "print PIB prescaler graph",
  158. "s n\tscale",
  159. (char const *) (0)
  160. };
  161. struct _file_ pib;
  162. unsigned count = 0;
  163. unsigned scale = 10;
  164. signed c;
  165. optind = 1;
  166. while ((c = getoptv (argc, argv, optv)) != -1)
  167. {
  168. switch (c)
  169. {
  170. case 's':
  171. scale = (unsigned)(uintspec (optarg, 1, UCHAR_MAX));
  172. break;
  173. default:
  174. break;
  175. }
  176. }
  177. argc -= optind;
  178. argv += optind;
  179. if (argc > 1)
  180. {
  181. error (1, ENOTSUP, "Only one file is permitted");
  182. }
  183. if ((argc) && (* argv))
  184. {
  185. pib.name = * argv;
  186. if ((pib.file = open (pib.name, O_BINARY|O_RDONLY)) == -1)
  187. {
  188. error (1, errno, "Can't open %s", pib.name);
  189. }
  190. count = pibscalers (&pib);
  191. if (count == PLC_CARRIERS)
  192. {
  193. qca7x00Prescalers (&pib, scale);
  194. }
  195. else if (count == AMP_CARRIERS)
  196. {
  197. error (1, ENOTSUP, "AR7x00 PIB Format");
  198. }
  199. else if (count == INT_CARRIERS)
  200. {
  201. int6x00Prescalers (&pib, scale);
  202. }
  203. else
  204. {
  205. error (1, ENOTSUP, "Unknown PIB Format");
  206. }
  207. close (pib.file);
  208. }
  209. return (0);
  210. }