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_host_dma.c 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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_dma.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. /* #include "usb0_host_dmacdrv.h" */
  40. /*******************************************************************************
  41. Typedef definitions
  42. *******************************************************************************/
  43. /*******************************************************************************
  44. Macro definitions
  45. *******************************************************************************/
  46. /*******************************************************************************
  47. Imported global variables and functions (from other files)
  48. *******************************************************************************/
  49. /*******************************************************************************
  50. Exported global variables and functions (to be accessed by other files)
  51. *******************************************************************************/
  52. /*******************************************************************************
  53. Private global variables and functions
  54. *******************************************************************************/
  55. static void usb0_host_dmaint(uint16_t fifo);
  56. static void usb0_host_dmaint_buf2fifo(uint16_t pipe);
  57. static void usb0_host_dmaint_fifo2buf(uint16_t pipe);
  58. /*******************************************************************************
  59. * Function Name: usb0_host_dma_stop_d0
  60. * Description : D0FIFO DMA stop
  61. * Arguments : uint16_t pipe : pipe number
  62. * : uint32_t remain : transfer byte
  63. * Return Value : none
  64. *******************************************************************************/
  65. void usb0_host_dma_stop_d0 (uint16_t pipe, uint32_t remain)
  66. {
  67. uint16_t dtln;
  68. uint16_t dfacc;
  69. uint16_t buffer;
  70. uint16_t sds_b = 1;
  71. dfacc = RZA_IO_RegRead_16(&USB200.D0FBCFG,
  72. USB_DnFBCFG_DFACC_SHIFT,
  73. USB_DnFBCFG_DFACC);
  74. if (dfacc == 2)
  75. {
  76. sds_b = 32;
  77. }
  78. else if (dfacc == 1)
  79. {
  80. sds_b = 16;
  81. }
  82. else
  83. {
  84. if (g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size == 2)
  85. {
  86. sds_b = 4;
  87. }
  88. else if (g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size == 1)
  89. {
  90. sds_b = 2;
  91. }
  92. else
  93. {
  94. sds_b = 1;
  95. }
  96. }
  97. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  98. {
  99. if (g_usb0_host_pipe_status[pipe] != USB_HOST_PIPE_DONE)
  100. {
  101. buffer = USB200.D0FIFOCTR;
  102. dtln = (buffer & USB_HOST_BITDTLN);
  103. if ((dtln % sds_b) != 0)
  104. {
  105. remain += (sds_b - (dtln % sds_b));
  106. }
  107. g_usb0_host_PipeDataSize[pipe] = (g_usb0_host_data_count[pipe] - remain);
  108. g_usb0_host_data_count[pipe] = remain;
  109. }
  110. }
  111. RZA_IO_RegWrite_16(&USB200.D0FIFOSEL,
  112. 0,
  113. USB_DnFIFOSEL_DREQE_SHIFT,
  114. USB_DnFIFOSEL_DREQE);
  115. }
  116. /*******************************************************************************
  117. * Function Name: usb0_host_dma_stop_d1
  118. * Description : D1FIFO DMA stop
  119. * Arguments : uint16_t pipe : pipe number
  120. * : uint32_t remain : transfer byte
  121. * Return Value : none
  122. *******************************************************************************/
  123. void usb0_host_dma_stop_d1 (uint16_t pipe, uint32_t remain)
  124. {
  125. uint16_t dtln;
  126. uint16_t dfacc;
  127. uint16_t buffer;
  128. uint16_t sds_b = 1;
  129. dfacc = RZA_IO_RegRead_16(&USB200.D1FBCFG,
  130. USB_DnFBCFG_DFACC_SHIFT,
  131. USB_DnFBCFG_DFACC);
  132. if (dfacc == 2)
  133. {
  134. sds_b = 32;
  135. }
  136. else if (dfacc == 1)
  137. {
  138. sds_b = 16;
  139. }
  140. else
  141. {
  142. if (g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size == 2)
  143. {
  144. sds_b = 4;
  145. }
  146. else if (g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size == 1)
  147. {
  148. sds_b = 2;
  149. }
  150. else
  151. {
  152. sds_b = 1;
  153. }
  154. }
  155. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
  156. {
  157. if (g_usb0_host_pipe_status[pipe] != USB_HOST_PIPE_DONE)
  158. {
  159. buffer = USB200.D1FIFOCTR;
  160. dtln = (buffer & USB_HOST_BITDTLN);
  161. if ((dtln % sds_b) != 0)
  162. {
  163. remain += (sds_b - (dtln % sds_b));
  164. }
  165. g_usb0_host_PipeDataSize[pipe] = (g_usb0_host_data_count[pipe] - remain);
  166. g_usb0_host_data_count[pipe] = remain;
  167. }
  168. }
  169. RZA_IO_RegWrite_16(&USB200.D1FIFOSEL,
  170. 0,
  171. USB_DnFIFOSEL_DREQE_SHIFT,
  172. USB_DnFIFOSEL_DREQE);
  173. }
  174. /*******************************************************************************
  175. * Function Name: usb0_host_dma_interrupt_d0fifo
  176. * Description : This function is DMA interrupt handler entry.
  177. * : Execute usb1_host_dmaint() after disabling DMA interrupt in this function.
  178. * : Disable DMA interrupt to DMAC executed when USB_HOST_D0FIFO_DMA is
  179. * : specified by dma->fifo.
  180. * : Register this function as DMA complete interrupt.
  181. * Arguments : uint32_t int_sense ; Interrupts detection mode
  182. * : ; INTC_LEVEL_SENSITIVE : Level sense
  183. * : ; INTC_EDGE_TRIGGER : Edge trigger
  184. * Return Value : none
  185. *******************************************************************************/
  186. void usb0_host_dma_interrupt_d0fifo (uint32_t int_sense)
  187. {
  188. usb0_host_dmaint(USB_HOST_D0FIFO);
  189. g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_READY;
  190. }
  191. /*******************************************************************************
  192. * Function Name: usb0_host_dma_interrupt_d1fifo
  193. * Description : This function is DMA interrupt handler entry.
  194. * : Execute usb0_host_dmaint() after disabling DMA interrupt in this function.
  195. * : Disable DMA interrupt to DMAC executed when USB_HOST_D1FIFO_DMA is
  196. * : specified by dma->fifo.
  197. * : Register this function as DMA complete interrupt.
  198. * Arguments : uint32_t int_sense ; Interrupts detection mode
  199. * : ; INTC_LEVEL_SENSITIVE : Level sense
  200. * : ; INTC_EDGE_TRIGGER : Edge trigger
  201. * Return Value : none
  202. *******************************************************************************/
  203. void usb0_host_dma_interrupt_d1fifo (uint32_t int_sense)
  204. {
  205. usb0_host_dmaint(USB_HOST_D1FIFO);
  206. g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_READY;
  207. }
  208. /*******************************************************************************
  209. * Function Name: usb0_host_dmaint
  210. * Description : This function is DMA transfer end interrupt
  211. * Arguments : uint16_t fifo ; fifo number
  212. * : ; USB_HOST_D0FIFO
  213. * : ; USB_HOST_D1FIFO
  214. * Return Value : none
  215. *******************************************************************************/
  216. static void usb0_host_dmaint (uint16_t fifo)
  217. {
  218. uint16_t pipe;
  219. pipe = g_usb0_host_DmaPipe[fifo];
  220. if (g_usb0_host_DmaInfo[fifo].dir == USB_HOST_BUF2FIFO)
  221. {
  222. usb0_host_dmaint_buf2fifo(pipe);
  223. }
  224. else
  225. {
  226. usb0_host_dmaint_fifo2buf(pipe);
  227. }
  228. }
  229. /*******************************************************************************
  230. * Function Name: usb0_host_dmaint_fifo2buf
  231. * Description : Executes read completion from FIFO by DMAC.
  232. * Arguments : uint16_t pipe : pipe number
  233. * Return Value : none
  234. *******************************************************************************/
  235. static void usb0_host_dmaint_fifo2buf (uint16_t pipe)
  236. {
  237. uint32_t remain;
  238. uint16_t useport;
  239. if (g_usb0_host_pipe_status[pipe] != USB_HOST_PIPE_DONE)
  240. {
  241. useport = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
  242. if (useport == USB_HOST_D0FIFO_DMA)
  243. {
  244. remain = Userdef_USB_usb0_host_stop_dma0();
  245. usb0_host_dma_stop_d0(pipe, remain);
  246. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  247. {
  248. if (g_usb0_host_DmaStatus[USB_HOST_D0FIFO] == USB_HOST_DMA_BUSYEND)
  249. {
  250. USB200.D0FIFOCTR = USB_HOST_BITBCLR;
  251. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  252. }
  253. else
  254. {
  255. usb0_host_enable_brdy_int(pipe);
  256. }
  257. }
  258. }
  259. else
  260. {
  261. remain = Userdef_USB_usb0_host_stop_dma1();
  262. usb0_host_dma_stop_d1(pipe, remain);
  263. if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
  264. {
  265. if (g_usb0_host_DmaStatus[USB_HOST_D1FIFO] == USB_HOST_DMA_BUSYEND)
  266. {
  267. USB200.D1FIFOCTR = USB_HOST_BITBCLR;
  268. g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
  269. }
  270. else
  271. {
  272. usb0_host_enable_brdy_int(pipe);
  273. }
  274. }
  275. }
  276. }
  277. }
  278. /*******************************************************************************
  279. * Function Name: usb0_host_dmaint_buf2fifo
  280. * Description : Executes write completion in FIFO by DMAC.
  281. * Arguments : uint16_t pipe : pipe number
  282. * Return Value : none
  283. *******************************************************************************/
  284. static void usb0_host_dmaint_buf2fifo (uint16_t pipe)
  285. {
  286. uint16_t useport;
  287. uint32_t remain;
  288. useport = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
  289. if (useport == USB_HOST_D0FIFO_DMA)
  290. {
  291. remain = Userdef_USB_usb0_host_stop_dma0();
  292. usb0_host_dma_stop_d0(pipe, remain);
  293. if (g_usb0_host_DmaBval[USB_HOST_D0FIFO] != 0)
  294. {
  295. RZA_IO_RegWrite_16(&USB200.D0FIFOCTR,
  296. 1,
  297. USB_DnFIFOCTR_BVAL_SHIFT,
  298. USB_DnFIFOCTR_BVAL);
  299. }
  300. }
  301. else
  302. {
  303. remain = Userdef_USB_usb0_host_stop_dma1();
  304. usb0_host_dma_stop_d1(pipe, remain);
  305. if (g_usb0_host_DmaBval[USB_HOST_D1FIFO] != 0)
  306. {
  307. RZA_IO_RegWrite_16(&USB200.D1FIFOCTR,
  308. 1,
  309. USB_DnFIFOCTR_BVAL_SHIFT,
  310. USB_DnFIFOCTR_BVAL);
  311. }
  312. }
  313. usb0_host_enable_bemp_int(pipe);
  314. }
  315. /* End of File */