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