1 /*******************************************************************************
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
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /*******************************************************************************
24 * File Name : usb1_host_dataio.c
26 * $Date:: 2014-07-09 16:29:19 +0900#$
31 * Description : RZ/A1H R7S72100 USB Sample Program
34 *******************************************************************************/
37 /*******************************************************************************
38 Includes <System Includes> , "Project Includes"
39 *******************************************************************************/
40 #include "usb1_host.h"
43 /*******************************************************************************
45 *******************************************************************************/
48 /*******************************************************************************
50 *******************************************************************************/
53 /*******************************************************************************
54 Imported global variables and functions (from other files)
55 *******************************************************************************/
58 /*******************************************************************************
59 Exported global variables and functions (to be accessed by other files)
60 *******************************************************************************/
63 /*******************************************************************************
64 Private global variables and functions
65 *******************************************************************************/
66 static uint16_t g_usb1_host_mbw[(USB_HOST_MAX_PIPE_NO + 1)];
68 static void usb1_host_start_receive_trns_c(uint16_t pipe, uint32_t size, uint8_t *data);
69 static void usb1_host_start_receive_trns_d0(uint16_t pipe, uint32_t size, uint8_t *data);
70 static void usb1_host_start_receive_trns_d1(uint16_t pipe, uint32_t size, uint8_t *data);
71 static void usb1_host_start_receive_dma_d0(uint16_t pipe, uint32_t size, uint8_t *data);
72 static void usb1_host_start_receive_dma_d1(uint16_t pipe, uint32_t size, uint8_t *data);
73 static uint16_t usb1_host_read_dma_d0(uint16_t pipe);
74 static uint16_t usb1_host_read_dma_d1(uint16_t pipe);
75 static uint16_t usb1_host_write_dma_d0(uint16_t pipe);
76 static uint16_t usb1_host_write_dma_d1(uint16_t pipe);
78 static void usb1_host_read_c_fifo(uint16_t pipe, uint16_t count);
79 static void usb1_host_write_c_fifo(uint16_t Pipe, uint16_t count);
80 static void usb1_host_read_d0_fifo(uint16_t pipe, uint16_t count);
81 static void usb1_host_write_d0_fifo(uint16_t pipe, uint16_t count);
82 static void usb1_host_read_d1_fifo(uint16_t pipe, uint16_t count);
83 static void usb1_host_write_d1_fifo(uint16_t pipe, uint16_t count);
85 static void usb1_host_clear_transaction_counter(uint16_t pipe);
86 static void usb1_host_set_transaction_counter(uint16_t pipe, uint32_t count);
88 static uint32_t usb1_host_com_get_dmasize(uint32_t trncount, uint32_t dtptr);
90 static uint16_t usb1_host_set_dfacc_d0(uint16_t mbw, uint32_t count);
91 static uint16_t usb1_host_set_dfacc_d1(uint16_t mbw, uint32_t count);
94 /*******************************************************************************
95 * Function Name: usb1_host_start_send_transfer
96 * Description : Starts the USB data communication using pipe specified by the argument.
97 * Arguments : uint16_t pipe ; Pipe Number
98 * : uint32_t size ; Data Size
99 * : uint8_t *data ; Data data Address
100 * Return Value : USB_HOST_WRITEEND ; Write end
101 * : USB_HOST_WRITESHRT ; short data
102 * : USB_HOST_WRITING ; Continue of data write
103 * : USB_HOST_WRITEDMA ; Write DMA
104 * : USB_HOST_FIFOERROR ; FIFO status
105 *******************************************************************************/
106 uint16_t usb1_host_start_send_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
112 g_usb1_host_data_count[pipe] = size;
113 g_usb1_host_data_pointer[pipe] = (uint8_t *)data;
114 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
116 usb1_host_clear_bemp_sts(pipe);
117 usb1_host_clear_brdy_sts(pipe);
118 usb1_host_clear_nrdy_sts(pipe);
120 mbw = usb1_host_get_mbw(size, (uint32_t)data);
122 usefifo = (uint16_t)(g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
126 case USB_HOST_D0FIFO_USE:
127 case USB_HOST_D0FIFO_DMA:
128 usefifo = USB_HOST_D0USE;
131 case USB_HOST_D1FIFO_USE:
132 case USB_HOST_D1FIFO_DMA:
133 usefifo = USB_HOST_D1USE;
137 usefifo = USB_HOST_CUSE;
141 usb1_host_set_curpipe(USB_HOST_PIPE0, usefifo, USB_HOST_NO, mbw);
143 usb1_host_clear_transaction_counter(pipe);
145 #if(1) /* ohci_wrapp */
147 usb1_host_aclrm(pipe);
150 status = usb1_host_write_buffer(pipe);
152 if (status != USB_HOST_FIFOERROR)
154 usb1_host_set_pid_buf(pipe);
160 /*******************************************************************************
161 * Function Name: usb1_host_write_buffer
162 * Description : Writes data in the buffer allocated in the pipe specified by
163 * : the argument. The FIFO for using is set in the pipe definition table.
164 * Arguments : uint16_t pipe ; Pipe Number
165 * Return Value : USB_HOST_WRITEEND ; Write end
166 * : USB_HOST_WRITESHRT ; short data
167 * : USB_HOST_WRITING ; Continue of data write
168 * : USB_HOST_WRITEDMA ; Write DMA
169 * : USB_HOST_FIFOERROR ; FIFO status
170 *******************************************************************************/
171 uint16_t usb1_host_write_buffer (uint16_t pipe)
176 g_usb1_host_PipeIgnore[pipe] = 0;
177 usefifo = (uint16_t)(g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
181 case USB_HOST_D0FIFO_USE:
182 status = usb1_host_write_buffer_d0(pipe);
185 case USB_HOST_D1FIFO_USE:
186 status = usb1_host_write_buffer_d1(pipe);
189 case USB_HOST_D0FIFO_DMA:
190 status = usb1_host_write_dma_d0(pipe);
193 case USB_HOST_D1FIFO_DMA:
194 status = usb1_host_write_dma_d1(pipe);
198 status = usb1_host_write_buffer_c(pipe);
204 case USB_HOST_WRITING: /* Continue of data write */
205 usb1_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
206 usb1_host_enable_brdy_int(pipe); /* Enable Ready Interrupt */
209 case USB_HOST_WRITEEND: /* End of data write */
210 case USB_HOST_WRITESHRT: /* End of data write */
211 usb1_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
213 usb1_host_clear_nrdy_sts(pipe);
214 usb1_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
216 /* for last transfer */
217 usb1_host_enable_bemp_int(pipe); /* Enable Empty Interrupt */
220 case USB_HOST_WRITEDMA: /* DMA write */
221 usb1_host_clear_nrdy_sts(pipe);
222 usb1_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
225 case USB_HOST_FIFOERROR: /* FIFO access status */
227 usb1_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
228 usb1_host_disable_bemp_int(pipe); /* Disable Empty Interrupt */
229 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
233 return status; /* End or Err or Continue */
236 /*******************************************************************************
237 * Function Name: usb1_host_write_buffer_c
238 * Description : Writes data in the buffer allocated in the pipe specified in
239 * : the argument. Writes data by CPU transfer using CFIFO.
240 * Arguments : uint16_t pipe ; Pipe Number
241 * Return Value : USB_HOST_WRITEEND ; Write end
242 * : USB_HOST_WRITESHRT ; short data
243 * : USB_HOST_WRITING ; Continue of data write
244 * : USB_HOST_WRITEDMA ; Write DMA
245 * : USB_HOST_FIFOERROR ; FIFO status
246 *******************************************************************************/
247 uint16_t usb1_host_write_buffer_c (uint16_t pipe)
256 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
258 if (pipe == USB_HOST_PIPE0)
260 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_CFIFO_WRITE, mbw);
264 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_NO, mbw);
267 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
269 return USB_HOST_FIFOERROR;
272 size = usb1_host_get_buf_size(pipe); /* Data buffer size */
273 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
275 if (g_usb1_host_data_count[pipe] <= (uint32_t)size)
277 status = USB_HOST_WRITEEND; /* write continues */
278 count = g_usb1_host_data_count[pipe];
282 status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
285 if ((count % mxps) != 0)
287 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
292 status = USB_HOST_WRITING; /* write continues */
293 count = (uint32_t)size;
296 usb1_host_write_c_fifo(pipe, (uint16_t)count);
298 if (g_usb1_host_data_count[pipe] < (uint32_t)size)
300 g_usb1_host_data_count[pipe] = 0;
302 if (RZA_IO_RegRead_16(&USB201.CFIFOCTR,
303 USB_CFIFOCTR_BVAL_SHIFT,
304 USB_CFIFOCTR_BVAL) == 0)
306 USB201.CFIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
311 g_usb1_host_data_count[pipe] -= count;
314 return status; /* End or Err or Continue */
317 /*******************************************************************************
318 * Function Name: usb1_host_write_buffer_d0
319 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
320 * : Writes data by CPU transfer using D0FIFO.
321 * Arguments : uint16_t pipe ; Pipe Number
322 * Return Value : USB_HOST_WRITEEND ; Write end
323 * : USB_HOST_WRITESHRT ; short data
324 * : USB_HOST_WRITING ; Continue of data write
325 * : USB_HOST_WRITEDMA ; Write DMA
326 * : USB_HOST_FIFOERROR ; FIFO status
327 *******************************************************************************/
328 uint16_t usb1_host_write_buffer_d0 (uint16_t pipe)
337 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
338 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D0USE, USB_HOST_NO, mbw);
340 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
342 return USB_HOST_FIFOERROR;
345 size = usb1_host_get_buf_size(pipe); /* Data buffer size */
346 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
348 if (g_usb1_host_data_count[pipe] <= (uint32_t)size)
350 status = USB_HOST_WRITEEND; /* write continues */
351 count = g_usb1_host_data_count[pipe];
355 status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
358 if ((count % mxps) != 0)
360 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
365 status = USB_HOST_WRITING; /* write continues */
366 count = (uint32_t)size;
369 usb1_host_write_d0_fifo(pipe, (uint16_t)count);
371 if (g_usb1_host_data_count[pipe] < (uint32_t)size)
373 g_usb1_host_data_count[pipe] = 0;
375 if (RZA_IO_RegRead_16(&USB201.D0FIFOCTR,
376 USB_DnFIFOCTR_BVAL_SHIFT,
377 USB_DnFIFOCTR_BVAL) == 0)
379 USB201.D0FIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
384 g_usb1_host_data_count[pipe] -= count;
387 return status; /* End or Err or Continue */
390 /*******************************************************************************
391 * Function Name: usb1_host_write_buffer_d1
392 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
393 * : Writes data by CPU transfer using D1FIFO.
394 * Arguments : uint16_t pipe ; Pipe Number
395 * Return Value : USB_HOST_WRITEEND ; Write end
396 * : USB_HOST_WRITESHRT ; short data
397 * : USB_HOST_WRITING ; Continue of data write
398 * : USB_HOST_WRITEDMA ; Write DMA
399 * : USB_HOST_FIFOERROR ; FIFO status
400 *******************************************************************************/
401 uint16_t usb1_host_write_buffer_d1 (uint16_t pipe)
410 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
411 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D1USE, USB_HOST_NO, mbw);
413 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
415 return USB_HOST_FIFOERROR;
418 size = usb1_host_get_buf_size(pipe); /* Data buffer size */
419 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
421 if (g_usb1_host_data_count[pipe] <= (uint32_t)size)
423 status = USB_HOST_WRITEEND; /* write continues */
424 count = g_usb1_host_data_count[pipe];
428 status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
431 if ((count % mxps) != 0)
433 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
438 status = USB_HOST_WRITING; /* write continues */
439 count = (uint32_t)size;
442 usb1_host_write_d1_fifo(pipe, (uint16_t)count);
444 if (g_usb1_host_data_count[pipe] < (uint32_t)size)
446 g_usb1_host_data_count[pipe] = 0;
448 if (RZA_IO_RegRead_16(&USB201.D1FIFOCTR,
449 USB_DnFIFOCTR_BVAL_SHIFT,
450 USB_DnFIFOCTR_BVAL) == 0)
452 USB201.D1FIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
457 g_usb1_host_data_count[pipe] -= count;
460 return status; /* End or Err or Continue */
463 /*******************************************************************************
464 * Function Name: usb1_host_write_dma_d0
465 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
466 * : Writes data by DMA transfer using D0FIFO.
467 * : The DMA-ch for using is specified by Userdef_USB_usb1_host_start_dma().
468 * Arguments : uint16_t pipe ; Pipe Number
469 * Return Value : USB_HOST_WRITEEND : Write end
470 * : USB_HOST_WRITESHRT : short data
471 * : USB_HOST_WRITING : Continue of data write
472 * : USB_HOST_WRITEDMA : Write DMA
473 * : USB_HOST_FIFOERROR : FIFO status
474 *******************************************************************************/
475 static uint16_t usb1_host_write_dma_d0 (uint16_t pipe)
484 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
485 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
487 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
489 return USB_HOST_FIFOERROR;
492 size = usb1_host_get_buf_size(pipe); /* Data buffer size */
493 count = g_usb1_host_data_count[pipe];
497 g_usb1_host_DmaPipe[USB_HOST_D0FIFO] = pipe;
499 if ((count % size) != 0)
501 g_usb1_host_DmaBval[USB_HOST_D0FIFO] = 1;
505 g_usb1_host_DmaBval[USB_HOST_D0FIFO] = 0;
508 dfacc = usb1_host_set_dfacc_d0(mbw, count);
510 if (mbw == USB_HOST_BITMBW_32)
512 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size = 2; /* 32bit transfer */
514 else if (mbw == USB_HOST_BITMBW_16)
516 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size = 1; /* 16bit transfer */
520 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size = 0; /* 8bit transfer */
523 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].fifo = USB_HOST_D0FIFO_DMA;
524 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].dir = USB_HOST_BUF2FIFO;
525 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].buffer = (uint32_t)g_usb1_host_data_pointer[pipe];
526 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].bytes = count;
528 Userdef_USB_usb1_host_start_dma(&g_usb1_host_DmaInfo[USB_HOST_D0FIFO], dfacc);
530 usb1_host_set_curpipe2(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw, dfacc);
532 RZA_IO_RegWrite_16(&USB201.D0FIFOSEL,
534 USB_DnFIFOSEL_DREQE_SHIFT,
535 USB_DnFIFOSEL_DREQE);
537 g_usb1_host_data_count[pipe] = 0;
538 g_usb1_host_data_pointer[pipe] += count;
540 status = USB_HOST_WRITEDMA; /* DMA write */
544 if (RZA_IO_RegRead_16(&USB201.D0FIFOCTR,
545 USB_DnFIFOCTR_BVAL_SHIFT,
546 USB_DnFIFOCTR_BVAL) == 0)
548 RZA_IO_RegWrite_16(&USB201.D0FIFOCTR,
550 USB_DnFIFOCTR_BVAL_SHIFT,
551 USB_DnFIFOCTR_BVAL); /* Short Packet */
553 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
556 return status; /* End or Err or Continue */
559 /*******************************************************************************
560 * Function Name: usb1_host_write_dma_d1
561 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
562 * : Writes data by DMA transfer using D1FIFO.
563 * : The DMA-ch for using is specified by Userdef_USB_usb1_host_start_dma().
564 * Arguments : uint16_t pipe ; Pipe Number
565 * Return Value : USB_HOST_WRITEEND : Write end
566 * : USB_HOST_WRITESHRT : short data
567 * : USB_HOST_WRITING : Continue of data write
568 * : USB_HOST_WRITEDMA : Write DMA
569 * : USB_HOST_FIFOERROR : FIFO status
570 *******************************************************************************/
571 static uint16_t usb1_host_write_dma_d1 (uint16_t pipe)
580 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
581 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
583 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
585 return USB_HOST_FIFOERROR;
588 size = usb1_host_get_buf_size(pipe); /* Data buffer size */
589 count = g_usb1_host_data_count[pipe];
593 g_usb1_host_DmaPipe[USB_HOST_D1FIFO] = pipe;
595 if ((count % size) != 0)
597 g_usb1_host_DmaBval[USB_HOST_D1FIFO] = 1;
601 g_usb1_host_DmaBval[USB_HOST_D1FIFO] = 0;
604 dfacc = usb1_host_set_dfacc_d1(mbw, count);
606 if (mbw == USB_HOST_BITMBW_32)
608 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size = 2; /* 32bit transfer */
610 else if (mbw == USB_HOST_BITMBW_16)
612 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size = 1; /* 16bit transfer */
616 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size = 0; /* 8bit transfer */
619 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].fifo = USB_HOST_D1FIFO_DMA;
620 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].dir = USB_HOST_BUF2FIFO;
621 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].buffer = (uint32_t)g_usb1_host_data_pointer[pipe];
622 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].bytes = count;
624 Userdef_USB_usb1_host_start_dma(&g_usb1_host_DmaInfo[USB_HOST_D1FIFO], dfacc);
626 usb1_host_set_curpipe2(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw , dfacc);
628 RZA_IO_RegWrite_16(&USB201.D1FIFOSEL,
630 USB_DnFIFOSEL_DREQE_SHIFT,
631 USB_DnFIFOSEL_DREQE);
633 g_usb1_host_data_count[pipe] = 0;
634 g_usb1_host_data_pointer[pipe] += count;
636 status = USB_HOST_WRITEDMA; /* DMA write */
640 if (RZA_IO_RegRead_16(&USB201.D1FIFOCTR,
641 USB_DnFIFOCTR_BVAL_SHIFT,
642 USB_DnFIFOCTR_BVAL) == 0)
644 RZA_IO_RegWrite_16(&USB201.D1FIFOCTR,
646 USB_DnFIFOCTR_BVAL_SHIFT,
647 USB_DnFIFOCTR_BVAL); /* Short Packet */
649 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
652 return status; /* End or Err or Continue */
655 /*******************************************************************************
656 * Function Name: usb1_host_start_receive_transfer
657 * Description : Starts USB data reception using the pipe specified in the argument.
658 * : The FIFO for using is set in the pipe definition table.
659 * Arguments : uint16_t pipe ; Pipe Number
660 * : uint32_t size ; Data Size
661 * : uint8_t *data ; Data Address
662 * Return Value : none
663 *******************************************************************************/
664 void usb1_host_start_receive_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
668 usb1_host_clear_bemp_sts(pipe);
669 usb1_host_clear_brdy_sts(pipe);
670 usb1_host_clear_nrdy_sts(pipe);
672 usefifo = (uint16_t)(g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
676 case USB_HOST_D0FIFO_USE:
677 usb1_host_start_receive_trns_d0(pipe, size, data);
680 case USB_HOST_D1FIFO_USE:
681 usb1_host_start_receive_trns_d1(pipe, size, data);
684 case USB_HOST_D0FIFO_DMA:
685 usb1_host_start_receive_dma_d0(pipe, size, data);
688 case USB_HOST_D1FIFO_DMA:
689 usb1_host_start_receive_dma_d1(pipe, size, data);
693 usb1_host_start_receive_trns_c(pipe, size, data);
698 /*******************************************************************************
699 * Function Name: usb1_host_start_receive_trns_c
700 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
701 * : Reads data by CPU transfer using CFIFO.
702 * : When storing data in the buffer allocated in the pipe specified in the
703 * : argument, BRDY interrupt is generated to read data
704 * : in the interrupt.
705 * Arguments : uint16_t pipe ; Pipe Number
706 * : uint32_t size ; Data Size
707 * : uint8_t *data ; Data Address
708 * Return Value : none
709 *******************************************************************************/
710 static void usb1_host_start_receive_trns_c (uint16_t pipe, uint32_t size, uint8_t * data)
714 usb1_host_set_pid_nak(pipe);
715 g_usb1_host_data_count[pipe] = size;
716 g_usb1_host_data_pointer[pipe] = (uint8_t *)data;
717 g_usb1_host_PipeIgnore[pipe] = 0;
719 g_usb1_host_PipeDataSize[pipe] = size;
720 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
722 mbw = usb1_host_get_mbw(size, (uint32_t)data);
723 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_CFIFO_READ, mbw);
724 USB201.CFIFOCTR = USB_HOST_BITBCLR;
726 usb1_host_set_transaction_counter(pipe, size);
728 #if(1) /* ohci_wrapp */
730 usb1_host_aclrm(pipe);
733 usb1_host_enable_nrdy_int(pipe);
734 usb1_host_enable_brdy_int(pipe);
736 usb1_host_set_pid_buf(pipe);
739 /*******************************************************************************
740 * Function Name: usb1_host_start_receive_trns_d0
741 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
742 * : Reads data by CPU transfer using D0FIFO.
743 * : This function does not read data from the buffer.
744 * : When storing data in the buffer allocated in the pipe specified
745 * : in the argument, BRDY interrupt is generated to read data in the
747 * Arguments : uint16_t pipe ; Pipe Number
748 * : uint32_t size ; Data Size
749 * : uint8_t *data ; Data Address
750 * Return Value : none
751 *******************************************************************************/
752 static void usb1_host_start_receive_trns_d0 (uint16_t pipe, uint32_t size, uint8_t * data)
756 usb1_host_set_pid_nak(pipe);
757 g_usb1_host_data_count[pipe] = size;
758 g_usb1_host_data_pointer[pipe] = (uint8_t *)data;
759 g_usb1_host_PipeIgnore[pipe] = 0;
761 g_usb1_host_PipeDataSize[pipe] = size;
762 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
764 mbw = usb1_host_get_mbw(size, (uint32_t)data);
765 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, mbw);
767 usb1_host_set_transaction_counter(pipe, size);
769 #if(1) /* ohci_wrapp */
771 usb1_host_aclrm(pipe);
774 usb1_host_enable_nrdy_int(pipe);
775 usb1_host_enable_brdy_int(pipe);
777 usb1_host_set_pid_buf(pipe);
780 /*******************************************************************************
781 * Function Name: usb1_host_start_receive_trns_d1
782 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
783 * : Reads data by CPU transfer using D1FIFO.
784 * : This function does not read data from the buffer.
785 * : When storing data in the buffer allocated in the pipe specified
786 * : in the argument, BRDY interrupt is generated to read data.
787 * Arguments : uint16_t pipe ; Pipe Number
788 * : uint32_t size ; Data Size
789 * : uint8_t *data ; Data Address
790 * Return Value : none
791 *******************************************************************************/
792 static void usb1_host_start_receive_trns_d1 (uint16_t pipe, uint32_t size, uint8_t * data)
796 usb1_host_set_pid_nak(pipe);
797 g_usb1_host_data_count[pipe] = size;
798 g_usb1_host_data_pointer[pipe] = (uint8_t *)data;
799 g_usb1_host_PipeIgnore[pipe] = 0;
801 g_usb1_host_PipeDataSize[pipe] = size;
802 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
804 mbw = usb1_host_get_mbw(size, (uint32_t)data);
805 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, mbw);
807 usb1_host_set_transaction_counter(pipe, size);
809 #if(1) /* ohci_wrapp */
811 usb1_host_aclrm(pipe);
814 usb1_host_enable_nrdy_int(pipe);
815 usb1_host_enable_brdy_int(pipe);
817 usb1_host_set_pid_buf(pipe);
820 /*******************************************************************************
821 * Function Name: usb1_host_start_receive_dma_d0
822 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
823 * : Reads data by DMA transfer using D0FIFO.
824 * : This function does not read data from the buffer.
825 * : When storing data in the buffer allocated in the pipe specified
826 * : in the argument, delivered read request to DMAC to read data from
827 * : the buffer by DMAC.
828 * Arguments : uint16_t pipe ; Pipe Number
829 * : uint32_t size ; Data Size
830 * : uint8_t *data ; Data Address
831 * Return Value : none
832 *******************************************************************************/
833 static void usb1_host_start_receive_dma_d0 (uint16_t pipe, uint32_t size, uint8_t * data)
837 usb1_host_set_pid_nak(pipe);
838 g_usb1_host_data_count[pipe] = size;
839 g_usb1_host_data_pointer[pipe] = (uint8_t *)data;
840 g_usb1_host_PipeIgnore[pipe] = 0;
842 g_usb1_host_PipeDataSize[pipe] = 0;
843 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
845 mbw = usb1_host_get_mbw(size, (uint32_t)data);
846 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, mbw);
848 usb1_host_set_transaction_counter(pipe, size);
850 #if(1) /* ohci_wrapp */
852 usb1_host_aclrm(pipe);
855 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
857 usb1_host_read_dma(pipe);
859 usb1_host_enable_nrdy_int(pipe);
860 usb1_host_enable_brdy_int(pipe);
864 usb1_host_enable_nrdy_int(pipe);
865 usb1_host_enable_brdy_int(pipe);
868 usb1_host_set_pid_buf(pipe);
871 /*******************************************************************************
872 * Function Name: usb1_host_start_receive_dma_d1
873 * Description : Read data from the buffer allocated in the pipe specified in the argument.
874 * : Reads data by DMA transfer using D0FIFO.
875 * : This function does not read data from the buffer.
876 * : When storing data in the buffer allocated in the pipe specified
877 * : in the argument, delivered read request to DMAC to read data from
878 * : the buffer by DMAC.
879 * Arguments : uint16_t pipe ; Pipe Number
880 * : uint32_t size ; Data Size
881 * : uint8_t *data ; Data Address
882 * Return Value : none
883 *******************************************************************************/
884 static void usb1_host_start_receive_dma_d1 (uint16_t pipe, uint32_t size, uint8_t * data)
888 usb1_host_set_pid_nak(pipe);
889 g_usb1_host_data_count[pipe] = size;
890 g_usb1_host_data_pointer[pipe] = (uint8_t *)data;
891 g_usb1_host_PipeIgnore[pipe] = 0;
893 g_usb1_host_PipeDataSize[pipe] = 0;
894 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
896 mbw = usb1_host_get_mbw(size, (uint32_t)data);
897 usb1_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, mbw);
899 usb1_host_set_transaction_counter(pipe, size);
901 #if(1) /* ohci_wrapp */
903 usb1_host_aclrm(pipe);
906 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
908 usb1_host_read_dma(pipe);
910 usb1_host_enable_nrdy_int(pipe);
911 usb1_host_enable_brdy_int(pipe);
915 usb1_host_enable_nrdy_int(pipe);
916 usb1_host_enable_brdy_int(pipe);
919 usb1_host_set_pid_buf(pipe);
922 /*******************************************************************************
923 * Function Name: usb1_host_read_buffer
924 * Description : Reads data from the buffer allocated in the pipe specified
926 * : Uses FIF0 set in the pipe definition table.
927 * Arguments : uint16_t pipe ; Pipe Number
928 * Return Value : USB_HOST_READEND ; Read end
929 * : USB_HOST_READSHRT ; short data
930 * : USB_HOST_READING ; Continue of data read
931 * : USB_HOST_READOVER ; buffer over
932 * : USB_HOST_FIFOERROR ; FIFO status
933 *******************************************************************************/
934 uint16_t usb1_host_read_buffer (uint16_t pipe)
938 g_usb1_host_PipeIgnore[pipe] = 0;
940 if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_USE)
942 status = usb1_host_read_buffer_d0(pipe);
944 else if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_USE)
946 status = usb1_host_read_buffer_d1(pipe);
950 status = usb1_host_read_buffer_c(pipe);
955 case USB_HOST_READING: /* Continue of data read */
958 case USB_HOST_READEND: /* End of data read */
959 case USB_HOST_READSHRT: /* End of data read */
960 usb1_host_disable_brdy_int(pipe);
961 g_usb1_host_PipeDataSize[pipe] -= g_usb1_host_data_count[pipe];
962 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
965 case USB_HOST_READOVER: /* buffer over */
966 if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_USE)
968 USB201.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
970 else if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_USE)
972 USB201.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
976 USB201.CFIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
978 usb1_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
979 #if(1) /* ohci_wrapp */
980 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
982 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
984 g_usb1_host_PipeDataSize[pipe] -= g_usb1_host_data_count[pipe];
987 case USB_HOST_FIFOERROR: /* FIFO access status */
989 usb1_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
990 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
994 return status; /* End or Err or Continue */
997 /*******************************************************************************
998 * Function Name: usb1_host_read_buffer_c
999 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
1000 * : Reads data by CPU transfer using CFIFO.
1001 * Arguments : uint16_t pipe ; Pipe Number
1002 * Return Value : USB_HOST_READEND ; Read end
1003 * : USB_HOST_READSHRT ; short data
1004 * : USB_HOST_READING ; Continue of data read
1005 * : USB_HOST_READOVER ; buffer over
1006 * : USB_HOST_FIFOERROR ; FIFO status
1007 *******************************************************************************/
1008 uint16_t usb1_host_read_buffer_c (uint16_t pipe)
1017 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
1018 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_NO, mbw);
1020 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
1022 return USB_HOST_FIFOERROR;
1025 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
1026 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
1028 if (g_usb1_host_data_count[pipe] < dtln) /* Buffer Over ? */
1030 status = USB_HOST_READOVER;
1031 usb1_host_set_pid_nak(pipe); /* Set NAK */
1032 count = g_usb1_host_data_count[pipe];
1034 else if (g_usb1_host_data_count[pipe] == dtln) /* just Receive Size */
1036 status = USB_HOST_READEND;
1037 usb1_host_set_pid_nak(pipe); /* Set NAK */
1042 status = USB_HOST_READSHRT; /* Null Packet receive */
1045 if ((count % mxps) != 0)
1047 status = USB_HOST_READSHRT; /* Short Packet receive */
1050 else /* continue Receive data */
1052 status = USB_HOST_READING;
1057 status = USB_HOST_READSHRT; /* Null Packet receive */
1058 usb1_host_set_pid_nak(pipe); /* Set NAK */
1061 if ((count % mxps) != 0)
1063 status = USB_HOST_READSHRT; /* Short Packet receive */
1064 usb1_host_set_pid_nak(pipe); /* Set NAK */
1068 if (count == 0) /* 0 length packet */
1070 USB201.CFIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
1074 usb1_host_read_c_fifo(pipe, (uint16_t)count);
1077 g_usb1_host_data_count[pipe] -= count;
1079 return status; /* End or Err or Continue */
1082 /*******************************************************************************
1083 * Function Name: usb1_host_read_buffer_d0
1084 * Description : Reads data from the buffer allocated in the pipe specified in
1086 * : Reads data by CPU transfer using D0FIFO.
1087 * Arguments : uint16_t pipe ; Pipe Number
1088 * Return Value : USB_HOST_READEND ; Read end
1089 * : USB_HOST_READSHRT ; short data
1090 * : USB_HOST_READING ; Continue of data read
1091 * : USB_HOST_READOVER ; buffer over
1092 * : USB_HOST_FIFOERROR ; FIFO status
1093 *******************************************************************************/
1094 uint16_t usb1_host_read_buffer_d0 (uint16_t pipe)
1102 uint16_t pipebuf_size;
1104 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
1105 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D0USE, USB_HOST_NO, mbw);
1107 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
1109 return USB_HOST_FIFOERROR;
1112 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
1113 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
1115 if (g_usb1_host_data_count[pipe] < dtln) /* Buffer Over ? */
1117 status = USB_HOST_READOVER;
1118 usb1_host_set_pid_nak(pipe); /* Set NAK */
1119 count = g_usb1_host_data_count[pipe];
1121 else if (g_usb1_host_data_count[pipe] == dtln) /* just Receive Size */
1123 status = USB_HOST_READEND;
1124 usb1_host_set_pid_nak(pipe); /* Set NAK */
1129 status = USB_HOST_READSHRT; /* Null Packet receive */
1132 if ((count % mxps) != 0)
1134 status = USB_HOST_READSHRT; /* Short Packet receive */
1137 else /* continue Receive data */
1139 status = USB_HOST_READING;
1144 status = USB_HOST_READSHRT; /* Null Packet receive */
1145 usb1_host_set_pid_nak(pipe); /* Set NAK */
1148 if ((count % mxps) != 0)
1150 status = USB_HOST_READSHRT; /* Short Packet receive */
1151 usb1_host_set_pid_nak(pipe); /* Set NAK */
1155 pipebuf_size = usb1_host_get_buf_size(pipe); /* Data buffer size */
1157 if (count != pipebuf_size)
1159 status = USB_HOST_READSHRT; /* Short Packet receive */
1160 usb1_host_set_pid_nak(pipe); /* Set NAK */
1165 if (count == 0) /* 0 length packet */
1167 USB201.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
1171 usb1_host_read_d0_fifo(pipe, (uint16_t)count);
1174 g_usb1_host_data_count[pipe] -= count;
1176 return status; /* End or Err or Continue */
1179 /*******************************************************************************
1180 * Function Name: usb1_host_read_buffer_d1
1181 * Description : Reads data from the buffer allocated in the pipe specified
1182 * : in the argument.
1183 * : Reads data by CPU transfer using D1FIFO.
1184 * Arguments : uint16_t pipe ; Pipe Number
1185 * Return Value : USB_HOST_READEND ; Read end
1186 * : USB_HOST_READSHRT ; short data
1187 * : USB_HOST_READING ; Continue of data read
1188 * : USB_HOST_READOVER ; buffer over
1189 * : USB_HOST_FIFOERROR ; FIFO status
1190 *******************************************************************************/
1191 uint16_t usb1_host_read_buffer_d1 (uint16_t pipe)
1199 uint16_t pipebuf_size;
1201 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
1202 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D1USE, USB_HOST_NO, mbw);
1204 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
1206 return USB_HOST_FIFOERROR;
1209 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
1210 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
1212 if (g_usb1_host_data_count[pipe] < dtln) /* Buffer Over ? */
1214 status = USB_HOST_READOVER;
1215 usb1_host_set_pid_nak(pipe); /* Set NAK */
1216 count = g_usb1_host_data_count[pipe];
1218 else if (g_usb1_host_data_count[pipe] == dtln) /* just Receive Size */
1220 status = USB_HOST_READEND;
1221 usb1_host_set_pid_nak(pipe); /* Set NAK */
1226 status = USB_HOST_READSHRT; /* Null Packet receive */
1229 if ((count % mxps) !=0)
1231 status = USB_HOST_READSHRT; /* Short Packet receive */
1234 else /* continue Receive data */
1236 status = USB_HOST_READING;
1241 status = USB_HOST_READSHRT; /* Null Packet receive */
1242 usb1_host_set_pid_nak(pipe); /* Set NAK */
1245 if ((count % mxps) != 0)
1247 status = USB_HOST_READSHRT; /* Short Packet receive */
1248 usb1_host_set_pid_nak(pipe); /* Set NAK */
1252 pipebuf_size = usb1_host_get_buf_size(pipe); /* Data buffer size */
1253 if (count != pipebuf_size)
1255 status = USB_HOST_READSHRT; /* Short Packet receive */
1256 usb1_host_set_pid_nak(pipe); /* Set NAK */
1261 if (count == 0) /* 0 length packet */
1263 USB201.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
1267 usb1_host_read_d1_fifo(pipe, (uint16_t)count);
1270 g_usb1_host_data_count[pipe] -= count;
1272 return status; /* End or Err or Continue */
1275 /*******************************************************************************
1276 * Function Name: usb1_host_read_dma
1277 * Description : Reads data from the buffer allocated in the pipe specified
1278 * : in the argument.
1279 * : Reads data by DMA transfer using D0FIFO or D1FIFO.
1280 * Arguments : uint16_t pipe ; Pipe Number
1281 * Return Value : USB_HOST_READEND ; Read end
1282 * : USB_HOST_READSHRT ; short data
1283 * : USB_HOST_READZERO ; zero data
1284 * : USB_HOST_READING ; Continue of data read
1285 * : USB_HOST_READOVER ; buffer over
1286 * : USB_HOST_FIFOERROR ; FIFO status
1287 *******************************************************************************/
1288 uint16_t usb1_host_read_dma (uint16_t pipe)
1292 g_usb1_host_PipeIgnore[pipe] = 0;
1294 if ((g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_DMA)
1296 status = usb1_host_read_dma_d0(pipe);
1300 status = usb1_host_read_dma_d1(pipe);
1305 case USB_HOST_READING: /* Continue of data read */
1308 case USB_HOST_READZERO: /* End of data read */
1309 usb1_host_disable_brdy_int(pipe);
1310 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
1313 case USB_HOST_READEND: /* End of data read */
1314 case USB_HOST_READSHRT: /* End of data read */
1315 usb1_host_disable_brdy_int(pipe);
1317 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
1319 g_usb1_host_PipeDataSize[pipe] -= g_usb1_host_data_count[pipe];
1323 case USB_HOST_READOVER: /* buffer over */
1324 usb1_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
1326 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
1328 g_usb1_host_PipeDataSize[pipe] -= g_usb1_host_data_count[pipe];
1330 #if(1) /* ohci_wrapp */
1331 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
1333 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
1337 case USB_HOST_FIFOERROR: /* FIFO access status */
1339 usb1_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
1340 g_usb1_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
1344 return status; /* End or Err or Continue */
1347 /*******************************************************************************
1348 * Function Name: usb1_host_read_dma_d0
1349 * Description : Writes data in the buffer allocated in the pipe specified
1350 * : in the argument.
1351 * : Reads data by DMA transfer using D0FIFO.
1352 * Arguments : uint16_t pipe ; Pipe Number
1353 * Return Value : USB_HOST_READEND ; Read end
1354 * : USB_HOST_READSHRT ; short data
1355 * : USB_HOST_READZERO ; zero data
1356 * : USB_HOST_READING ; Continue of data read
1357 * : USB_HOST_READOVER ; buffer over
1358 * : USB_HOST_FIFOERROR ; FIFO status
1359 *******************************************************************************/
1360 static uint16_t usb1_host_read_dma_d0 (uint16_t pipe)
1369 uint16_t pipebuf_size;
1371 g_usb1_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_READY;
1373 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
1375 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
1377 count = g_usb1_host_data_count[pipe];
1378 status = USB_HOST_READING;
1382 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
1384 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
1386 return USB_HOST_FIFOERROR;
1389 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
1390 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
1392 if (g_usb1_host_data_count[pipe] < dtln) /* Buffer Over ? */
1394 status = USB_HOST_READOVER;
1395 count = g_usb1_host_data_count[pipe];
1397 else if (g_usb1_host_data_count[pipe] == dtln) /* just Receive Size */
1399 status = USB_HOST_READEND;
1404 status = USB_HOST_READSHRT; /* Null Packet receive */
1407 if ((count % mxps) != 0)
1409 status = USB_HOST_READSHRT; /* Short Packet receive */
1412 else /* continue Receive data */
1414 status = USB_HOST_READING;
1419 status = USB_HOST_READSHRT; /* Null Packet receive */
1422 if ((count % mxps) != 0)
1424 status = USB_HOST_READSHRT; /* Short Packet receive */
1428 pipebuf_size = usb1_host_get_buf_size(pipe); /* Data buffer size */
1430 if (count != pipebuf_size)
1432 status = USB_HOST_READSHRT; /* Short Packet receive */
1438 if (count == 0) /* 0 length packet */
1440 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
1442 USB201.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
1443 status = USB_HOST_READZERO; /* Null Packet receive */
1447 usb1_host_set_curpipe(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
1448 /* transaction counter No set */
1449 /* FRDY = 1, DTLN = 0 -> BRDY */
1454 dfacc = usb1_host_set_dfacc_d0(mbw, count);
1456 if (mbw == USB_HOST_BITMBW_32)
1458 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size = 2; /* 32bit transfer */
1460 else if (mbw == USB_HOST_BITMBW_16)
1462 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size = 1; /* 16bit transfer */
1466 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].size = 0; /* 8bit transfer */
1469 g_usb1_host_DmaPipe[USB_HOST_D0FIFO] = pipe; /* not use in read operation */
1470 g_usb1_host_DmaBval[USB_HOST_D0FIFO] = 0; /* not use in read operation */
1472 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].fifo = USB_HOST_D0FIFO_DMA;
1473 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].dir = USB_HOST_FIFO2BUF;
1474 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].buffer = (uint32_t)g_usb1_host_data_pointer[pipe];
1475 g_usb1_host_DmaInfo[USB_HOST_D0FIFO].bytes = count;
1477 if (status == USB_HOST_READING)
1479 g_usb1_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_BUSY;
1483 g_usb1_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_BUSYEND;
1486 Userdef_USB_usb1_host_start_dma(&g_usb1_host_DmaInfo[USB_HOST_D0FIFO], dfacc);
1488 usb1_host_set_curpipe2(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw , dfacc);
1490 RZA_IO_RegWrite_16(&USB201.D0FIFOSEL,
1492 USB_DnFIFOSEL_DREQE_SHIFT,
1493 USB_DnFIFOSEL_DREQE);
1496 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
1498 g_usb1_host_data_count[pipe] -= count;
1499 g_usb1_host_data_pointer[pipe] += count;
1500 g_usb1_host_PipeDataSize[pipe] += count;
1503 return status; /* End or Err or Continue */
1506 /*******************************************************************************
1507 * Function Name: usb1_host_read_dma_d1
1508 * Description : Reads data from the buffer allocated in the pipe specified in
1510 * : Reads data by DMA transfer using D1FIFO.
1511 * Arguments : uint16_t pipe ; Pipe Number
1512 * Return Value : USB_HOST_READEND ; Read end
1513 * : USB_HOST_READSHRT ; short data
1514 * : USB_HOST_READZERO ; zero data
1515 * : USB_HOST_READING ; Continue of data read
1516 * : USB_HOST_READOVER ; buffer over
1517 * : USB_HOST_FIFOERROR ; FIFO status
1518 *******************************************************************************/
1519 static uint16_t usb1_host_read_dma_d1 (uint16_t pipe)
1528 uint16_t pipebuf_size;
1530 g_usb1_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_READY;
1532 mbw = usb1_host_get_mbw(g_usb1_host_data_count[pipe], (uint32_t)g_usb1_host_data_pointer[pipe]);
1534 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
1536 count = g_usb1_host_data_count[pipe];
1537 status = USB_HOST_READING;
1541 buffer = usb1_host_change_fifo_port(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
1543 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
1545 return USB_HOST_FIFOERROR;
1548 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
1549 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
1551 if (g_usb1_host_data_count[pipe] < dtln) /* Buffer Over ? */
1553 status = USB_HOST_READOVER;
1554 count = g_usb1_host_data_count[pipe];
1556 else if (g_usb1_host_data_count[pipe] == dtln) /* just Receive Size */
1558 status = USB_HOST_READEND;
1563 status = USB_HOST_READSHRT; /* Null Packet receive */
1566 if ((count % mxps) != 0)
1568 status = USB_HOST_READSHRT; /* Short Packet receive */
1571 else /* continue Receive data */
1573 status = USB_HOST_READING;
1578 status = USB_HOST_READSHRT; /* Null Packet receive */
1581 if ((count % mxps) != 0)
1583 status = USB_HOST_READSHRT; /* Short Packet receive */
1587 pipebuf_size = usb1_host_get_buf_size(pipe); /* Data buffer size */
1589 if (count != pipebuf_size)
1591 status = USB_HOST_READSHRT; /* Short Packet receive */
1597 if (count == 0) /* 0 length packet */
1599 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
1601 USB201.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
1602 status = USB_HOST_READZERO; /* Null Packet receive */
1606 usb1_host_set_curpipe(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
1607 /* transaction counter No set */
1608 /* FRDY = 1, DTLN = 0 -> BRDY */
1613 dfacc = usb1_host_set_dfacc_d1(mbw, count);
1615 if (mbw == USB_HOST_BITMBW_32)
1617 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size = 2; /* 32bit transfer */
1619 else if (mbw == USB_HOST_BITMBW_16)
1621 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size = 1; /* 16bit transfer */
1625 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].size = 0; /* 8bit transfer */
1628 g_usb1_host_DmaPipe[USB_HOST_D1FIFO] = pipe; /* not use in read operation */
1629 g_usb1_host_DmaBval[USB_HOST_D1FIFO] = 0; /* not use in read operation */
1631 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].fifo = USB_HOST_D1FIFO_DMA;
1632 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].dir = USB_HOST_FIFO2BUF;
1633 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].buffer = (uint32_t)g_usb1_host_data_pointer[pipe];
1634 g_usb1_host_DmaInfo[USB_HOST_D1FIFO].bytes = count;
1636 if (status == USB_HOST_READING)
1638 g_usb1_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_BUSY;
1642 g_usb1_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_BUSYEND;
1645 Userdef_USB_usb1_host_start_dma(&g_usb1_host_DmaInfo[USB_HOST_D1FIFO], dfacc);
1647 usb1_host_set_curpipe2(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw , dfacc);
1649 RZA_IO_RegWrite_16(&USB201.D1FIFOSEL,
1651 USB_DnFIFOSEL_DREQE_SHIFT,
1652 USB_DnFIFOSEL_DREQE);
1655 if (RZA_IO_RegRead_16(&g_usb1_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
1657 g_usb1_host_data_count[pipe] -= count;
1658 g_usb1_host_data_pointer[pipe] += count;
1659 g_usb1_host_PipeDataSize[pipe] += count;
1662 return status; /* End or Err or Continue */
1665 /*******************************************************************************
1666 * Function Name: usb1_host_change_fifo_port
1667 * Description : Allocates FIF0 specified by the argument in the pipe assigned
1668 * : by the argument. After allocating FIF0, waits in the software
1669 * : till the corresponding pipe becomes ready.
1670 * Arguments : uint16_t pipe ; Pipe Number
1671 * : uint16_t fifosel ; Select FIFO
1672 * : uint16_t isel ; FIFO Access Direction
1673 * : uint16_t mbw ; FIFO Port Access Bit Width
1674 * Return Value : USB_HOST_FIFOERROR ; Error
1675 * : Others ; CFIFOCTR/D0FIFOCTR/D1FIFOCTR Register Value
1676 *******************************************************************************/
1677 uint16_t usb1_host_change_fifo_port (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
1681 volatile uint32_t loop2;
1683 usb1_host_set_curpipe(pipe, fifosel, isel, mbw);
1685 for (loop = 0; loop < 4; loop++)
1690 buffer = USB201.CFIFOCTR;
1693 case USB_HOST_D0USE:
1694 case USB_HOST_D0DMA:
1695 buffer = USB201.D0FIFOCTR;
1698 case USB_HOST_D1USE:
1699 case USB_HOST_D1DMA:
1700 buffer = USB201.D1FIFOCTR;
1708 if ((buffer & USB_HOST_BITFRDY) == USB_HOST_BITFRDY)
1721 return USB_HOST_FIFOERROR;
1724 /*******************************************************************************
1725 * Function Name: usb1_host_set_curpipe
1726 * Description : Allocates FIF0 specified by the argument in the pipe assigned
1727 * : by the argument.
1728 * Arguments : uint16_t pipe ; Pipe Number
1729 * : uint16_t fifosel ; Select FIFO
1730 * : uint16_t isel ; FIFO Access Direction
1731 * : uint16_t mbw ; FIFO Port Access Bit Width
1732 * Return Value : none
1733 *******************************************************************************/
1734 void usb1_host_set_curpipe (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
1738 volatile uint32_t loop2;
1740 g_usb1_host_mbw[pipe] = mbw;
1745 buffer = USB201.CFIFOSEL;
1746 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE);
1747 buffer |= (uint16_t)(~isel & USB_HOST_BITISEL);
1748 USB201.CFIFOSEL = buffer;
1750 for (loop = 0; loop < 4; loop++)
1752 if ((USB201.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
1753 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
1765 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
1766 buffer |= (uint16_t)(isel | pipe | mbw);
1767 USB201.CFIFOSEL = buffer;
1769 for (loop = 0; loop < 4; loop++)
1771 if ((USB201.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
1772 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
1785 case USB_HOST_D0DMA:
1786 case USB_HOST_D0USE:
1787 buffer = USB201.D0FIFOSEL;
1788 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
1789 USB201.D0FIFOSEL = buffer;
1791 for (loop = 0; loop < 4; loop++)
1793 if ((USB201.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
1804 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
1805 buffer |= (uint16_t)(pipe | mbw);
1806 USB201.D0FIFOSEL = buffer;
1808 for (loop = 0; loop < 4; loop++)
1810 if ((USB201.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
1823 case USB_HOST_D1DMA:
1824 case USB_HOST_D1USE:
1825 buffer = USB201.D1FIFOSEL;
1826 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
1827 USB201.D1FIFOSEL = buffer;
1829 for (loop = 0; loop < 4; loop++)
1831 if ((USB201.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
1843 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
1844 buffer |= (uint16_t)(pipe | mbw);
1845 USB201.D1FIFOSEL = buffer;
1847 for (loop = 0; loop < 4; loop++)
1849 if ((USB201.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
1867 * Depending on the external bus speed of CPU, you may need to wait for 450ns here.
1868 * For details, please look at the data sheet. */
1877 /*******************************************************************************
1878 * Function Name: usb1_host_set_curpipe2
1879 * Description : Allocates FIF0 specified by the argument in the pipe assigned
1880 * : by the argument.(DFACC)
1881 * Arguments : uint16_t pipe ; Pipe Number
1882 * : uint16_t fifosel ; Select FIFO
1883 * : uint16_t isel ; FIFO Access Direction
1884 * : uint16_t mbw ; FIFO Port Access Bit Width
1885 * : uint16_t dfacc ; DFACC Access mode
1886 * Return Value : none
1887 *******************************************************************************/
1888 void usb1_host_set_curpipe2 (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw, uint16_t dfacc)
1892 #ifdef __USB_HOST_DF_ACC_ENABLE__
1895 volatile uint32_t loop2;
1897 g_usb1_host_mbw[pipe] = mbw;
1902 buffer = USB201.CFIFOSEL;
1903 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE);
1904 buffer |= (uint16_t)(~isel & USB_HOST_BITISEL);
1905 USB201.CFIFOSEL = buffer;
1907 for (loop = 0; loop < 4; loop++)
1909 if ((USB201.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
1910 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
1922 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
1923 buffer |= (uint16_t)(isel | pipe | mbw);
1924 USB201.CFIFOSEL = buffer;
1926 for (loop = 0; loop < 4; loop++)
1928 if ((USB201.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
1929 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
1942 case USB_HOST_D0DMA:
1943 case USB_HOST_D0USE:
1944 buffer = USB201.D0FIFOSEL;
1945 #ifdef __USB_HOST_DF_ACC_ENABLE__
1946 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
1950 buffer |= (uint16_t)(USB_HOST_BITMBW_32);
1953 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
1955 USB201.D0FIFOSEL = buffer;
1957 for (loop = 0; loop < 4; loop++)
1959 if ((USB201.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
1971 #ifdef __USB_HOST_DF_ACC_ENABLE__
1974 dummy = USB201.D0FIFO.UINT32;
1978 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
1979 buffer |= (uint16_t)(pipe | mbw);
1980 USB201.D0FIFOSEL = buffer;
1982 for (loop = 0; loop < 4; loop++)
1984 if ((USB201.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
1997 case USB_HOST_D1DMA:
1998 case USB_HOST_D1USE:
1999 buffer = USB201.D1FIFOSEL;
2000 #ifdef __USB_HOST_DF_ACC_ENABLE__
2001 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
2005 buffer |= (uint16_t)(USB_HOST_BITMBW_32);
2008 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
2010 USB201.D1FIFOSEL = buffer;
2012 for (loop = 0; loop < 4; loop++)
2014 if ((USB201.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
2026 #ifdef __USB_HOST_DF_ACC_ENABLE__
2029 dummy = USB201.D1FIFO.UINT32;
2030 loop = dummy; // avoid warning.
2034 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
2035 buffer |= (uint16_t)(pipe | mbw);
2036 USB201.D1FIFOSEL = buffer;
2038 for (loop = 0; loop < 4; loop++)
2040 if ((USB201.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
2058 * Depending on the external bus speed of CPU, you may need to wait for 450ns here.
2059 * For details, please look at the data sheet. */
2067 /*******************************************************************************
2068 * Function Name: usb1_host_write_c_fifo
2069 * Description : Writes data in CFIFO.
2070 * : Writes data by BYTE/WORD/LONG according to access size
2071 * : to the pipe specified by the arguments.
2072 * : Before executing this function, allocating CFIF0 in the specified pipe
2073 * : should be completed.
2074 * : Before executing this function, access size to the specified pipe
2075 * : should be fixed and set in g_usb1_host_mbw[].
2076 * Arguments : uint16_t pipe ; Pipe Number
2077 * : uint16_t count ; Data Size(Byte)
2078 * Return Value : none
2079 *******************************************************************************/
2080 static void usb1_host_write_c_fifo (uint16_t pipe, uint16_t count)
2084 if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_8)
2086 for (even = count; even; --even)
2088 USB201.CFIFO.UINT8[HH] = *g_usb1_host_data_pointer[pipe];
2089 g_usb1_host_data_pointer[pipe] += 1;
2092 else if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_16)
2094 for (even = (uint16_t)(count / 2); even; --even)
2096 USB201.CFIFO.UINT16[H] = *((uint16_t *)g_usb1_host_data_pointer[pipe]);
2097 g_usb1_host_data_pointer[pipe] += 2;
2102 for (even = (uint16_t)(count / 4); even; --even)
2104 USB201.CFIFO.UINT32 = *((uint32_t *)g_usb1_host_data_pointer[pipe]);
2105 g_usb1_host_data_pointer[pipe] += 4;
2110 /*******************************************************************************
2111 * Function Name: usb1_host_read_c_fifo
2112 * Description : Reads data from CFIFO.
2113 * : Reads data by BYTE/WORD/LONG according to access size
2114 * : to the pipe specified by the arguments.
2115 * : Before executing this function, allocating CFIF0 in the specified pipe
2116 * : should be completed.
2117 * : Before executing this function, access size to the specified pipe
2118 * : should be fixed and set in g_usb0_host_mbw[].
2119 * Arguments : uint16_t pipe ; Pipe Number
2120 * : uint16_t count ; Data Size(Byte)
2121 * Return Value : none
2122 *******************************************************************************/
2123 static void usb1_host_read_c_fifo (uint16_t pipe, uint16_t count)
2127 if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_8)
2129 for (even = count; even; --even)
2131 *g_usb1_host_data_pointer[pipe] = USB201.CFIFO.UINT8[HH];
2132 g_usb1_host_data_pointer[pipe] += 1;
2135 else if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_16)
2137 for (even = (uint16_t)((count + 1) / 2); even; --even)
2139 *((uint16_t *)g_usb1_host_data_pointer[pipe]) = USB201.CFIFO.UINT16[H];
2140 g_usb1_host_data_pointer[pipe] += 2;
2145 for (even = (uint16_t)((count + 3) / 4); even; --even)
2147 *((uint32_t *)g_usb1_host_data_pointer[pipe]) = USB201.CFIFO.UINT32;
2148 g_usb1_host_data_pointer[pipe] += 4;
2153 /*******************************************************************************
2154 * Function Name: usb1_host_write_d0_fifo
2155 * Description : Writes data in D0FIFO.
2156 * : Writes data by BYTE/WORD/LONG according to access size
2157 * : to the pipe specified by the arguments.
2158 * : Before executing this function, allocating CFIF0 in the specified pipe
2159 * : should be completed.
2160 * : Before executing this function, access size to the specified pipe
2161 * : should be fixed and set in g_usb0_host_mbw[].
2162 * Arguments : uint16_t pipe ; Pipe Number
2163 * : uint16_t count ; Data Size(Byte)
2164 * Return Value : none
2165 *******************************************************************************/
2166 static void usb1_host_write_d0_fifo (uint16_t pipe, uint16_t count)
2170 if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_8)
2172 for (even = count; even; --even)
2174 USB201.D0FIFO.UINT8[HH] = *g_usb1_host_data_pointer[pipe];
2175 g_usb1_host_data_pointer[pipe] += 1;
2178 else if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_16)
2180 for (even = (uint16_t)(count / 2); even; --even)
2182 USB201.D0FIFO.UINT16[H] = *((uint16_t *)g_usb1_host_data_pointer[pipe]);
2183 g_usb1_host_data_pointer[pipe] += 2;
2188 for (even = (uint16_t)(count / 4); even; --even)
2190 USB201.D0FIFO.UINT32 = *((uint32_t *)g_usb1_host_data_pointer[pipe]);
2191 g_usb1_host_data_pointer[pipe] += 4;
2196 /*******************************************************************************
2197 * Function Name: usb1_host_read_d0_fifo
2198 * Description : Reads data from D0FIFO.
2199 * : Reads data by BYTE/WORD/LONG according to access size
2200 * : to the pipe specified by the arguments.
2201 * : Before executing this function, allocating DOFIF0 in the specified pipe
2202 * : should be completed.
2203 * : Before executing this function, access size to the specified pipe
2204 * : should be fixed and set in g_usb0_host_mbw[].
2205 * Arguments : uint16_t Pipe ; Pipe Number
2206 * : uint16_t count ; Data Size(Byte)
2207 * Return Value : none
2208 *******************************************************************************/
2209 static void usb1_host_read_d0_fifo (uint16_t pipe, uint16_t count)
2213 if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_8)
2215 for (even = count; even; --even)
2217 *g_usb1_host_data_pointer[pipe] = USB201.D0FIFO.UINT8[HH];
2218 g_usb1_host_data_pointer[pipe] += 1;
2221 else if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_16)
2223 for (even = (uint16_t)((count + 1) / 2); even; --even)
2225 *((uint16_t *)g_usb1_host_data_pointer[pipe]) = USB201.D0FIFO.UINT16[H];
2226 g_usb1_host_data_pointer[pipe] += 2;
2231 for (even = (uint16_t)((count + 3) / 4); even; --even)
2233 *((uint32_t *)g_usb1_host_data_pointer[pipe]) = USB201.D0FIFO.UINT32;
2234 g_usb1_host_data_pointer[pipe] += 4;
2239 /*******************************************************************************
2240 * Function Name: usb1_host_write_d1_fifo
2241 * Description : Writes data in D1FIFO.
2242 * : Writes data by BYTE/WORD/LONG according to access size
2243 * : to the pipe specified by the arguments.
2244 * : Before executing this function, allocating D1FIF0 in the specified pipe
2245 * : should be completed.
2246 * : Before executing this function, access size to the specified pipe
2247 * : should be fixed and set in g_usb1_host_mbw[].
2248 * Arguments : uint16_t pipe ; Pipe Number
2249 * : uint16_t count ; Data Size(Byte)
2250 * Return Value : none
2251 *******************************************************************************/
2252 static void usb1_host_write_d1_fifo (uint16_t pipe, uint16_t count)
2256 if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_8)
2258 for (even = count; even; --even)
2260 USB201.D1FIFO.UINT8[HH] = *g_usb1_host_data_pointer[pipe];
2261 g_usb1_host_data_pointer[pipe] += 1;
2264 else if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_16)
2266 for (even = (uint16_t)(count / 2); even; --even)
2268 USB201.D1FIFO.UINT16[H] = *((uint16_t *)g_usb1_host_data_pointer[pipe]);
2269 g_usb1_host_data_pointer[pipe] += 2;
2274 for (even = (uint16_t)(count / 4); even; --even)
2276 USB201.D1FIFO.UINT32 = *((uint32_t *)g_usb1_host_data_pointer[pipe]);
2277 g_usb1_host_data_pointer[pipe] += 4;
2282 /*******************************************************************************
2283 * Function Name: usb1_host_read_d1_fifo
2284 * Description : Reads data from D1FIFO.
2285 * : Reads data by BYTE/WORD/LONG according to access size
2286 * : to the pipe specified by the arguments.
2287 * : Before executing this function, allocating D1FIF0 in the specified pipe
2288 * : should be completed.
2289 * : Before executing this function, access size to the specified pipe
2290 * : should be fixed and set in g_usb1_host_mbw[].
2291 * Arguments : uint16_t pipe ; Pipe Number
2292 * : uint16_t count ; Data Size(Byte)
2293 * Return Value : none
2294 *******************************************************************************/
2295 static void usb1_host_read_d1_fifo (uint16_t pipe, uint16_t count)
2299 if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_8)
2301 for (even = count; even; --even)
2303 *g_usb1_host_data_pointer[pipe] = USB201.D1FIFO.UINT8[HH];
2304 g_usb1_host_data_pointer[pipe] += 1;
2307 else if (g_usb1_host_mbw[pipe] == USB_HOST_BITMBW_16)
2309 for (even = (uint16_t)((count + 1) / 2); even; --even)
2311 *((uint16_t *)g_usb1_host_data_pointer[pipe]) = USB201.D1FIFO.UINT16[H];
2312 g_usb1_host_data_pointer[pipe] += 2;
2317 for (even = (uint16_t)((count + 3) / 4); even; --even)
2319 *((uint32_t *)g_usb1_host_data_pointer[pipe]) = USB201.D1FIFO.UINT32;
2320 g_usb1_host_data_pointer[pipe] += 4;
2325 /*******************************************************************************
2326 * Function Name: usb1_host_com_get_dmasize
2327 * Description : Calculates access width of DMA transfer by the argument to
2328 return as the Return Value.
2329 * Arguments : uint32_t trncount : transfer byte
2330 * : uint32_t dtptr : transfer data pointer
2331 * Return Value : DMA transfer size : 0 8bit
2334 *******************************************************************************/
2335 static uint32_t usb1_host_com_get_dmasize (uint32_t trncount, uint32_t dtptr)
2339 if (((trncount & 0x0001) != 0) || ((dtptr & 0x00000001) != 0))
2341 /* When transfer byte count is odd */
2342 /* or transfer data area is 8-bit alignment */
2343 size = 0; /* 8bit */
2345 else if (((trncount & 0x0003) != 0) || ((dtptr & 0x00000003) != 0))
2347 /* When the transfer byte count is multiples of 2 */
2348 /* or the transfer data area is 16-bit alignment */
2349 size = 1; /* 16bit */
2353 /* When the transfer byte count is multiples of 4 */
2354 /* or the transfer data area is 32-bit alignment */
2355 size = 2; /* 32bit */
2361 /*******************************************************************************
2362 * Function Name: usb1_host_get_mbw
2363 * Description : Calculates access width of DMA to return the value set in MBW.
2364 * Arguments : uint32_t trncount : transfer byte
2365 * : uint32_t dtptr : transfer data pointer
2366 * Return Value : FIFO transfer size : USB_HOST_BITMBW_8 8bit
2367 * : : USB_HOST_BITMBW_16 16bit
2368 * : : USB_HOST_BITMBW_32 32bit
2369 *******************************************************************************/
2370 uint16_t usb1_host_get_mbw (uint32_t trncount, uint32_t dtptr)
2375 size = usb1_host_com_get_dmasize(trncount, dtptr);
2380 mbw = USB_HOST_BITMBW_8;
2385 mbw = USB_HOST_BITMBW_16;
2390 mbw = USB_HOST_BITMBW_32;
2396 /*******************************************************************************
2397 * Function Name: usb1_host_set_transaction_counter
2398 * Description : Sets transaction counter by the argument(PIPEnTRN).
2399 * : Clears transaction before setting to enable transaction counter setting.
2400 * Arguments : uint16_t pipe ; Pipe number
2401 * : uint32_t bsize : Data transfer size
2402 * Return Value : none
2403 *******************************************************************************/
2404 static void usb1_host_set_transaction_counter (uint16_t pipe, uint32_t bsize)
2414 mxps = usb1_host_get_mxps(pipe); /* Max Packet Size */
2416 if ((bsize % mxps) == 0)
2418 cnt = (uint16_t)(bsize / mxps);
2422 cnt = (uint16_t)((bsize / mxps) + 1);
2427 case USB_HOST_PIPE1:
2428 RZA_IO_RegWrite_16(&USB201.PIPE1TRE,
2430 USB_PIPEnTRE_TRCLR_SHIFT,
2431 USB_PIPEnTRE_TRCLR);
2432 USB201.PIPE1TRN = cnt;
2433 RZA_IO_RegWrite_16(&USB201.PIPE1TRE,
2435 USB_PIPEnTRE_TRENB_SHIFT,
2436 USB_PIPEnTRE_TRENB);
2439 case USB_HOST_PIPE2:
2440 RZA_IO_RegWrite_16(&USB201.PIPE2TRE,
2442 USB_PIPEnTRE_TRCLR_SHIFT,
2443 USB_PIPEnTRE_TRCLR);
2444 USB201.PIPE2TRN = cnt;
2445 RZA_IO_RegWrite_16(&USB201.PIPE2TRE,
2447 USB_PIPEnTRE_TRENB_SHIFT,
2448 USB_PIPEnTRE_TRENB);
2451 case USB_HOST_PIPE3:
2452 RZA_IO_RegWrite_16(&USB201.PIPE3TRE,
2454 USB_PIPEnTRE_TRCLR_SHIFT,
2455 USB_PIPEnTRE_TRCLR);
2456 USB201.PIPE3TRN = cnt;
2457 RZA_IO_RegWrite_16(&USB201.PIPE3TRE,
2459 USB_PIPEnTRE_TRENB_SHIFT,
2460 USB_PIPEnTRE_TRENB);
2463 case USB_HOST_PIPE4:
2464 RZA_IO_RegWrite_16(&USB201.PIPE4TRE,
2466 USB_PIPEnTRE_TRCLR_SHIFT,
2467 USB_PIPEnTRE_TRCLR);
2468 USB201.PIPE4TRN = cnt;
2469 RZA_IO_RegWrite_16(&USB201.PIPE4TRE,
2471 USB_PIPEnTRE_TRENB_SHIFT,
2472 USB_PIPEnTRE_TRENB);
2475 case USB_HOST_PIPE5:
2476 RZA_IO_RegWrite_16(&USB201.PIPE5TRE,
2478 USB_PIPEnTRE_TRCLR_SHIFT,
2479 USB_PIPEnTRE_TRCLR);
2480 USB201.PIPE5TRN = cnt;
2481 RZA_IO_RegWrite_16(&USB201.PIPE5TRE,
2483 USB_PIPEnTRE_TRENB_SHIFT,
2484 USB_PIPEnTRE_TRENB);
2487 case USB_HOST_PIPE9:
2488 RZA_IO_RegWrite_16(&USB201.PIPE9TRE,
2490 USB_PIPEnTRE_TRCLR_SHIFT,
2491 USB_PIPEnTRE_TRCLR);
2492 USB201.PIPE9TRN = cnt;
2493 RZA_IO_RegWrite_16(&USB201.PIPE9TRE,
2495 USB_PIPEnTRE_TRENB_SHIFT,
2496 USB_PIPEnTRE_TRENB);
2504 /*******************************************************************************
2505 * Function Name: usb1_host_clear_transaction_counter
2506 * Description : Clears the transaction counter by the argument.
2507 * : After executing this function, the transaction counter is invalid.
2508 * Arguments : uint16_t pipe ; Pipe number
2509 * Return Value : none
2510 *******************************************************************************/
2511 void usb1_host_clear_transaction_counter (uint16_t pipe)
2515 case USB_HOST_PIPE1:
2516 RZA_IO_RegWrite_16(&USB201.PIPE1TRE,
2518 USB_PIPEnTRE_TRENB_SHIFT,
2519 USB_PIPEnTRE_TRENB);
2520 RZA_IO_RegWrite_16(&USB201.PIPE1TRE,
2522 USB_PIPEnTRE_TRCLR_SHIFT,
2523 USB_PIPEnTRE_TRCLR);
2526 case USB_HOST_PIPE2:
2527 RZA_IO_RegWrite_16(&USB201.PIPE2TRE,
2529 USB_PIPEnTRE_TRENB_SHIFT,
2530 USB_PIPEnTRE_TRENB);
2531 RZA_IO_RegWrite_16(&USB201.PIPE2TRE,
2533 USB_PIPEnTRE_TRCLR_SHIFT,
2534 USB_PIPEnTRE_TRCLR);
2537 case USB_HOST_PIPE3:
2538 RZA_IO_RegWrite_16(&USB201.PIPE3TRE,
2540 USB_PIPEnTRE_TRENB_SHIFT,
2541 USB_PIPEnTRE_TRENB);
2542 RZA_IO_RegWrite_16(&USB201.PIPE3TRE,
2544 USB_PIPEnTRE_TRCLR_SHIFT,
2545 USB_PIPEnTRE_TRCLR);
2548 case USB_HOST_PIPE4:
2549 RZA_IO_RegWrite_16(&USB201.PIPE4TRE,
2551 USB_PIPEnTRE_TRENB_SHIFT,
2552 USB_PIPEnTRE_TRENB);
2553 RZA_IO_RegWrite_16(&USB201.PIPE4TRE,
2555 USB_PIPEnTRE_TRCLR_SHIFT,
2556 USB_PIPEnTRE_TRCLR);
2559 case USB_HOST_PIPE5:
2560 RZA_IO_RegWrite_16(&USB201.PIPE5TRE,
2562 USB_PIPEnTRE_TRENB_SHIFT,
2563 USB_PIPEnTRE_TRENB);
2564 RZA_IO_RegWrite_16(&USB201.PIPE5TRE,
2566 USB_PIPEnTRE_TRCLR_SHIFT,
2567 USB_PIPEnTRE_TRCLR);
2570 case USB_HOST_PIPE9:
2571 RZA_IO_RegWrite_16(&USB201.PIPE9TRE,
2573 USB_PIPEnTRE_TRENB_SHIFT,
2574 USB_PIPEnTRE_TRENB);
2575 RZA_IO_RegWrite_16(&USB201.PIPE9TRE,
2577 USB_PIPEnTRE_TRCLR_SHIFT,
2578 USB_PIPEnTRE_TRCLR);
2586 /*******************************************************************************
2587 * Function Name: usb1_host_stop_transfer
2588 * Description : Stops the USB transfer in the pipe specified by the argument.
2589 * : After stopping the USB transfer, clears the buffer allocated in
2591 * : After executing this function, allocation in FIF0 becomes USB_HOST_PIPE0;
2592 * : invalid. After executing this function, BRDY/NRDY/BEMP interrupt
2593 * : in the corresponding pipe becomes invalid. Sequence bit is also
2595 * Arguments : uint16_t pipe ; Pipe Number
2596 * Return Value : none
2597 *******************************************************************************/
2598 void usb1_host_stop_transfer (uint16_t pipe)
2603 usb1_host_set_pid_nak(pipe);
2605 usefifo = (uint16_t)(g_usb1_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
2609 case USB_HOST_D0FIFO_USE:
2610 usb1_host_clear_transaction_counter(pipe);
2611 USB201.D0FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
2614 case USB_HOST_D1FIFO_USE:
2615 usb1_host_clear_transaction_counter(pipe);
2616 USB201.D1FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
2619 case USB_HOST_D0FIFO_DMA:
2620 remain = Userdef_USB_usb1_host_stop_dma0();
2621 usb1_host_dma_stop_d0(pipe, remain);
2622 usb1_host_clear_transaction_counter(pipe);
2623 USB201.D0FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
2626 case USB_HOST_D1FIFO_DMA:
2627 remain = Userdef_USB_usb1_host_stop_dma1();
2628 usb1_host_dma_stop_d1(pipe, remain);
2629 usb1_host_clear_transaction_counter(pipe);
2630 USB201.D1FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
2634 usb1_host_clear_transaction_counter(pipe);
2635 USB201.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
2639 /* Interrupt of pipe set is disabled */
2640 usb1_host_disable_brdy_int(pipe);
2641 usb1_host_disable_nrdy_int(pipe);
2642 usb1_host_disable_bemp_int(pipe);
2644 #if(1) /* ohci_wrapp */
2646 usb1_host_aclrm(pipe);
2648 usb1_host_set_csclr(pipe);
2651 /*******************************************************************************
2652 * Function Name: usb1_host_set_dfacc_d0
2653 * Description : Sets the DFACC setting value in D0FIFO using the transfer size.
2654 * Arguments : uint16_t mbw ; MBW
2655 * : uint16_t count ; data count
2656 * Return Value : DFACC Access mode
2657 *******************************************************************************/
2658 static uint16_t usb1_host_set_dfacc_d0 (uint16_t mbw, uint32_t count)
2662 #ifndef __USB_HOST_DF_ACC_ENABLE__
2663 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2665 USB_DnFBCFG_DFACC_SHIFT,
2667 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2669 USB_DnFBCFG_TENDE_SHIFT,
2673 if (mbw == USB_HOST_BITMBW_32)
2675 if ((count % 32) == 0)
2677 /* 32byte transfer */
2678 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2680 USB_DnFBCFG_DFACC_SHIFT,
2682 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2684 USB_DnFBCFG_TENDE_SHIFT,
2688 else if ((count % 16) == 0)
2690 /* 16byte transfer */
2691 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2693 USB_DnFBCFG_DFACC_SHIFT,
2695 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2697 USB_DnFBCFG_TENDE_SHIFT,
2703 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2705 USB_DnFBCFG_DFACC_SHIFT,
2707 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2709 USB_DnFBCFG_TENDE_SHIFT,
2714 else if (mbw == USB_HOST_BITMBW_16)
2716 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2718 USB_DnFBCFG_DFACC_SHIFT,
2720 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2722 USB_DnFBCFG_TENDE_SHIFT,
2728 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2730 USB_DnFBCFG_DFACC_SHIFT,
2732 RZA_IO_RegWrite_16(&USB201.D0FBCFG,
2734 USB_DnFBCFG_TENDE_SHIFT,
2743 /*******************************************************************************
2744 * Function Name: usb1_host_set_dfacc_d1
2745 * Description : Sets the DFACC setting value in D0FIFO using the transfer size.
2746 * Arguments : uint16_t mbw ; MBW
2747 * : uint16_t count ; data count
2748 * Return Value : DFACC Access mode
2749 *******************************************************************************/
2750 static uint16_t usb1_host_set_dfacc_d1 (uint16_t mbw, uint32_t count)
2754 #ifndef __USB_HOST_DF_ACC_ENABLE__
2755 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2757 USB_DnFBCFG_DFACC_SHIFT,
2759 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2761 USB_DnFBCFG_TENDE_SHIFT,
2765 if (mbw == USB_HOST_BITMBW_32)
2767 if ((count % 32) == 0)
2769 /* 32byte transfer */
2770 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2772 USB_DnFBCFG_DFACC_SHIFT,
2774 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2776 USB_DnFBCFG_TENDE_SHIFT,
2780 else if ((count % 16) == 0)
2782 /* 16byte transfer */
2783 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2785 USB_DnFBCFG_DFACC_SHIFT,
2787 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2789 USB_DnFBCFG_TENDE_SHIFT,
2795 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2797 USB_DnFBCFG_DFACC_SHIFT,
2799 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2801 USB_DnFBCFG_TENDE_SHIFT,
2806 else if (mbw == USB_HOST_BITMBW_16)
2808 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2810 USB_DnFBCFG_DFACC_SHIFT,
2812 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2814 USB_DnFBCFG_TENDE_SHIFT,
2820 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2822 USB_DnFBCFG_DFACC_SHIFT,
2824 RZA_IO_RegWrite_16(&USB201.D1FBCFG,
2826 USB_DnFBCFG_TENDE_SHIFT,