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_userdef.c 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  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_userdef.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 <stdio.h>
  39. #include "r_typedefs.h"
  40. #include "iodefine.h"
  41. #include "devdrv_usb_function_api.h"
  42. #include "usb0_function_dmacdrv.h" /* common DMAC driver for USB */
  43. /*******************************************************************************
  44. Typedef definitions
  45. *******************************************************************************/
  46. /*******************************************************************************
  47. Macro definitions
  48. *******************************************************************************/
  49. #define DUMMY_ACCESS OSTM0CNT
  50. /* #define CACHE_WRITEBACK */
  51. /*******************************************************************************
  52. Imported global variables and functions (from other files)
  53. *******************************************************************************/
  54. extern int32_t io_cwb(unsigned long start, unsigned long end);
  55. /*******************************************************************************
  56. Exported global variables and functions (to be accessed by other files)
  57. *******************************************************************************/
  58. static void usb0_function_enable_dmac0(uint32_t src, uint32_t dst, uint32_t count,
  59. uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc);
  60. static void usb0_function_enable_dmac1(uint32_t src, uint32_t dst, uint32_t count,
  61. uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc);
  62. static void Userdef_USB_usb0_function_delay_10us_2(void);
  63. /*******************************************************************************
  64. Private global variables and functions
  65. *******************************************************************************/
  66. /*******************************************************************************
  67. * Function Name: Userdef_USB_usb0_function_d0fifo_dmaintid
  68. * Description : get D0FIFO DMA Interrupt ID
  69. * Arguments : none
  70. * Return Value : D0FIFO DMA Interrupt ID
  71. *******************************************************************************/
  72. IRQn_Type Userdef_USB_usb0_function_d0fifo_dmaintid (void)
  73. {
  74. #if 0
  75. return DMAINT1_IRQn;
  76. #else
  77. return 0xFFFF;
  78. #endif
  79. }
  80. /*******************************************************************************
  81. * Function Name: Userdef_USB_usb0_function_d1fifo_dmaintid
  82. * Description : get D1FIFO DMA Interrupt ID
  83. * Arguments : none
  84. * Return Value : D1FIFO DMA Interrupt ID
  85. *******************************************************************************/
  86. IRQn_Type Userdef_USB_usb0_function_d1fifo_dmaintid (void)
  87. {
  88. #if 0
  89. return DMAINT1_IRQn;
  90. #else
  91. return 0xFFFF;
  92. #endif
  93. }
  94. /*******************************************************************************
  95. * Function Name: Userdef_USB_usb0_function_attach
  96. * Description : Wait for the software of 1ms.
  97. * : Alter this function according to the user's system.
  98. * Arguments : none
  99. * Return Value : none
  100. *******************************************************************************/
  101. void Userdef_USB_usb0_function_attach (void)
  102. {
  103. printf("\n");
  104. printf("channel 0 attach device\n");
  105. printf("\n");
  106. }
  107. /*******************************************************************************
  108. * Function Name: Userdef_USB_usb0_function_detach
  109. * Description : Wait for the software of 1ms.
  110. * : Alter this function according to the user's system.
  111. * Arguments : none
  112. * Return Value : none
  113. *******************************************************************************/
  114. void Userdef_USB_usb0_function_detach (void)
  115. {
  116. printf("\n");
  117. printf("channel 0 detach device\n");
  118. printf("\n");
  119. }
  120. /*******************************************************************************
  121. * Function Name: Userdef_USB_usb0_function_delay_1ms
  122. * Description : Wait for the software of 1ms.
  123. * : Alter this function according to the user's system.
  124. * Arguments : none
  125. * Return Value : none
  126. *******************************************************************************/
  127. void Userdef_USB_usb0_function_delay_1ms (void)
  128. {
  129. volatile int i;
  130. volatile unsigned long tmp;
  131. /*
  132. * Wait 1ms (Please change for your MCU).
  133. */
  134. for (i = 0; i < 1440; ++i)
  135. {
  136. tmp = DUMMY_ACCESS;
  137. }
  138. }
  139. /*******************************************************************************
  140. * Function Name: Userdef_USB_usb0_function_delay_xms
  141. * Description : Wait for the software in the period of time specified by the
  142. * : argument.
  143. * : Alter this function according to the user's system.
  144. * Arguments : uint32_t msec ; Wait Time (msec)
  145. * Return Value : none
  146. *******************************************************************************/
  147. void Userdef_USB_usb0_function_delay_xms (uint32_t msec)
  148. {
  149. volatile unsigned short i;
  150. for (i = 0; i < msec; ++i)
  151. {
  152. Userdef_USB_usb0_function_delay_1ms();
  153. }
  154. }
  155. /*******************************************************************************
  156. * Function Name: Userdef_USB_usb0_function_delay_10us
  157. * Description : Waits for software for the period specified by the argument.
  158. * : Alter this function according to the user's system.
  159. * Arguments : uint32_t usec ; Wait Time(x 10usec)
  160. * Return Value : none
  161. *******************************************************************************/
  162. void Userdef_USB_usb0_function_delay_10us (uint32_t usec)
  163. {
  164. volatile int i;
  165. /* Wait 10us (Please change for your MCU) */
  166. for (i = 0; i < usec; ++i)
  167. {
  168. Userdef_USB_usb0_function_delay_10us_2();
  169. }
  170. }
  171. /*******************************************************************************
  172. * Function Name: Userdef_USB_usb0_function_delay_10us_2
  173. * Description : Waits for software for the period specified by the argument.
  174. * : Alter this function according to the user's system.
  175. * Arguments : none
  176. * Return Value : none
  177. *******************************************************************************/
  178. static void Userdef_USB_usb0_function_delay_10us_2 (void)
  179. {
  180. volatile int i;
  181. volatile unsigned long tmp;
  182. /* Wait 1us (Please change for your MCU) */
  183. for (i = 0; i < 14; ++i)
  184. {
  185. tmp = DUMMY_ACCESS;
  186. }
  187. }
  188. /*******************************************************************************
  189. * Function Name: Userdef_USB_usb0_function_delay_500ns
  190. * Description : Wait for software for 500ns.
  191. * : Alter this function according to the user's system.
  192. * Arguments : none
  193. * Return Value : none
  194. *******************************************************************************/
  195. void Userdef_USB_usb0_function_delay_500ns (void)
  196. {
  197. volatile int i;
  198. volatile unsigned long tmp;
  199. /* Wait 500ns (Please change for your MCU) */
  200. /* Wait 500ns I clock 266MHz */
  201. tmp = DUMMY_ACCESS;
  202. }
  203. /*******************************************************************************
  204. * Function Name: Userdef_USB_usb0_function_start_dma
  205. * Description : Enables DMA transfer on the information specified by the argument.
  206. * : Set DMAC register by this function to enable DMA transfer.
  207. * : After executing this function, USB module is set to start DMA
  208. * : transfer. DMA transfer should not wait for DMA transfer complete.
  209. * Arguments : USB_FUNCTION_DMA_t *dma : DMA parameter
  210. * : typedef struct{
  211. * : uint32_t fifo; FIFO for using
  212. * : uint32_t buffer; Start address of transfer source/destination
  213. * : uint32_t bytes; Transfer size(Byte)
  214. * : uint32_t dir; Transfer direction(0:Buffer->FIFO, 1:FIFO->Buffer)
  215. * : uint32_t size; DMA transfer size
  216. * : } USB_FUNCTION_DMA_t;
  217. * : uint16_t dfacc ; 0 : cycle steal mode
  218. * : 1 : 16byte continuous mode
  219. * : 2 : 32byte continuous mode
  220. * Return Value : none
  221. *******************************************************************************/
  222. void Userdef_USB_usb0_function_start_dma (USB_FUNCTION_DMA_t * dma, uint16_t dfacc)
  223. {
  224. uint32_t trncount;
  225. uint32_t src;
  226. uint32_t dst;
  227. uint32_t size;
  228. uint32_t dir;
  229. #ifdef CACHE_WRITEBACK
  230. uint32_t ptr;
  231. #endif
  232. trncount = dma->bytes;
  233. dir = dma->dir;
  234. if (dir == USB_FUNCTION_FIFO2BUF)
  235. {
  236. /* DxFIFO determination */
  237. dst = dma->buffer;
  238. #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
  239. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  240. {
  241. src = (uint32_t)(&USB200.D0FIFO.UINT32);
  242. }
  243. else
  244. {
  245. src = (uint32_t)(&USB200.D1FIFO.UINT32);
  246. }
  247. size = dma->size;
  248. if (size == 0)
  249. {
  250. src += 3; /* byte access */
  251. }
  252. else if (size == 1)
  253. {
  254. src += 2; /* short access */
  255. }
  256. else
  257. {
  258. /* Do Nothing */
  259. }
  260. #else
  261. size = dma->size;
  262. if (size == 2)
  263. {
  264. /* 32bit access */
  265. if (dfacc == 2)
  266. {
  267. /* 32byte access */
  268. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  269. {
  270. src = (uint32_t)(&USB200.D0FIFOB0);
  271. }
  272. else
  273. {
  274. src = (uint32_t)(&USB200.D1FIFOB0);
  275. }
  276. }
  277. else if (dfacc == 1)
  278. {
  279. /* 16byte access */
  280. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  281. {
  282. src = (uint32_t)(&USB200.D0FIFOB0);
  283. }
  284. else
  285. {
  286. src = (uint32_t)(&USB200.D1FIFOB0);
  287. }
  288. }
  289. else
  290. {
  291. /* normal access */
  292. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  293. {
  294. src = (uint32_t)(&USB200.D0FIFO.UINT32);
  295. }
  296. else
  297. {
  298. src = (uint32_t)(&USB200.D1FIFO.UINT32);
  299. }
  300. }
  301. }
  302. else if (size == 1)
  303. {
  304. /* 16bit access */
  305. dfacc = 0; /* force normal access */
  306. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  307. {
  308. src = (uint32_t)(&USB200.D0FIFO.UINT32);
  309. }
  310. else
  311. {
  312. src = (uint32_t)(&USB200.D1FIFO.UINT32);
  313. }
  314. src += 2; /* short access */
  315. }
  316. else
  317. {
  318. /* 8bit access */
  319. dfacc = 0; /* force normal access */
  320. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  321. {
  322. src = (uint32_t)(&USB200.D0FIFO.UINT32);
  323. }
  324. else
  325. {
  326. src = (uint32_t)(&USB200.D1FIFO.UINT32);
  327. }
  328. src += 3; /* byte access */
  329. }
  330. #endif
  331. }
  332. else
  333. {
  334. /* DxFIFO determination */
  335. src = dma->buffer;
  336. #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
  337. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  338. {
  339. dst = (uint32_t)(&USB200.D0FIFO.UINT32);
  340. }
  341. else
  342. {
  343. dst = (uint32_t)(&USB200.D1FIFO.UINT32);
  344. }
  345. size = dma->size;
  346. if (size == 0)
  347. {
  348. dst += 3; /* byte access */
  349. }
  350. else if (size == 1)
  351. {
  352. dst += 2; /* short access */
  353. }
  354. else
  355. {
  356. /* Do Nothing */
  357. }
  358. #else
  359. size = dma->size;
  360. if (size == 2)
  361. {
  362. /* 32bit access */
  363. if (dfacc == 2)
  364. {
  365. /* 32byte access */
  366. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  367. {
  368. dst = (uint32_t)(&USB200.D0FIFOB0);
  369. }
  370. else
  371. {
  372. dst = (uint32_t)(&USB200.D1FIFOB0);
  373. }
  374. }
  375. else if (dfacc == 1)
  376. {
  377. /* 16byte access */
  378. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  379. {
  380. dst = (uint32_t)(&USB200.D0FIFOB0);
  381. }
  382. else
  383. {
  384. dst = (uint32_t)(&USB200.D1FIFOB0);
  385. }
  386. }
  387. else
  388. {
  389. /* normal access */
  390. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  391. {
  392. dst = (uint32_t)(&USB200.D0FIFO.UINT32);
  393. }
  394. else
  395. {
  396. dst = (uint32_t)(&USB200.D1FIFO.UINT32);
  397. }
  398. }
  399. }
  400. else if (size == 1)
  401. {
  402. /* 16bit access */
  403. dfacc = 0; /* force normal access */
  404. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  405. {
  406. dst = (uint32_t)(&USB200.D0FIFO.UINT32);
  407. }
  408. else
  409. {
  410. dst = (uint32_t)(&USB200.D1FIFO.UINT32);
  411. }
  412. dst += 2; /* short access */
  413. }
  414. else
  415. {
  416. /* 8bit access */
  417. dfacc = 0; /* force normal access */
  418. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  419. {
  420. dst = (uint32_t)(&USB200.D0FIFO.UINT32);
  421. }
  422. else
  423. {
  424. dst = (uint32_t)(&USB200.D1FIFO.UINT32);
  425. }
  426. dst += 3; /* byte access */
  427. }
  428. #endif
  429. }
  430. #ifdef CACHE_WRITEBACK
  431. ptr = (uint32_t)dma->buffer;
  432. if ((ptr & 0x20000000ul) == 0)
  433. {
  434. io_cwb((uint32_t)ptr, (uint32_t)(ptr) + trncount);
  435. }
  436. #endif
  437. if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
  438. {
  439. usb0_function_enable_dmac0(src, dst, trncount, size, dir, dma->fifo, dfacc);
  440. }
  441. else
  442. {
  443. usb0_function_enable_dmac1(src, dst, trncount, size, dir, dma->fifo, dfacc);
  444. }
  445. }
  446. /*******************************************************************************
  447. * Function Name: usb0_function_enable_dmac0
  448. * Description : Enables DMA transfer on the information specified by the argument.
  449. * Arguments : uint32_t src : src address
  450. * : uint32_t dst : dst address
  451. * : uint32_t count : transfer byte
  452. * : uint32_t size : transfer size
  453. * : uint32_t dir : direction
  454. * : uint32_t fifo : FIFO(D0FIFO or D1FIFO)
  455. * : uint16_t dfacc : 0 : normal access
  456. * : : 1 : 16byte access
  457. * : : 2 : 32byte access
  458. * Return Value : none
  459. *******************************************************************************/
  460. static void usb0_function_enable_dmac0 (uint32_t src, uint32_t dst, uint32_t count,
  461. uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc)
  462. {
  463. dmac_transinfo_t trans_info;
  464. uint32_t request_factor = 0;
  465. int32_t ret;
  466. /* ==== Variable setting for DMAC initialization ==== */
  467. trans_info.src_addr = (uint32_t)src; /* Start address of transfer source */
  468. trans_info.dst_addr = (uint32_t)dst; /* Start address of transfer destination */
  469. trans_info.count = (uint32_t)count; /* Total byte count to be transferred */
  470. #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
  471. if (size == 0)
  472. {
  473. trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
  474. trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
  475. }
  476. else if (size == 1)
  477. {
  478. trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
  479. trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
  480. }
  481. else if (size == 2)
  482. {
  483. trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
  484. trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
  485. }
  486. else
  487. {
  488. printf("size error!!\n");
  489. }
  490. #else
  491. if (dfacc == 2)
  492. {
  493. /* 32byte access */
  494. trans_info.src_size = DMAC_TRANS_SIZE_256; /* Transfer source transfer size */
  495. trans_info.dst_size = DMAC_TRANS_SIZE_256; /* Transfer destination transfer size */
  496. }
  497. else if (dfacc == 1)
  498. {
  499. /* 16byte access */
  500. trans_info.src_size = DMAC_TRANS_SIZE_128; /* Transfer source transfer size */
  501. trans_info.dst_size = DMAC_TRANS_SIZE_128; /* Transfer destination transfer size */
  502. }
  503. else
  504. {
  505. /* normal access */
  506. if (size == 0)
  507. {
  508. trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
  509. trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
  510. }
  511. else if (size == 1)
  512. {
  513. trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
  514. trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
  515. }
  516. else if (size == 2)
  517. {
  518. trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
  519. trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
  520. }
  521. else
  522. {
  523. printf("size error!!\n");
  524. }
  525. }
  526. #endif
  527. if (dir == USB_FUNCTION_FIFO2BUF)
  528. {
  529. request_factor =DMAC_REQ_USB0_DMA0_RX; /* USB_0 channel 0 receive FIFO full */
  530. trans_info.saddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer source address */
  531. trans_info.daddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer destination address */
  532. }
  533. else if (dir == USB_FUNCTION_BUF2FIFO)
  534. {
  535. request_factor =DMAC_REQ_USB0_DMA0_TX; /* USB_0 channel 0 receive FIFO empty */
  536. trans_info.saddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer source address */
  537. trans_info.daddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer destination address */
  538. }
  539. else
  540. {
  541. /* Do Nothing */
  542. }
  543. /* ==== DMAC initialization ==== */
  544. usb0_function_DMAC1_PeriReqInit((const dmac_transinfo_t *)&trans_info,
  545. DMAC_MODE_REGISTER,
  546. DMAC_SAMPLE_SINGLE,
  547. request_factor,
  548. 0); /* Don't care DMAC_REQ_REQD is setting in
  549. usb0_function_DMAC1_PeriReqInit() */
  550. /* ==== DMAC startup ==== */
  551. ret = usb0_function_DMAC1_Open(DMAC_REQ_MODE_PERI);
  552. if (ret != 0)
  553. {
  554. printf("DMAC1 Open error!!\n");
  555. }
  556. return;
  557. }
  558. /*******************************************************************************
  559. * Function Name: usb0_function_enable_dmac1
  560. * Description : Enables DMA transfer on the information specified by the argument.
  561. * Arguments : uint32_t src : src address
  562. * : uint32_t dst : dst address
  563. * : uint32_t count : transfer byte
  564. * : uint32_t size : transfer size
  565. * : uint32_t dir : direction
  566. * : uint32_t fifo : FIFO(D0FIFO or D1FIFO)
  567. * : uint16_t dfacc : 0 : normal access
  568. * : : 1 : 16byte access
  569. * : : 2 : 32byte access
  570. * Return Value : none
  571. *******************************************************************************/
  572. static void usb0_function_enable_dmac1 (uint32_t src, uint32_t dst, uint32_t count,
  573. uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc)
  574. {
  575. dmac_transinfo_t trans_info;
  576. uint32_t request_factor = 0;
  577. int32_t ret;
  578. /* ==== Variable setting for DMAC initialization ==== */
  579. trans_info.src_addr = (uint32_t)src; /* Start address of transfer source */
  580. trans_info.dst_addr = (uint32_t)dst; /* Start address of transfer destination */
  581. trans_info.count = (uint32_t)count; /* Total byte count to be transferred */
  582. #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
  583. if (size == 0)
  584. {
  585. trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
  586. trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
  587. }
  588. else if (size == 1)
  589. {
  590. trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
  591. trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
  592. }
  593. else if (size == 2)
  594. {
  595. trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
  596. trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
  597. }
  598. else
  599. {
  600. printf("size error!!\n");
  601. }
  602. #else
  603. if (dfacc == 2)
  604. {
  605. /* 32byte access */
  606. trans_info.src_size = DMAC_TRANS_SIZE_256; /* Transfer source transfer size */
  607. trans_info.dst_size = DMAC_TRANS_SIZE_256; /* Transfer destination transfer size */
  608. }
  609. else if (dfacc == 1)
  610. {
  611. /* 16byte access */
  612. trans_info.src_size = DMAC_TRANS_SIZE_128; /* Transfer source transfer size */
  613. trans_info.dst_size = DMAC_TRANS_SIZE_128; /* Transfer destination transfer size */
  614. }
  615. else
  616. {
  617. /* normal access */
  618. if (size == 0)
  619. {
  620. trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
  621. trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
  622. }
  623. else if (size == 1)
  624. {
  625. trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
  626. trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
  627. }
  628. else if (size == 2)
  629. {
  630. trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
  631. trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
  632. }
  633. else
  634. {
  635. printf("size error!!\n");
  636. }
  637. }
  638. #endif
  639. if (dir == USB_FUNCTION_FIFO2BUF)
  640. {
  641. request_factor =DMAC_REQ_USB0_DMA1_RX; /* USB_0 channel 0 receive FIFO full */
  642. trans_info.saddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer source address */
  643. trans_info.daddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer destination address */
  644. }
  645. else if (dir == USB_FUNCTION_BUF2FIFO)
  646. {
  647. request_factor =DMAC_REQ_USB0_DMA1_TX; /* USB_0 channel 0 receive FIFO empty */
  648. trans_info.saddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer source address */
  649. trans_info.daddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer destination address */
  650. }
  651. else
  652. {
  653. /* Do Nothing */
  654. }
  655. /* ==== DMAC initialization ==== */
  656. usb0_function_DMAC2_PeriReqInit((const dmac_transinfo_t *)&trans_info,
  657. DMAC_MODE_REGISTER,
  658. DMAC_SAMPLE_SINGLE,
  659. request_factor,
  660. 0); /* Don't care DMAC_REQ_REQD is setting in
  661. usb0_function_DMAC1_PeriReqInit() */
  662. /* ==== DMAC startup ==== */
  663. ret = usb0_function_DMAC2_Open(DMAC_REQ_MODE_PERI);
  664. if (ret != 0)
  665. {
  666. printf("DMAC2 Open error!!\n");
  667. }
  668. return;
  669. }
  670. /*******************************************************************************
  671. * Function Name: Userdef_USB_usb0_function_stop_dma0
  672. * Description : Disables DMA transfer.
  673. * : This function should be executed to DMAC executed at the time
  674. * : of specification of D0_FIF0_DMA in dma->fifo.
  675. * Arguments : none
  676. * Return Value : uint32_t return Transfer Counter register(DMATCRn) value
  677. * : regarding to the bus width.
  678. *******************************************************************************/
  679. uint32_t Userdef_USB_usb0_function_stop_dma0 (void)
  680. {
  681. uint32_t remain;
  682. /* ==== DMAC release ==== */
  683. usb0_function_DMAC1_Close(&remain);
  684. return remain;
  685. }
  686. /*******************************************************************************
  687. * Function Name: Userdef_USB_usb0_function_stop_dma1
  688. * Description : Disables DMA transfer.
  689. * : This function should be executed to DMAC executed at the time
  690. * : of specification of D1_FIF0_DMA in dma->fifo.
  691. * Arguments : none
  692. * Return Value : uint32_t return Transfer Counter register(DMATCRn) value
  693. * : regarding to the bus width.
  694. *******************************************************************************/
  695. uint32_t Userdef_USB_usb0_function_stop_dma1 (void)
  696. {
  697. uint32_t remain;
  698. /* ==== DMAC release ==== */
  699. usb0_function_DMAC2_Close(&remain);
  700. return remain;
  701. }
  702. /* End of File */