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