psout.c.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. psout.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='psnotch.c.html' title=' psnotch.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='psread.c.html' title=' psread.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * Copyright (c) 2013 Qualcomm Atheros, Inc.
  24. *
  25. * All rights reserved.
  26. *
  27. * Redistribution and use in source and binary forms, with or
  28. * without modification, are permitted (subject to the limitations
  29. * in the disclaimer below) provided that the following conditions
  30. * are met:
  31. *
  32. * * Redistributions of source code must retain the above copyright
  33. * notice, this list of conditions and the following disclaimer.
  34. *
  35. * * Redistributions in binary form must reproduce the above
  36. * copyright notice, this list of conditions and the following
  37. * disclaimer in the documentation and/or other materials
  38. * provided with the distribution.
  39. *
  40. * * Neither the name of Qualcomm Atheros nor the names of
  41. * its contributors may be used to endorse or promote products
  42. * derived from this software without specific prior written
  43. * permission.
  44. *
  45. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE
  46. * GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE
  47. * COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot; AND ANY EXPRESS OR
  48. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  49. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  50. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
  51. * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  52. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  53. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  54. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  55. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  56. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  57. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59. *
  60. *--------------------------------------------------------------------*/
  61. /*====================================================================*
  62. *
  63. * psout.c - Export PIB Prescalers;
  64. *
  65. *
  66. * Contributor(s):
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. *
  69. *--------------------------------------------------------------------*/
  70. /*====================================================================*
  71. * system header files;
  72. *--------------------------------------------------------------------*/
  73. #include &lt;math.h&gt;
  74. #include &lt;stdio.h&gt;
  75. #include &lt;string.h&gt;
  76. #include &lt;unistd.h&gt;
  77. #include &lt;errno.h&gt;
  78. #include &lt;sys/stat.h&gt;
  79. /*====================================================================*
  80. * custom header files;
  81. *--------------------------------------------------------------------*/
  82. #include &quot;../tools/getoptv.h&quot;
  83. #include &quot;../tools/number.h&quot;
  84. #include &quot;../tools/chars.h&quot;
  85. #include &quot;../tools/types.h&quot;
  86. #include &quot;../tools/error.h&quot;
  87. #include &quot;../tools/files.h&quot;
  88. #include &quot;../tools/endian.h&quot;
  89. #include &quot;../pib/pib.h&quot;
  90. #include &quot;../plc/plc.h&quot;
  91. /*====================================================================*
  92. * custom source files;
  93. *--------------------------------------------------------------------*/
  94. #ifndef MAKEFILE
  95. #include &quot;../tools/getoptv.c&quot;
  96. #include &quot;../tools/putoptv.c&quot;
  97. #include &quot;../tools/version.c&quot;
  98. #include &quot;../tools/checksum32.c&quot;
  99. #include &quot;../tools/fdchecksum32.c&quot;
  100. #include &quot;../tools/error.c&quot;
  101. #endif
  102. #ifndef MAKEFILE
  103. #include &quot;../pib/pibfile.c&quot;
  104. #include &quot;../pib/pibfile1.c&quot;
  105. #include &quot;../pib/pibfile2.c&quot;
  106. #include &quot;../pib/pibscalers.c&quot;
  107. #endif
  108. /*====================================================================*
  109. * program constants;
  110. *--------------------------------------------------------------------*/
  111. #define PSOUT_VERBOSE (1 &lt;&lt; 0)
  112. #define PSOUT_SILENCE (1 &lt;&lt; 1)
  113. /*====================================================================*
  114. *
  115. * void ar7x00Prescalers (struct _file_ * pib);
  116. *
  117. *--------------------------------------------------------------------*/
  118. static void ar7x00Prescalers (struct _file_ * pib)
  119. {
  120. #if 0
  121. uint32_t value;
  122. uint32_t temp;
  123. uint32_t buffer = 0;
  124. unsigned bits = 0;
  125. unsigned index = 0;
  126. if (lseek (pib-&gt;file, AMP_PRESCALER_OFFSET, SEEK_SET) != AMP_PRESCALER_OFFSET)
  127. {
  128. error (1, errno, FILE_CANTSEEK, pib-&gt;name);
  129. }
  130. /* no dependency on math lib */
  131. while (index &lt; AMP_CARRIERS)
  132. {
  133. if (read (pib-&gt;file, &amp;temp, sizeof (temp)) != sizeof (temp))
  134. {
  135. error (1, errno, FILE_CANTREAD, pib-&gt;name);
  136. }
  137. temp = LE32TOH (temp);
  138. buffer |= (temp &lt;&lt; bits);
  139. if (bits == 0)
  140. {
  141. bits = 8 * sizeof (buffer);
  142. }
  143. else
  144. {
  145. if (lseek (pib-&gt;file, -1, SEEK_CUR) == -1)
  146. {
  147. error (1, errno, &quot;could not seek backwards&quot;);
  148. }
  149. bits += 8 * (sizeof (buffer) - 1);
  150. }
  151. while (bits &gt;= 10)
  152. {
  153. value = (buffer &amp; 0x000003FF);
  154. printf (&quot;%08d %08X\n&quot;, index, value);
  155. buffer = buffer &gt;&gt; 10;
  156. ++index;
  157. bits -= 10;
  158. }
  159. }
  160. #elif 0
  161. uint32_t value;
  162. uint32_t temp;
  163. uint32_t buffer = 0;
  164. unsigned bits = 0;
  165. unsigned index = 0;
  166. if (lseek (pib-&gt;file, AMP_PRESCALER_OFFSET, SEEK_SET) != AMP_PRESCALER_OFFSET)
  167. {
  168. error (1, errno, FILE_CANTSEEK, pib-&gt;name);
  169. }
  170. /* more generic code, but requires math lib, add -lm to LFLAGS */
  171. while (index &lt; AMP_CARRIERS)
  172. {
  173. if (read (pib-&gt;file, &amp;temp, sizeof (temp)) != sizeof (temp))
  174. {
  175. error (1, errno, FILE_CANTREAD, pib-&gt;name);
  176. }
  177. temp = LE32TOH (temp);
  178. buffer |= (temp &lt;&lt; bits);
  179. if (lseek (pib-&gt;file, (off_t)(-ceil (bits / 8.0)), SEEK_CUR) == -1)
  180. {
  181. error (1, errno, &quot;could not seek backwards&quot;);
  182. }
  183. bits += 8 * (sizeof (buffer) - (unsigned)(ceil (bits / 8.0)));
  184. while (bits &gt;= 10)
  185. {
  186. value = (buffer &amp; 0x000003FF);
  187. printf (&quot;%08d %08X\n&quot;, index, value);
  188. buffer = buffer &gt;&gt; 10;
  189. ++index;
  190. bits -= 10;
  191. }
  192. }
  193. #else
  194. uint16_t upper;
  195. uint16_t lower;
  196. unsigned index = 0;
  197. byte buffer [AMP_PRESCALER_LENGTH];
  198. byte * p = buffer;
  199. if (lseek (pib-&gt;file, AMP_PRESCALER_OFFSET, SEEK_SET) != AMP_PRESCALER_OFFSET)
  200. {
  201. error (1, errno, FILE_CANTSEEK, pib-&gt;name);
  202. }
  203. if (read (pib-&gt;file, buffer, sizeof (buffer)) != sizeof (buffer))
  204. {
  205. error (1, errno, FILE_CANTREAD, pib-&gt;name);
  206. }
  207. /*
  208. * |00000000|00111111|11112222|22222233|33333333|
  209. * |01234567|89012345|67890123|45678901|23456789|
  210. */
  211. while (index &lt; AMP_CARRIERS)
  212. {
  213. lower = (*p++ &amp; 0xFF) &gt;&gt; 0;
  214. upper = (*p &amp; 0x03) &lt;&lt; 8;
  215. printf (&quot;%08d %08X\n&quot;, index++, upper | lower);
  216. lower = (*p++ &amp; 0xFC) &gt;&gt; 2;
  217. upper = (*p &amp; 0x0F) &lt;&lt; 6;
  218. printf (&quot;%08d %08X\n&quot;, index++, upper | lower);
  219. lower = (*p++ &amp; 0xF0) &gt;&gt; 4;
  220. upper = (*p &amp; 0x3F) &lt;&lt; 4;
  221. printf (&quot;%08d %08X\n&quot;, index++, upper | lower);
  222. lower = (*p++ &amp; 0xC0) &gt;&gt; 6;
  223. upper = (*p++ &amp; 0xFF) &lt;&lt; 2;
  224. printf (&quot;%08d %08X\n&quot;, index++, upper | lower);
  225. }
  226. #endif
  227. return;
  228. }
  229. /*====================================================================*
  230. *
  231. * void int6x00Prescalers (struct _file_ * pib);
  232. *
  233. *--------------------------------------------------------------------*/
  234. static void int6x00Prescalers (struct _file_ * pib)
  235. {
  236. unsigned index = 0;
  237. if (lseek (pib-&gt;file, INT_PRESCALER_OFFSET, SEEK_SET) != INT_PRESCALER_OFFSET)
  238. {
  239. error (1, errno, FILE_CANTSEEK, pib-&gt;name);
  240. }
  241. while (index &lt; INT_CARRIERS)
  242. {
  243. uint32_t value;
  244. if (read (pib-&gt;file, &amp;value, sizeof (value)) != sizeof (value))
  245. {
  246. error (1, errno, FILE_CANTREAD, pib-&gt;name);
  247. }
  248. printf (&quot;%08d %08X\n&quot;, index++, LE32TOH (value));
  249. }
  250. return;
  251. }
  252. /*====================================================================*
  253. *
  254. * void qca7x00Prescalers (struct _file_ * pib);
  255. *
  256. *--------------------------------------------------------------------*/
  257. static void qca7x00Prescalers (struct _file_ * pib)
  258. {
  259. unsigned index = 0;
  260. byte buffer [QCA_PRESCALER_LENGTH];
  261. byte * p = buffer;
  262. if (lseek (pib-&gt;file, QCA_PRESCALER_OFFSET, SEEK_SET) != QCA_PRESCALER_OFFSET)
  263. {
  264. error (1, errno, FILE_CANTSEEK, pib-&gt;name);
  265. }
  266. if (read (pib-&gt;file, buffer, sizeof (buffer)) != sizeof (buffer))
  267. {
  268. error (1, errno, FILE_CANTREAD, pib-&gt;name);
  269. }
  270. while (index &lt; PLC_CARRIERS)
  271. {
  272. printf (&quot;%08d %08x\n&quot;, index++, *p++);
  273. }
  274. }
  275. /*====================================================================*
  276. *
  277. * int main (int argc, char const * argv [])
  278. *
  279. *
  280. *--------------------------------------------------------------------*/
  281. int main (int argc, char const * argv [])
  282. {
  283. static char const * optv [] =
  284. {
  285. &quot;&quot;,
  286. &quot;pibfile [&gt; scalers]&quot;,
  287. &quot;Export PIB Prescalers&quot;,
  288. (char const *) (0)
  289. };
  290. struct _file_ pib;
  291. unsigned scalers;
  292. signed c;
  293. optind = 1;
  294. while ((c = getoptv (argc, argv, optv)) != -1)
  295. {
  296. switch ((char) (c))
  297. {
  298. default:
  299. break;
  300. }
  301. }
  302. argc -= optind;
  303. argv += optind;
  304. if (argc &gt; 1)
  305. {
  306. error (1, ENOTSUP, &quot;Only one file is permitted&quot;);
  307. }
  308. if ((argc) &amp;&amp; (* argv))
  309. {
  310. pib.name = * argv;
  311. if ((pib.file = open (pib.name, O_BINARY|O_RDONLY)) == -1)
  312. {
  313. error (1, errno, &quot;Can't open %s&quot;, pib.name);
  314. }
  315. if (pibfile (&amp;pib))
  316. {
  317. error (1, errno, &quot;Bad PIB file: %s&quot;, pib.name);
  318. }
  319. scalers = pibscalers (&amp;pib);
  320. if (scalers == PLC_CARRIERS)
  321. {
  322. qca7x00Prescalers (&amp;pib);
  323. }
  324. else if (scalers == AMP_CARRIERS)
  325. {
  326. ar7x00Prescalers (&amp;pib);
  327. }
  328. else if (scalers == INT_CARRIERS)
  329. {
  330. int6x00Prescalers (&amp;pib);
  331. }
  332. else
  333. {
  334. error (1, ENOTSUP, &quot;Unexpected number of carriers&quot;);
  335. }
  336. close (pib.file);
  337. }
  338. return (0);
  339. }
  340. </pre>
  341. <div class='footerlink'>
  342. [<a href='psnotch.c.html' title=' psnotch.c '>PREV</a>]
  343. [<a href='toolkit.html' title=' Index '>HOME</a>]
  344. [<a href='psread.c.html' title=' psread.c '>NEXT</a>]
  345. </div>
  346. </body>
  347. </html>