Keyboard firmwares for Atmel AVR and Cortex-M
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

usb0_host_intrn.c 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*******************************************************************************
  2. * DISCLAIMER
  3. * This software is supplied by Renesas Electronics Corporation and is only
  4. * intended for use with Renesas products. No other uses are authorized. This
  5. * software is owned by Renesas Electronics Corporation and is protected under
  6. * all applicable laws, including copyright laws.
  7. * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
  8. * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
  9. * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
  10. * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
  11. * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
  12. * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
  13. * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
  14. * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
  15. * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  16. * Renesas reserves the right, without notice, to make changes to this software
  17. * and to discontinue the availability of this software. By using this software,
  18. * you agree to the additional terms and conditions found by accessing the
  19. * following link:
  20. * http://www.renesas.com/disclaimer
  21. * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
  22. *******************************************************************************/
  23. /*******************************************************************************
  24. * File Name : usb0_host_intrn.c
  25. * $Rev: 1116 $
  26. * $Date:: 2014-07-09 16:29:19 +0900#$
  27. * Device(s) : RZ/A1H
  28. * Tool-Chain :
  29. * OS : None
  30. * H/W Platform :
  31. * Description : RZ/A1H R7S72100 USB Sample Program
  32. * Operation :
  33. * Limitations :
  34. *******************************************************************************/
  35. /*******************************************************************************
  36. Includes <System Includes> , "Project Includes"
  37. *******************************************************************************/
  38. #include "usb0_host.h"
  39. #if(1) /* ohci_wrapp */
  40. #include "ohci_wrapp_RZ_A1_local.h"
  41. #endif
  42. /*******************************************************************************
  43. Typedef definitions
  44. *******************************************************************************/
  45. /*******************************************************************************
  46. Macro definitions
  47. *******************************************************************************/
  48. /*******************************************************************************
  49. Imported global variables and functions (from other files)
  50. *******************************************************************************/
  51. /*******************************************************************************
  52. Exported global variables and functions (to be accessed by other files)
  53. *******************************************************************************/
  54. /*******************************************************************************
  55. Private global variables and functions
  56. *******************************************************************************/
  57. /*******************************************************************************
  58. * Function Name: usb0_host_brdy_int
  59. * Description : Executes BRDY interrupt(USB_HOST_PIPE1-9).
  60. * : According to the pipe that interrupt is generated in,
  61. * : reads/writes buffer allocated in the pipe.
  62. * : This function is executed in the BRDY interrupt handler.
  63. * : This function clears BRDY interrupt status and BEMP interrupt
  64. * : status.
  65. * Arguments : uint16_t status ; BRDYSTS Register Value
  66. * : uint16_t int_enb ; BRDYENB Register Value
  67. * Return Value : none
  68. *******************************************************************************/
  69. void usb0_host_brdy_int (uint16_t status, uint16_t int_enb)
  70. {
  71. uint32_t int_sense = 0;
  72. uint16_t pipe;
  73. uint16_t pipebit;
  74. for (pipe = USB_HOST_PIPE1; pipe <= USB_HOST_MAX_PIPE_NO; pipe++)
  75. {
  76. pipebit = g_usb0_host_bit_set[pipe];
  77. if ((status & pipebit) && (int_enb & pipebit))
  78. {
  79. USB200.BRDYSTS = (uint16_t)~pipebit;
  80. USB200.BEMPSTS = (uint16_t)~pipebit;
  81. if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_DMA)
  82. {
  83. if (g_usb0_host_DmaStatus[USB_HOST_D0FIFO] != USB_HOST_DMA_READY)
  84. {
  85. usb0_host_dma_interrupt_d0fifo(int_sense);
  86. }
  87. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  88. {
  89. usb0_host_read_dma(pipe);
  90. usb0_host_disable_brdy_int(pipe);
  91. }
  92. else
  93. {
  94. USB200.D0FIFOCTR = USB_HOST_BITBCLR;
  95. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  96. }
  97. }
  98. else if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_DMA)
  99. {
  100. if (g_usb0_host_DmaStatus[USB_HOST_D1FIFO] != USB_HOST_DMA_READY)
  101. {
  102. usb0_host_dma_interrupt_d1fifo(int_sense);
  103. }
  104. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  105. {
  106. usb0_host_read_dma(pipe);
  107. usb0_host_disable_brdy_int(pipe);
  108. }
  109. else
  110. {
  111. USB200.D1FIFOCTR = USB_HOST_BITBCLR;
  112. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  113. }
  114. }
  115. else
  116. {
  117. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
  118. {
  119. usb0_host_read_buffer(pipe);
  120. }
  121. else
  122. {
  123. usb0_host_write_buffer(pipe);
  124. }
  125. }
  126. #if(1) /* ohci_wrapp */
  127. switch (g_usb0_host_pipe_status[pipe])
  128. {
  129. case USB_HOST_PIPE_DONE:
  130. ohciwrapp_loc_TransEnd(pipe, TD_CC_NOERROR);
  131. break;
  132. case USB_HOST_PIPE_NORES:
  133. case USB_HOST_PIPE_STALL:
  134. case USB_HOST_PIPE_ERROR:
  135. ohciwrapp_loc_TransEnd(pipe, TD_CC_STALL);
  136. break;
  137. default:
  138. /* Do Nothing */
  139. break;
  140. }
  141. #endif
  142. }
  143. }
  144. }
  145. /*******************************************************************************
  146. * Function Name: usb0_host_nrdy_int
  147. * Description : Executes NRDY interrupt(USB_HOST_PIPE1-9).
  148. * : Checks NRDY interrupt cause by PID. When the cause if STALL,
  149. * : regards the pipe state as STALL and ends the processing.
  150. * : Then the cause is not STALL, increments the error count to
  151. * : communicate again. When the error count is 3, determines
  152. * : the pipe state as USB_HOST_PIPE_NORES and ends the processing.
  153. * : This function is executed in the NRDY interrupt handler.
  154. * : This function clears NRDY interrupt status.
  155. * Arguments : uint16_t status ; NRDYSTS Register Value
  156. * : uint16_t int_enb ; NRDYENB Register Value
  157. * Return Value : none
  158. *******************************************************************************/
  159. void usb0_host_nrdy_int (uint16_t status, uint16_t int_enb)
  160. {
  161. uint16_t pid;
  162. uint16_t pipe;
  163. uint16_t bitcheck;
  164. bitcheck = (uint16_t)(status & int_enb);
  165. USB200.NRDYSTS = (uint16_t)~status;
  166. for (pipe = USB_HOST_PIPE1; pipe <= USB_HOST_MAX_PIPE_NO; pipe++)
  167. {
  168. if ((bitcheck&g_usb0_host_bit_set[pipe]) == g_usb0_host_bit_set[pipe])
  169. {
  170. if (RZA_IO_RegRead_16(&USB200.SYSCFG0,
  171. USB_SYSCFG_DCFM_SHIFT,
  172. USB_SYSCFG_DCFM) == 1)
  173. {
  174. if (g_usb0_host_pipe_status[pipe] == USB_HOST_PIPE_WAIT)
  175. {
  176. pid = usb0_host_get_pid(pipe);
  177. if ((pid == USB_HOST_PID_STALL) || (pid == USB_HOST_PID_STALL2))
  178. {
  179. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_STALL;
  180. #if(1) /* ohci_wrapp */
  181. ohciwrapp_loc_TransEnd(pipe, TD_CC_STALL);
  182. #endif
  183. }
  184. else
  185. {
  186. #if(1) /* ohci_wrapp */
  187. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_NORES;
  188. ohciwrapp_loc_TransEnd(pipe, TD_CC_DEVICENOTRESPONDING);
  189. #else
  190. g_usb0_host_PipeIgnore[pipe]++;
  191. if (g_usb0_host_PipeIgnore[pipe] == 3)
  192. {
  193. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_NORES;
  194. }
  195. else
  196. {
  197. usb0_host_set_pid_buf(pipe);
  198. }
  199. #endif
  200. }
  201. }
  202. }
  203. else
  204. {
  205. /* USB Function */
  206. }
  207. }
  208. }
  209. }
  210. /*******************************************************************************
  211. * Function Name: usb0_host_bemp_int
  212. * Description : Executes BEMP interrupt(USB_HOST_PIPE1-9).
  213. * Arguments : uint16_t status ; BEMPSTS Register Value
  214. * : uint16_t int_enb ; BEMPENB Register Value
  215. * Return Value : none
  216. *******************************************************************************/
  217. void usb0_host_bemp_int (uint16_t status, uint16_t int_enb)
  218. {
  219. uint16_t pid;
  220. uint16_t pipe;
  221. uint16_t bitcheck;
  222. uint16_t inbuf;
  223. bitcheck = (uint16_t)(status & int_enb);
  224. USB200.BEMPSTS = (uint16_t)~status;
  225. for (pipe = USB_HOST_PIPE1; pipe <= USB_HOST_MAX_PIPE_NO; pipe++)
  226. {
  227. if ((bitcheck&g_usb0_host_bit_set[pipe]) == g_usb0_host_bit_set[pipe])
  228. {
  229. pid = usb0_host_get_pid(pipe);
  230. if ((pid == USB_HOST_PID_STALL) || (pid == USB_HOST_PID_STALL2))
  231. {
  232. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_STALL;
  233. #if(1) /* ohci_wrapp */
  234. ohciwrapp_loc_TransEnd(pipe, TD_CC_STALL);
  235. #endif
  236. }
  237. else
  238. {
  239. inbuf = usb0_host_get_inbuf(pipe);
  240. if (inbuf == 0)
  241. {
  242. usb0_host_disable_bemp_int(pipe);
  243. usb0_host_set_pid_nak(pipe);
  244. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  245. #if(1) /* ohci_wrapp */
  246. ohciwrapp_loc_TransEnd(pipe, TD_CC_NOERROR);
  247. #endif
  248. }
  249. }
  250. }
  251. }
  252. }
  253. /* End of File */