Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usb0_function_intrn.c 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_function_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_function.h"
  39. /*******************************************************************************
  40. Typedef definitions
  41. *******************************************************************************/
  42. /*******************************************************************************
  43. Macro definitions
  44. *******************************************************************************/
  45. /*******************************************************************************
  46. Imported global variables and functions (from other files)
  47. *******************************************************************************/
  48. /*******************************************************************************
  49. Exported global variables and functions (to be accessed by other files)
  50. *******************************************************************************/
  51. /*******************************************************************************
  52. Private global variables and functions
  53. *******************************************************************************/
  54. /*******************************************************************************
  55. * Function Name: usb0_function_brdy_int
  56. * Description : Executes BRDY interrupt(USB_FUNCTION_PIPE1-9).
  57. * : According to the pipe that interrupt is generated in,
  58. * : reads/writes buffer allocated in the pipe.
  59. * : This function is executed in the BRDY interrupt handler.
  60. * : This function clears BRDY interrupt status and BEMP interrupt
  61. * : status.
  62. * Arguments : uint16_t Status ; BRDYSTS Register Value
  63. * : uint16_t Int_enbl ; BRDYENB Register Value
  64. * Return Value : none
  65. *******************************************************************************/
  66. #if 0
  67. void usb0_function_brdy_int (uint16_t status, uint16_t int_enb)
  68. {
  69. uint32_t int_sense = 0;
  70. uint16_t pipe;
  71. uint16_t pipebit;
  72. for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
  73. {
  74. pipebit = g_usb0_function_bit_set[pipe];
  75. if ((status & pipebit) && (int_enb & pipebit))
  76. {
  77. USB200.BRDYSTS = (uint16_t)~pipebit;
  78. USB200.BEMPSTS = (uint16_t)~pipebit;
  79. if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D0FIFO_DMA)
  80. {
  81. if (g_usb0_function_DmaStatus[USB_FUNCTION_D0FIFO] != USB_FUNCTION_DMA_READY)
  82. {
  83. usb0_function_dma_interrupt_d0fifo(int_sense);
  84. }
  85. if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  86. {
  87. usb0_function_read_dma(pipe);
  88. usb0_function_disable_brdy_int(pipe);
  89. }
  90. else
  91. {
  92. USB200.D0FIFOCTR = USB_FUNCTION_BITBCLR;
  93. g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
  94. }
  95. }
  96. else if ((g_usb0_function_PipeTbl[pipe] & USB_FUNCTION_FIFO_USE) == USB_FUNCTION_D1FIFO_DMA)
  97. {
  98. if (g_usb0_function_DmaStatus[USB_FUNCTION_D1FIFO] != USB_FUNCTION_DMA_READY)
  99. {
  100. usb0_function_dma_interrupt_d1fifo(int_sense);
  101. }
  102. if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  103. {
  104. usb0_function_read_dma(pipe);
  105. usb0_function_disable_brdy_int(pipe);
  106. }
  107. else
  108. {
  109. USB200.D1FIFOCTR = USB_FUNCTION_BITBCLR;
  110. g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
  111. }
  112. }
  113. else
  114. {
  115. if (RZA_IO_RegRead_16(&g_usb0_function_pipecfg[pipe], USB_PIPECFG_DIR_SHIFT, USB_PIPECFG_DIR) == 0)
  116. {
  117. usb0_function_read_buffer(pipe);
  118. }
  119. else
  120. {
  121. usb0_function_write_buffer(pipe);
  122. }
  123. }
  124. }
  125. }
  126. }
  127. #endif
  128. /*******************************************************************************
  129. * Function Name: usb0_function_nrdy_int
  130. * Description : Executes NRDY interrupt(USB_FUNCTION_PIPE1-9).
  131. * : Checks NRDY interrupt cause by PID. When the cause if STALL,
  132. * : regards the pipe state as STALL and ends the processing.
  133. * : Then the cause is not STALL, increments the error count to
  134. * : communicate again. When the error count is 3, determines
  135. * : the pipe state as DEVDRV_USBF_PIPE_NORES and ends the processing.
  136. * : This function is executed in the NRDY interrupt handler.
  137. * : This function clears NRDY interrupt status.
  138. * Arguments : uint16_t status ; NRDYSTS Register Value
  139. * : uint16_t int_enb ; NRDYENB Register Value
  140. * Return Value : none
  141. *******************************************************************************/
  142. void usb0_function_nrdy_int (uint16_t status, uint16_t int_enb)
  143. {
  144. uint16_t pid;
  145. uint16_t pipe;
  146. uint16_t bitcheck;
  147. bitcheck = (uint16_t)(status & int_enb);
  148. USB200.NRDYSTS = (uint16_t)~status;
  149. for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
  150. {
  151. if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
  152. {
  153. if (RZA_IO_RegRead_16(&USB200.SYSCFG0, USB_SYSCFG_DCFM_SHIFT, USB_SYSCFG_DCFM) == 1)
  154. {
  155. if (g_usb0_function_pipe_status[pipe] == DEVDRV_USBF_PIPE_WAIT)
  156. {
  157. pid = usb0_function_get_pid(pipe);
  158. if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
  159. {
  160. g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
  161. }
  162. else
  163. {
  164. g_usb0_function_PipeIgnore[pipe]++;
  165. if (g_usb0_function_PipeIgnore[pipe] == 3)
  166. {
  167. g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_NORES;
  168. }
  169. else
  170. {
  171. usb0_function_set_pid_buf(pipe);
  172. }
  173. }
  174. }
  175. }
  176. else
  177. {
  178. /* USB Function */
  179. }
  180. }
  181. }
  182. }
  183. /*******************************************************************************
  184. * Function Name: usb0_function_bemp_int
  185. * Description : Executes BEMP interrupt(USB_FUNCTION_PIPE1-9).
  186. * Arguments : uint16_t status ; BEMPSTS Register Value
  187. * : uint16_t int_enb ; BEMPENB Register Value
  188. * Return Value : none
  189. *******************************************************************************/
  190. void usb0_function_bemp_int (uint16_t status, uint16_t int_enb)
  191. {
  192. uint16_t pid;
  193. uint16_t pipe;
  194. uint16_t bitcheck;
  195. uint16_t inbuf;
  196. bitcheck = (uint16_t)(status & int_enb);
  197. USB200.BEMPSTS = (uint16_t)~status;
  198. for (pipe = USB_FUNCTION_PIPE1; pipe <= USB_FUNCTION_MAX_PIPE_NO; pipe++)
  199. {
  200. if ((bitcheck&g_usb0_function_bit_set[pipe]) == g_usb0_function_bit_set[pipe])
  201. {
  202. pid = usb0_function_get_pid(pipe);
  203. if ((pid == DEVDRV_USBF_PID_STALL) || (pid == DEVDRV_USBF_PID_STALL2))
  204. {
  205. g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_STALL;
  206. }
  207. else
  208. {
  209. inbuf = usb0_function_get_inbuf(pipe);
  210. if (inbuf == 0)
  211. {
  212. usb0_function_disable_bemp_int(pipe);
  213. usb0_function_set_pid_nak(pipe);
  214. g_usb0_function_pipe_status[pipe] = DEVDRV_USBF_PIPE_DONE;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. /* End of File */