psgen.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*====================================================================*
  2. *
  3. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  4. *
  5. * All rights reserved.
  6. *
  7. *====================================================================*/
  8. /*====================================================================*
  9. *
  10. * psgen.h - header for psgen utility
  11. *
  12. * Contributor(s):
  13. * Nathaniel Houghton <nhoughto@qca.qualcomm.com>
  14. *
  15. *--------------------------------------------------------------------*/
  16. #ifndef PSGEN_HEADER
  17. #define PSGEN_HEADER
  18. #define _GETOPT_H
  19. /*====================================================================*
  20. * system header files;
  21. *--------------------------------------------------------------------*/
  22. #include <ctype.h>
  23. #include <math.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. /*====================================================================*
  28. * custom header files;
  29. *--------------------------------------------------------------------*/
  30. #include "../tools/files.h"
  31. /*====================================================================*
  32. * program constants;
  33. *--------------------------------------------------------------------*/
  34. #define GAIN_ENABLE_OFFSET_6400 0x1F6E
  35. #define AMP_CARRIERS 2880
  36. #define INT_CARRIERS 1155
  37. #define HPAV_CARRIER_WIDTH 24414
  38. #define TWEAK_ABSOLUTE 0
  39. #define TWEAK_RELATIVE 1
  40. /*====================================================================*
  41. * program macros;
  42. *--------------------------------------------------------------------*/
  43. #define PRESCALER_FREQ_WIDTH(x) ((x)->carriers_per_prescaler * HPAV_CARRIER_WIDTH)
  44. /*====================================================================*
  45. *
  46. *--------------------------------------------------------------------*/
  47. struct rs_item
  48. {
  49. char * name;
  50. char * value;
  51. char * unit;
  52. };
  53. struct rs_file
  54. {
  55. int item_count;
  56. int trace_start;
  57. int trace_end;
  58. char * path;
  59. struct rs_item * item;
  60. };
  61. struct notch
  62. {
  63. double sf;
  64. double ef;
  65. };
  66. struct notch_set
  67. {
  68. int count;
  69. double depth;
  70. struct notch * notch;
  71. };
  72. struct dev_config
  73. {
  74. struct device_spec * dspec;
  75. struct prescalers * ps;
  76. signed gain_adj;
  77. uint32_t truncated;
  78. uint32_t notched;
  79. double average;
  80. };
  81. struct device_spec
  82. {
  83. const char * name;
  84. unsigned prescaler_count;
  85. unsigned prescaler_unity;
  86. unsigned prescaler_max;
  87. unsigned carriers_per_prescaler;
  88. int tail_start;
  89. int (* update_pib) (const char *, struct dev_config *);
  90. int (* set_tx_gain) (struct _file_ *, int);
  91. int (* check_tx_gain) (int);
  92. };
  93. struct trace
  94. {
  95. int count;
  96. double * freq;
  97. double * value;
  98. };
  99. struct prescalers
  100. {
  101. uint32_t count;
  102. uint32_t * value;
  103. };
  104. struct tweak
  105. {
  106. double sf;
  107. double ef;
  108. double sv;
  109. double ev;
  110. struct tweak * next;
  111. };
  112. const char * strtodouble (const char *, double *);
  113. double estimate_trace_value (struct trace *, double, double);
  114. int create_trace_rs (struct rs_file *, struct trace *);
  115. int load_rs_file (const char *, struct rs_file *);
  116. void free_rs_file (struct rs_file *);
  117. void free_tweaks (struct tweak *);
  118. int parse_tweak (struct tweak *, const char *);
  119. int parse_range (const char *, double *, double *);
  120. int create_trace_copy (struct trace *, struct trace *);
  121. int reshape_trace (struct trace *, struct trace *, struct device_spec *, double, double);
  122. void free_trace_data (struct trace *);
  123. int find_trace_index_range (struct trace *, double, double, uint32_t *, uint32_t *);
  124. int apply_tweak (struct trace *, struct tweak *, int);
  125. int output_prescalers (struct trace *, struct trace *, struct device_spec *, int);
  126. int replace_prescalers_around_notches (struct prescalers *, uint32_t);
  127. /*====================================================================*
  128. * currently generic
  129. *--------------------------------------------------------------------*/
  130. double ps_to_amp (uint32_t, uint32_t);
  131. uint32_t amp_to_ps (double, uint32_t, struct device_spec *);
  132. uint32_t freq_to_index (double, struct device_spec *);
  133. double index_to_freq (uint32_t, struct device_spec *);
  134. /*--------------------------------------------------------------------*
  135. * lynx/panther
  136. *--------------------------------------------------------------------*/
  137. int psin (struct _file_ *, struct dev_config *);
  138. int update_pib (const char *, struct dev_config *);
  139. int set_tx_gain_6400 (struct _file_ *, int);
  140. int set_tx_gain_7400 (struct _file_ *, int);
  141. int check_tx_gain_6400 (int);
  142. int check_tx_gain_7400 (int);
  143. void dump_trace (struct trace *);
  144. struct dev_config * generate_config (struct trace *, struct trace *, struct device_spec *, int, struct prescalers *, double, double);
  145. struct prescalers * load_prescalers (const char *, struct device_spec *);
  146. void print_config (struct dev_config *, FILE *);
  147. void print_config_stats (struct dev_config *, FILE *);
  148. void free_dev_config (struct dev_config *);
  149. void show_prescalers (struct prescalers *, unsigned scale);
  150. void show_trace (struct trace *, unsigned scale);
  151. /*====================================================================*
  152. *
  153. *--------------------------------------------------------------------*/
  154. #ifdef WIN32
  155. double rint (double);
  156. #endif
  157. /*====================================================================*
  158. *
  159. *--------------------------------------------------------------------*/
  160. #endif