psin.c.html 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. psin.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='psgraph.c.html' title=' psgraph.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='pskey.c.html' title=' pskey.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. * psin.c - load prescalers into int6000 parameter file;
  64. *
  65. *
  66. * Contributor(s):
  67. * Charles Maier &lt;cmaier@qca.qualcomm.com&gt;
  68. * Nathaniel Houghton &lt;nhoughto@qca.qualcomm.com&gt;
  69. *
  70. *--------------------------------------------------------------------*/
  71. /*====================================================================*
  72. * system header files;
  73. *--------------------------------------------------------------------*/
  74. #include &lt;stdio.h&gt;
  75. #include &lt;stdint.h&gt;
  76. #include &lt;ctype.h&gt;
  77. #include &lt;string.h&gt;
  78. #include &lt;unistd.h&gt;
  79. #include &lt;errno.h&gt;
  80. /*====================================================================*
  81. * custom header files;
  82. *--------------------------------------------------------------------*/
  83. #include &quot;../tools/endian.h&quot;
  84. #include &quot;../tools/getoptv.h&quot;
  85. #include &quot;../tools/number.h&quot;
  86. #include &quot;../tools/chars.h&quot;
  87. #include &quot;../tools/types.h&quot;
  88. #include &quot;../tools/error.h&quot;
  89. #include &quot;../tools/files.h&quot;
  90. #include &quot;../key/HPAVKey.h&quot;
  91. #include &quot;../pib/pib.h&quot;
  92. #include &quot;../plc/plc.h&quot;
  93. /*====================================================================*
  94. * custom source files;
  95. *--------------------------------------------------------------------*/
  96. #ifndef MAKEFILE
  97. #include &quot;../tools/getoptv.c&quot;
  98. #include &quot;../tools/putoptv.c&quot;
  99. #include &quot;../tools/version.c&quot;
  100. #include &quot;../tools/fdchecksum32.c&quot;
  101. #include &quot;../tools/hexdecode.c&quot;
  102. #include &quot;../tools/hexstring.c&quot;
  103. #include &quot;../tools/todigit.c&quot;
  104. #include &quot;../tools/error.c&quot;
  105. #endif
  106. #ifndef MAKEFILE
  107. #include &quot;../pib/pibfile1.c&quot;
  108. #include &quot;../pib/piblock.c&quot;
  109. #include &quot;../pib/pibscalers.c&quot;
  110. #endif
  111. #ifndef MAKEFILE
  112. #include &quot;../key/keys.c&quot;
  113. #endif
  114. /*====================================================================*
  115. *
  116. *
  117. * signed ar7x00_psin (struct _file_ * pib, uint32_t value, uint32_t index);
  118. *
  119. * Places a single 10 bit prescaler into the pib file at index;
  120. *
  121. *--------------------------------------------------------------------*/
  122. signed ar7x00_psin (struct _file_ * pib, uint32_t value, uint32_t index)
  123. {
  124. off_t offset = AMP_PRESCALER_OFFSET + (index * 10 / 8);
  125. uint8_t bit_offset = (index * 10) % 8;
  126. uint16_t tmp;
  127. if (lseek (pib-&gt;file, offset, SEEK_SET) != offset)
  128. {
  129. return (-1);
  130. }
  131. if (read (pib-&gt;file, &amp;tmp, sizeof (tmp)) != sizeof (tmp))
  132. {
  133. return (-1);
  134. }
  135. if (lseek (pib-&gt;file, offset, SEEK_SET) != offset)
  136. {
  137. return (-1);
  138. }
  139. value &amp;= 0x03FF;
  140. tmp = LE16TOH (tmp);
  141. tmp &amp;= ~(0x03FF &lt;&lt; bit_offset);
  142. tmp |= value &lt;&lt; bit_offset;
  143. tmp = HTOLE16 (tmp);
  144. if (write (pib-&gt;file, &amp;tmp, sizeof (tmp)) != sizeof (tmp))
  145. {
  146. return (-1);
  147. }
  148. return (0);
  149. }
  150. /*====================================================================*
  151. *
  152. * signed psin (struct _file_ * pib);
  153. *
  154. *
  155. *--------------------------------------------------------------------*/
  156. static signed psin (struct _file_ * pib)
  157. {
  158. unsigned index = 0;
  159. unsigned count = 0;
  160. unsigned limit = pibscalers (pib);
  161. uint32_t value = 0;
  162. signed c;
  163. if ((limit != INT_CARRIERS) &amp;&amp; (limit != AMP_CARRIERS))
  164. {
  165. error (1, 0, &quot;Don't understand this PIB's prescaler format&quot;);
  166. }
  167. if (limit == INT_CARRIERS)
  168. {
  169. if (lseek (pib-&gt;file, INT_PRESCALER_OFFSET, SEEK_SET) != INT_PRESCALER_OFFSET)
  170. {
  171. error (1, errno, FILE_CANTSEEK, pib-&gt;name);
  172. }
  173. }
  174. while ((c = getc (stdin)) != EOF)
  175. {
  176. if (isspace (c))
  177. {
  178. continue;
  179. }
  180. if ((c == '#') || (c == ';'))
  181. {
  182. do
  183. {
  184. c = getc (stdin);
  185. }
  186. while (nobreak (c));
  187. continue;
  188. }
  189. index = 0;
  190. while (isdigit (c))
  191. {
  192. index *= 10;
  193. index += c - '0';
  194. c = getc (stdin);
  195. }
  196. if (index != count)
  197. {
  198. error (1, ECANCELED, &quot;Carrier %d out of order&quot;, index);
  199. }
  200. if (index &gt;= limit)
  201. {
  202. error (1, EOVERFLOW, &quot;Too many prescalers&quot;);
  203. }
  204. while (isblank (c))
  205. {
  206. c = getc (stdin);
  207. }
  208. value = 0;
  209. while (isxdigit (c))
  210. {
  211. value *= 16;
  212. value += todigit (c);
  213. c = getc (stdin);
  214. }
  215. if (limit == INT_CARRIERS)
  216. {
  217. value = HTOLE32 (value);
  218. if (write (pib-&gt;file, &amp;value, sizeof (value)) != sizeof (value))
  219. {
  220. error (1, errno, &quot;Can't save %s&quot;, pib-&gt;name);
  221. }
  222. }
  223. else if (limit == AMP_CARRIERS)
  224. {
  225. if (value &amp; ~0x03FF)
  226. {
  227. error (1, errno, &quot;Position %d has invalid prescaler value&quot;, index);
  228. }
  229. if (ar7x00_psin (pib, value, index))
  230. {
  231. error (1, errno, &quot;Can't update %s&quot;, pib-&gt;name);
  232. }
  233. }
  234. while (nobreak (c))
  235. {
  236. c = getc (stdin);
  237. };
  238. count++;
  239. }
  240. return (0);
  241. }
  242. /*====================================================================*
  243. *
  244. * int main (int argc, char const * argv [])
  245. *
  246. *
  247. *--------------------------------------------------------------------*/
  248. int main (int argc, char const * argv [])
  249. {
  250. static char const * optv [] =
  251. {
  252. &quot;&quot;,
  253. &quot;pibfile [&lt; scalers]&quot;,
  254. &quot;load prescalers into int6000 parameter file&quot;,
  255. (char const *) (0)
  256. };
  257. struct _file_ pib;
  258. signed c;
  259. optind = 1;
  260. while ((c = getoptv (argc, argv, optv)) != -1)
  261. {
  262. switch ((char) (c))
  263. {
  264. default:
  265. break;
  266. }
  267. }
  268. argc -= optind;
  269. argv += optind;
  270. if (argc &gt; 1)
  271. {
  272. error (1, ECANCELED, &quot;Only one target file allowed&quot;);
  273. }
  274. if ((argc) &amp;&amp; (* argv))
  275. {
  276. pib.name = * argv;
  277. if ((pib.file = open (pib.name, O_BINARY|O_RDWR)) == -1)
  278. {
  279. error (1, errno, &quot;Can't open %s&quot;, pib.name);
  280. }
  281. else if (pibfile1 (&amp;pib))
  282. {
  283. error (1, errno, &quot;Bad PIB file: %s&quot;, pib.name);
  284. }
  285. else if (psin (&amp;pib))
  286. {
  287. error (1, ECANCELED, &quot;%s&quot;, pib.name);
  288. }
  289. else if (piblock (&amp;pib))
  290. {
  291. error (1, ECANCELED, &quot;%s&quot;, pib.name);
  292. }
  293. close (pib.file);
  294. }
  295. return (0);
  296. }
  297. </pre>
  298. <div class='footerlink'>
  299. [<a href='psgraph.c.html' title=' psgraph.c '>PREV</a>]
  300. [<a href='toolkit.html' title=' Index '>HOME</a>]
  301. [<a href='pskey.c.html' title=' pskey.c '>NEXT</a>]
  302. </div>
  303. </body>
  304. </html>