psdump.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * psin.c - load prescalers into int6000 parameter file;
  11. *
  12. * Contributor(s):
  13. * Charles Maier <cmaier@qca.qualcomm.com>
  14. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  15. *
  16. *--------------------------------------------------------------------*/
  17. /*====================================================================*
  18. * system header files;
  19. *--------------------------------------------------------------------*/
  20. #include <stdio.h>
  21. #include <stdint.h>
  22. #include <ctype.h>
  23. #include <string.h>
  24. #include <unistd.h>
  25. #include <errno.h>
  26. /*====================================================================*
  27. * custom header files;
  28. *--------------------------------------------------------------------*/
  29. #include "../tools/getoptv.h"
  30. #include "../tools/number.h"
  31. #include "../tools/chars.h"
  32. #include "../tools/types.h"
  33. #include "../tools/error.h"
  34. #include "../pib/pib.h"
  35. #include "../plc/plc.h"
  36. /*====================================================================*
  37. * custom source files;
  38. *--------------------------------------------------------------------*/
  39. #ifndef MAKEFILE
  40. #include "../tools/getoptv.c"
  41. #include "../tools/putoptv.c"
  42. #include "../tools/version.c"
  43. #include "../tools/fdchecksum32.c"
  44. #include "../tools/hexdecode.c"
  45. #include "../tools/hexstring.c"
  46. #include "../tools/uintspec.c"
  47. #include "../tools/todigit.c"
  48. #include "../tools/error.c"
  49. #endif
  50. /*====================================================================*
  51. * program constants;
  52. *--------------------------------------------------------------------*/
  53. #define SCALE_FACTOR 0
  54. /*====================================================================*
  55. *
  56. * signed ar7x00_psin (struct _file_ * pib, uint32_t value, uint32_t index);
  57. *
  58. * signed ar7x00_psin (struct _file_ * pib, uint32_t value, uint32_t index);
  59. *
  60. * Places a single 10 bit prescaler into the pib file at index;
  61. *
  62. *--------------------------------------------------------------------*/
  63. signed ar7x00_psin (struct _file_ * pib, uint32_t value, uint32_t index)
  64. {
  65. off_t offset = AMP_PRESCALER_OFFSET + (index * 10 / 8);
  66. uint8_t bit_offset = (index * 10) % 8;
  67. uint16_t tmp;
  68. if (lseek (pib->file, offset, SEEK_SET) != offset)
  69. {
  70. return (-1);
  71. }
  72. if (read (pib->file, & tmp, sizeof (tmp)) != sizeof (tmp))
  73. {
  74. return (-1);
  75. }
  76. if (lseek (pib->file, offset, SEEK_SET) != offset)
  77. {
  78. return (-1);
  79. }
  80. value &= 0x03FF;
  81. tmp = LE16TOH (tmp);
  82. tmp &= ~ (0x03FF << bit_offset);
  83. tmp |= value << bit_offset;
  84. tmp = HTOLE16 (tmp);
  85. if (write (pib->file, & tmp, sizeof (tmp)) != sizeof (tmp))
  86. {
  87. return (-1);
  88. }
  89. return (0);
  90. }
  91. /*====================================================================*
  92. *
  93. * void psgraph ();
  94. *
  95. *--------------------------------------------------------------------*/
  96. static void psgraph (unsigned limit, unsigned scale)
  97. {
  98. unsigned count = 0;
  99. signed c;
  100. while ((c = getc (stdin)) != EOF)
  101. {
  102. unsigned index = 0;
  103. unsigned value = 0;
  104. if (isspace (c))
  105. {
  106. continue;
  107. }
  108. if ((c == '#') || (c == ';'))
  109. {
  110. do
  111. {
  112. c = getc (stdin);
  113. }
  114. while (nobreak (c));
  115. continue;
  116. }
  117. while (isdigit (c))
  118. {
  119. index *= 10;
  120. index += c - '0';
  121. c = getc (stdin);
  122. }
  123. if (index != count)
  124. {
  125. error (1, ECANCELED, "Carrier %d out of order", index);
  126. }
  127. if (index >= limit)
  128. {
  129. error (1, EOVERFLOW, "Too many prescalers");
  130. }
  131. while (isblank (c))
  132. {
  133. c = getc (stdin);
  134. }
  135. while (isxdigit (c))
  136. {
  137. value *= 16;
  138. value += todigit (c);
  139. c = getc (stdin);
  140. }
  141. while (nobreak (c))
  142. {
  143. c = getc (stdin);
  144. };
  145. printf ("%04d %3d", index, value);
  146. if (scale)
  147. {
  148. printf (" %06.4f ", INDEX_TO_FREQ (index));
  149. while (value > scale)
  150. {
  151. value -= scale;
  152. putc ('#', stdout);
  153. }
  154. }
  155. putc ('\n', stdout);
  156. count++;
  157. }
  158. return;
  159. }
  160. /*====================================================================*
  161. *
  162. * int main (int argc, char const * argv [])
  163. *
  164. *
  165. *--------------------------------------------------------------------*/
  166. int main (int argc, char const * argv [])
  167. {
  168. static char const * optv [] =
  169. {
  170. "s:",
  171. "pibfile [< prescalers]",
  172. "dump prescaler file in human readable format",
  173. "s n\tscale factor is (n) [" LITERAL (SCALE_FACTOR) "]",
  174. (char const *) (0)
  175. };
  176. unsigned limit = AMP_CARRIERS;
  177. unsigned scale = SCALE_FACTOR;
  178. signed c;
  179. optind = 1;
  180. while (~ (c = getoptv (argc, argv, optv)))
  181. {
  182. switch ((char) (c))
  183. {
  184. case 's':
  185. scale = (unsigned) (uintspec (optarg, 0, 10));
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191. argc -= optind;
  192. argv += optind;
  193. if ((argc) || (* argv))
  194. {
  195. error (1, ECANCELED, ERROR_TOOMANY);
  196. }
  197. psgraph (limit, scale);
  198. return (0);
  199. }