pseudo.c.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. pseudo.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='PrintRule.c.html' title=' PrintRule.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='psgraph.c.html' title=' psgraph.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * encapsulate and transmit as many Ethernet frames as possible
  24. * without overflowing the SPI write buffer;
  25. *
  26. *--------------------------------------------------------------------*/
  27. function transmit frame do read write buffer space available register;
  28. while transmit queue is not empty and write buffer space is available do encapsulate transmit frame;
  29. write transmit frame to write buffer;
  30. if error then return failure;
  31. end if;
  32. update transmit statistics;
  33. remove frame from transmit queue;
  34. end while;
  35. return (success);
  36. end function;
  37. /*====================================================================*
  38. *
  39. * read as many frames as possible from the read buffer;
  40. *
  41. *--------------------------------------------------------------------*/
  42. function receive frame do allocate an input buffer;
  43. if no memory available then return failure;
  44. end if;
  45. read read space available register;
  46. if read buffer is empty then return failure;
  47. end if;
  48. write frame length into buffer size register;
  49. if mode is legacy then send read command;
  50. end if;
  51. while read buffer is not empty do read read buffer into frame buffer;
  52. extract Ethernet frame from frame buffer;
  53. update read statistics;
  54. end while;
  55. return (success);
  56. end function;
  57. /*====================================================================*
  58. *
  59. * state machine to manage QCA7000 SPI slave synchronization;
  60. *
  61. *--------------------------------------------------------------------*/
  62. function synchronize SPI slave do allocate a static reset counter;
  63. if synchronization state is CPU on then read QCA7000 signature register;
  64. read QCA7000 signature register;
  65. if signature is invalid then set synchronization state to unknown;
  66. else read SPI write buffer space available register;
  67. if write buffer is empty then qca-&gt;SynchState = QCASPI_SYNC_READY;
  68. set synchronization state to ready;
  69. return;
  70. else set synchronization state to unknown;
  71. end if;
  72. end if;
  73. end if;
  74. if synchronization stats is ready then if mode is legacy then return;
  75. end if;
  76. read QCA7000 signature register;
  77. if signature is invalid then set synchronization state to unknown;
  78. return;
  79. end if;
  80. end if;
  81. if synchronization state is unknown then if mode is legacy then use GPIO to reset QCA7000;
  82. else read QCA7000 signature register;
  83. if signature is invalid then return;
  84. end if;
  85. set soc_core_reset bit in QCA SPI configuration register;
  86. end if set synchronization state to reset;
  87. clear reset counter;
  88. return;
  89. end if;
  90. if synchronization state is reset then increment reset counter;
  91. if reset counter exceeds reset limit then set synchronization state to unknown;
  92. end if;
  93. end if;
  94. return;
  95. end function;
  96. /*====================================================================*
  97. *
  98. * handle QCA7000 interrupts and transmit requests; interrupts are
  99. * from the QCA7000; transmit requests are from the host computer;
  100. *
  101. *--------------------------------------------------------------------*/
  102. function interrupt serivce routine do while terminate is false do set thread state to interruptable;
  103. if no interrupts and synchronization state is synchronized and transmit queue is empty then allow other tasks to run;
  104. end if set thread state to busy;
  105. check synchronization state;
  106. if syncrhonization state is not synchronized then flush transmit queue;
  107. suspend for a while;
  108. end if;
  109. if interrupt occurred then disable SPI interrupts;
  110. read SPI interrupt cause register;
  111. if SPI interrupt cause is CPU on then update synchronization state;
  112. if synchronization state is synchronized then continue;
  113. end if;
  114. end if;
  115. if SPI interrupt cause is packet available then if synchronization state is synchronized then call receive frame function;
  116. end if;
  117. end if;
  118. if SPI interrupt cause is read buffer error then set synchronization state to unknown;
  119. continue;
  120. end if;
  121. if SPI interrupt cause is write buffer error then set synchronization state to unknown;
  122. continue;
  123. end if;
  124. clear SPI interrupt cause register;
  125. clear SPI interrupt register;
  126. end if;
  127. if transmit queue is not empty then call transmit frame function;
  128. end if;
  129. end while;
  130. set thread state to dormant;
  131. return;
  132. end function;
  133. /*====================================================================*
  134. *
  135. * basic interrupt handler; count interrupts since last service;
  136. * wake up dormant service routine;
  137. *
  138. *--------------------------------------------------------------------*/
  139. function interrupt handler do increment interrupt count;
  140. if thread is available and thread is dormant then wake up thread to service interrupt;
  141. end if;
  142. return (success);
  143. end function;
  144. </pre>
  145. <div class='footerlink'>
  146. [<a href='PrintRule.c.html' title=' PrintRule.c '>PREV</a>]
  147. [<a href='toolkit.html' title=' Index '>HOME</a>]
  148. [<a href='psgraph.c.html' title=' psgraph.c '>NEXT</a>]
  149. </div>
  150. </body>
  151. </html>