mdiogen.c.html 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. mdiogen.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='mdiodump.c.html' title=' mdiodump.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='mdustats.c.html' title=' mdustats.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. /*====================================================================*&quot;
  62. *
  63. * mdiogen.c -
  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;unistd.h&gt;
  76. #include &lt;fcntl.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/number.h&quot;
  83. #include &quot;../tools/memory.h&quot;
  84. #include &quot;../tools/endian.h&quot;
  85. #include &quot;../tools/error.h&quot;
  86. #include &quot;../mdio/mdio.h&quot;
  87. /*====================================================================*
  88. * custom source files;
  89. *--------------------------------------------------------------------*/
  90. #ifndef MAKEFILE
  91. #include &quot;../tools/error.c&quot;
  92. #endif
  93. /*====================================================================*
  94. * program variables;
  95. *--------------------------------------------------------------------*/
  96. const char * program_name;
  97. /*====================================================================*
  98. *
  99. * void regview (void const * memory, uint16_t offset, uint16_t length, FILE *fp);
  100. *
  101. * memory.h
  102. *
  103. * print memory as a binary dump showing absolute memory offsets and
  104. * 16-bit binary register maps; sample output looks like:
  105. *
  106. * ADDR DATA 5432-1098-7654-3210
  107. * 0000 0000 0000-0000-0000-0000
  108. * 0002 0000 0000-0000-0000-0000
  109. * 0004 0000 0000-0000-0000-0000
  110. * 0008 0000 0000-0000-0000-0000
  111. * 0010 0000 0000-0000-0000-0000
  112. *
  113. *
  114. *--------------------------------------------------------------------*/
  115. static void regview (void const * memory, uint16_t offset, uint16_t extent, FILE *fp)
  116. {
  117. uint16_t * origin = (uint16_t *)(memory);
  118. printf (&quot;ADDR DATA 5432-1098-7654-3210\n&quot;);
  119. while (extent &gt;= sizeof (* origin))
  120. {
  121. signed bit = sizeof (* origin) &lt;&lt; 3;
  122. printf (&quot;%04u &quot;, offset);
  123. printf (&quot;%04X &quot;, LE16TOH (*origin));
  124. while (bit--)
  125. {
  126. putc (((* origin &gt;&gt; bit) &amp; 1)? '1': '0', fp);
  127. if ((bit) &amp;&amp; !(bit%4))
  128. {
  129. putc ('-', fp);
  130. }
  131. }
  132. putc ('\n', fp);
  133. offset += sizeof (* origin);
  134. extent -= sizeof (* origin);
  135. origin++;
  136. }
  137. return;
  138. }
  139. /*====================================================================*
  140. *
  141. * int main (int argc, const char * argv []);
  142. *
  143. * this is a basic program that produces an MDIO program block
  144. * using macros defined in mdio.h; the output filename is fixed;
  145. *
  146. * declare your MDIO program by editing array program [] based on
  147. * the MDIO program rules defined in the Atheros PLC Firmware TRM
  148. * under the description of the VS_MOD_OP;
  149. *
  150. *
  151. *--------------------------------------------------------------------*/
  152. #define MDIO_PROGRAM &quot;mdio.bin&quot;
  153. int main (int argc, const char * argv [])
  154. {
  155. uint16_t program [] =
  156. {
  157. #if 1
  158. MDIO16_START (1, 0, 9),
  159. MDIO16_INSTR (1, 1, 0x18, 0x00, 2),
  160. 0x0000,
  161. 0xFFFF,
  162. MDIO16_INSTR (1, 1, 0x10, 0x16, 2),
  163. 0x003F,
  164. 0xFFFF,
  165. MDIO16_INSTR (1, 1, 0x10, 0x17, 2),
  166. 0x7E3F,
  167. 0xFFFF,
  168. MDIO16_INSTR (1, 1, 0x18, 0x00, 2),
  169. 0x0000,
  170. 0xFFFF,
  171. MDIO16_INSTR (1, 1, 0x10, 0x02, 2),
  172. 0x0700,
  173. 0xFFFF,
  174. MDIO16_INSTR (1, 1, 0x10, 0x03, 2),
  175. 0x0000,
  176. 0xFFFF,
  177. MDIO16_INSTR (1, 1, 0x18, 0x00, 2),
  178. 0x0000,
  179. 0xFFFF,
  180. MDIO16_INSTR (1, 1, 0x14, 0x00, 2),
  181. 0x007D,
  182. 0xFFFF,
  183. MDIO16_INSTR (1, 1, 0x14, 0x01, 2),
  184. 0x0000,
  185. 0xFFFF,
  186. #else
  187. MDIO16_START (1, 0, 24),
  188. MDIO32_INSTR (0x2c, 0x7e3f003f, 0xffffffff),
  189. MDIO32_INSTR (0x8, 0x500, 0xffffffff),
  190. MDIO32_INSTR (0x100, 0x7d, 0xffffffff),
  191. MDIO32_INSTR (0x30, 0x19f005f2, 0xffffffff),
  192. MDIO32_INSTR (0x200, 0x7d, 0xffffffff),
  193. MDIO32_INSTR (0x300, 0x7d, 0xffffffff),
  194. MDIO32_INSTR (0x400, 0x7d, 0xffffffff),
  195. MDIO32_INSTR (0x500, 0x7d, 0xffffffff),
  196. #endif
  197. };
  198. signed fd;
  199. program_name = * argv;
  200. if (--argc)
  201. {
  202. error (1, ECANCELED, &quot;Too many command line arguments&quot;);
  203. }
  204. regview (&amp;program, 0, sizeof (program), stdout);
  205. if ((fd = open (MDIO_PROGRAM, O_CREAT|O_WRONLY|O_TRUNC, S_IRWXU | S_IRGRP | S_IROTH)) == -1)
  206. {
  207. error (1, errno, &quot;Can't open %s&quot;, MDIO_PROGRAM);
  208. }
  209. if (write (fd, program, sizeof (program)) != sizeof (program))
  210. {
  211. unlink (MDIO_PROGRAM);
  212. error (1, errno, &quot;Can't write %s&quot;, MDIO_PROGRAM);
  213. }
  214. if (sizeof (program) % sizeof (uint32_t))
  215. {
  216. uint32_t zeros = 0;
  217. ssize_t count = sizeof (uint32_t) - sizeof (program) % sizeof (uint32_t);
  218. if (write (fd, &amp;zeros, count) != count)
  219. {
  220. unlink (MDIO_PROGRAM);
  221. error (1, errno, &quot;Can't write %s&quot;, MDIO_PROGRAM);
  222. }
  223. }
  224. close (fd);
  225. return (0);
  226. }
  227. </pre>
  228. <div class='footerlink'>
  229. [<a href='mdiodump.c.html' title=' mdiodump.c '>PREV</a>]
  230. [<a href='toolkit.html' title=' Index '>HOME</a>]
  231. [<a href='mdustats.c.html' title=' mdustats.c '>NEXT</a>]
  232. </div>
  233. </body>
  234. </html>