USBHost library. NOTE: This library is only officially supported on the LPC1768 platform. For more information, please see the handbook page.

Dependencies:   FATFileSystem mbed-rtos

Dependents:   BTstack WallbotWii SD to Flash Data Transfer USBHost-MSD_HelloWorld ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Pull requests against this repository are no longer supported. Please raise against mbed OS 5 as documented above.

Committer:
Kojto
Date:
Thu Jul 27 12:24:30 2017 +0100
Revision:
39:d96aa62afc5b
Update USBHost - add targets directory

This corresponds to mbed-os/master commit 9207365

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 39:d96aa62afc5b 1 /*******************************************************************************
Kojto 39:d96aa62afc5b 2 * DISCLAIMER
Kojto 39:d96aa62afc5b 3 * This software is supplied by Renesas Electronics Corporation and is only
Kojto 39:d96aa62afc5b 4 * intended for use with Renesas products. No other uses are authorized. This
Kojto 39:d96aa62afc5b 5 * software is owned by Renesas Electronics Corporation and is protected under
Kojto 39:d96aa62afc5b 6 * all applicable laws, including copyright laws.
Kojto 39:d96aa62afc5b 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
Kojto 39:d96aa62afc5b 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
Kojto 39:d96aa62afc5b 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
Kojto 39:d96aa62afc5b 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
Kojto 39:d96aa62afc5b 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
Kojto 39:d96aa62afc5b 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
Kojto 39:d96aa62afc5b 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
Kojto 39:d96aa62afc5b 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
Kojto 39:d96aa62afc5b 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Kojto 39:d96aa62afc5b 16 * Renesas reserves the right, without notice, to make changes to this software
Kojto 39:d96aa62afc5b 17 * and to discontinue the availability of this software. By using this software,
Kojto 39:d96aa62afc5b 18 * you agree to the additional terms and conditions found by accessing the
Kojto 39:d96aa62afc5b 19 * following link:
Kojto 39:d96aa62afc5b 20 * http://www.renesas.com/disclaimer
Kojto 39:d96aa62afc5b 21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
Kojto 39:d96aa62afc5b 22 *******************************************************************************/
Kojto 39:d96aa62afc5b 23 /*******************************************************************************
Kojto 39:d96aa62afc5b 24 * File Name : usb0_host_dataio.c
Kojto 39:d96aa62afc5b 25 * $Rev: 1116 $
Kojto 39:d96aa62afc5b 26 * $Date:: 2014-07-09 16:29:19 +0900#$
Kojto 39:d96aa62afc5b 27 * Device(s) : RZ/A1H
Kojto 39:d96aa62afc5b 28 * Tool-Chain :
Kojto 39:d96aa62afc5b 29 * OS : None
Kojto 39:d96aa62afc5b 30 * H/W Platform :
Kojto 39:d96aa62afc5b 31 * Description : RZ/A1H R7S72100 USB Sample Program
Kojto 39:d96aa62afc5b 32 * Operation :
Kojto 39:d96aa62afc5b 33 * Limitations :
Kojto 39:d96aa62afc5b 34 *******************************************************************************/
Kojto 39:d96aa62afc5b 35
Kojto 39:d96aa62afc5b 36
Kojto 39:d96aa62afc5b 37 /*******************************************************************************
Kojto 39:d96aa62afc5b 38 Includes <System Includes> , "Project Includes"
Kojto 39:d96aa62afc5b 39 *******************************************************************************/
Kojto 39:d96aa62afc5b 40 #include "usb0_host.h"
Kojto 39:d96aa62afc5b 41
Kojto 39:d96aa62afc5b 42
Kojto 39:d96aa62afc5b 43 /*******************************************************************************
Kojto 39:d96aa62afc5b 44 Typedef definitions
Kojto 39:d96aa62afc5b 45 *******************************************************************************/
Kojto 39:d96aa62afc5b 46
Kojto 39:d96aa62afc5b 47
Kojto 39:d96aa62afc5b 48 /*******************************************************************************
Kojto 39:d96aa62afc5b 49 Macro definitions
Kojto 39:d96aa62afc5b 50 *******************************************************************************/
Kojto 39:d96aa62afc5b 51
Kojto 39:d96aa62afc5b 52
Kojto 39:d96aa62afc5b 53 /*******************************************************************************
Kojto 39:d96aa62afc5b 54 Imported global variables and functions (from other files)
Kojto 39:d96aa62afc5b 55 *******************************************************************************/
Kojto 39:d96aa62afc5b 56
Kojto 39:d96aa62afc5b 57
Kojto 39:d96aa62afc5b 58 /*******************************************************************************
Kojto 39:d96aa62afc5b 59 Exported global variables and functions (to be accessed by other files)
Kojto 39:d96aa62afc5b 60 *******************************************************************************/
Kojto 39:d96aa62afc5b 61
Kojto 39:d96aa62afc5b 62
Kojto 39:d96aa62afc5b 63 /*******************************************************************************
Kojto 39:d96aa62afc5b 64 Private global variables and functions
Kojto 39:d96aa62afc5b 65 *******************************************************************************/
Kojto 39:d96aa62afc5b 66 static uint16_t g_usb0_host_mbw[(USB_HOST_MAX_PIPE_NO + 1)];
Kojto 39:d96aa62afc5b 67
Kojto 39:d96aa62afc5b 68 static void usb0_host_start_receive_trns_c(uint16_t pipe, uint32_t size, uint8_t *data);
Kojto 39:d96aa62afc5b 69 static void usb0_host_start_receive_trns_d0(uint16_t pipe, uint32_t size, uint8_t *data);
Kojto 39:d96aa62afc5b 70 static void usb0_host_start_receive_trns_d1(uint16_t pipe, uint32_t size, uint8_t *data);
Kojto 39:d96aa62afc5b 71 static void usb0_host_start_receive_dma_d0(uint16_t pipe, uint32_t size, uint8_t *data);
Kojto 39:d96aa62afc5b 72 static void usb0_host_start_receive_dma_d1(uint16_t pipe, uint32_t size, uint8_t *data);
Kojto 39:d96aa62afc5b 73 static uint16_t usb0_host_read_dma_d0(uint16_t pipe);
Kojto 39:d96aa62afc5b 74 static uint16_t usb0_host_read_dma_d1(uint16_t pipe);
Kojto 39:d96aa62afc5b 75 static uint16_t usb0_host_write_dma_d0(uint16_t pipe);
Kojto 39:d96aa62afc5b 76 static uint16_t usb0_host_write_dma_d1(uint16_t pipe);
Kojto 39:d96aa62afc5b 77
Kojto 39:d96aa62afc5b 78 static void usb0_host_read_c_fifo(uint16_t pipe, uint16_t count);
Kojto 39:d96aa62afc5b 79 static void usb0_host_write_c_fifo(uint16_t Pipe, uint16_t count);
Kojto 39:d96aa62afc5b 80 static void usb0_host_read_d0_fifo(uint16_t pipe, uint16_t count);
Kojto 39:d96aa62afc5b 81 static void usb0_host_write_d0_fifo(uint16_t pipe, uint16_t count);
Kojto 39:d96aa62afc5b 82 static void usb0_host_read_d1_fifo(uint16_t pipe, uint16_t count);
Kojto 39:d96aa62afc5b 83 static void usb0_host_write_d1_fifo(uint16_t pipe, uint16_t count);
Kojto 39:d96aa62afc5b 84
Kojto 39:d96aa62afc5b 85 static void usb0_host_clear_transaction_counter(uint16_t pipe);
Kojto 39:d96aa62afc5b 86 static void usb0_host_set_transaction_counter(uint16_t pipe, uint32_t count);
Kojto 39:d96aa62afc5b 87
Kojto 39:d96aa62afc5b 88 static uint32_t usb0_host_com_get_dmasize(uint32_t trncount, uint32_t dtptr);
Kojto 39:d96aa62afc5b 89
Kojto 39:d96aa62afc5b 90 static uint16_t usb0_host_set_dfacc_d0(uint16_t mbw, uint32_t count);
Kojto 39:d96aa62afc5b 91 static uint16_t usb0_host_set_dfacc_d1(uint16_t mbw, uint32_t count);
Kojto 39:d96aa62afc5b 92
Kojto 39:d96aa62afc5b 93
Kojto 39:d96aa62afc5b 94 /*******************************************************************************
Kojto 39:d96aa62afc5b 95 * Function Name: usb0_host_start_send_transfer
Kojto 39:d96aa62afc5b 96 * Description : Starts the USB data communication using pipe specified by the argument.
Kojto 39:d96aa62afc5b 97 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 98 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 99 * : uint8_t *data ; Data data Address
Kojto 39:d96aa62afc5b 100 * Return Value : USB_HOST_WRITEEND ; Write end
Kojto 39:d96aa62afc5b 101 * : USB_HOST_WRITESHRT ; short data
Kojto 39:d96aa62afc5b 102 * : USB_HOST_WRITING ; Continue of data write
Kojto 39:d96aa62afc5b 103 * : USB_HOST_WRITEDMA ; Write DMA
Kojto 39:d96aa62afc5b 104 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 105 *******************************************************************************/
Kojto 39:d96aa62afc5b 106 uint16_t usb0_host_start_send_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 107 {
Kojto 39:d96aa62afc5b 108 uint16_t status;
Kojto 39:d96aa62afc5b 109 uint16_t usefifo;
Kojto 39:d96aa62afc5b 110 uint16_t mbw;
Kojto 39:d96aa62afc5b 111
Kojto 39:d96aa62afc5b 112 g_usb0_host_data_count[pipe] = size;
Kojto 39:d96aa62afc5b 113 g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
Kojto 39:d96aa62afc5b 114 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 115
Kojto 39:d96aa62afc5b 116 usb0_host_clear_bemp_sts(pipe);
Kojto 39:d96aa62afc5b 117 usb0_host_clear_brdy_sts(pipe);
Kojto 39:d96aa62afc5b 118 usb0_host_clear_nrdy_sts(pipe);
Kojto 39:d96aa62afc5b 119
Kojto 39:d96aa62afc5b 120 mbw = usb0_host_get_mbw(size, (uint32_t)data);
Kojto 39:d96aa62afc5b 121
Kojto 39:d96aa62afc5b 122 usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
Kojto 39:d96aa62afc5b 123
Kojto 39:d96aa62afc5b 124 switch (usefifo)
Kojto 39:d96aa62afc5b 125 {
Kojto 39:d96aa62afc5b 126 case USB_HOST_D0FIFO_USE:
Kojto 39:d96aa62afc5b 127 case USB_HOST_D0FIFO_DMA:
Kojto 39:d96aa62afc5b 128 usefifo = USB_HOST_D0USE;
Kojto 39:d96aa62afc5b 129 break;
Kojto 39:d96aa62afc5b 130
Kojto 39:d96aa62afc5b 131 case USB_HOST_D1FIFO_USE:
Kojto 39:d96aa62afc5b 132 case USB_HOST_D1FIFO_DMA:
Kojto 39:d96aa62afc5b 133 usefifo = USB_HOST_D1USE;
Kojto 39:d96aa62afc5b 134 break;
Kojto 39:d96aa62afc5b 135
Kojto 39:d96aa62afc5b 136 default:
Kojto 39:d96aa62afc5b 137 usefifo = USB_HOST_CUSE;
Kojto 39:d96aa62afc5b 138 break;
Kojto 39:d96aa62afc5b 139 };
Kojto 39:d96aa62afc5b 140
Kojto 39:d96aa62afc5b 141 usb0_host_set_curpipe(USB_HOST_PIPE0, usefifo, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 142
Kojto 39:d96aa62afc5b 143 usb0_host_clear_transaction_counter(pipe);
Kojto 39:d96aa62afc5b 144
Kojto 39:d96aa62afc5b 145 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 146 #else
Kojto 39:d96aa62afc5b 147 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 148 #endif
Kojto 39:d96aa62afc5b 149
Kojto 39:d96aa62afc5b 150 status = usb0_host_write_buffer(pipe);
Kojto 39:d96aa62afc5b 151
Kojto 39:d96aa62afc5b 152 if (status != USB_HOST_FIFOERROR)
Kojto 39:d96aa62afc5b 153 {
Kojto 39:d96aa62afc5b 154 usb0_host_set_pid_buf(pipe);
Kojto 39:d96aa62afc5b 155 }
Kojto 39:d96aa62afc5b 156
Kojto 39:d96aa62afc5b 157 return status;
Kojto 39:d96aa62afc5b 158 }
Kojto 39:d96aa62afc5b 159
Kojto 39:d96aa62afc5b 160 /*******************************************************************************
Kojto 39:d96aa62afc5b 161 * Function Name: usb0_host_write_buffer
Kojto 39:d96aa62afc5b 162 * Description : Writes data in the buffer allocated in the pipe specified by
Kojto 39:d96aa62afc5b 163 * : the argument. The FIFO for using is set in the pipe definition table.
Kojto 39:d96aa62afc5b 164 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 165 * Return Value : USB_HOST_WRITEEND ; Write end
Kojto 39:d96aa62afc5b 166 * : USB_HOST_WRITESHRT ; short data
Kojto 39:d96aa62afc5b 167 * : USB_HOST_WRITING ; Continue of data write
Kojto 39:d96aa62afc5b 168 * : USB_HOST_WRITEDMA ; Write DMA
Kojto 39:d96aa62afc5b 169 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 170 *******************************************************************************/
Kojto 39:d96aa62afc5b 171 uint16_t usb0_host_write_buffer (uint16_t pipe)
Kojto 39:d96aa62afc5b 172 {
Kojto 39:d96aa62afc5b 173 uint16_t status;
Kojto 39:d96aa62afc5b 174 uint16_t usefifo;
Kojto 39:d96aa62afc5b 175
Kojto 39:d96aa62afc5b 176 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 177 usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
Kojto 39:d96aa62afc5b 178
Kojto 39:d96aa62afc5b 179 switch (usefifo)
Kojto 39:d96aa62afc5b 180 {
Kojto 39:d96aa62afc5b 181 case USB_HOST_D0FIFO_USE:
Kojto 39:d96aa62afc5b 182 status = usb0_host_write_buffer_d0(pipe);
Kojto 39:d96aa62afc5b 183 break;
Kojto 39:d96aa62afc5b 184
Kojto 39:d96aa62afc5b 185 case USB_HOST_D1FIFO_USE:
Kojto 39:d96aa62afc5b 186 status = usb0_host_write_buffer_d1(pipe);
Kojto 39:d96aa62afc5b 187 break;
Kojto 39:d96aa62afc5b 188
Kojto 39:d96aa62afc5b 189 case USB_HOST_D0FIFO_DMA:
Kojto 39:d96aa62afc5b 190 status = usb0_host_write_dma_d0(pipe);
Kojto 39:d96aa62afc5b 191 break;
Kojto 39:d96aa62afc5b 192
Kojto 39:d96aa62afc5b 193 case USB_HOST_D1FIFO_DMA:
Kojto 39:d96aa62afc5b 194 status = usb0_host_write_dma_d1(pipe);
Kojto 39:d96aa62afc5b 195 break;
Kojto 39:d96aa62afc5b 196
Kojto 39:d96aa62afc5b 197 default:
Kojto 39:d96aa62afc5b 198 status = usb0_host_write_buffer_c(pipe);
Kojto 39:d96aa62afc5b 199 break;
Kojto 39:d96aa62afc5b 200 };
Kojto 39:d96aa62afc5b 201
Kojto 39:d96aa62afc5b 202 switch (status)
Kojto 39:d96aa62afc5b 203 {
Kojto 39:d96aa62afc5b 204 case USB_HOST_WRITING: /* Continue of data write */
Kojto 39:d96aa62afc5b 205 usb0_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
Kojto 39:d96aa62afc5b 206 usb0_host_enable_brdy_int(pipe); /* Enable Ready Interrupt */
Kojto 39:d96aa62afc5b 207 break;
Kojto 39:d96aa62afc5b 208
Kojto 39:d96aa62afc5b 209 case USB_HOST_WRITEEND: /* End of data write */
Kojto 39:d96aa62afc5b 210 case USB_HOST_WRITESHRT: /* End of data write */
Kojto 39:d96aa62afc5b 211 usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
Kojto 39:d96aa62afc5b 212
Kojto 39:d96aa62afc5b 213 usb0_host_clear_nrdy_sts(pipe);
Kojto 39:d96aa62afc5b 214 usb0_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
Kojto 39:d96aa62afc5b 215
Kojto 39:d96aa62afc5b 216 /* for last transfer */
Kojto 39:d96aa62afc5b 217 usb0_host_enable_bemp_int(pipe); /* Enable Empty Interrupt */
Kojto 39:d96aa62afc5b 218 break;
Kojto 39:d96aa62afc5b 219
Kojto 39:d96aa62afc5b 220 case USB_HOST_WRITEDMA: /* DMA write */
Kojto 39:d96aa62afc5b 221 usb0_host_clear_nrdy_sts(pipe);
Kojto 39:d96aa62afc5b 222 usb0_host_enable_nrdy_int(pipe); /* Error (NORES or STALL) */
Kojto 39:d96aa62afc5b 223 break;
Kojto 39:d96aa62afc5b 224
Kojto 39:d96aa62afc5b 225 case USB_HOST_FIFOERROR: /* FIFO access status */
Kojto 39:d96aa62afc5b 226 default:
Kojto 39:d96aa62afc5b 227 usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
Kojto 39:d96aa62afc5b 228 usb0_host_disable_bemp_int(pipe); /* Disable Empty Interrupt */
Kojto 39:d96aa62afc5b 229 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
Kojto 39:d96aa62afc5b 230 break;
Kojto 39:d96aa62afc5b 231 }
Kojto 39:d96aa62afc5b 232
Kojto 39:d96aa62afc5b 233 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 234 }
Kojto 39:d96aa62afc5b 235
Kojto 39:d96aa62afc5b 236 /*******************************************************************************
Kojto 39:d96aa62afc5b 237 * Function Name: usb0_host_write_buffer_c
Kojto 39:d96aa62afc5b 238 * Description : Writes data in the buffer allocated in the pipe specified in
Kojto 39:d96aa62afc5b 239 * : the argument. Writes data by CPU transfer using CFIFO.
Kojto 39:d96aa62afc5b 240 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 241 * Return Value : USB_HOST_WRITEEND ; Write end
Kojto 39:d96aa62afc5b 242 * : USB_HOST_WRITESHRT ; short data
Kojto 39:d96aa62afc5b 243 * : USB_HOST_WRITING ; Continue of data write
Kojto 39:d96aa62afc5b 244 * : USB_HOST_WRITEDMA ; Write DMA
Kojto 39:d96aa62afc5b 245 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 246 *******************************************************************************/
Kojto 39:d96aa62afc5b 247 uint16_t usb0_host_write_buffer_c (uint16_t pipe)
Kojto 39:d96aa62afc5b 248 {
Kojto 39:d96aa62afc5b 249 uint32_t count;
Kojto 39:d96aa62afc5b 250 uint16_t size;
Kojto 39:d96aa62afc5b 251 uint16_t buffer;
Kojto 39:d96aa62afc5b 252 uint16_t mxps;
Kojto 39:d96aa62afc5b 253 uint16_t status;
Kojto 39:d96aa62afc5b 254 uint16_t mbw;
Kojto 39:d96aa62afc5b 255
Kojto 39:d96aa62afc5b 256 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 257
Kojto 39:d96aa62afc5b 258 if (pipe == USB_HOST_PIPE0)
Kojto 39:d96aa62afc5b 259 {
Kojto 39:d96aa62afc5b 260 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_CFIFO_WRITE, mbw);
Kojto 39:d96aa62afc5b 261 }
Kojto 39:d96aa62afc5b 262 else
Kojto 39:d96aa62afc5b 263 {
Kojto 39:d96aa62afc5b 264 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 265 }
Kojto 39:d96aa62afc5b 266
Kojto 39:d96aa62afc5b 267 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 268 {
Kojto 39:d96aa62afc5b 269 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 270 }
Kojto 39:d96aa62afc5b 271
Kojto 39:d96aa62afc5b 272 size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 273 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 274
Kojto 39:d96aa62afc5b 275 if (g_usb0_host_data_count[pipe] <= (uint32_t)size)
Kojto 39:d96aa62afc5b 276 {
Kojto 39:d96aa62afc5b 277 status = USB_HOST_WRITEEND; /* write continues */
Kojto 39:d96aa62afc5b 278 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 279
Kojto 39:d96aa62afc5b 280 if (count == 0)
Kojto 39:d96aa62afc5b 281 {
Kojto 39:d96aa62afc5b 282 status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
Kojto 39:d96aa62afc5b 283 }
Kojto 39:d96aa62afc5b 284
Kojto 39:d96aa62afc5b 285 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 286 {
Kojto 39:d96aa62afc5b 287 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
Kojto 39:d96aa62afc5b 288 }
Kojto 39:d96aa62afc5b 289 }
Kojto 39:d96aa62afc5b 290 else
Kojto 39:d96aa62afc5b 291 {
Kojto 39:d96aa62afc5b 292 status = USB_HOST_WRITING; /* write continues */
Kojto 39:d96aa62afc5b 293 count = (uint32_t)size;
Kojto 39:d96aa62afc5b 294 }
Kojto 39:d96aa62afc5b 295
Kojto 39:d96aa62afc5b 296 usb0_host_write_c_fifo(pipe, (uint16_t)count);
Kojto 39:d96aa62afc5b 297
Kojto 39:d96aa62afc5b 298 if (g_usb0_host_data_count[pipe] < (uint32_t)size)
Kojto 39:d96aa62afc5b 299 {
Kojto 39:d96aa62afc5b 300 g_usb0_host_data_count[pipe] = 0;
Kojto 39:d96aa62afc5b 301
Kojto 39:d96aa62afc5b 302 if (RZA_IO_RegRead_16(&USB200.CFIFOCTR,
Kojto 39:d96aa62afc5b 303 USB_CFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 304 USB_CFIFOCTR_BVAL) == 0)
Kojto 39:d96aa62afc5b 305 {
Kojto 39:d96aa62afc5b 306 USB200.CFIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
Kojto 39:d96aa62afc5b 307 }
Kojto 39:d96aa62afc5b 308 }
Kojto 39:d96aa62afc5b 309 else
Kojto 39:d96aa62afc5b 310 {
Kojto 39:d96aa62afc5b 311 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 312 }
Kojto 39:d96aa62afc5b 313
Kojto 39:d96aa62afc5b 314 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 315 }
Kojto 39:d96aa62afc5b 316
Kojto 39:d96aa62afc5b 317 /*******************************************************************************
Kojto 39:d96aa62afc5b 318 * Function Name: usb0_host_write_buffer_d0
Kojto 39:d96aa62afc5b 319 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 320 * : Writes data by CPU transfer using D0FIFO.
Kojto 39:d96aa62afc5b 321 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 322 * Return Value : USB_HOST_WRITEEND ; Write end
Kojto 39:d96aa62afc5b 323 * : USB_HOST_WRITESHRT ; short data
Kojto 39:d96aa62afc5b 324 * : USB_HOST_WRITING ; Continue of data write
Kojto 39:d96aa62afc5b 325 * : USB_HOST_WRITEDMA ; Write DMA
Kojto 39:d96aa62afc5b 326 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 327 *******************************************************************************/
Kojto 39:d96aa62afc5b 328 uint16_t usb0_host_write_buffer_d0 (uint16_t pipe)
Kojto 39:d96aa62afc5b 329 {
Kojto 39:d96aa62afc5b 330 uint32_t count;
Kojto 39:d96aa62afc5b 331 uint16_t size;
Kojto 39:d96aa62afc5b 332 uint16_t buffer;
Kojto 39:d96aa62afc5b 333 uint16_t mxps;
Kojto 39:d96aa62afc5b 334 uint16_t status;
Kojto 39:d96aa62afc5b 335 uint16_t mbw;
Kojto 39:d96aa62afc5b 336
Kojto 39:d96aa62afc5b 337 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 338 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 339
Kojto 39:d96aa62afc5b 340 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 341 {
Kojto 39:d96aa62afc5b 342 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 343 }
Kojto 39:d96aa62afc5b 344
Kojto 39:d96aa62afc5b 345 size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 346 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 347
Kojto 39:d96aa62afc5b 348 if (g_usb0_host_data_count[pipe] <= (uint32_t)size)
Kojto 39:d96aa62afc5b 349 {
Kojto 39:d96aa62afc5b 350 status = USB_HOST_WRITEEND; /* write continues */
Kojto 39:d96aa62afc5b 351 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 352
Kojto 39:d96aa62afc5b 353 if (count == 0)
Kojto 39:d96aa62afc5b 354 {
Kojto 39:d96aa62afc5b 355 status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
Kojto 39:d96aa62afc5b 356 }
Kojto 39:d96aa62afc5b 357
Kojto 39:d96aa62afc5b 358 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 359 {
Kojto 39:d96aa62afc5b 360 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
Kojto 39:d96aa62afc5b 361 }
Kojto 39:d96aa62afc5b 362 }
Kojto 39:d96aa62afc5b 363 else
Kojto 39:d96aa62afc5b 364 {
Kojto 39:d96aa62afc5b 365 status = USB_HOST_WRITING; /* write continues */
Kojto 39:d96aa62afc5b 366 count = (uint32_t)size;
Kojto 39:d96aa62afc5b 367 }
Kojto 39:d96aa62afc5b 368
Kojto 39:d96aa62afc5b 369 usb0_host_write_d0_fifo(pipe, (uint16_t)count);
Kojto 39:d96aa62afc5b 370
Kojto 39:d96aa62afc5b 371 if (g_usb0_host_data_count[pipe] < (uint32_t)size)
Kojto 39:d96aa62afc5b 372 {
Kojto 39:d96aa62afc5b 373 g_usb0_host_data_count[pipe] = 0;
Kojto 39:d96aa62afc5b 374
Kojto 39:d96aa62afc5b 375 if (RZA_IO_RegRead_16(&USB200.D0FIFOCTR,
Kojto 39:d96aa62afc5b 376 USB_DnFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 377 USB_DnFIFOCTR_BVAL) == 0)
Kojto 39:d96aa62afc5b 378 {
Kojto 39:d96aa62afc5b 379 USB200.D0FIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
Kojto 39:d96aa62afc5b 380 }
Kojto 39:d96aa62afc5b 381 }
Kojto 39:d96aa62afc5b 382 else
Kojto 39:d96aa62afc5b 383 {
Kojto 39:d96aa62afc5b 384 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 385 }
Kojto 39:d96aa62afc5b 386
Kojto 39:d96aa62afc5b 387 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 388 }
Kojto 39:d96aa62afc5b 389
Kojto 39:d96aa62afc5b 390 /*******************************************************************************
Kojto 39:d96aa62afc5b 391 * Function Name: usb0_host_write_buffer_d1
Kojto 39:d96aa62afc5b 392 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 393 * : Writes data by CPU transfer using D1FIFO.
Kojto 39:d96aa62afc5b 394 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 395 * Return Value : USB_HOST_WRITEEND ; Write end
Kojto 39:d96aa62afc5b 396 * : USB_HOST_WRITESHRT ; short data
Kojto 39:d96aa62afc5b 397 * : USB_HOST_WRITING ; Continue of data write
Kojto 39:d96aa62afc5b 398 * : USB_HOST_WRITEDMA ; Write DMA
Kojto 39:d96aa62afc5b 399 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 400 *******************************************************************************/
Kojto 39:d96aa62afc5b 401 uint16_t usb0_host_write_buffer_d1 (uint16_t pipe)
Kojto 39:d96aa62afc5b 402 {
Kojto 39:d96aa62afc5b 403 uint32_t count;
Kojto 39:d96aa62afc5b 404 uint16_t size;
Kojto 39:d96aa62afc5b 405 uint16_t buffer;
Kojto 39:d96aa62afc5b 406 uint16_t mxps;
Kojto 39:d96aa62afc5b 407 uint16_t status;
Kojto 39:d96aa62afc5b 408 uint16_t mbw;
Kojto 39:d96aa62afc5b 409
Kojto 39:d96aa62afc5b 410 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 411 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 412
Kojto 39:d96aa62afc5b 413 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 414 {
Kojto 39:d96aa62afc5b 415 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 416 }
Kojto 39:d96aa62afc5b 417
Kojto 39:d96aa62afc5b 418 size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 419 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 420
Kojto 39:d96aa62afc5b 421 if (g_usb0_host_data_count[pipe] <= (uint32_t)size)
Kojto 39:d96aa62afc5b 422 {
Kojto 39:d96aa62afc5b 423 status = USB_HOST_WRITEEND; /* write continues */
Kojto 39:d96aa62afc5b 424 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 425
Kojto 39:d96aa62afc5b 426 if (count == 0)
Kojto 39:d96aa62afc5b 427 {
Kojto 39:d96aa62afc5b 428 status = USB_HOST_WRITESHRT; /* Null Packet is end of write */
Kojto 39:d96aa62afc5b 429 }
Kojto 39:d96aa62afc5b 430
Kojto 39:d96aa62afc5b 431 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 432 {
Kojto 39:d96aa62afc5b 433 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
Kojto 39:d96aa62afc5b 434 }
Kojto 39:d96aa62afc5b 435 }
Kojto 39:d96aa62afc5b 436 else
Kojto 39:d96aa62afc5b 437 {
Kojto 39:d96aa62afc5b 438 status = USB_HOST_WRITING; /* write continues */
Kojto 39:d96aa62afc5b 439 count = (uint32_t)size;
Kojto 39:d96aa62afc5b 440 }
Kojto 39:d96aa62afc5b 441
Kojto 39:d96aa62afc5b 442 usb0_host_write_d1_fifo(pipe, (uint16_t)count);
Kojto 39:d96aa62afc5b 443
Kojto 39:d96aa62afc5b 444 if (g_usb0_host_data_count[pipe] < (uint32_t)size)
Kojto 39:d96aa62afc5b 445 {
Kojto 39:d96aa62afc5b 446 g_usb0_host_data_count[pipe] = 0;
Kojto 39:d96aa62afc5b 447
Kojto 39:d96aa62afc5b 448 if (RZA_IO_RegRead_16(&USB200.D1FIFOCTR,
Kojto 39:d96aa62afc5b 449 USB_DnFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 450 USB_DnFIFOCTR_BVAL) == 0)
Kojto 39:d96aa62afc5b 451 {
Kojto 39:d96aa62afc5b 452 USB200.D1FIFOCTR = USB_HOST_BITBVAL; /* Short Packet */
Kojto 39:d96aa62afc5b 453 }
Kojto 39:d96aa62afc5b 454 }
Kojto 39:d96aa62afc5b 455 else
Kojto 39:d96aa62afc5b 456 {
Kojto 39:d96aa62afc5b 457 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 458 }
Kojto 39:d96aa62afc5b 459
Kojto 39:d96aa62afc5b 460 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 461 }
Kojto 39:d96aa62afc5b 462
Kojto 39:d96aa62afc5b 463 /*******************************************************************************
Kojto 39:d96aa62afc5b 464 * Function Name: usb0_host_write_dma_d0
Kojto 39:d96aa62afc5b 465 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 466 * : Writes data by DMA transfer using D0FIFO.
Kojto 39:d96aa62afc5b 467 * : The DMA-ch for using is specified by Userdef_USB_usb0_host_start_dma().
Kojto 39:d96aa62afc5b 468 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 469 * Return Value : USB_HOST_WRITEEND : Write end
Kojto 39:d96aa62afc5b 470 * : USB_HOST_WRITESHRT : short data
Kojto 39:d96aa62afc5b 471 * : USB_HOST_WRITING : Continue of data write
Kojto 39:d96aa62afc5b 472 * : USB_HOST_WRITEDMA : Write DMA
Kojto 39:d96aa62afc5b 473 * : USB_HOST_FIFOERROR : FIFO status
Kojto 39:d96aa62afc5b 474 *******************************************************************************/
Kojto 39:d96aa62afc5b 475 static uint16_t usb0_host_write_dma_d0 (uint16_t pipe)
Kojto 39:d96aa62afc5b 476 {
Kojto 39:d96aa62afc5b 477 uint32_t count;
Kojto 39:d96aa62afc5b 478 uint16_t size;
Kojto 39:d96aa62afc5b 479 uint16_t buffer;
Kojto 39:d96aa62afc5b 480 uint16_t status;
Kojto 39:d96aa62afc5b 481 uint16_t mbw;
Kojto 39:d96aa62afc5b 482 uint16_t dfacc = 0;
Kojto 39:d96aa62afc5b 483
Kojto 39:d96aa62afc5b 484 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 485 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 486
Kojto 39:d96aa62afc5b 487 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 488 {
Kojto 39:d96aa62afc5b 489 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 490 }
Kojto 39:d96aa62afc5b 491
Kojto 39:d96aa62afc5b 492 size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 493 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 494
Kojto 39:d96aa62afc5b 495 if (count != 0)
Kojto 39:d96aa62afc5b 496 {
Kojto 39:d96aa62afc5b 497 g_usb0_host_DmaPipe[USB_HOST_D0FIFO] = pipe;
Kojto 39:d96aa62afc5b 498
Kojto 39:d96aa62afc5b 499 if ((count % size) != 0)
Kojto 39:d96aa62afc5b 500 {
Kojto 39:d96aa62afc5b 501 g_usb0_host_DmaBval[USB_HOST_D0FIFO] = 1;
Kojto 39:d96aa62afc5b 502 }
Kojto 39:d96aa62afc5b 503 else
Kojto 39:d96aa62afc5b 504 {
Kojto 39:d96aa62afc5b 505 g_usb0_host_DmaBval[USB_HOST_D0FIFO] = 0;
Kojto 39:d96aa62afc5b 506 }
Kojto 39:d96aa62afc5b 507
Kojto 39:d96aa62afc5b 508 dfacc = usb0_host_set_dfacc_d0(mbw, count);
Kojto 39:d96aa62afc5b 509
Kojto 39:d96aa62afc5b 510 if (mbw == USB_HOST_BITMBW_32)
Kojto 39:d96aa62afc5b 511 {
Kojto 39:d96aa62afc5b 512 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 2; /* 32bit transfer */
Kojto 39:d96aa62afc5b 513 }
Kojto 39:d96aa62afc5b 514 else if (mbw == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 515 {
Kojto 39:d96aa62afc5b 516 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 1; /* 16bit transfer */
Kojto 39:d96aa62afc5b 517 }
Kojto 39:d96aa62afc5b 518 else
Kojto 39:d96aa62afc5b 519 {
Kojto 39:d96aa62afc5b 520 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 0; /* 8bit transfer */
Kojto 39:d96aa62afc5b 521 }
Kojto 39:d96aa62afc5b 522
Kojto 39:d96aa62afc5b 523 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].fifo = USB_HOST_D0FIFO_DMA;
Kojto 39:d96aa62afc5b 524 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].dir = USB_HOST_BUF2FIFO;
Kojto 39:d96aa62afc5b 525 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 526 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].bytes = count;
Kojto 39:d96aa62afc5b 527
Kojto 39:d96aa62afc5b 528 Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D0FIFO], dfacc);
Kojto 39:d96aa62afc5b 529
Kojto 39:d96aa62afc5b 530 usb0_host_set_curpipe2(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw, dfacc);
Kojto 39:d96aa62afc5b 531
Kojto 39:d96aa62afc5b 532 RZA_IO_RegWrite_16(&USB200.D0FIFOSEL,
Kojto 39:d96aa62afc5b 533 1,
Kojto 39:d96aa62afc5b 534 USB_DnFIFOSEL_DREQE_SHIFT,
Kojto 39:d96aa62afc5b 535 USB_DnFIFOSEL_DREQE);
Kojto 39:d96aa62afc5b 536
Kojto 39:d96aa62afc5b 537 g_usb0_host_data_count[pipe] = 0;
Kojto 39:d96aa62afc5b 538 g_usb0_host_data_pointer[pipe] += count;
Kojto 39:d96aa62afc5b 539
Kojto 39:d96aa62afc5b 540 status = USB_HOST_WRITEDMA; /* DMA write */
Kojto 39:d96aa62afc5b 541 }
Kojto 39:d96aa62afc5b 542 else
Kojto 39:d96aa62afc5b 543 {
Kojto 39:d96aa62afc5b 544 if (RZA_IO_RegRead_16(&USB200.D0FIFOCTR,
Kojto 39:d96aa62afc5b 545 USB_DnFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 546 USB_DnFIFOCTR_BVAL) == 0)
Kojto 39:d96aa62afc5b 547 {
Kojto 39:d96aa62afc5b 548 RZA_IO_RegWrite_16(&USB200.D0FIFOCTR,
Kojto 39:d96aa62afc5b 549 1,
Kojto 39:d96aa62afc5b 550 USB_DnFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 551 USB_DnFIFOCTR_BVAL); /* Short Packet */
Kojto 39:d96aa62afc5b 552 }
Kojto 39:d96aa62afc5b 553 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
Kojto 39:d96aa62afc5b 554 }
Kojto 39:d96aa62afc5b 555
Kojto 39:d96aa62afc5b 556 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 557 }
Kojto 39:d96aa62afc5b 558
Kojto 39:d96aa62afc5b 559 /*******************************************************************************
Kojto 39:d96aa62afc5b 560 * Function Name: usb0_host_write_dma_d1
Kojto 39:d96aa62afc5b 561 * Description : Writes data in the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 562 * : Writes data by DMA transfer using D1FIFO.
Kojto 39:d96aa62afc5b 563 * : The DMA-ch for using is specified by Userdef_USB_usb0_host_start_dma().
Kojto 39:d96aa62afc5b 564 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 565 * Return Value : USB_HOST_WRITEEND : Write end
Kojto 39:d96aa62afc5b 566 * : USB_HOST_WRITESHRT : short data
Kojto 39:d96aa62afc5b 567 * : USB_HOST_WRITING : Continue of data write
Kojto 39:d96aa62afc5b 568 * : USB_HOST_WRITEDMA : Write DMA
Kojto 39:d96aa62afc5b 569 * : USB_HOST_FIFOERROR : FIFO status
Kojto 39:d96aa62afc5b 570 *******************************************************************************/
Kojto 39:d96aa62afc5b 571 static uint16_t usb0_host_write_dma_d1 (uint16_t pipe)
Kojto 39:d96aa62afc5b 572 {
Kojto 39:d96aa62afc5b 573 uint32_t count;
Kojto 39:d96aa62afc5b 574 uint16_t size;
Kojto 39:d96aa62afc5b 575 uint16_t buffer;
Kojto 39:d96aa62afc5b 576 uint16_t status;
Kojto 39:d96aa62afc5b 577 uint16_t mbw;
Kojto 39:d96aa62afc5b 578 uint16_t dfacc = 0;
Kojto 39:d96aa62afc5b 579
Kojto 39:d96aa62afc5b 580 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 581 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 582
Kojto 39:d96aa62afc5b 583 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 584 {
Kojto 39:d96aa62afc5b 585 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 586 }
Kojto 39:d96aa62afc5b 587
Kojto 39:d96aa62afc5b 588 size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 589 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 590
Kojto 39:d96aa62afc5b 591 if (count != 0)
Kojto 39:d96aa62afc5b 592 {
Kojto 39:d96aa62afc5b 593 g_usb0_host_DmaPipe[USB_HOST_D1FIFO] = pipe;
Kojto 39:d96aa62afc5b 594
Kojto 39:d96aa62afc5b 595 if ((count % size) != 0)
Kojto 39:d96aa62afc5b 596 {
Kojto 39:d96aa62afc5b 597 g_usb0_host_DmaBval[USB_HOST_D1FIFO] = 1;
Kojto 39:d96aa62afc5b 598 }
Kojto 39:d96aa62afc5b 599 else
Kojto 39:d96aa62afc5b 600 {
Kojto 39:d96aa62afc5b 601 g_usb0_host_DmaBval[USB_HOST_D1FIFO] = 0;
Kojto 39:d96aa62afc5b 602 }
Kojto 39:d96aa62afc5b 603
Kojto 39:d96aa62afc5b 604 dfacc = usb0_host_set_dfacc_d1(mbw, count);
Kojto 39:d96aa62afc5b 605
Kojto 39:d96aa62afc5b 606 if (mbw == USB_HOST_BITMBW_32)
Kojto 39:d96aa62afc5b 607 {
Kojto 39:d96aa62afc5b 608 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 2; /* 32bit transfer */
Kojto 39:d96aa62afc5b 609 }
Kojto 39:d96aa62afc5b 610 else if (mbw == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 611 {
Kojto 39:d96aa62afc5b 612 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 1; /* 16bit transfer */
Kojto 39:d96aa62afc5b 613 }
Kojto 39:d96aa62afc5b 614 else
Kojto 39:d96aa62afc5b 615 {
Kojto 39:d96aa62afc5b 616 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 0; /* 8bit transfer */
Kojto 39:d96aa62afc5b 617 }
Kojto 39:d96aa62afc5b 618
Kojto 39:d96aa62afc5b 619 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].fifo = USB_HOST_D1FIFO_DMA;
Kojto 39:d96aa62afc5b 620 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].dir = USB_HOST_BUF2FIFO;
Kojto 39:d96aa62afc5b 621 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 622 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].bytes = count;
Kojto 39:d96aa62afc5b 623
Kojto 39:d96aa62afc5b 624 Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D1FIFO], dfacc);
Kojto 39:d96aa62afc5b 625
Kojto 39:d96aa62afc5b 626 usb0_host_set_curpipe2(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw, dfacc);
Kojto 39:d96aa62afc5b 627
Kojto 39:d96aa62afc5b 628 RZA_IO_RegWrite_16(&USB200.D1FIFOSEL,
Kojto 39:d96aa62afc5b 629 1,
Kojto 39:d96aa62afc5b 630 USB_DnFIFOSEL_DREQE_SHIFT,
Kojto 39:d96aa62afc5b 631 USB_DnFIFOSEL_DREQE);
Kojto 39:d96aa62afc5b 632
Kojto 39:d96aa62afc5b 633 g_usb0_host_data_count[pipe] = 0;
Kojto 39:d96aa62afc5b 634 g_usb0_host_data_pointer[pipe] += count;
Kojto 39:d96aa62afc5b 635
Kojto 39:d96aa62afc5b 636 status = USB_HOST_WRITEDMA; /* DMA write */
Kojto 39:d96aa62afc5b 637 }
Kojto 39:d96aa62afc5b 638 else
Kojto 39:d96aa62afc5b 639 {
Kojto 39:d96aa62afc5b 640 if (RZA_IO_RegRead_16(&USB200.D1FIFOCTR,
Kojto 39:d96aa62afc5b 641 USB_DnFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 642 USB_DnFIFOCTR_BVAL) == 0)
Kojto 39:d96aa62afc5b 643 {
Kojto 39:d96aa62afc5b 644 RZA_IO_RegWrite_16(&USB200.D1FIFOCTR,
Kojto 39:d96aa62afc5b 645 1,
Kojto 39:d96aa62afc5b 646 USB_DnFIFOCTR_BVAL_SHIFT,
Kojto 39:d96aa62afc5b 647 USB_DnFIFOCTR_BVAL); /* Short Packet */
Kojto 39:d96aa62afc5b 648 }
Kojto 39:d96aa62afc5b 649 status = USB_HOST_WRITESHRT; /* Short Packet is end of write */
Kojto 39:d96aa62afc5b 650 }
Kojto 39:d96aa62afc5b 651
Kojto 39:d96aa62afc5b 652 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 653 }
Kojto 39:d96aa62afc5b 654
Kojto 39:d96aa62afc5b 655 /*******************************************************************************
Kojto 39:d96aa62afc5b 656 * Function Name: usb0_host_start_receive_transfer
Kojto 39:d96aa62afc5b 657 * Description : Starts USB data reception using the pipe specified in the argument.
Kojto 39:d96aa62afc5b 658 * : The FIFO for using is set in the pipe definition table.
Kojto 39:d96aa62afc5b 659 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 660 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 661 * : uint8_t *data ; Data Address
Kojto 39:d96aa62afc5b 662 * Return Value : none
Kojto 39:d96aa62afc5b 663 *******************************************************************************/
Kojto 39:d96aa62afc5b 664 void usb0_host_start_receive_transfer (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 665 {
Kojto 39:d96aa62afc5b 666 uint16_t usefifo;
Kojto 39:d96aa62afc5b 667
Kojto 39:d96aa62afc5b 668 usb0_host_clear_bemp_sts(pipe);
Kojto 39:d96aa62afc5b 669 usb0_host_clear_brdy_sts(pipe);
Kojto 39:d96aa62afc5b 670 usb0_host_clear_nrdy_sts(pipe);
Kojto 39:d96aa62afc5b 671
Kojto 39:d96aa62afc5b 672 usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
Kojto 39:d96aa62afc5b 673
Kojto 39:d96aa62afc5b 674 switch (usefifo)
Kojto 39:d96aa62afc5b 675 {
Kojto 39:d96aa62afc5b 676 case USB_HOST_D0FIFO_USE:
Kojto 39:d96aa62afc5b 677 usb0_host_start_receive_trns_d0(pipe, size, data);
Kojto 39:d96aa62afc5b 678 break;
Kojto 39:d96aa62afc5b 679
Kojto 39:d96aa62afc5b 680 case USB_HOST_D1FIFO_USE:
Kojto 39:d96aa62afc5b 681 usb0_host_start_receive_trns_d1(pipe, size, data);
Kojto 39:d96aa62afc5b 682 break;
Kojto 39:d96aa62afc5b 683
Kojto 39:d96aa62afc5b 684 case USB_HOST_D0FIFO_DMA:
Kojto 39:d96aa62afc5b 685 usb0_host_start_receive_dma_d0(pipe, size, data);
Kojto 39:d96aa62afc5b 686 break;
Kojto 39:d96aa62afc5b 687
Kojto 39:d96aa62afc5b 688 case USB_HOST_D1FIFO_DMA:
Kojto 39:d96aa62afc5b 689 usb0_host_start_receive_dma_d1(pipe, size, data);
Kojto 39:d96aa62afc5b 690 break;
Kojto 39:d96aa62afc5b 691
Kojto 39:d96aa62afc5b 692 default:
Kojto 39:d96aa62afc5b 693 usb0_host_start_receive_trns_c(pipe, size, data);
Kojto 39:d96aa62afc5b 694 break;
Kojto 39:d96aa62afc5b 695 }
Kojto 39:d96aa62afc5b 696 }
Kojto 39:d96aa62afc5b 697
Kojto 39:d96aa62afc5b 698 /*******************************************************************************
Kojto 39:d96aa62afc5b 699 * Function Name: usb0_host_start_receive_trns_c
Kojto 39:d96aa62afc5b 700 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 701 * : Reads data by CPU transfer using CFIFO.
Kojto 39:d96aa62afc5b 702 * : When storing data in the buffer allocated in the pipe specified in the
Kojto 39:d96aa62afc5b 703 * : argument, BRDY interrupt is generated to read data
Kojto 39:d96aa62afc5b 704 * : in the interrupt.
Kojto 39:d96aa62afc5b 705 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 706 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 707 * : uint8_t *data ; Data Address
Kojto 39:d96aa62afc5b 708 * Return Value : none
Kojto 39:d96aa62afc5b 709 *******************************************************************************/
Kojto 39:d96aa62afc5b 710 static void usb0_host_start_receive_trns_c (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 711 {
Kojto 39:d96aa62afc5b 712 uint16_t mbw;
Kojto 39:d96aa62afc5b 713
Kojto 39:d96aa62afc5b 714 usb0_host_set_pid_nak(pipe);
Kojto 39:d96aa62afc5b 715 g_usb0_host_data_count[pipe] = size;
Kojto 39:d96aa62afc5b 716 g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
Kojto 39:d96aa62afc5b 717 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 718
Kojto 39:d96aa62afc5b 719 g_usb0_host_PipeDataSize[pipe] = size;
Kojto 39:d96aa62afc5b 720 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 721
Kojto 39:d96aa62afc5b 722 mbw = usb0_host_get_mbw(size, (uint32_t)data);
Kojto 39:d96aa62afc5b 723 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_CUSE, USB_HOST_CFIFO_READ, mbw);
Kojto 39:d96aa62afc5b 724 USB200.CFIFOCTR = USB_HOST_BITBCLR;
Kojto 39:d96aa62afc5b 725
Kojto 39:d96aa62afc5b 726 usb0_host_set_transaction_counter(pipe, size);
Kojto 39:d96aa62afc5b 727
Kojto 39:d96aa62afc5b 728 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 729 #else
Kojto 39:d96aa62afc5b 730 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 731 #endif
Kojto 39:d96aa62afc5b 732
Kojto 39:d96aa62afc5b 733 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 734 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 735
Kojto 39:d96aa62afc5b 736 usb0_host_set_pid_buf(pipe);
Kojto 39:d96aa62afc5b 737 }
Kojto 39:d96aa62afc5b 738
Kojto 39:d96aa62afc5b 739 /*******************************************************************************
Kojto 39:d96aa62afc5b 740 * Function Name: usb0_host_start_receive_trns_d0
Kojto 39:d96aa62afc5b 741 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 742 * : Reads data by CPU transfer using D0FIFO.
Kojto 39:d96aa62afc5b 743 * : This function does not read data from the buffer.
Kojto 39:d96aa62afc5b 744 * : When storing data in the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 745 * : in the argument, BRDY interrupt is generated to read data in the
Kojto 39:d96aa62afc5b 746 * : interrupt.
Kojto 39:d96aa62afc5b 747 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 748 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 749 * : uint8_t *data ; Data Address
Kojto 39:d96aa62afc5b 750 * Return Value : none
Kojto 39:d96aa62afc5b 751 *******************************************************************************/
Kojto 39:d96aa62afc5b 752 static void usb0_host_start_receive_trns_d0 (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 753 {
Kojto 39:d96aa62afc5b 754 uint16_t mbw;
Kojto 39:d96aa62afc5b 755
Kojto 39:d96aa62afc5b 756 usb0_host_set_pid_nak(pipe);
Kojto 39:d96aa62afc5b 757 g_usb0_host_data_count[pipe] = size;
Kojto 39:d96aa62afc5b 758 g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
Kojto 39:d96aa62afc5b 759 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 760
Kojto 39:d96aa62afc5b 761 g_usb0_host_PipeDataSize[pipe] = size;
Kojto 39:d96aa62afc5b 762 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 763
Kojto 39:d96aa62afc5b 764 mbw = usb0_host_get_mbw(size, (uint32_t)data);
Kojto 39:d96aa62afc5b 765 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 766
Kojto 39:d96aa62afc5b 767 usb0_host_set_transaction_counter(pipe, size);
Kojto 39:d96aa62afc5b 768
Kojto 39:d96aa62afc5b 769 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 770 #else
Kojto 39:d96aa62afc5b 771 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 772 #endif
Kojto 39:d96aa62afc5b 773
Kojto 39:d96aa62afc5b 774 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 775 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 776
Kojto 39:d96aa62afc5b 777 usb0_host_set_pid_buf(pipe);
Kojto 39:d96aa62afc5b 778 }
Kojto 39:d96aa62afc5b 779
Kojto 39:d96aa62afc5b 780 /*******************************************************************************
Kojto 39:d96aa62afc5b 781 * Function Name: usb0_host_start_receive_trns_d1
Kojto 39:d96aa62afc5b 782 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 783 * : Reads data by CPU transfer using D1FIFO.
Kojto 39:d96aa62afc5b 784 * : This function does not read data from the buffer.
Kojto 39:d96aa62afc5b 785 * : When storing data in the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 786 * : in the argument, BRDY interrupt is generated to read data.
Kojto 39:d96aa62afc5b 787 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 788 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 789 * : uint8_t *data ; Data Address
Kojto 39:d96aa62afc5b 790 * Return Value : none
Kojto 39:d96aa62afc5b 791 *******************************************************************************/
Kojto 39:d96aa62afc5b 792 static void usb0_host_start_receive_trns_d1 (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 793 {
Kojto 39:d96aa62afc5b 794 uint16_t mbw;
Kojto 39:d96aa62afc5b 795
Kojto 39:d96aa62afc5b 796 usb0_host_set_pid_nak(pipe);
Kojto 39:d96aa62afc5b 797 g_usb0_host_data_count[pipe] = size;
Kojto 39:d96aa62afc5b 798 g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
Kojto 39:d96aa62afc5b 799 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 800
Kojto 39:d96aa62afc5b 801 g_usb0_host_PipeDataSize[pipe] = size;
Kojto 39:d96aa62afc5b 802 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 803
Kojto 39:d96aa62afc5b 804 mbw = usb0_host_get_mbw(size, (uint32_t)data);
Kojto 39:d96aa62afc5b 805 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 806
Kojto 39:d96aa62afc5b 807 usb0_host_set_transaction_counter(pipe, size);
Kojto 39:d96aa62afc5b 808
Kojto 39:d96aa62afc5b 809 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 810 #else
Kojto 39:d96aa62afc5b 811 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 812 #endif
Kojto 39:d96aa62afc5b 813
Kojto 39:d96aa62afc5b 814 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 815 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 816
Kojto 39:d96aa62afc5b 817 usb0_host_set_pid_buf(pipe);
Kojto 39:d96aa62afc5b 818 }
Kojto 39:d96aa62afc5b 819
Kojto 39:d96aa62afc5b 820 /*******************************************************************************
Kojto 39:d96aa62afc5b 821 * Function Name: usb0_host_start_receive_dma_d0
Kojto 39:d96aa62afc5b 822 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 823 * : Reads data by DMA transfer using D0FIFO.
Kojto 39:d96aa62afc5b 824 * : This function does not read data from the buffer.
Kojto 39:d96aa62afc5b 825 * : When storing data in the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 826 * : in the argument, delivered read request to DMAC to read data from
Kojto 39:d96aa62afc5b 827 * : the buffer by DMAC.
Kojto 39:d96aa62afc5b 828 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 829 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 830 * : uint8_t *data ; Data Address
Kojto 39:d96aa62afc5b 831 * Return Value : none
Kojto 39:d96aa62afc5b 832 *******************************************************************************/
Kojto 39:d96aa62afc5b 833 static void usb0_host_start_receive_dma_d0 (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 834 {
Kojto 39:d96aa62afc5b 835 uint16_t mbw;
Kojto 39:d96aa62afc5b 836
Kojto 39:d96aa62afc5b 837 usb0_host_set_pid_nak(pipe);
Kojto 39:d96aa62afc5b 838 g_usb0_host_data_count[pipe] = size;
Kojto 39:d96aa62afc5b 839 g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
Kojto 39:d96aa62afc5b 840 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 841
Kojto 39:d96aa62afc5b 842 g_usb0_host_PipeDataSize[pipe] = 0;
Kojto 39:d96aa62afc5b 843 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 844
Kojto 39:d96aa62afc5b 845 mbw = usb0_host_get_mbw(size, (uint32_t)data);
Kojto 39:d96aa62afc5b 846 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D0USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 847
Kojto 39:d96aa62afc5b 848 usb0_host_set_transaction_counter(pipe, size);
Kojto 39:d96aa62afc5b 849
Kojto 39:d96aa62afc5b 850 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 851 #else
Kojto 39:d96aa62afc5b 852 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 853 #endif
Kojto 39:d96aa62afc5b 854
Kojto 39:d96aa62afc5b 855 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
Kojto 39:d96aa62afc5b 856 {
Kojto 39:d96aa62afc5b 857 usb0_host_read_dma(pipe);
Kojto 39:d96aa62afc5b 858
Kojto 39:d96aa62afc5b 859 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 860 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 861 }
Kojto 39:d96aa62afc5b 862 else
Kojto 39:d96aa62afc5b 863 {
Kojto 39:d96aa62afc5b 864 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 865 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 866 }
Kojto 39:d96aa62afc5b 867
Kojto 39:d96aa62afc5b 868 usb0_host_set_pid_buf(pipe);
Kojto 39:d96aa62afc5b 869 }
Kojto 39:d96aa62afc5b 870
Kojto 39:d96aa62afc5b 871 /*******************************************************************************
Kojto 39:d96aa62afc5b 872 * Function Name: usb0_host_start_receive_dma_d1
Kojto 39:d96aa62afc5b 873 * Description : Read data from the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 874 * : Reads data by DMA transfer using D0FIFO.
Kojto 39:d96aa62afc5b 875 * : This function does not read data from the buffer.
Kojto 39:d96aa62afc5b 876 * : When storing data in the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 877 * : in the argument, delivered read request to DMAC to read data from
Kojto 39:d96aa62afc5b 878 * : the buffer by DMAC.
Kojto 39:d96aa62afc5b 879 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 880 * : uint32_t size ; Data Size
Kojto 39:d96aa62afc5b 881 * : uint8_t *data ; Data Address
Kojto 39:d96aa62afc5b 882 * Return Value : none
Kojto 39:d96aa62afc5b 883 *******************************************************************************/
Kojto 39:d96aa62afc5b 884 static void usb0_host_start_receive_dma_d1 (uint16_t pipe, uint32_t size, uint8_t * data)
Kojto 39:d96aa62afc5b 885 {
Kojto 39:d96aa62afc5b 886 uint16_t mbw;
Kojto 39:d96aa62afc5b 887
Kojto 39:d96aa62afc5b 888 usb0_host_set_pid_nak(pipe);
Kojto 39:d96aa62afc5b 889 g_usb0_host_data_count[pipe] = size;
Kojto 39:d96aa62afc5b 890 g_usb0_host_data_pointer[pipe] = (uint8_t *)data;
Kojto 39:d96aa62afc5b 891 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 892
Kojto 39:d96aa62afc5b 893 g_usb0_host_PipeDataSize[pipe] = 0;
Kojto 39:d96aa62afc5b 894 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_WAIT;
Kojto 39:d96aa62afc5b 895
Kojto 39:d96aa62afc5b 896 mbw = usb0_host_get_mbw(size, (uint32_t)data);
Kojto 39:d96aa62afc5b 897 usb0_host_set_curpipe(USB_HOST_PIPE0, USB_HOST_D1USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 898
Kojto 39:d96aa62afc5b 899 usb0_host_set_transaction_counter(pipe, size);
Kojto 39:d96aa62afc5b 900
Kojto 39:d96aa62afc5b 901 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 902 #else
Kojto 39:d96aa62afc5b 903 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 904 #endif
Kojto 39:d96aa62afc5b 905
Kojto 39:d96aa62afc5b 906 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
Kojto 39:d96aa62afc5b 907 {
Kojto 39:d96aa62afc5b 908 usb0_host_read_dma(pipe);
Kojto 39:d96aa62afc5b 909
Kojto 39:d96aa62afc5b 910 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 911 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 912 }
Kojto 39:d96aa62afc5b 913 else
Kojto 39:d96aa62afc5b 914 {
Kojto 39:d96aa62afc5b 915 usb0_host_enable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 916 usb0_host_enable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 917 }
Kojto 39:d96aa62afc5b 918
Kojto 39:d96aa62afc5b 919 usb0_host_set_pid_buf(pipe);
Kojto 39:d96aa62afc5b 920 }
Kojto 39:d96aa62afc5b 921
Kojto 39:d96aa62afc5b 922 /*******************************************************************************
Kojto 39:d96aa62afc5b 923 * Function Name: usb0_host_read_buffer
Kojto 39:d96aa62afc5b 924 * Description : Reads data from the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 925 * : in the argument.
Kojto 39:d96aa62afc5b 926 * : Uses FIF0 set in the pipe definition table.
Kojto 39:d96aa62afc5b 927 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 928 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 929 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 930 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 931 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 932 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 933 *******************************************************************************/
Kojto 39:d96aa62afc5b 934 uint16_t usb0_host_read_buffer (uint16_t pipe)
Kojto 39:d96aa62afc5b 935 {
Kojto 39:d96aa62afc5b 936 uint16_t status;
Kojto 39:d96aa62afc5b 937
Kojto 39:d96aa62afc5b 938 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 939
Kojto 39:d96aa62afc5b 940 if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_USE)
Kojto 39:d96aa62afc5b 941 {
Kojto 39:d96aa62afc5b 942 status = usb0_host_read_buffer_d0(pipe);
Kojto 39:d96aa62afc5b 943 }
Kojto 39:d96aa62afc5b 944 else if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_USE)
Kojto 39:d96aa62afc5b 945 {
Kojto 39:d96aa62afc5b 946 status = usb0_host_read_buffer_d1(pipe);
Kojto 39:d96aa62afc5b 947 }
Kojto 39:d96aa62afc5b 948 else
Kojto 39:d96aa62afc5b 949 {
Kojto 39:d96aa62afc5b 950 status = usb0_host_read_buffer_c(pipe);
Kojto 39:d96aa62afc5b 951 }
Kojto 39:d96aa62afc5b 952
Kojto 39:d96aa62afc5b 953 switch (status)
Kojto 39:d96aa62afc5b 954 {
Kojto 39:d96aa62afc5b 955 case USB_HOST_READING: /* Continue of data read */
Kojto 39:d96aa62afc5b 956 break;
Kojto 39:d96aa62afc5b 957
Kojto 39:d96aa62afc5b 958 case USB_HOST_READEND: /* End of data read */
Kojto 39:d96aa62afc5b 959 case USB_HOST_READSHRT: /* End of data read */
Kojto 39:d96aa62afc5b 960 usb0_host_disable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 961 g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 962 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
Kojto 39:d96aa62afc5b 963 break;
Kojto 39:d96aa62afc5b 964
Kojto 39:d96aa62afc5b 965 case USB_HOST_READOVER: /* buffer over */
Kojto 39:d96aa62afc5b 966 if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_USE)
Kojto 39:d96aa62afc5b 967 {
Kojto 39:d96aa62afc5b 968 USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 969 }
Kojto 39:d96aa62afc5b 970 else if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D1FIFO_USE)
Kojto 39:d96aa62afc5b 971 {
Kojto 39:d96aa62afc5b 972 USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 973 }
Kojto 39:d96aa62afc5b 974 else
Kojto 39:d96aa62afc5b 975 {
Kojto 39:d96aa62afc5b 976 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 977 }
Kojto 39:d96aa62afc5b 978 usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
Kojto 39:d96aa62afc5b 979 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 980 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
Kojto 39:d96aa62afc5b 981 #else
Kojto 39:d96aa62afc5b 982 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
Kojto 39:d96aa62afc5b 983 #endif
Kojto 39:d96aa62afc5b 984 g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 985 break;
Kojto 39:d96aa62afc5b 986
Kojto 39:d96aa62afc5b 987 case USB_HOST_FIFOERROR: /* FIFO access status */
Kojto 39:d96aa62afc5b 988 default:
Kojto 39:d96aa62afc5b 989 usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
Kojto 39:d96aa62afc5b 990 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
Kojto 39:d96aa62afc5b 991 break;
Kojto 39:d96aa62afc5b 992 }
Kojto 39:d96aa62afc5b 993
Kojto 39:d96aa62afc5b 994 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 995 }
Kojto 39:d96aa62afc5b 996
Kojto 39:d96aa62afc5b 997 /*******************************************************************************
Kojto 39:d96aa62afc5b 998 * Function Name: usb0_host_read_buffer_c
Kojto 39:d96aa62afc5b 999 * Description : Reads data from the buffer allocated in the pipe specified in the argument.
Kojto 39:d96aa62afc5b 1000 * : Reads data by CPU transfer using CFIFO.
Kojto 39:d96aa62afc5b 1001 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1002 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 1003 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 1004 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 1005 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 1006 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 1007 *******************************************************************************/
Kojto 39:d96aa62afc5b 1008 uint16_t usb0_host_read_buffer_c (uint16_t pipe)
Kojto 39:d96aa62afc5b 1009 {
Kojto 39:d96aa62afc5b 1010 uint32_t count;
Kojto 39:d96aa62afc5b 1011 uint32_t dtln;
Kojto 39:d96aa62afc5b 1012 uint16_t buffer;
Kojto 39:d96aa62afc5b 1013 uint16_t mxps;
Kojto 39:d96aa62afc5b 1014 uint16_t status;
Kojto 39:d96aa62afc5b 1015 uint16_t mbw;
Kojto 39:d96aa62afc5b 1016
Kojto 39:d96aa62afc5b 1017 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 1018 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_CUSE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1019
Kojto 39:d96aa62afc5b 1020 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 1021 {
Kojto 39:d96aa62afc5b 1022 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 1023 }
Kojto 39:d96aa62afc5b 1024
Kojto 39:d96aa62afc5b 1025 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
Kojto 39:d96aa62afc5b 1026 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 1027
Kojto 39:d96aa62afc5b 1028 if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
Kojto 39:d96aa62afc5b 1029 {
Kojto 39:d96aa62afc5b 1030 status = USB_HOST_READOVER;
Kojto 39:d96aa62afc5b 1031 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1032 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1033 }
Kojto 39:d96aa62afc5b 1034 else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
Kojto 39:d96aa62afc5b 1035 {
Kojto 39:d96aa62afc5b 1036 status = USB_HOST_READEND;
Kojto 39:d96aa62afc5b 1037 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1038 count = dtln;
Kojto 39:d96aa62afc5b 1039
Kojto 39:d96aa62afc5b 1040 if (count == 0)
Kojto 39:d96aa62afc5b 1041 {
Kojto 39:d96aa62afc5b 1042 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1043 }
Kojto 39:d96aa62afc5b 1044
Kojto 39:d96aa62afc5b 1045 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1046 {
Kojto 39:d96aa62afc5b 1047 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1048 }
Kojto 39:d96aa62afc5b 1049 }
Kojto 39:d96aa62afc5b 1050 else /* continue Receive data */
Kojto 39:d96aa62afc5b 1051 {
Kojto 39:d96aa62afc5b 1052 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1053 count = dtln;
Kojto 39:d96aa62afc5b 1054
Kojto 39:d96aa62afc5b 1055 if (count == 0)
Kojto 39:d96aa62afc5b 1056 {
Kojto 39:d96aa62afc5b 1057 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1058 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1059 }
Kojto 39:d96aa62afc5b 1060
Kojto 39:d96aa62afc5b 1061 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1062 {
Kojto 39:d96aa62afc5b 1063 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1064 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1065 }
Kojto 39:d96aa62afc5b 1066 }
Kojto 39:d96aa62afc5b 1067
Kojto 39:d96aa62afc5b 1068 if (count == 0) /* 0 length packet */
Kojto 39:d96aa62afc5b 1069 {
Kojto 39:d96aa62afc5b 1070 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 1071 }
Kojto 39:d96aa62afc5b 1072 else
Kojto 39:d96aa62afc5b 1073 {
Kojto 39:d96aa62afc5b 1074 usb0_host_read_c_fifo(pipe, (uint16_t)count);
Kojto 39:d96aa62afc5b 1075 }
Kojto 39:d96aa62afc5b 1076
Kojto 39:d96aa62afc5b 1077 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 1078
Kojto 39:d96aa62afc5b 1079 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 1080 }
Kojto 39:d96aa62afc5b 1081
Kojto 39:d96aa62afc5b 1082 /*******************************************************************************
Kojto 39:d96aa62afc5b 1083 * Function Name: usb0_host_read_buffer_d0
Kojto 39:d96aa62afc5b 1084 * Description : Reads data from the buffer allocated in the pipe specified in
Kojto 39:d96aa62afc5b 1085 * : the argument.
Kojto 39:d96aa62afc5b 1086 * : Reads data by CPU transfer using D0FIFO.
Kojto 39:d96aa62afc5b 1087 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1088 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 1089 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 1090 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 1091 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 1092 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 1093 *******************************************************************************/
Kojto 39:d96aa62afc5b 1094 uint16_t usb0_host_read_buffer_d0 (uint16_t pipe)
Kojto 39:d96aa62afc5b 1095 {
Kojto 39:d96aa62afc5b 1096 uint32_t count;
Kojto 39:d96aa62afc5b 1097 uint32_t dtln;
Kojto 39:d96aa62afc5b 1098 uint16_t buffer;
Kojto 39:d96aa62afc5b 1099 uint16_t mxps;
Kojto 39:d96aa62afc5b 1100 uint16_t status;
Kojto 39:d96aa62afc5b 1101 uint16_t mbw;
Kojto 39:d96aa62afc5b 1102 uint16_t pipebuf_size;
Kojto 39:d96aa62afc5b 1103
Kojto 39:d96aa62afc5b 1104 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 1105 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1106
Kojto 39:d96aa62afc5b 1107 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 1108 {
Kojto 39:d96aa62afc5b 1109 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 1110 }
Kojto 39:d96aa62afc5b 1111
Kojto 39:d96aa62afc5b 1112 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
Kojto 39:d96aa62afc5b 1113 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 1114
Kojto 39:d96aa62afc5b 1115 if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
Kojto 39:d96aa62afc5b 1116 {
Kojto 39:d96aa62afc5b 1117 status = USB_HOST_READOVER;
Kojto 39:d96aa62afc5b 1118 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1119 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1120 }
Kojto 39:d96aa62afc5b 1121 else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
Kojto 39:d96aa62afc5b 1122 {
Kojto 39:d96aa62afc5b 1123 status = USB_HOST_READEND;
Kojto 39:d96aa62afc5b 1124 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1125 count = dtln;
Kojto 39:d96aa62afc5b 1126
Kojto 39:d96aa62afc5b 1127 if (count == 0)
Kojto 39:d96aa62afc5b 1128 {
Kojto 39:d96aa62afc5b 1129 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1130 }
Kojto 39:d96aa62afc5b 1131
Kojto 39:d96aa62afc5b 1132 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1133 {
Kojto 39:d96aa62afc5b 1134 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1135 }
Kojto 39:d96aa62afc5b 1136 }
Kojto 39:d96aa62afc5b 1137 else /* continue Receive data */
Kojto 39:d96aa62afc5b 1138 {
Kojto 39:d96aa62afc5b 1139 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1140 count = dtln;
Kojto 39:d96aa62afc5b 1141
Kojto 39:d96aa62afc5b 1142 if (count == 0)
Kojto 39:d96aa62afc5b 1143 {
Kojto 39:d96aa62afc5b 1144 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1145 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1146 }
Kojto 39:d96aa62afc5b 1147
Kojto 39:d96aa62afc5b 1148 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1149 {
Kojto 39:d96aa62afc5b 1150 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1151 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1152 }
Kojto 39:d96aa62afc5b 1153 else
Kojto 39:d96aa62afc5b 1154 {
Kojto 39:d96aa62afc5b 1155 pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 1156
Kojto 39:d96aa62afc5b 1157 if (count != pipebuf_size)
Kojto 39:d96aa62afc5b 1158 {
Kojto 39:d96aa62afc5b 1159 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1160 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1161 }
Kojto 39:d96aa62afc5b 1162 }
Kojto 39:d96aa62afc5b 1163 }
Kojto 39:d96aa62afc5b 1164
Kojto 39:d96aa62afc5b 1165 if (count == 0) /* 0 length packet */
Kojto 39:d96aa62afc5b 1166 {
Kojto 39:d96aa62afc5b 1167 USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 1168 }
Kojto 39:d96aa62afc5b 1169 else
Kojto 39:d96aa62afc5b 1170 {
Kojto 39:d96aa62afc5b 1171 usb0_host_read_d0_fifo(pipe, (uint16_t)count);
Kojto 39:d96aa62afc5b 1172 }
Kojto 39:d96aa62afc5b 1173
Kojto 39:d96aa62afc5b 1174 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 1175
Kojto 39:d96aa62afc5b 1176 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 1177 }
Kojto 39:d96aa62afc5b 1178
Kojto 39:d96aa62afc5b 1179 /*******************************************************************************
Kojto 39:d96aa62afc5b 1180 * Function Name: usb0_host_read_buffer_d1
Kojto 39:d96aa62afc5b 1181 * Description : Reads data from the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 1182 * : in the argument.
Kojto 39:d96aa62afc5b 1183 * : Reads data by CPU transfer using D1FIFO.
Kojto 39:d96aa62afc5b 1184 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1185 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 1186 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 1187 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 1188 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 1189 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 1190 *******************************************************************************/
Kojto 39:d96aa62afc5b 1191 uint16_t usb0_host_read_buffer_d1 (uint16_t pipe)
Kojto 39:d96aa62afc5b 1192 {
Kojto 39:d96aa62afc5b 1193 uint32_t count;
Kojto 39:d96aa62afc5b 1194 uint32_t dtln;
Kojto 39:d96aa62afc5b 1195 uint16_t buffer;
Kojto 39:d96aa62afc5b 1196 uint16_t mxps;
Kojto 39:d96aa62afc5b 1197 uint16_t status;
Kojto 39:d96aa62afc5b 1198 uint16_t mbw;
Kojto 39:d96aa62afc5b 1199 uint16_t pipebuf_size;
Kojto 39:d96aa62afc5b 1200
Kojto 39:d96aa62afc5b 1201 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 1202 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1USE, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1203
Kojto 39:d96aa62afc5b 1204 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 1205 {
Kojto 39:d96aa62afc5b 1206 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 1207 }
Kojto 39:d96aa62afc5b 1208
Kojto 39:d96aa62afc5b 1209 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
Kojto 39:d96aa62afc5b 1210 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 1211
Kojto 39:d96aa62afc5b 1212 if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
Kojto 39:d96aa62afc5b 1213 {
Kojto 39:d96aa62afc5b 1214 status = USB_HOST_READOVER;
Kojto 39:d96aa62afc5b 1215 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1216 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1217 }
Kojto 39:d96aa62afc5b 1218 else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
Kojto 39:d96aa62afc5b 1219 {
Kojto 39:d96aa62afc5b 1220 status = USB_HOST_READEND;
Kojto 39:d96aa62afc5b 1221 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1222 count = dtln;
Kojto 39:d96aa62afc5b 1223
Kojto 39:d96aa62afc5b 1224 if (count == 0)
Kojto 39:d96aa62afc5b 1225 {
Kojto 39:d96aa62afc5b 1226 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1227 }
Kojto 39:d96aa62afc5b 1228
Kojto 39:d96aa62afc5b 1229 if ((count % mxps) !=0)
Kojto 39:d96aa62afc5b 1230 {
Kojto 39:d96aa62afc5b 1231 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1232 }
Kojto 39:d96aa62afc5b 1233 }
Kojto 39:d96aa62afc5b 1234 else /* continue Receive data */
Kojto 39:d96aa62afc5b 1235 {
Kojto 39:d96aa62afc5b 1236 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1237 count = dtln;
Kojto 39:d96aa62afc5b 1238
Kojto 39:d96aa62afc5b 1239 if (count == 0)
Kojto 39:d96aa62afc5b 1240 {
Kojto 39:d96aa62afc5b 1241 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1242 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1243 }
Kojto 39:d96aa62afc5b 1244
Kojto 39:d96aa62afc5b 1245 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1246 {
Kojto 39:d96aa62afc5b 1247 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1248 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1249 }
Kojto 39:d96aa62afc5b 1250 else
Kojto 39:d96aa62afc5b 1251 {
Kojto 39:d96aa62afc5b 1252 pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 1253 if (count != pipebuf_size)
Kojto 39:d96aa62afc5b 1254 {
Kojto 39:d96aa62afc5b 1255 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1256 usb0_host_set_pid_nak(pipe); /* Set NAK */
Kojto 39:d96aa62afc5b 1257 }
Kojto 39:d96aa62afc5b 1258 }
Kojto 39:d96aa62afc5b 1259 }
Kojto 39:d96aa62afc5b 1260
Kojto 39:d96aa62afc5b 1261 if (count == 0) /* 0 length packet */
Kojto 39:d96aa62afc5b 1262 {
Kojto 39:d96aa62afc5b 1263 USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 1264 }
Kojto 39:d96aa62afc5b 1265 else
Kojto 39:d96aa62afc5b 1266 {
Kojto 39:d96aa62afc5b 1267 usb0_host_read_d1_fifo(pipe, (uint16_t)count);
Kojto 39:d96aa62afc5b 1268 }
Kojto 39:d96aa62afc5b 1269
Kojto 39:d96aa62afc5b 1270 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 1271
Kojto 39:d96aa62afc5b 1272 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 1273 }
Kojto 39:d96aa62afc5b 1274
Kojto 39:d96aa62afc5b 1275 /*******************************************************************************
Kojto 39:d96aa62afc5b 1276 * Function Name: usb0_host_read_dma
Kojto 39:d96aa62afc5b 1277 * Description : Reads data from the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 1278 * : in the argument.
Kojto 39:d96aa62afc5b 1279 * : Reads data by DMA transfer using D0FIFO or D1FIFO.
Kojto 39:d96aa62afc5b 1280 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1281 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 1282 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 1283 * : USB_HOST_READZERO ; zero data
Kojto 39:d96aa62afc5b 1284 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 1285 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 1286 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 1287 *******************************************************************************/
Kojto 39:d96aa62afc5b 1288 uint16_t usb0_host_read_dma (uint16_t pipe)
Kojto 39:d96aa62afc5b 1289 {
Kojto 39:d96aa62afc5b 1290 uint16_t status;
Kojto 39:d96aa62afc5b 1291
Kojto 39:d96aa62afc5b 1292 g_usb0_host_PipeIgnore[pipe] = 0;
Kojto 39:d96aa62afc5b 1293
Kojto 39:d96aa62afc5b 1294 if ((g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE) == USB_HOST_D0FIFO_DMA)
Kojto 39:d96aa62afc5b 1295 {
Kojto 39:d96aa62afc5b 1296 status = usb0_host_read_dma_d0(pipe);
Kojto 39:d96aa62afc5b 1297 }
Kojto 39:d96aa62afc5b 1298 else
Kojto 39:d96aa62afc5b 1299 {
Kojto 39:d96aa62afc5b 1300 status = usb0_host_read_dma_d1(pipe);
Kojto 39:d96aa62afc5b 1301 }
Kojto 39:d96aa62afc5b 1302
Kojto 39:d96aa62afc5b 1303 switch (status)
Kojto 39:d96aa62afc5b 1304 {
Kojto 39:d96aa62afc5b 1305 case USB_HOST_READING: /* Continue of data read */
Kojto 39:d96aa62afc5b 1306 break;
Kojto 39:d96aa62afc5b 1307
Kojto 39:d96aa62afc5b 1308 case USB_HOST_READZERO: /* End of data read */
Kojto 39:d96aa62afc5b 1309 usb0_host_disable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 1310 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
Kojto 39:d96aa62afc5b 1311 break;
Kojto 39:d96aa62afc5b 1312
Kojto 39:d96aa62afc5b 1313 case USB_HOST_READEND: /* End of data read */
Kojto 39:d96aa62afc5b 1314 case USB_HOST_READSHRT: /* End of data read */
Kojto 39:d96aa62afc5b 1315 usb0_host_disable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 1316
Kojto 39:d96aa62afc5b 1317 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
Kojto 39:d96aa62afc5b 1318 {
Kojto 39:d96aa62afc5b 1319 g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1320 }
Kojto 39:d96aa62afc5b 1321 break;
Kojto 39:d96aa62afc5b 1322
Kojto 39:d96aa62afc5b 1323 case USB_HOST_READOVER: /* buffer over */
Kojto 39:d96aa62afc5b 1324 usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
Kojto 39:d96aa62afc5b 1325
Kojto 39:d96aa62afc5b 1326 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
Kojto 39:d96aa62afc5b 1327 {
Kojto 39:d96aa62afc5b 1328 g_usb0_host_PipeDataSize[pipe] -= g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1329 }
Kojto 39:d96aa62afc5b 1330 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 1331 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_DONE;
Kojto 39:d96aa62afc5b 1332 #else
Kojto 39:d96aa62afc5b 1333 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
Kojto 39:d96aa62afc5b 1334 #endif
Kojto 39:d96aa62afc5b 1335 break;
Kojto 39:d96aa62afc5b 1336
Kojto 39:d96aa62afc5b 1337 case USB_HOST_FIFOERROR: /* FIFO access status */
Kojto 39:d96aa62afc5b 1338 default:
Kojto 39:d96aa62afc5b 1339 usb0_host_disable_brdy_int(pipe); /* Disable Ready Interrupt */
Kojto 39:d96aa62afc5b 1340 g_usb0_host_pipe_status[pipe] = USB_HOST_PIPE_ERROR;
Kojto 39:d96aa62afc5b 1341 break;
Kojto 39:d96aa62afc5b 1342 }
Kojto 39:d96aa62afc5b 1343
Kojto 39:d96aa62afc5b 1344 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 1345 }
Kojto 39:d96aa62afc5b 1346
Kojto 39:d96aa62afc5b 1347 /*******************************************************************************
Kojto 39:d96aa62afc5b 1348 * Function Name: usb0_host_read_dma_d0
Kojto 39:d96aa62afc5b 1349 * Description : Writes data in the buffer allocated in the pipe specified
Kojto 39:d96aa62afc5b 1350 * : in the argument.
Kojto 39:d96aa62afc5b 1351 * : Reads data by DMA transfer using D0FIFO.
Kojto 39:d96aa62afc5b 1352 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1353 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 1354 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 1355 * : USB_HOST_READZERO ; zero data
Kojto 39:d96aa62afc5b 1356 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 1357 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 1358 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 1359 *******************************************************************************/
Kojto 39:d96aa62afc5b 1360 static uint16_t usb0_host_read_dma_d0 (uint16_t pipe)
Kojto 39:d96aa62afc5b 1361 {
Kojto 39:d96aa62afc5b 1362 uint32_t count;
Kojto 39:d96aa62afc5b 1363 uint32_t dtln;
Kojto 39:d96aa62afc5b 1364 uint16_t buffer;
Kojto 39:d96aa62afc5b 1365 uint16_t mxps;
Kojto 39:d96aa62afc5b 1366 uint16_t status;
Kojto 39:d96aa62afc5b 1367 uint16_t mbw;
Kojto 39:d96aa62afc5b 1368 uint16_t dfacc = 0;
Kojto 39:d96aa62afc5b 1369 uint16_t pipebuf_size;
Kojto 39:d96aa62afc5b 1370
Kojto 39:d96aa62afc5b 1371 g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_READY;
Kojto 39:d96aa62afc5b 1372
Kojto 39:d96aa62afc5b 1373 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 1374
Kojto 39:d96aa62afc5b 1375 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
Kojto 39:d96aa62afc5b 1376 {
Kojto 39:d96aa62afc5b 1377 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1378 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1379 }
Kojto 39:d96aa62afc5b 1380 else
Kojto 39:d96aa62afc5b 1381 {
Kojto 39:d96aa62afc5b 1382 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1383
Kojto 39:d96aa62afc5b 1384 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 1385 {
Kojto 39:d96aa62afc5b 1386 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 1387 }
Kojto 39:d96aa62afc5b 1388
Kojto 39:d96aa62afc5b 1389 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
Kojto 39:d96aa62afc5b 1390 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 1391
Kojto 39:d96aa62afc5b 1392 if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
Kojto 39:d96aa62afc5b 1393 {
Kojto 39:d96aa62afc5b 1394 status = USB_HOST_READOVER;
Kojto 39:d96aa62afc5b 1395 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1396 }
Kojto 39:d96aa62afc5b 1397 else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
Kojto 39:d96aa62afc5b 1398 {
Kojto 39:d96aa62afc5b 1399 status = USB_HOST_READEND;
Kojto 39:d96aa62afc5b 1400 count = dtln;
Kojto 39:d96aa62afc5b 1401
Kojto 39:d96aa62afc5b 1402 if (count == 0)
Kojto 39:d96aa62afc5b 1403 {
Kojto 39:d96aa62afc5b 1404 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1405 }
Kojto 39:d96aa62afc5b 1406
Kojto 39:d96aa62afc5b 1407 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1408 {
Kojto 39:d96aa62afc5b 1409 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1410 }
Kojto 39:d96aa62afc5b 1411 }
Kojto 39:d96aa62afc5b 1412 else /* continue Receive data */
Kojto 39:d96aa62afc5b 1413 {
Kojto 39:d96aa62afc5b 1414 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1415 count = dtln;
Kojto 39:d96aa62afc5b 1416
Kojto 39:d96aa62afc5b 1417 if (count == 0)
Kojto 39:d96aa62afc5b 1418 {
Kojto 39:d96aa62afc5b 1419 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1420 }
Kojto 39:d96aa62afc5b 1421
Kojto 39:d96aa62afc5b 1422 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1423 {
Kojto 39:d96aa62afc5b 1424 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1425 }
Kojto 39:d96aa62afc5b 1426 else
Kojto 39:d96aa62afc5b 1427 {
Kojto 39:d96aa62afc5b 1428 pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 1429
Kojto 39:d96aa62afc5b 1430 if (count != pipebuf_size)
Kojto 39:d96aa62afc5b 1431 {
Kojto 39:d96aa62afc5b 1432 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1433 }
Kojto 39:d96aa62afc5b 1434 }
Kojto 39:d96aa62afc5b 1435 }
Kojto 39:d96aa62afc5b 1436 }
Kojto 39:d96aa62afc5b 1437
Kojto 39:d96aa62afc5b 1438 if (count == 0) /* 0 length packet */
Kojto 39:d96aa62afc5b 1439 {
Kojto 39:d96aa62afc5b 1440 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
Kojto 39:d96aa62afc5b 1441 {
Kojto 39:d96aa62afc5b 1442 USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Clear B_CLR */
Kojto 39:d96aa62afc5b 1443 status = USB_HOST_READZERO; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1444 }
Kojto 39:d96aa62afc5b 1445 else
Kojto 39:d96aa62afc5b 1446 {
Kojto 39:d96aa62afc5b 1447 usb0_host_set_curpipe(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1448 /* transaction counter No set */
Kojto 39:d96aa62afc5b 1449 /* FRDY = 1, DTLN = 0 -> BRDY */
Kojto 39:d96aa62afc5b 1450 }
Kojto 39:d96aa62afc5b 1451 }
Kojto 39:d96aa62afc5b 1452 else
Kojto 39:d96aa62afc5b 1453 {
Kojto 39:d96aa62afc5b 1454 dfacc = usb0_host_set_dfacc_d0(mbw, count);
Kojto 39:d96aa62afc5b 1455
Kojto 39:d96aa62afc5b 1456 if (mbw == USB_HOST_BITMBW_32)
Kojto 39:d96aa62afc5b 1457 {
Kojto 39:d96aa62afc5b 1458 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 2; /* 32bit transfer */
Kojto 39:d96aa62afc5b 1459 }
Kojto 39:d96aa62afc5b 1460 else if (mbw == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 1461 {
Kojto 39:d96aa62afc5b 1462 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 1; /* 16bit transfer */
Kojto 39:d96aa62afc5b 1463 }
Kojto 39:d96aa62afc5b 1464 else
Kojto 39:d96aa62afc5b 1465 {
Kojto 39:d96aa62afc5b 1466 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].size = 0; /* 8bit transfer */
Kojto 39:d96aa62afc5b 1467 }
Kojto 39:d96aa62afc5b 1468
Kojto 39:d96aa62afc5b 1469 g_usb0_host_DmaPipe[USB_HOST_D0FIFO] = pipe; /* not use in read operation */
Kojto 39:d96aa62afc5b 1470 g_usb0_host_DmaBval[USB_HOST_D0FIFO] = 0; /* not use in read operation */
Kojto 39:d96aa62afc5b 1471
Kojto 39:d96aa62afc5b 1472 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].fifo = USB_HOST_D0FIFO_DMA;
Kojto 39:d96aa62afc5b 1473 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].dir = USB_HOST_FIFO2BUF;
Kojto 39:d96aa62afc5b 1474 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 1475 g_usb0_host_DmaInfo[USB_HOST_D0FIFO].bytes = count;
Kojto 39:d96aa62afc5b 1476
Kojto 39:d96aa62afc5b 1477 if (status == USB_HOST_READING)
Kojto 39:d96aa62afc5b 1478 {
Kojto 39:d96aa62afc5b 1479 g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_BUSY;
Kojto 39:d96aa62afc5b 1480 }
Kojto 39:d96aa62afc5b 1481 else
Kojto 39:d96aa62afc5b 1482 {
Kojto 39:d96aa62afc5b 1483 g_usb0_host_DmaStatus[USB_HOST_D0FIFO] = USB_HOST_DMA_BUSYEND;
Kojto 39:d96aa62afc5b 1484 }
Kojto 39:d96aa62afc5b 1485
Kojto 39:d96aa62afc5b 1486 Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D0FIFO], dfacc);
Kojto 39:d96aa62afc5b 1487
Kojto 39:d96aa62afc5b 1488 usb0_host_set_curpipe2(pipe, USB_HOST_D0DMA, USB_HOST_NO, mbw, dfacc);
Kojto 39:d96aa62afc5b 1489
Kojto 39:d96aa62afc5b 1490 RZA_IO_RegWrite_16(&USB200.D0FIFOSEL,
Kojto 39:d96aa62afc5b 1491 1,
Kojto 39:d96aa62afc5b 1492 USB_DnFIFOSEL_DREQE_SHIFT,
Kojto 39:d96aa62afc5b 1493 USB_DnFIFOSEL_DREQE);
Kojto 39:d96aa62afc5b 1494 }
Kojto 39:d96aa62afc5b 1495
Kojto 39:d96aa62afc5b 1496 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
Kojto 39:d96aa62afc5b 1497 {
Kojto 39:d96aa62afc5b 1498 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 1499 g_usb0_host_data_pointer[pipe] += count;
Kojto 39:d96aa62afc5b 1500 g_usb0_host_PipeDataSize[pipe] += count;
Kojto 39:d96aa62afc5b 1501 }
Kojto 39:d96aa62afc5b 1502
Kojto 39:d96aa62afc5b 1503 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 1504 }
Kojto 39:d96aa62afc5b 1505
Kojto 39:d96aa62afc5b 1506 /*******************************************************************************
Kojto 39:d96aa62afc5b 1507 * Function Name: usb0_host_read_dma_d1
Kojto 39:d96aa62afc5b 1508 * Description : Reads data from the buffer allocated in the pipe specified in
Kojto 39:d96aa62afc5b 1509 * : the argument.
Kojto 39:d96aa62afc5b 1510 * : Reads data by DMA transfer using D1FIFO.
Kojto 39:d96aa62afc5b 1511 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1512 * Return Value : USB_HOST_READEND ; Read end
Kojto 39:d96aa62afc5b 1513 * : USB_HOST_READSHRT ; short data
Kojto 39:d96aa62afc5b 1514 * : USB_HOST_READZERO ; zero data
Kojto 39:d96aa62afc5b 1515 * : USB_HOST_READING ; Continue of data read
Kojto 39:d96aa62afc5b 1516 * : USB_HOST_READOVER ; buffer over
Kojto 39:d96aa62afc5b 1517 * : USB_HOST_FIFOERROR ; FIFO status
Kojto 39:d96aa62afc5b 1518 *******************************************************************************/
Kojto 39:d96aa62afc5b 1519 static uint16_t usb0_host_read_dma_d1 (uint16_t pipe)
Kojto 39:d96aa62afc5b 1520 {
Kojto 39:d96aa62afc5b 1521 uint32_t count;
Kojto 39:d96aa62afc5b 1522 uint32_t dtln;
Kojto 39:d96aa62afc5b 1523 uint16_t buffer;
Kojto 39:d96aa62afc5b 1524 uint16_t mxps;
Kojto 39:d96aa62afc5b 1525 uint16_t status;
Kojto 39:d96aa62afc5b 1526 uint16_t mbw;
Kojto 39:d96aa62afc5b 1527 uint16_t dfacc = 0;
Kojto 39:d96aa62afc5b 1528 uint16_t pipebuf_size;
Kojto 39:d96aa62afc5b 1529
Kojto 39:d96aa62afc5b 1530 g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_READY;
Kojto 39:d96aa62afc5b 1531
Kojto 39:d96aa62afc5b 1532 mbw = usb0_host_get_mbw(g_usb0_host_data_count[pipe], (uint32_t)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 1533
Kojto 39:d96aa62afc5b 1534 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 1)
Kojto 39:d96aa62afc5b 1535 {
Kojto 39:d96aa62afc5b 1536 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1537 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1538 }
Kojto 39:d96aa62afc5b 1539 else
Kojto 39:d96aa62afc5b 1540 {
Kojto 39:d96aa62afc5b 1541 buffer = usb0_host_change_fifo_port(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1542
Kojto 39:d96aa62afc5b 1543 if (buffer == USB_HOST_FIFOERROR) /* FIFO access status */
Kojto 39:d96aa62afc5b 1544 {
Kojto 39:d96aa62afc5b 1545 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 1546 }
Kojto 39:d96aa62afc5b 1547
Kojto 39:d96aa62afc5b 1548 dtln = (uint32_t)(buffer & USB_HOST_BITDTLN);
Kojto 39:d96aa62afc5b 1549 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 1550
Kojto 39:d96aa62afc5b 1551 if (g_usb0_host_data_count[pipe] < dtln) /* Buffer Over ? */
Kojto 39:d96aa62afc5b 1552 {
Kojto 39:d96aa62afc5b 1553 status = USB_HOST_READOVER;
Kojto 39:d96aa62afc5b 1554 count = g_usb0_host_data_count[pipe];
Kojto 39:d96aa62afc5b 1555 }
Kojto 39:d96aa62afc5b 1556 else if (g_usb0_host_data_count[pipe] == dtln) /* just Receive Size */
Kojto 39:d96aa62afc5b 1557 {
Kojto 39:d96aa62afc5b 1558 status = USB_HOST_READEND;
Kojto 39:d96aa62afc5b 1559 count = dtln;
Kojto 39:d96aa62afc5b 1560
Kojto 39:d96aa62afc5b 1561 if (count == 0)
Kojto 39:d96aa62afc5b 1562 {
Kojto 39:d96aa62afc5b 1563 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1564 }
Kojto 39:d96aa62afc5b 1565
Kojto 39:d96aa62afc5b 1566 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1567 {
Kojto 39:d96aa62afc5b 1568 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1569 }
Kojto 39:d96aa62afc5b 1570 }
Kojto 39:d96aa62afc5b 1571 else /* continue Receive data */
Kojto 39:d96aa62afc5b 1572 {
Kojto 39:d96aa62afc5b 1573 status = USB_HOST_READING;
Kojto 39:d96aa62afc5b 1574 count = dtln;
Kojto 39:d96aa62afc5b 1575
Kojto 39:d96aa62afc5b 1576 if (count == 0)
Kojto 39:d96aa62afc5b 1577 {
Kojto 39:d96aa62afc5b 1578 status = USB_HOST_READSHRT; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1579 }
Kojto 39:d96aa62afc5b 1580
Kojto 39:d96aa62afc5b 1581 if ((count % mxps) != 0)
Kojto 39:d96aa62afc5b 1582 {
Kojto 39:d96aa62afc5b 1583 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1584 }
Kojto 39:d96aa62afc5b 1585 else
Kojto 39:d96aa62afc5b 1586 {
Kojto 39:d96aa62afc5b 1587 pipebuf_size = usb0_host_get_buf_size(pipe); /* Data buffer size */
Kojto 39:d96aa62afc5b 1588
Kojto 39:d96aa62afc5b 1589 if (count != pipebuf_size)
Kojto 39:d96aa62afc5b 1590 {
Kojto 39:d96aa62afc5b 1591 status = USB_HOST_READSHRT; /* Short Packet receive */
Kojto 39:d96aa62afc5b 1592 }
Kojto 39:d96aa62afc5b 1593 }
Kojto 39:d96aa62afc5b 1594 }
Kojto 39:d96aa62afc5b 1595 }
Kojto 39:d96aa62afc5b 1596
Kojto 39:d96aa62afc5b 1597 if (count == 0) /* 0 length packet */
Kojto 39:d96aa62afc5b 1598 {
Kojto 39:d96aa62afc5b 1599 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
Kojto 39:d96aa62afc5b 1600 {
Kojto 39:d96aa62afc5b 1601 USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Clear BCLR */
Kojto 39:d96aa62afc5b 1602 status = USB_HOST_READZERO; /* Null Packet receive */
Kojto 39:d96aa62afc5b 1603 }
Kojto 39:d96aa62afc5b 1604 else
Kojto 39:d96aa62afc5b 1605 {
Kojto 39:d96aa62afc5b 1606 usb0_host_set_curpipe(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw);
Kojto 39:d96aa62afc5b 1607 /* transaction counter No set */
Kojto 39:d96aa62afc5b 1608 /* FRDY = 1, DTLN = 0 -> BRDY */
Kojto 39:d96aa62afc5b 1609 }
Kojto 39:d96aa62afc5b 1610 }
Kojto 39:d96aa62afc5b 1611 else
Kojto 39:d96aa62afc5b 1612 {
Kojto 39:d96aa62afc5b 1613 dfacc = usb0_host_set_dfacc_d1(mbw, count);
Kojto 39:d96aa62afc5b 1614
Kojto 39:d96aa62afc5b 1615 if (mbw == USB_HOST_BITMBW_32)
Kojto 39:d96aa62afc5b 1616 {
Kojto 39:d96aa62afc5b 1617 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 2; /* 32bit transfer */
Kojto 39:d96aa62afc5b 1618 }
Kojto 39:d96aa62afc5b 1619 else if (mbw == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 1620 {
Kojto 39:d96aa62afc5b 1621 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 1; /* 16bit transfer */
Kojto 39:d96aa62afc5b 1622 }
Kojto 39:d96aa62afc5b 1623 else
Kojto 39:d96aa62afc5b 1624 {
Kojto 39:d96aa62afc5b 1625 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].size = 0; /* 8bit transfer */
Kojto 39:d96aa62afc5b 1626 }
Kojto 39:d96aa62afc5b 1627
Kojto 39:d96aa62afc5b 1628 g_usb0_host_DmaPipe[USB_HOST_D1FIFO] = pipe; /* not use in read operation */
Kojto 39:d96aa62afc5b 1629 g_usb0_host_DmaBval[USB_HOST_D1FIFO] = 0; /* not use in read operation */
Kojto 39:d96aa62afc5b 1630
Kojto 39:d96aa62afc5b 1631 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].fifo = USB_HOST_D1FIFO_DMA;
Kojto 39:d96aa62afc5b 1632 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].dir = USB_HOST_FIFO2BUF;
Kojto 39:d96aa62afc5b 1633 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].buffer = (uint32_t)g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 1634 g_usb0_host_DmaInfo[USB_HOST_D1FIFO].bytes = count;
Kojto 39:d96aa62afc5b 1635
Kojto 39:d96aa62afc5b 1636 if (status == USB_HOST_READING)
Kojto 39:d96aa62afc5b 1637 {
Kojto 39:d96aa62afc5b 1638 g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_BUSY;
Kojto 39:d96aa62afc5b 1639 }
Kojto 39:d96aa62afc5b 1640 else
Kojto 39:d96aa62afc5b 1641 {
Kojto 39:d96aa62afc5b 1642 g_usb0_host_DmaStatus[USB_HOST_D1FIFO] = USB_HOST_DMA_BUSYEND;
Kojto 39:d96aa62afc5b 1643 }
Kojto 39:d96aa62afc5b 1644
Kojto 39:d96aa62afc5b 1645 Userdef_USB_usb0_host_start_dma(&g_usb0_host_DmaInfo[USB_HOST_D1FIFO], dfacc);
Kojto 39:d96aa62afc5b 1646
Kojto 39:d96aa62afc5b 1647 usb0_host_set_curpipe2(pipe, USB_HOST_D1DMA, USB_HOST_NO, mbw, dfacc);
Kojto 39:d96aa62afc5b 1648
Kojto 39:d96aa62afc5b 1649 RZA_IO_RegWrite_16(&USB200.D1FIFOSEL,
Kojto 39:d96aa62afc5b 1650 1,
Kojto 39:d96aa62afc5b 1651 USB_DnFIFOSEL_DREQE_SHIFT,
Kojto 39:d96aa62afc5b 1652 USB_DnFIFOSEL_DREQE);
Kojto 39:d96aa62afc5b 1653 }
Kojto 39:d96aa62afc5b 1654
Kojto 39:d96aa62afc5b 1655 if (RZA_IO_RegRead_16(&g_usb0_host_pipecfg[pipe], USB_PIPECFG_BFRE_SHIFT, USB_PIPECFG_BFRE) == 0)
Kojto 39:d96aa62afc5b 1656 {
Kojto 39:d96aa62afc5b 1657 g_usb0_host_data_count[pipe] -= count;
Kojto 39:d96aa62afc5b 1658 g_usb0_host_data_pointer[pipe] += count;
Kojto 39:d96aa62afc5b 1659 g_usb0_host_PipeDataSize[pipe] += count;
Kojto 39:d96aa62afc5b 1660 }
Kojto 39:d96aa62afc5b 1661
Kojto 39:d96aa62afc5b 1662 return status; /* End or Err or Continue */
Kojto 39:d96aa62afc5b 1663 }
Kojto 39:d96aa62afc5b 1664
Kojto 39:d96aa62afc5b 1665 /*******************************************************************************
Kojto 39:d96aa62afc5b 1666 * Function Name: usb0_host_change_fifo_port
Kojto 39:d96aa62afc5b 1667 * Description : Allocates FIF0 specified by the argument in the pipe assigned
Kojto 39:d96aa62afc5b 1668 * : by the argument. After allocating FIF0, waits in the software
Kojto 39:d96aa62afc5b 1669 * : till the corresponding pipe becomes ready.
Kojto 39:d96aa62afc5b 1670 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1671 * : uint16_t fifosel ; Select FIFO
Kojto 39:d96aa62afc5b 1672 * : uint16_t isel ; FIFO Access Direction
Kojto 39:d96aa62afc5b 1673 * : uint16_t mbw ; FIFO Port Access Bit Width
Kojto 39:d96aa62afc5b 1674 * Return Value : USB_HOST_FIFOERROR ; Error
Kojto 39:d96aa62afc5b 1675 * : Others ; CFIFOCTR/D0FIFOCTR/D1FIFOCTR Register Value
Kojto 39:d96aa62afc5b 1676 *******************************************************************************/
Kojto 39:d96aa62afc5b 1677 uint16_t usb0_host_change_fifo_port (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
Kojto 39:d96aa62afc5b 1678 {
Kojto 39:d96aa62afc5b 1679 uint16_t buffer;
Kojto 39:d96aa62afc5b 1680 uint32_t loop;
Kojto 39:d96aa62afc5b 1681 volatile uint32_t loop2;
Kojto 39:d96aa62afc5b 1682
Kojto 39:d96aa62afc5b 1683 usb0_host_set_curpipe(pipe, fifosel, isel, mbw);
Kojto 39:d96aa62afc5b 1684
Kojto 39:d96aa62afc5b 1685 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1686 {
Kojto 39:d96aa62afc5b 1687 switch (fifosel)
Kojto 39:d96aa62afc5b 1688 {
Kojto 39:d96aa62afc5b 1689 case USB_HOST_CUSE:
Kojto 39:d96aa62afc5b 1690 buffer = USB200.CFIFOCTR;
Kojto 39:d96aa62afc5b 1691 break;
Kojto 39:d96aa62afc5b 1692
Kojto 39:d96aa62afc5b 1693 case USB_HOST_D0USE:
Kojto 39:d96aa62afc5b 1694 case USB_HOST_D0DMA:
Kojto 39:d96aa62afc5b 1695 buffer = USB200.D0FIFOCTR;
Kojto 39:d96aa62afc5b 1696 break;
Kojto 39:d96aa62afc5b 1697
Kojto 39:d96aa62afc5b 1698 case USB_HOST_D1USE:
Kojto 39:d96aa62afc5b 1699 case USB_HOST_D1DMA:
Kojto 39:d96aa62afc5b 1700 buffer = USB200.D1FIFOCTR;
Kojto 39:d96aa62afc5b 1701 break;
Kojto 39:d96aa62afc5b 1702
Kojto 39:d96aa62afc5b 1703 default:
Kojto 39:d96aa62afc5b 1704 buffer = 0;
Kojto 39:d96aa62afc5b 1705 break;
Kojto 39:d96aa62afc5b 1706 }
Kojto 39:d96aa62afc5b 1707
Kojto 39:d96aa62afc5b 1708 if ((buffer & USB_HOST_BITFRDY) == USB_HOST_BITFRDY)
Kojto 39:d96aa62afc5b 1709 {
Kojto 39:d96aa62afc5b 1710 return buffer;
Kojto 39:d96aa62afc5b 1711 }
Kojto 39:d96aa62afc5b 1712
Kojto 39:d96aa62afc5b 1713 loop2 = 25;
Kojto 39:d96aa62afc5b 1714
Kojto 39:d96aa62afc5b 1715 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1716 {
Kojto 39:d96aa62afc5b 1717 /* wait */
Kojto 39:d96aa62afc5b 1718 }
Kojto 39:d96aa62afc5b 1719 }
Kojto 39:d96aa62afc5b 1720
Kojto 39:d96aa62afc5b 1721 return USB_HOST_FIFOERROR;
Kojto 39:d96aa62afc5b 1722 }
Kojto 39:d96aa62afc5b 1723
Kojto 39:d96aa62afc5b 1724 /*******************************************************************************
Kojto 39:d96aa62afc5b 1725 * Function Name: usb0_host_set_curpipe
Kojto 39:d96aa62afc5b 1726 * Description : Allocates FIF0 specified by the argument in the pipe assigned
Kojto 39:d96aa62afc5b 1727 * : by the argument.
Kojto 39:d96aa62afc5b 1728 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1729 * : uint16_t fifosel ; Select FIFO
Kojto 39:d96aa62afc5b 1730 * : uint16_t isel ; FIFO Access Direction
Kojto 39:d96aa62afc5b 1731 * : uint16_t mbw ; FIFO Port Access Bit Width
Kojto 39:d96aa62afc5b 1732 * Return Value : none
Kojto 39:d96aa62afc5b 1733 *******************************************************************************/
Kojto 39:d96aa62afc5b 1734 void usb0_host_set_curpipe (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw)
Kojto 39:d96aa62afc5b 1735 {
Kojto 39:d96aa62afc5b 1736 uint16_t buffer;
Kojto 39:d96aa62afc5b 1737 uint32_t loop;
Kojto 39:d96aa62afc5b 1738 volatile uint32_t loop2;
Kojto 39:d96aa62afc5b 1739
Kojto 39:d96aa62afc5b 1740 g_usb0_host_mbw[pipe] = mbw;
Kojto 39:d96aa62afc5b 1741
Kojto 39:d96aa62afc5b 1742 switch (fifosel)
Kojto 39:d96aa62afc5b 1743 {
Kojto 39:d96aa62afc5b 1744 case USB_HOST_CUSE:
Kojto 39:d96aa62afc5b 1745 buffer = USB200.CFIFOSEL;
Kojto 39:d96aa62afc5b 1746 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 1747 buffer |= (uint16_t)(~isel & USB_HOST_BITISEL);
Kojto 39:d96aa62afc5b 1748 USB200.CFIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1749
Kojto 39:d96aa62afc5b 1750 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1751 {
Kojto 39:d96aa62afc5b 1752 if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1753 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
Kojto 39:d96aa62afc5b 1754 {
Kojto 39:d96aa62afc5b 1755 break;
Kojto 39:d96aa62afc5b 1756 }
Kojto 39:d96aa62afc5b 1757
Kojto 39:d96aa62afc5b 1758 loop2 = 100;
Kojto 39:d96aa62afc5b 1759 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1760 {
Kojto 39:d96aa62afc5b 1761 /* wait */
Kojto 39:d96aa62afc5b 1762 }
Kojto 39:d96aa62afc5b 1763 }
Kojto 39:d96aa62afc5b 1764
Kojto 39:d96aa62afc5b 1765 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 1766 buffer |= (uint16_t)(isel | pipe | mbw);
Kojto 39:d96aa62afc5b 1767 USB200.CFIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1768
Kojto 39:d96aa62afc5b 1769 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1770 {
Kojto 39:d96aa62afc5b 1771 if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1772 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
Kojto 39:d96aa62afc5b 1773 {
Kojto 39:d96aa62afc5b 1774 break;
Kojto 39:d96aa62afc5b 1775 }
Kojto 39:d96aa62afc5b 1776
Kojto 39:d96aa62afc5b 1777 loop2 = 100;
Kojto 39:d96aa62afc5b 1778 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1779 {
Kojto 39:d96aa62afc5b 1780 /* wait */
Kojto 39:d96aa62afc5b 1781 }
Kojto 39:d96aa62afc5b 1782 }
Kojto 39:d96aa62afc5b 1783 break;
Kojto 39:d96aa62afc5b 1784
Kojto 39:d96aa62afc5b 1785 case USB_HOST_D0DMA:
Kojto 39:d96aa62afc5b 1786 case USB_HOST_D0USE:
Kojto 39:d96aa62afc5b 1787 buffer = USB200.D0FIFOSEL;
Kojto 39:d96aa62afc5b 1788 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 1789 USB200.D0FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1790
Kojto 39:d96aa62afc5b 1791 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1792 {
Kojto 39:d96aa62afc5b 1793 if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1794 {
Kojto 39:d96aa62afc5b 1795 break;
Kojto 39:d96aa62afc5b 1796 }
Kojto 39:d96aa62afc5b 1797
Kojto 39:d96aa62afc5b 1798 loop2 = 100;
Kojto 39:d96aa62afc5b 1799 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1800 {
Kojto 39:d96aa62afc5b 1801 /* wait */
Kojto 39:d96aa62afc5b 1802 }
Kojto 39:d96aa62afc5b 1803 }
Kojto 39:d96aa62afc5b 1804 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 1805 buffer |= (uint16_t)(pipe | mbw);
Kojto 39:d96aa62afc5b 1806 USB200.D0FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1807
Kojto 39:d96aa62afc5b 1808 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1809 {
Kojto 39:d96aa62afc5b 1810 if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1811 {
Kojto 39:d96aa62afc5b 1812 break;
Kojto 39:d96aa62afc5b 1813 }
Kojto 39:d96aa62afc5b 1814
Kojto 39:d96aa62afc5b 1815 loop2 = 100;
Kojto 39:d96aa62afc5b 1816 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1817 {
Kojto 39:d96aa62afc5b 1818 /* wait */
Kojto 39:d96aa62afc5b 1819 }
Kojto 39:d96aa62afc5b 1820 }
Kojto 39:d96aa62afc5b 1821 break;
Kojto 39:d96aa62afc5b 1822
Kojto 39:d96aa62afc5b 1823 case USB_HOST_D1DMA:
Kojto 39:d96aa62afc5b 1824 case USB_HOST_D1USE:
Kojto 39:d96aa62afc5b 1825 buffer = USB200.D1FIFOSEL;
Kojto 39:d96aa62afc5b 1826 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 1827 USB200.D1FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1828
Kojto 39:d96aa62afc5b 1829 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1830 {
Kojto 39:d96aa62afc5b 1831 if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1832 {
Kojto 39:d96aa62afc5b 1833 break;
Kojto 39:d96aa62afc5b 1834 }
Kojto 39:d96aa62afc5b 1835
Kojto 39:d96aa62afc5b 1836 loop2 = 100;
Kojto 39:d96aa62afc5b 1837 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1838 {
Kojto 39:d96aa62afc5b 1839 /* wait */
Kojto 39:d96aa62afc5b 1840 }
Kojto 39:d96aa62afc5b 1841 }
Kojto 39:d96aa62afc5b 1842
Kojto 39:d96aa62afc5b 1843 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 1844 buffer |= (uint16_t)(pipe | mbw);
Kojto 39:d96aa62afc5b 1845 USB200.D1FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1846
Kojto 39:d96aa62afc5b 1847 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1848 {
Kojto 39:d96aa62afc5b 1849 if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1850 {
Kojto 39:d96aa62afc5b 1851 break;
Kojto 39:d96aa62afc5b 1852 }
Kojto 39:d96aa62afc5b 1853
Kojto 39:d96aa62afc5b 1854 loop2 = 100;
Kojto 39:d96aa62afc5b 1855 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1856 {
Kojto 39:d96aa62afc5b 1857 /* wait */
Kojto 39:d96aa62afc5b 1858 }
Kojto 39:d96aa62afc5b 1859 }
Kojto 39:d96aa62afc5b 1860 break;
Kojto 39:d96aa62afc5b 1861
Kojto 39:d96aa62afc5b 1862 default:
Kojto 39:d96aa62afc5b 1863 break;
Kojto 39:d96aa62afc5b 1864 }
Kojto 39:d96aa62afc5b 1865
Kojto 39:d96aa62afc5b 1866 /* Cautions !!!
Kojto 39:d96aa62afc5b 1867 * Depending on the external bus speed of CPU, you may need to wait for 450ns here.
Kojto 39:d96aa62afc5b 1868 * For details, please look at the data sheet. */
Kojto 39:d96aa62afc5b 1869 loop2 = 100;
Kojto 39:d96aa62afc5b 1870
Kojto 39:d96aa62afc5b 1871 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1872 {
Kojto 39:d96aa62afc5b 1873 /* wait */
Kojto 39:d96aa62afc5b 1874 }
Kojto 39:d96aa62afc5b 1875 }
Kojto 39:d96aa62afc5b 1876
Kojto 39:d96aa62afc5b 1877 /*******************************************************************************
Kojto 39:d96aa62afc5b 1878 * Function Name: usb0_host_set_curpipe2
Kojto 39:d96aa62afc5b 1879 * Description : Allocates FIF0 specified by the argument in the pipe assigned
Kojto 39:d96aa62afc5b 1880 * : by the argument.(DFACC)
Kojto 39:d96aa62afc5b 1881 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 1882 * : uint16_t fifosel ; Select FIFO
Kojto 39:d96aa62afc5b 1883 * : uint16_t isel ; FIFO Access Direction
Kojto 39:d96aa62afc5b 1884 * : uint16_t mbw ; FIFO Port Access Bit Width
Kojto 39:d96aa62afc5b 1885 * : uint16_t dfacc ; DFACC Access mode
Kojto 39:d96aa62afc5b 1886 * Return Value : none
Kojto 39:d96aa62afc5b 1887 *******************************************************************************/
Kojto 39:d96aa62afc5b 1888 void usb0_host_set_curpipe2 (uint16_t pipe, uint16_t fifosel, uint16_t isel, uint16_t mbw, uint16_t dfacc)
Kojto 39:d96aa62afc5b 1889 {
Kojto 39:d96aa62afc5b 1890 uint16_t buffer;
Kojto 39:d96aa62afc5b 1891 uint32_t loop;
Kojto 39:d96aa62afc5b 1892 #ifdef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 1893 uint32_t dummy;
Kojto 39:d96aa62afc5b 1894 #endif
Kojto 39:d96aa62afc5b 1895 volatile uint32_t loop2;
Kojto 39:d96aa62afc5b 1896
Kojto 39:d96aa62afc5b 1897 g_usb0_host_mbw[pipe] = mbw;
Kojto 39:d96aa62afc5b 1898
Kojto 39:d96aa62afc5b 1899 switch (fifosel)
Kojto 39:d96aa62afc5b 1900 {
Kojto 39:d96aa62afc5b 1901 case USB_HOST_CUSE:
Kojto 39:d96aa62afc5b 1902 buffer = USB200.CFIFOSEL;
Kojto 39:d96aa62afc5b 1903 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 1904 buffer |= (uint16_t)(~isel & USB_HOST_BITISEL);
Kojto 39:d96aa62afc5b 1905 USB200.CFIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1906
Kojto 39:d96aa62afc5b 1907 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1908 {
Kojto 39:d96aa62afc5b 1909 if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1910 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
Kojto 39:d96aa62afc5b 1911 {
Kojto 39:d96aa62afc5b 1912 break;
Kojto 39:d96aa62afc5b 1913 }
Kojto 39:d96aa62afc5b 1914
Kojto 39:d96aa62afc5b 1915 loop2 = 100;
Kojto 39:d96aa62afc5b 1916 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1917 {
Kojto 39:d96aa62afc5b 1918 /* wait */
Kojto 39:d96aa62afc5b 1919 }
Kojto 39:d96aa62afc5b 1920 }
Kojto 39:d96aa62afc5b 1921
Kojto 39:d96aa62afc5b 1922 buffer &= (uint16_t)~(USB_HOST_BITISEL | USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 1923 buffer |= (uint16_t)(isel | pipe | mbw);
Kojto 39:d96aa62afc5b 1924 USB200.CFIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1925
Kojto 39:d96aa62afc5b 1926 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1927 {
Kojto 39:d96aa62afc5b 1928 if ((USB200.CFIFOSEL & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1929 == (buffer & (USB_HOST_BITISEL | USB_HOST_BITCURPIPE)))
Kojto 39:d96aa62afc5b 1930 {
Kojto 39:d96aa62afc5b 1931 break;
Kojto 39:d96aa62afc5b 1932 }
Kojto 39:d96aa62afc5b 1933
Kojto 39:d96aa62afc5b 1934 loop2 = 100;
Kojto 39:d96aa62afc5b 1935 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1936 {
Kojto 39:d96aa62afc5b 1937 /* wait */
Kojto 39:d96aa62afc5b 1938 }
Kojto 39:d96aa62afc5b 1939 }
Kojto 39:d96aa62afc5b 1940 break;
Kojto 39:d96aa62afc5b 1941
Kojto 39:d96aa62afc5b 1942 case USB_HOST_D0DMA:
Kojto 39:d96aa62afc5b 1943 case USB_HOST_D0USE:
Kojto 39:d96aa62afc5b 1944 buffer = USB200.D0FIFOSEL;
Kojto 39:d96aa62afc5b 1945 #ifdef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 1946 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 1947
Kojto 39:d96aa62afc5b 1948 if (dfacc != 0)
Kojto 39:d96aa62afc5b 1949 {
Kojto 39:d96aa62afc5b 1950 buffer |= (uint16_t)(USB_HOST_BITMBW_32);
Kojto 39:d96aa62afc5b 1951 }
Kojto 39:d96aa62afc5b 1952 #else
Kojto 39:d96aa62afc5b 1953 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 1954 #endif
Kojto 39:d96aa62afc5b 1955 USB200.D0FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1956
Kojto 39:d96aa62afc5b 1957 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1958 {
Kojto 39:d96aa62afc5b 1959 if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1960 {
Kojto 39:d96aa62afc5b 1961 break;
Kojto 39:d96aa62afc5b 1962 }
Kojto 39:d96aa62afc5b 1963
Kojto 39:d96aa62afc5b 1964 loop2 = 100;
Kojto 39:d96aa62afc5b 1965 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1966 {
Kojto 39:d96aa62afc5b 1967 /* wait */
Kojto 39:d96aa62afc5b 1968 }
Kojto 39:d96aa62afc5b 1969 }
Kojto 39:d96aa62afc5b 1970
Kojto 39:d96aa62afc5b 1971 #ifdef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 1972 if (dfacc != 0)
Kojto 39:d96aa62afc5b 1973 {
Kojto 39:d96aa62afc5b 1974 dummy = USB200.D0FIFO.UINT32;
Kojto 39:d96aa62afc5b 1975 }
Kojto 39:d96aa62afc5b 1976 #endif
Kojto 39:d96aa62afc5b 1977
Kojto 39:d96aa62afc5b 1978 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 1979 buffer |= (uint16_t)(pipe | mbw);
Kojto 39:d96aa62afc5b 1980 USB200.D0FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 1981
Kojto 39:d96aa62afc5b 1982 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 1983 {
Kojto 39:d96aa62afc5b 1984 if ((USB200.D0FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 1985 {
Kojto 39:d96aa62afc5b 1986 break;
Kojto 39:d96aa62afc5b 1987 }
Kojto 39:d96aa62afc5b 1988
Kojto 39:d96aa62afc5b 1989 loop2 = 100;
Kojto 39:d96aa62afc5b 1990 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 1991 {
Kojto 39:d96aa62afc5b 1992 /* wait */
Kojto 39:d96aa62afc5b 1993 }
Kojto 39:d96aa62afc5b 1994 }
Kojto 39:d96aa62afc5b 1995 break;
Kojto 39:d96aa62afc5b 1996
Kojto 39:d96aa62afc5b 1997 case USB_HOST_D1DMA:
Kojto 39:d96aa62afc5b 1998 case USB_HOST_D1USE:
Kojto 39:d96aa62afc5b 1999 buffer = USB200.D1FIFOSEL;
Kojto 39:d96aa62afc5b 2000 #ifdef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 2001 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 2002
Kojto 39:d96aa62afc5b 2003 if (dfacc != 0)
Kojto 39:d96aa62afc5b 2004 {
Kojto 39:d96aa62afc5b 2005 buffer |= (uint16_t)(USB_HOST_BITMBW_32);
Kojto 39:d96aa62afc5b 2006 }
Kojto 39:d96aa62afc5b 2007 #else
Kojto 39:d96aa62afc5b 2008 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE);
Kojto 39:d96aa62afc5b 2009 #endif
Kojto 39:d96aa62afc5b 2010 USB200.D1FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 2011
Kojto 39:d96aa62afc5b 2012 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 2013 {
Kojto 39:d96aa62afc5b 2014 if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 2015 {
Kojto 39:d96aa62afc5b 2016 break;
Kojto 39:d96aa62afc5b 2017 }
Kojto 39:d96aa62afc5b 2018
Kojto 39:d96aa62afc5b 2019 loop2 = 100;
Kojto 39:d96aa62afc5b 2020 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 2021 {
Kojto 39:d96aa62afc5b 2022 /* wait */
Kojto 39:d96aa62afc5b 2023 }
Kojto 39:d96aa62afc5b 2024 }
Kojto 39:d96aa62afc5b 2025
Kojto 39:d96aa62afc5b 2026 #ifdef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 2027 if (dfacc != 0)
Kojto 39:d96aa62afc5b 2028 {
Kojto 39:d96aa62afc5b 2029 dummy = USB200.D1FIFO.UINT32;
Kojto 39:d96aa62afc5b 2030 loop = dummy; // avoid warning.
Kojto 39:d96aa62afc5b 2031 }
Kojto 39:d96aa62afc5b 2032 #endif
Kojto 39:d96aa62afc5b 2033
Kojto 39:d96aa62afc5b 2034 buffer &= (uint16_t)~(USB_HOST_BITCURPIPE | USB_HOST_BITMBW);
Kojto 39:d96aa62afc5b 2035 buffer |= (uint16_t)(pipe | mbw);
Kojto 39:d96aa62afc5b 2036 USB200.D1FIFOSEL = buffer;
Kojto 39:d96aa62afc5b 2037
Kojto 39:d96aa62afc5b 2038 for (loop = 0; loop < 4; loop++)
Kojto 39:d96aa62afc5b 2039 {
Kojto 39:d96aa62afc5b 2040 if ((USB200.D1FIFOSEL & USB_HOST_BITCURPIPE) == (buffer & USB_HOST_BITCURPIPE))
Kojto 39:d96aa62afc5b 2041 {
Kojto 39:d96aa62afc5b 2042 break;
Kojto 39:d96aa62afc5b 2043 }
Kojto 39:d96aa62afc5b 2044
Kojto 39:d96aa62afc5b 2045 loop2 = 100;
Kojto 39:d96aa62afc5b 2046 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 2047 {
Kojto 39:d96aa62afc5b 2048 /* wait */
Kojto 39:d96aa62afc5b 2049 }
Kojto 39:d96aa62afc5b 2050 }
Kojto 39:d96aa62afc5b 2051 break;
Kojto 39:d96aa62afc5b 2052
Kojto 39:d96aa62afc5b 2053 default:
Kojto 39:d96aa62afc5b 2054 break;
Kojto 39:d96aa62afc5b 2055 }
Kojto 39:d96aa62afc5b 2056
Kojto 39:d96aa62afc5b 2057 /* Cautions !!!
Kojto 39:d96aa62afc5b 2058 * Depending on the external bus speed of CPU, you may need to wait for 450ns here.
Kojto 39:d96aa62afc5b 2059 * For details, please look at the data sheet. */
Kojto 39:d96aa62afc5b 2060 loop2 = 100;
Kojto 39:d96aa62afc5b 2061 while (loop2-- > 0)
Kojto 39:d96aa62afc5b 2062 {
Kojto 39:d96aa62afc5b 2063 /* wait */
Kojto 39:d96aa62afc5b 2064 }
Kojto 39:d96aa62afc5b 2065 }
Kojto 39:d96aa62afc5b 2066
Kojto 39:d96aa62afc5b 2067 /*******************************************************************************
Kojto 39:d96aa62afc5b 2068 * Function Name: usb0_host_write_c_fifo
Kojto 39:d96aa62afc5b 2069 * Description : Writes data in CFIFO.
Kojto 39:d96aa62afc5b 2070 * : Writes data by BYTE/WORD/LONG according to access size
Kojto 39:d96aa62afc5b 2071 * : to the pipe specified by the arguments.
Kojto 39:d96aa62afc5b 2072 * : Before executing this function, allocating CFIF0 in the specified pipe
Kojto 39:d96aa62afc5b 2073 * : should be completed.
Kojto 39:d96aa62afc5b 2074 * : Before executing this function, access size to the specified pipe
Kojto 39:d96aa62afc5b 2075 * : should be fixed and set in g_usb1_host_mbw[].
Kojto 39:d96aa62afc5b 2076 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2077 * : uint16_t count ; Data Size(Byte)
Kojto 39:d96aa62afc5b 2078 * Return Value : none
Kojto 39:d96aa62afc5b 2079 *******************************************************************************/
Kojto 39:d96aa62afc5b 2080 static void usb0_host_write_c_fifo (uint16_t pipe, uint16_t count)
Kojto 39:d96aa62afc5b 2081 {
Kojto 39:d96aa62afc5b 2082 uint16_t even;
Kojto 39:d96aa62afc5b 2083
Kojto 39:d96aa62afc5b 2084 if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
Kojto 39:d96aa62afc5b 2085 {
Kojto 39:d96aa62afc5b 2086 for (even = count; even; --even)
Kojto 39:d96aa62afc5b 2087 {
Kojto 39:d96aa62afc5b 2088 USB200.CFIFO.UINT8[HH] = *g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 2089 g_usb0_host_data_pointer[pipe] += 1;
Kojto 39:d96aa62afc5b 2090 }
Kojto 39:d96aa62afc5b 2091 }
Kojto 39:d96aa62afc5b 2092 else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2093 {
Kojto 39:d96aa62afc5b 2094 for (even = (uint16_t)(count / 2); even; --even)
Kojto 39:d96aa62afc5b 2095 {
Kojto 39:d96aa62afc5b 2096 USB200.CFIFO.UINT16[H] = *((uint16_t *)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 2097 g_usb0_host_data_pointer[pipe] += 2;
Kojto 39:d96aa62afc5b 2098 }
Kojto 39:d96aa62afc5b 2099 }
Kojto 39:d96aa62afc5b 2100 else
Kojto 39:d96aa62afc5b 2101 {
Kojto 39:d96aa62afc5b 2102 for (even = (uint16_t)(count / 4); even; --even)
Kojto 39:d96aa62afc5b 2103 {
Kojto 39:d96aa62afc5b 2104 USB200.CFIFO.UINT32 = *((uint32_t *)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 2105 g_usb0_host_data_pointer[pipe] += 4;
Kojto 39:d96aa62afc5b 2106 }
Kojto 39:d96aa62afc5b 2107 }
Kojto 39:d96aa62afc5b 2108 }
Kojto 39:d96aa62afc5b 2109
Kojto 39:d96aa62afc5b 2110 /*******************************************************************************
Kojto 39:d96aa62afc5b 2111 * Function Name: usb0_host_read_c_fifo
Kojto 39:d96aa62afc5b 2112 * Description : Reads data from CFIFO.
Kojto 39:d96aa62afc5b 2113 * : Reads data by BYTE/WORD/LONG according to access size
Kojto 39:d96aa62afc5b 2114 * : to the pipe specified by the arguments.
Kojto 39:d96aa62afc5b 2115 * : Before executing this function, allocating CFIF0 in the specified pipe
Kojto 39:d96aa62afc5b 2116 * : should be completed.
Kojto 39:d96aa62afc5b 2117 * : Before executing this function, access size to the specified pipe
Kojto 39:d96aa62afc5b 2118 * : should be fixed and set in g_usb0_host_mbw[].
Kojto 39:d96aa62afc5b 2119 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2120 * : uint16_t count ; Data Size(Byte)
Kojto 39:d96aa62afc5b 2121 * Return Value : none
Kojto 39:d96aa62afc5b 2122 *******************************************************************************/
Kojto 39:d96aa62afc5b 2123 static void usb0_host_read_c_fifo (uint16_t pipe, uint16_t count)
Kojto 39:d96aa62afc5b 2124 {
Kojto 39:d96aa62afc5b 2125 uint16_t even;
Kojto 39:d96aa62afc5b 2126
Kojto 39:d96aa62afc5b 2127 if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
Kojto 39:d96aa62afc5b 2128 {
Kojto 39:d96aa62afc5b 2129 for (even = count; even; --even)
Kojto 39:d96aa62afc5b 2130 {
Kojto 39:d96aa62afc5b 2131 *g_usb0_host_data_pointer[pipe] = USB200.CFIFO.UINT8[HH];
Kojto 39:d96aa62afc5b 2132 g_usb0_host_data_pointer[pipe] += 1;
Kojto 39:d96aa62afc5b 2133 }
Kojto 39:d96aa62afc5b 2134 }
Kojto 39:d96aa62afc5b 2135 else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2136 {
Kojto 39:d96aa62afc5b 2137 for (even = (uint16_t)((count + 1) / 2); even; --even)
Kojto 39:d96aa62afc5b 2138 {
Kojto 39:d96aa62afc5b 2139 *((uint16_t *)g_usb0_host_data_pointer[pipe]) = USB200.CFIFO.UINT16[H];
Kojto 39:d96aa62afc5b 2140 g_usb0_host_data_pointer[pipe] += 2;
Kojto 39:d96aa62afc5b 2141 }
Kojto 39:d96aa62afc5b 2142 }
Kojto 39:d96aa62afc5b 2143 else
Kojto 39:d96aa62afc5b 2144 {
Kojto 39:d96aa62afc5b 2145 for (even = (uint16_t)((count + 3) / 4); even; --even)
Kojto 39:d96aa62afc5b 2146 {
Kojto 39:d96aa62afc5b 2147 *((uint32_t *)g_usb0_host_data_pointer[pipe]) = USB200.CFIFO.UINT32;
Kojto 39:d96aa62afc5b 2148 g_usb0_host_data_pointer[pipe] += 4;
Kojto 39:d96aa62afc5b 2149 }
Kojto 39:d96aa62afc5b 2150 }
Kojto 39:d96aa62afc5b 2151 }
Kojto 39:d96aa62afc5b 2152
Kojto 39:d96aa62afc5b 2153 /*******************************************************************************
Kojto 39:d96aa62afc5b 2154 * Function Name: usb0_host_write_d0_fifo
Kojto 39:d96aa62afc5b 2155 * Description : Writes data in D0FIFO.
Kojto 39:d96aa62afc5b 2156 * : Writes data by BYTE/WORD/LONG according to access size
Kojto 39:d96aa62afc5b 2157 * : to the pipe specified by the arguments.
Kojto 39:d96aa62afc5b 2158 * : Before executing this function, allocating CFIF0 in the specified pipe
Kojto 39:d96aa62afc5b 2159 * : should be completed.
Kojto 39:d96aa62afc5b 2160 * : Before executing this function, access size to the specified pipe
Kojto 39:d96aa62afc5b 2161 * : should be fixed and set in g_usb0_host_mbw[].
Kojto 39:d96aa62afc5b 2162 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2163 * : uint16_t count ; Data Size(Byte)
Kojto 39:d96aa62afc5b 2164 * Return Value : none
Kojto 39:d96aa62afc5b 2165 *******************************************************************************/
Kojto 39:d96aa62afc5b 2166 static void usb0_host_write_d0_fifo (uint16_t pipe, uint16_t count)
Kojto 39:d96aa62afc5b 2167 {
Kojto 39:d96aa62afc5b 2168 uint16_t even;
Kojto 39:d96aa62afc5b 2169
Kojto 39:d96aa62afc5b 2170 if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
Kojto 39:d96aa62afc5b 2171 {
Kojto 39:d96aa62afc5b 2172 for (even = count; even; --even)
Kojto 39:d96aa62afc5b 2173 {
Kojto 39:d96aa62afc5b 2174 USB200.D0FIFO.UINT8[HH] = *g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 2175 g_usb0_host_data_pointer[pipe] += 1;
Kojto 39:d96aa62afc5b 2176 }
Kojto 39:d96aa62afc5b 2177 }
Kojto 39:d96aa62afc5b 2178 else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2179 {
Kojto 39:d96aa62afc5b 2180 for (even = (uint16_t)(count / 2); even; --even)
Kojto 39:d96aa62afc5b 2181 {
Kojto 39:d96aa62afc5b 2182 USB200.D0FIFO.UINT16[H] = *((uint16_t *)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 2183 g_usb0_host_data_pointer[pipe] += 2;
Kojto 39:d96aa62afc5b 2184 }
Kojto 39:d96aa62afc5b 2185 }
Kojto 39:d96aa62afc5b 2186 else
Kojto 39:d96aa62afc5b 2187 {
Kojto 39:d96aa62afc5b 2188 for (even = (uint16_t)(count / 4); even; --even)
Kojto 39:d96aa62afc5b 2189 {
Kojto 39:d96aa62afc5b 2190 USB200.D0FIFO.UINT32 = *((uint32_t *)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 2191 g_usb0_host_data_pointer[pipe] += 4;
Kojto 39:d96aa62afc5b 2192 }
Kojto 39:d96aa62afc5b 2193 }
Kojto 39:d96aa62afc5b 2194 }
Kojto 39:d96aa62afc5b 2195
Kojto 39:d96aa62afc5b 2196 /*******************************************************************************
Kojto 39:d96aa62afc5b 2197 * Function Name: usb0_host_read_d0_fifo
Kojto 39:d96aa62afc5b 2198 * Description : Reads data from D0FIFO.
Kojto 39:d96aa62afc5b 2199 * : Reads data by BYTE/WORD/LONG according to access size
Kojto 39:d96aa62afc5b 2200 * : to the pipe specified by the arguments.
Kojto 39:d96aa62afc5b 2201 * : Before executing this function, allocating DOFIF0 in the specified pipe
Kojto 39:d96aa62afc5b 2202 * : should be completed.
Kojto 39:d96aa62afc5b 2203 * : Before executing this function, access size to the specified pipe
Kojto 39:d96aa62afc5b 2204 * : should be fixed and set in g_usb0_host_mbw[].
Kojto 39:d96aa62afc5b 2205 * Arguments : uint16_t Pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2206 * : uint16_t count ; Data Size(Byte)
Kojto 39:d96aa62afc5b 2207 * Return Value : none
Kojto 39:d96aa62afc5b 2208 *******************************************************************************/
Kojto 39:d96aa62afc5b 2209 static void usb0_host_read_d0_fifo (uint16_t pipe, uint16_t count)
Kojto 39:d96aa62afc5b 2210 {
Kojto 39:d96aa62afc5b 2211 uint16_t even;
Kojto 39:d96aa62afc5b 2212
Kojto 39:d96aa62afc5b 2213 if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
Kojto 39:d96aa62afc5b 2214 {
Kojto 39:d96aa62afc5b 2215 for (even = count; even; --even)
Kojto 39:d96aa62afc5b 2216 {
Kojto 39:d96aa62afc5b 2217 *g_usb0_host_data_pointer[pipe] = USB200.D0FIFO.UINT8[HH];
Kojto 39:d96aa62afc5b 2218 g_usb0_host_data_pointer[pipe] += 1;
Kojto 39:d96aa62afc5b 2219 }
Kojto 39:d96aa62afc5b 2220 }
Kojto 39:d96aa62afc5b 2221 else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2222 {
Kojto 39:d96aa62afc5b 2223 for (even = (uint16_t)((count + 1) / 2); even; --even)
Kojto 39:d96aa62afc5b 2224 {
Kojto 39:d96aa62afc5b 2225 *((uint16_t *)g_usb0_host_data_pointer[pipe]) = USB200.D0FIFO.UINT16[H];
Kojto 39:d96aa62afc5b 2226 g_usb0_host_data_pointer[pipe] += 2;
Kojto 39:d96aa62afc5b 2227 }
Kojto 39:d96aa62afc5b 2228 }
Kojto 39:d96aa62afc5b 2229 else
Kojto 39:d96aa62afc5b 2230 {
Kojto 39:d96aa62afc5b 2231 for (even = (uint16_t)((count + 3) / 4); even; --even)
Kojto 39:d96aa62afc5b 2232 {
Kojto 39:d96aa62afc5b 2233 *((uint32_t *)g_usb0_host_data_pointer[pipe]) = USB200.D0FIFO.UINT32;
Kojto 39:d96aa62afc5b 2234 g_usb0_host_data_pointer[pipe] += 4;
Kojto 39:d96aa62afc5b 2235 }
Kojto 39:d96aa62afc5b 2236 }
Kojto 39:d96aa62afc5b 2237 }
Kojto 39:d96aa62afc5b 2238
Kojto 39:d96aa62afc5b 2239 /*******************************************************************************
Kojto 39:d96aa62afc5b 2240 * Function Name: usb0_host_write_d1_fifo
Kojto 39:d96aa62afc5b 2241 * Description : Writes data in D1FIFO.
Kojto 39:d96aa62afc5b 2242 * : Writes data by BYTE/WORD/LONG according to access size
Kojto 39:d96aa62afc5b 2243 * : to the pipe specified by the arguments.
Kojto 39:d96aa62afc5b 2244 * : Before executing this function, allocating D1FIF0 in the specified pipe
Kojto 39:d96aa62afc5b 2245 * : should be completed.
Kojto 39:d96aa62afc5b 2246 * : Before executing this function, access size to the specified pipe
Kojto 39:d96aa62afc5b 2247 * : should be fixed and set in g_usb1_host_mbw[].
Kojto 39:d96aa62afc5b 2248 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2249 * : uint16_t count ; Data Size(Byte)
Kojto 39:d96aa62afc5b 2250 * Return Value : none
Kojto 39:d96aa62afc5b 2251 *******************************************************************************/
Kojto 39:d96aa62afc5b 2252 static void usb0_host_write_d1_fifo (uint16_t pipe, uint16_t count)
Kojto 39:d96aa62afc5b 2253 {
Kojto 39:d96aa62afc5b 2254 uint16_t even;
Kojto 39:d96aa62afc5b 2255
Kojto 39:d96aa62afc5b 2256 if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
Kojto 39:d96aa62afc5b 2257 {
Kojto 39:d96aa62afc5b 2258 for (even = count; even; --even)
Kojto 39:d96aa62afc5b 2259 {
Kojto 39:d96aa62afc5b 2260 USB200.D1FIFO.UINT8[HH] = *g_usb0_host_data_pointer[pipe];
Kojto 39:d96aa62afc5b 2261 g_usb0_host_data_pointer[pipe] += 1;
Kojto 39:d96aa62afc5b 2262 }
Kojto 39:d96aa62afc5b 2263 }
Kojto 39:d96aa62afc5b 2264 else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2265 {
Kojto 39:d96aa62afc5b 2266 for (even = (uint16_t)(count / 2); even; --even)
Kojto 39:d96aa62afc5b 2267 {
Kojto 39:d96aa62afc5b 2268 USB200.D1FIFO.UINT16[H] = *((uint16_t *)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 2269 g_usb0_host_data_pointer[pipe] += 2;
Kojto 39:d96aa62afc5b 2270 }
Kojto 39:d96aa62afc5b 2271 }
Kojto 39:d96aa62afc5b 2272 else
Kojto 39:d96aa62afc5b 2273 {
Kojto 39:d96aa62afc5b 2274 for (even = (uint16_t)(count / 4); even; --even)
Kojto 39:d96aa62afc5b 2275 {
Kojto 39:d96aa62afc5b 2276 USB200.D1FIFO.UINT32 = *((uint32_t *)g_usb0_host_data_pointer[pipe]);
Kojto 39:d96aa62afc5b 2277 g_usb0_host_data_pointer[pipe] += 4;
Kojto 39:d96aa62afc5b 2278 }
Kojto 39:d96aa62afc5b 2279 }
Kojto 39:d96aa62afc5b 2280 }
Kojto 39:d96aa62afc5b 2281
Kojto 39:d96aa62afc5b 2282 /*******************************************************************************
Kojto 39:d96aa62afc5b 2283 * Function Name: usb0_host_read_d1_fifo
Kojto 39:d96aa62afc5b 2284 * Description : Reads data from D1FIFO.
Kojto 39:d96aa62afc5b 2285 * : Reads data by BYTE/WORD/LONG according to access size
Kojto 39:d96aa62afc5b 2286 * : to the pipe specified by the arguments.
Kojto 39:d96aa62afc5b 2287 * : Before executing this function, allocating D1FIF0 in the specified pipe
Kojto 39:d96aa62afc5b 2288 * : should be completed.
Kojto 39:d96aa62afc5b 2289 * : Before executing this function, access size to the specified pipe
Kojto 39:d96aa62afc5b 2290 * : should be fixed and set in g_usb1_host_mbw[].
Kojto 39:d96aa62afc5b 2291 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2292 * : uint16_t count ; Data Size(Byte)
Kojto 39:d96aa62afc5b 2293 * Return Value : none
Kojto 39:d96aa62afc5b 2294 *******************************************************************************/
Kojto 39:d96aa62afc5b 2295 static void usb0_host_read_d1_fifo (uint16_t pipe, uint16_t count)
Kojto 39:d96aa62afc5b 2296 {
Kojto 39:d96aa62afc5b 2297 uint16_t even;
Kojto 39:d96aa62afc5b 2298
Kojto 39:d96aa62afc5b 2299 if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_8)
Kojto 39:d96aa62afc5b 2300 {
Kojto 39:d96aa62afc5b 2301 for (even = count; even; --even)
Kojto 39:d96aa62afc5b 2302 {
Kojto 39:d96aa62afc5b 2303 *g_usb0_host_data_pointer[pipe] = USB200.D1FIFO.UINT8[HH];
Kojto 39:d96aa62afc5b 2304 g_usb0_host_data_pointer[pipe] += 1;
Kojto 39:d96aa62afc5b 2305 }
Kojto 39:d96aa62afc5b 2306 }
Kojto 39:d96aa62afc5b 2307 else if (g_usb0_host_mbw[pipe] == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2308 {
Kojto 39:d96aa62afc5b 2309 for (even = (uint16_t)((count + 1) / 2); even; --even)
Kojto 39:d96aa62afc5b 2310 {
Kojto 39:d96aa62afc5b 2311 *((uint16_t *)g_usb0_host_data_pointer[pipe]) = USB200.D1FIFO.UINT16[H];
Kojto 39:d96aa62afc5b 2312 g_usb0_host_data_pointer[pipe] += 2;
Kojto 39:d96aa62afc5b 2313 }
Kojto 39:d96aa62afc5b 2314 }
Kojto 39:d96aa62afc5b 2315 else
Kojto 39:d96aa62afc5b 2316 {
Kojto 39:d96aa62afc5b 2317 for (even = (uint16_t)((count + 3) / 4); even; --even)
Kojto 39:d96aa62afc5b 2318 {
Kojto 39:d96aa62afc5b 2319 *((uint32_t *)g_usb0_host_data_pointer[pipe]) = USB200.D1FIFO.UINT32;
Kojto 39:d96aa62afc5b 2320 g_usb0_host_data_pointer[pipe] += 4;
Kojto 39:d96aa62afc5b 2321 }
Kojto 39:d96aa62afc5b 2322 }
Kojto 39:d96aa62afc5b 2323 }
Kojto 39:d96aa62afc5b 2324
Kojto 39:d96aa62afc5b 2325 /*******************************************************************************
Kojto 39:d96aa62afc5b 2326 * Function Name: usb0_host_com_get_dmasize
Kojto 39:d96aa62afc5b 2327 * Description : Calculates access width of DMA transfer by the argument to
Kojto 39:d96aa62afc5b 2328 return as the Return Value.
Kojto 39:d96aa62afc5b 2329 * Arguments : uint32_t trncount : transfer byte
Kojto 39:d96aa62afc5b 2330 * : uint32_t dtptr : transfer data pointer
Kojto 39:d96aa62afc5b 2331 * Return Value : DMA transfer size : 0 8bit
Kojto 39:d96aa62afc5b 2332 * : : 1 16bit
Kojto 39:d96aa62afc5b 2333 * : : 2 32bit
Kojto 39:d96aa62afc5b 2334 *******************************************************************************/
Kojto 39:d96aa62afc5b 2335 static uint32_t usb0_host_com_get_dmasize (uint32_t trncount, uint32_t dtptr)
Kojto 39:d96aa62afc5b 2336 {
Kojto 39:d96aa62afc5b 2337 uint32_t size;
Kojto 39:d96aa62afc5b 2338
Kojto 39:d96aa62afc5b 2339 if (((trncount & 0x0001) != 0) || ((dtptr & 0x00000001) != 0))
Kojto 39:d96aa62afc5b 2340 {
Kojto 39:d96aa62afc5b 2341 /* When transfer byte count is odd */
Kojto 39:d96aa62afc5b 2342 /* or transfer data area is 8-bit alignment */
Kojto 39:d96aa62afc5b 2343 size = 0; /* 8bit */
Kojto 39:d96aa62afc5b 2344 }
Kojto 39:d96aa62afc5b 2345 else if (((trncount & 0x0003) != 0) || ((dtptr & 0x00000003) != 0))
Kojto 39:d96aa62afc5b 2346 {
Kojto 39:d96aa62afc5b 2347 /* When the transfer byte count is multiples of 2 */
Kojto 39:d96aa62afc5b 2348 /* or the transfer data area is 16-bit alignment */
Kojto 39:d96aa62afc5b 2349 size = 1; /* 16bit */
Kojto 39:d96aa62afc5b 2350 }
Kojto 39:d96aa62afc5b 2351 else
Kojto 39:d96aa62afc5b 2352 {
Kojto 39:d96aa62afc5b 2353 /* When the transfer byte count is multiples of 4 */
Kojto 39:d96aa62afc5b 2354 /* or the transfer data area is 32-bit alignment */
Kojto 39:d96aa62afc5b 2355 size = 2; /* 32bit */
Kojto 39:d96aa62afc5b 2356 }
Kojto 39:d96aa62afc5b 2357
Kojto 39:d96aa62afc5b 2358 return size;
Kojto 39:d96aa62afc5b 2359 }
Kojto 39:d96aa62afc5b 2360
Kojto 39:d96aa62afc5b 2361 /*******************************************************************************
Kojto 39:d96aa62afc5b 2362 * Function Name: usb0_host_get_mbw
Kojto 39:d96aa62afc5b 2363 * Description : Calculates access width of DMA to return the value set in MBW.
Kojto 39:d96aa62afc5b 2364 * Arguments : uint32_t trncount : transfer byte
Kojto 39:d96aa62afc5b 2365 * : uint32_t dtptr : transfer data pointer
Kojto 39:d96aa62afc5b 2366 * Return Value : FIFO transfer size : USB_HOST_BITMBW_8 8bit
Kojto 39:d96aa62afc5b 2367 * : : USB_HOST_BITMBW_16 16bit
Kojto 39:d96aa62afc5b 2368 * : : USB_HOST_BITMBW_32 32bit
Kojto 39:d96aa62afc5b 2369 *******************************************************************************/
Kojto 39:d96aa62afc5b 2370 uint16_t usb0_host_get_mbw (uint32_t trncount, uint32_t dtptr)
Kojto 39:d96aa62afc5b 2371 {
Kojto 39:d96aa62afc5b 2372 uint32_t size;
Kojto 39:d96aa62afc5b 2373 uint16_t mbw;
Kojto 39:d96aa62afc5b 2374
Kojto 39:d96aa62afc5b 2375 size = usb0_host_com_get_dmasize(trncount, dtptr);
Kojto 39:d96aa62afc5b 2376
Kojto 39:d96aa62afc5b 2377 if (size == 0)
Kojto 39:d96aa62afc5b 2378 {
Kojto 39:d96aa62afc5b 2379 /* 8bit */
Kojto 39:d96aa62afc5b 2380 mbw = USB_HOST_BITMBW_8;
Kojto 39:d96aa62afc5b 2381 }
Kojto 39:d96aa62afc5b 2382 else if (size == 1)
Kojto 39:d96aa62afc5b 2383 {
Kojto 39:d96aa62afc5b 2384 /* 16bit */
Kojto 39:d96aa62afc5b 2385 mbw = USB_HOST_BITMBW_16;
Kojto 39:d96aa62afc5b 2386 }
Kojto 39:d96aa62afc5b 2387 else
Kojto 39:d96aa62afc5b 2388 {
Kojto 39:d96aa62afc5b 2389 /* 32bit */
Kojto 39:d96aa62afc5b 2390 mbw = USB_HOST_BITMBW_32;
Kojto 39:d96aa62afc5b 2391 }
Kojto 39:d96aa62afc5b 2392
Kojto 39:d96aa62afc5b 2393 return mbw;
Kojto 39:d96aa62afc5b 2394 }
Kojto 39:d96aa62afc5b 2395
Kojto 39:d96aa62afc5b 2396 /*******************************************************************************
Kojto 39:d96aa62afc5b 2397 * Function Name: usb0_host_set_transaction_counter
Kojto 39:d96aa62afc5b 2398 * Description : Sets transaction counter by the argument(PIPEnTRN).
Kojto 39:d96aa62afc5b 2399 * : Clears transaction before setting to enable transaction counter setting.
Kojto 39:d96aa62afc5b 2400 * Arguments : uint16_t pipe ; Pipe number
Kojto 39:d96aa62afc5b 2401 * : uint32_t bsize : Data transfer size
Kojto 39:d96aa62afc5b 2402 * Return Value : none
Kojto 39:d96aa62afc5b 2403 *******************************************************************************/
Kojto 39:d96aa62afc5b 2404 static void usb0_host_set_transaction_counter (uint16_t pipe, uint32_t bsize)
Kojto 39:d96aa62afc5b 2405 {
Kojto 39:d96aa62afc5b 2406 uint16_t mxps;
Kojto 39:d96aa62afc5b 2407 uint16_t cnt;
Kojto 39:d96aa62afc5b 2408
Kojto 39:d96aa62afc5b 2409 if (bsize == 0)
Kojto 39:d96aa62afc5b 2410 {
Kojto 39:d96aa62afc5b 2411 return;
Kojto 39:d96aa62afc5b 2412 }
Kojto 39:d96aa62afc5b 2413
Kojto 39:d96aa62afc5b 2414 mxps = usb0_host_get_mxps(pipe); /* Max Packet Size */
Kojto 39:d96aa62afc5b 2415
Kojto 39:d96aa62afc5b 2416 if ((bsize % mxps) == 0)
Kojto 39:d96aa62afc5b 2417 {
Kojto 39:d96aa62afc5b 2418 cnt = (uint16_t)(bsize / mxps);
Kojto 39:d96aa62afc5b 2419 }
Kojto 39:d96aa62afc5b 2420 else
Kojto 39:d96aa62afc5b 2421 {
Kojto 39:d96aa62afc5b 2422 cnt = (uint16_t)((bsize / mxps) + 1);
Kojto 39:d96aa62afc5b 2423 }
Kojto 39:d96aa62afc5b 2424
Kojto 39:d96aa62afc5b 2425 switch (pipe)
Kojto 39:d96aa62afc5b 2426 {
Kojto 39:d96aa62afc5b 2427 case USB_HOST_PIPE1:
Kojto 39:d96aa62afc5b 2428 RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
Kojto 39:d96aa62afc5b 2429 1,
Kojto 39:d96aa62afc5b 2430 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2431 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2432 USB200.PIPE1TRN = cnt;
Kojto 39:d96aa62afc5b 2433 RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
Kojto 39:d96aa62afc5b 2434 1,
Kojto 39:d96aa62afc5b 2435 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2436 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2437 break;
Kojto 39:d96aa62afc5b 2438
Kojto 39:d96aa62afc5b 2439 case USB_HOST_PIPE2:
Kojto 39:d96aa62afc5b 2440 RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
Kojto 39:d96aa62afc5b 2441 1,
Kojto 39:d96aa62afc5b 2442 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2443 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2444 USB200.PIPE2TRN = cnt;
Kojto 39:d96aa62afc5b 2445 RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
Kojto 39:d96aa62afc5b 2446 1,
Kojto 39:d96aa62afc5b 2447 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2448 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2449 break;
Kojto 39:d96aa62afc5b 2450
Kojto 39:d96aa62afc5b 2451 case USB_HOST_PIPE3:
Kojto 39:d96aa62afc5b 2452 RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
Kojto 39:d96aa62afc5b 2453 1,
Kojto 39:d96aa62afc5b 2454 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2455 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2456 USB200.PIPE3TRN = cnt;
Kojto 39:d96aa62afc5b 2457 RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
Kojto 39:d96aa62afc5b 2458 1,
Kojto 39:d96aa62afc5b 2459 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2460 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2461 break;
Kojto 39:d96aa62afc5b 2462
Kojto 39:d96aa62afc5b 2463 case USB_HOST_PIPE4:
Kojto 39:d96aa62afc5b 2464 RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
Kojto 39:d96aa62afc5b 2465 1,
Kojto 39:d96aa62afc5b 2466 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2467 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2468 USB200.PIPE4TRN = cnt;
Kojto 39:d96aa62afc5b 2469 RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
Kojto 39:d96aa62afc5b 2470 1,
Kojto 39:d96aa62afc5b 2471 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2472 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2473 break;
Kojto 39:d96aa62afc5b 2474
Kojto 39:d96aa62afc5b 2475 case USB_HOST_PIPE5:
Kojto 39:d96aa62afc5b 2476 RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
Kojto 39:d96aa62afc5b 2477 1,
Kojto 39:d96aa62afc5b 2478 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2479 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2480 USB200.PIPE5TRN = cnt;
Kojto 39:d96aa62afc5b 2481 RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
Kojto 39:d96aa62afc5b 2482 1,
Kojto 39:d96aa62afc5b 2483 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2484 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2485 break;
Kojto 39:d96aa62afc5b 2486
Kojto 39:d96aa62afc5b 2487 case USB_HOST_PIPE9:
Kojto 39:d96aa62afc5b 2488 RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
Kojto 39:d96aa62afc5b 2489 1,
Kojto 39:d96aa62afc5b 2490 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2491 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2492 USB200.PIPE9TRN = cnt;
Kojto 39:d96aa62afc5b 2493 RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
Kojto 39:d96aa62afc5b 2494 1,
Kojto 39:d96aa62afc5b 2495 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2496 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2497 break;
Kojto 39:d96aa62afc5b 2498
Kojto 39:d96aa62afc5b 2499 default:
Kojto 39:d96aa62afc5b 2500 break;
Kojto 39:d96aa62afc5b 2501 }
Kojto 39:d96aa62afc5b 2502 }
Kojto 39:d96aa62afc5b 2503
Kojto 39:d96aa62afc5b 2504 /*******************************************************************************
Kojto 39:d96aa62afc5b 2505 * Function Name: usb0_host_clear_transaction_counter
Kojto 39:d96aa62afc5b 2506 * Description : Clears the transaction counter by the argument.
Kojto 39:d96aa62afc5b 2507 * : After executing this function, the transaction counter is invalid.
Kojto 39:d96aa62afc5b 2508 * Arguments : uint16_t pipe ; Pipe number
Kojto 39:d96aa62afc5b 2509 * Return Value : none
Kojto 39:d96aa62afc5b 2510 *******************************************************************************/
Kojto 39:d96aa62afc5b 2511 void usb0_host_clear_transaction_counter (uint16_t pipe)
Kojto 39:d96aa62afc5b 2512 {
Kojto 39:d96aa62afc5b 2513 switch (pipe)
Kojto 39:d96aa62afc5b 2514 {
Kojto 39:d96aa62afc5b 2515 case USB_HOST_PIPE1:
Kojto 39:d96aa62afc5b 2516 RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
Kojto 39:d96aa62afc5b 2517 0,
Kojto 39:d96aa62afc5b 2518 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2519 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2520 RZA_IO_RegWrite_16(&USB200.PIPE1TRE,
Kojto 39:d96aa62afc5b 2521 1,
Kojto 39:d96aa62afc5b 2522 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2523 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2524 break;
Kojto 39:d96aa62afc5b 2525
Kojto 39:d96aa62afc5b 2526 case USB_HOST_PIPE2:
Kojto 39:d96aa62afc5b 2527 RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
Kojto 39:d96aa62afc5b 2528 0,
Kojto 39:d96aa62afc5b 2529 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2530 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2531 RZA_IO_RegWrite_16(&USB200.PIPE2TRE,
Kojto 39:d96aa62afc5b 2532 1,
Kojto 39:d96aa62afc5b 2533 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2534 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2535 break;
Kojto 39:d96aa62afc5b 2536
Kojto 39:d96aa62afc5b 2537 case USB_HOST_PIPE3:
Kojto 39:d96aa62afc5b 2538 RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
Kojto 39:d96aa62afc5b 2539 0,
Kojto 39:d96aa62afc5b 2540 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2541 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2542 RZA_IO_RegWrite_16(&USB200.PIPE3TRE,
Kojto 39:d96aa62afc5b 2543 1,
Kojto 39:d96aa62afc5b 2544 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2545 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2546 break;
Kojto 39:d96aa62afc5b 2547
Kojto 39:d96aa62afc5b 2548 case USB_HOST_PIPE4:
Kojto 39:d96aa62afc5b 2549 RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
Kojto 39:d96aa62afc5b 2550 0,
Kojto 39:d96aa62afc5b 2551 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2552 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2553 RZA_IO_RegWrite_16(&USB200.PIPE4TRE,
Kojto 39:d96aa62afc5b 2554 1,
Kojto 39:d96aa62afc5b 2555 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2556 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2557 break;
Kojto 39:d96aa62afc5b 2558
Kojto 39:d96aa62afc5b 2559 case USB_HOST_PIPE5:
Kojto 39:d96aa62afc5b 2560 RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
Kojto 39:d96aa62afc5b 2561 0,
Kojto 39:d96aa62afc5b 2562 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2563 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2564 RZA_IO_RegWrite_16(&USB200.PIPE5TRE,
Kojto 39:d96aa62afc5b 2565 1,
Kojto 39:d96aa62afc5b 2566 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2567 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2568 break;
Kojto 39:d96aa62afc5b 2569
Kojto 39:d96aa62afc5b 2570 case USB_HOST_PIPE9:
Kojto 39:d96aa62afc5b 2571 RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
Kojto 39:d96aa62afc5b 2572 0,
Kojto 39:d96aa62afc5b 2573 USB_PIPEnTRE_TRENB_SHIFT,
Kojto 39:d96aa62afc5b 2574 USB_PIPEnTRE_TRENB);
Kojto 39:d96aa62afc5b 2575 RZA_IO_RegWrite_16(&USB200.PIPE9TRE,
Kojto 39:d96aa62afc5b 2576 1,
Kojto 39:d96aa62afc5b 2577 USB_PIPEnTRE_TRCLR_SHIFT,
Kojto 39:d96aa62afc5b 2578 USB_PIPEnTRE_TRCLR);
Kojto 39:d96aa62afc5b 2579 break;
Kojto 39:d96aa62afc5b 2580
Kojto 39:d96aa62afc5b 2581 default:
Kojto 39:d96aa62afc5b 2582 break;
Kojto 39:d96aa62afc5b 2583 }
Kojto 39:d96aa62afc5b 2584 }
Kojto 39:d96aa62afc5b 2585
Kojto 39:d96aa62afc5b 2586 /*******************************************************************************
Kojto 39:d96aa62afc5b 2587 * Function Name: usb0_host_stop_transfer
Kojto 39:d96aa62afc5b 2588 * Description : Stops the USB transfer in the pipe specified by the argument.
Kojto 39:d96aa62afc5b 2589 * : After stopping the USB transfer, clears the buffer allocated in
Kojto 39:d96aa62afc5b 2590 * : the pipe.
Kojto 39:d96aa62afc5b 2591 * : After executing this function, allocation in FIF0 becomes USB_HOST_PIPE0;
Kojto 39:d96aa62afc5b 2592 * : invalid. After executing this function, BRDY/NRDY/BEMP interrupt
Kojto 39:d96aa62afc5b 2593 * : in the corresponding pipe becomes invalid. Sequence bit is also
Kojto 39:d96aa62afc5b 2594 * : cleared.
Kojto 39:d96aa62afc5b 2595 * Arguments : uint16_t pipe ; Pipe Number
Kojto 39:d96aa62afc5b 2596 * Return Value : none
Kojto 39:d96aa62afc5b 2597 *******************************************************************************/
Kojto 39:d96aa62afc5b 2598 void usb0_host_stop_transfer (uint16_t pipe)
Kojto 39:d96aa62afc5b 2599 {
Kojto 39:d96aa62afc5b 2600 uint16_t usefifo;
Kojto 39:d96aa62afc5b 2601 uint32_t remain;
Kojto 39:d96aa62afc5b 2602
Kojto 39:d96aa62afc5b 2603 usb0_host_set_pid_nak(pipe);
Kojto 39:d96aa62afc5b 2604
Kojto 39:d96aa62afc5b 2605 usefifo = (uint16_t)(g_usb0_host_PipeTbl[pipe] & USB_HOST_FIFO_USE);
Kojto 39:d96aa62afc5b 2606
Kojto 39:d96aa62afc5b 2607 switch (usefifo)
Kojto 39:d96aa62afc5b 2608 {
Kojto 39:d96aa62afc5b 2609 case USB_HOST_D0FIFO_USE:
Kojto 39:d96aa62afc5b 2610 usb0_host_clear_transaction_counter(pipe);
Kojto 39:d96aa62afc5b 2611 USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 2612 break;
Kojto 39:d96aa62afc5b 2613
Kojto 39:d96aa62afc5b 2614 case USB_HOST_D1FIFO_USE:
Kojto 39:d96aa62afc5b 2615 usb0_host_clear_transaction_counter(pipe);
Kojto 39:d96aa62afc5b 2616 USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 2617 break;
Kojto 39:d96aa62afc5b 2618
Kojto 39:d96aa62afc5b 2619 case USB_HOST_D0FIFO_DMA:
Kojto 39:d96aa62afc5b 2620 remain = Userdef_USB_usb0_host_stop_dma0();
Kojto 39:d96aa62afc5b 2621 usb0_host_dma_stop_d0(pipe, remain);
Kojto 39:d96aa62afc5b 2622 usb0_host_clear_transaction_counter(pipe);
Kojto 39:d96aa62afc5b 2623 USB200.D0FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 2624 break;
Kojto 39:d96aa62afc5b 2625
Kojto 39:d96aa62afc5b 2626 case USB_HOST_D1FIFO_DMA:
Kojto 39:d96aa62afc5b 2627 remain = Userdef_USB_usb0_host_stop_dma1();
Kojto 39:d96aa62afc5b 2628 usb0_host_dma_stop_d1(pipe, remain);
Kojto 39:d96aa62afc5b 2629 usb0_host_clear_transaction_counter(pipe);
Kojto 39:d96aa62afc5b 2630 USB200.D1FIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 2631 break;
Kojto 39:d96aa62afc5b 2632
Kojto 39:d96aa62afc5b 2633 default:
Kojto 39:d96aa62afc5b 2634 usb0_host_clear_transaction_counter(pipe);
Kojto 39:d96aa62afc5b 2635 USB200.CFIFOCTR = USB_HOST_BITBCLR; /* Buffer Clear */
Kojto 39:d96aa62afc5b 2636 break;
Kojto 39:d96aa62afc5b 2637 }
Kojto 39:d96aa62afc5b 2638
Kojto 39:d96aa62afc5b 2639 /* Interrupt of pipe set is disabled */
Kojto 39:d96aa62afc5b 2640 usb0_host_disable_brdy_int(pipe);
Kojto 39:d96aa62afc5b 2641 usb0_host_disable_nrdy_int(pipe);
Kojto 39:d96aa62afc5b 2642 usb0_host_disable_bemp_int(pipe);
Kojto 39:d96aa62afc5b 2643
Kojto 39:d96aa62afc5b 2644 #if(1) /* ohci_wrapp */
Kojto 39:d96aa62afc5b 2645 #else
Kojto 39:d96aa62afc5b 2646 usb0_host_aclrm(pipe);
Kojto 39:d96aa62afc5b 2647 #endif
Kojto 39:d96aa62afc5b 2648 usb0_host_set_csclr(pipe);
Kojto 39:d96aa62afc5b 2649 }
Kojto 39:d96aa62afc5b 2650
Kojto 39:d96aa62afc5b 2651 /*******************************************************************************
Kojto 39:d96aa62afc5b 2652 * Function Name: usb0_host_set_dfacc_d0
Kojto 39:d96aa62afc5b 2653 * Description : Sets the DFACC setting value in D0FIFO using the transfer size.
Kojto 39:d96aa62afc5b 2654 * Arguments : uint16_t mbw ; MBW
Kojto 39:d96aa62afc5b 2655 * : uint16_t count ; data count
Kojto 39:d96aa62afc5b 2656 * Return Value : DFACC Access mode
Kojto 39:d96aa62afc5b 2657 *******************************************************************************/
Kojto 39:d96aa62afc5b 2658 static uint16_t usb0_host_set_dfacc_d0 (uint16_t mbw, uint32_t count)
Kojto 39:d96aa62afc5b 2659 {
Kojto 39:d96aa62afc5b 2660 uint16_t dfacc = 0;
Kojto 39:d96aa62afc5b 2661
Kojto 39:d96aa62afc5b 2662 #ifndef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 2663 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2664 0,
Kojto 39:d96aa62afc5b 2665 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2666 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2667 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2668 0,
Kojto 39:d96aa62afc5b 2669 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2670 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2671 dfacc = 0;
Kojto 39:d96aa62afc5b 2672 #else
Kojto 39:d96aa62afc5b 2673 if (mbw == USB_HOST_BITMBW_32)
Kojto 39:d96aa62afc5b 2674 {
Kojto 39:d96aa62afc5b 2675 if ((count % 32) == 0)
Kojto 39:d96aa62afc5b 2676 {
Kojto 39:d96aa62afc5b 2677 /* 32byte transfer */
Kojto 39:d96aa62afc5b 2678 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2679 2,
Kojto 39:d96aa62afc5b 2680 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2681 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2682 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2683 0,
Kojto 39:d96aa62afc5b 2684 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2685 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2686 dfacc = 2;
Kojto 39:d96aa62afc5b 2687 }
Kojto 39:d96aa62afc5b 2688 else if ((count % 16) == 0)
Kojto 39:d96aa62afc5b 2689 {
Kojto 39:d96aa62afc5b 2690 /* 16byte transfer */
Kojto 39:d96aa62afc5b 2691 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2692 1,
Kojto 39:d96aa62afc5b 2693 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2694 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2695 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2696 0,
Kojto 39:d96aa62afc5b 2697 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2698 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2699 dfacc = 1;
Kojto 39:d96aa62afc5b 2700 }
Kojto 39:d96aa62afc5b 2701 else
Kojto 39:d96aa62afc5b 2702 {
Kojto 39:d96aa62afc5b 2703 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2704 0,
Kojto 39:d96aa62afc5b 2705 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2706 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2707 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2708 0,
Kojto 39:d96aa62afc5b 2709 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2710 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2711 dfacc = 0;
Kojto 39:d96aa62afc5b 2712 }
Kojto 39:d96aa62afc5b 2713 }
Kojto 39:d96aa62afc5b 2714 else if (mbw == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2715 {
Kojto 39:d96aa62afc5b 2716 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2717 0,
Kojto 39:d96aa62afc5b 2718 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2719 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2720 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2721 0,
Kojto 39:d96aa62afc5b 2722 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2723 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2724 dfacc = 0;
Kojto 39:d96aa62afc5b 2725 }
Kojto 39:d96aa62afc5b 2726 else
Kojto 39:d96aa62afc5b 2727 {
Kojto 39:d96aa62afc5b 2728 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2729 0,
Kojto 39:d96aa62afc5b 2730 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2731 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2732 RZA_IO_RegWrite_16(&USB200.D0FBCFG,
Kojto 39:d96aa62afc5b 2733 0,
Kojto 39:d96aa62afc5b 2734 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2735 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2736 dfacc = 0;
Kojto 39:d96aa62afc5b 2737 }
Kojto 39:d96aa62afc5b 2738 #endif
Kojto 39:d96aa62afc5b 2739
Kojto 39:d96aa62afc5b 2740 return dfacc;
Kojto 39:d96aa62afc5b 2741 }
Kojto 39:d96aa62afc5b 2742
Kojto 39:d96aa62afc5b 2743 /*******************************************************************************
Kojto 39:d96aa62afc5b 2744 * Function Name: usb0_host_set_dfacc_d1
Kojto 39:d96aa62afc5b 2745 * Description : Sets the DFACC setting value in D1FIFO using the transfer size.
Kojto 39:d96aa62afc5b 2746 * Arguments : uint16_t mbw ; MBW
Kojto 39:d96aa62afc5b 2747 * : uint16_t count ; data count
Kojto 39:d96aa62afc5b 2748 * Return Value : DFACC Access mode
Kojto 39:d96aa62afc5b 2749 *******************************************************************************/
Kojto 39:d96aa62afc5b 2750 static uint16_t usb0_host_set_dfacc_d1 (uint16_t mbw, uint32_t count)
Kojto 39:d96aa62afc5b 2751 {
Kojto 39:d96aa62afc5b 2752 uint16_t dfacc = 0;
Kojto 39:d96aa62afc5b 2753
Kojto 39:d96aa62afc5b 2754 #ifndef __USB_HOST_DF_ACC_ENABLE__
Kojto 39:d96aa62afc5b 2755 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2756 0,
Kojto 39:d96aa62afc5b 2757 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2758 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2759 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2760 0,
Kojto 39:d96aa62afc5b 2761 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2762 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2763 dfacc = 0;
Kojto 39:d96aa62afc5b 2764 #else
Kojto 39:d96aa62afc5b 2765 if (mbw == USB_HOST_BITMBW_32)
Kojto 39:d96aa62afc5b 2766 {
Kojto 39:d96aa62afc5b 2767 if ((count % 32) == 0)
Kojto 39:d96aa62afc5b 2768 {
Kojto 39:d96aa62afc5b 2769 /* 32byte transfer */
Kojto 39:d96aa62afc5b 2770 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2771 2,
Kojto 39:d96aa62afc5b 2772 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2773 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2774 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2775 0,
Kojto 39:d96aa62afc5b 2776 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2777 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2778 dfacc = 2;
Kojto 39:d96aa62afc5b 2779 }
Kojto 39:d96aa62afc5b 2780 else if ((count % 16) == 0)
Kojto 39:d96aa62afc5b 2781 {
Kojto 39:d96aa62afc5b 2782 /* 16byte transfer */
Kojto 39:d96aa62afc5b 2783 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2784 1,
Kojto 39:d96aa62afc5b 2785 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2786 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2787 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2788 0,
Kojto 39:d96aa62afc5b 2789 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2790 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2791 dfacc = 1;
Kojto 39:d96aa62afc5b 2792 }
Kojto 39:d96aa62afc5b 2793 else
Kojto 39:d96aa62afc5b 2794 {
Kojto 39:d96aa62afc5b 2795 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2796 0,
Kojto 39:d96aa62afc5b 2797 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2798 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2799 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2800 0,
Kojto 39:d96aa62afc5b 2801 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2802 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2803 dfacc = 0;
Kojto 39:d96aa62afc5b 2804 }
Kojto 39:d96aa62afc5b 2805 }
Kojto 39:d96aa62afc5b 2806 else if (mbw == USB_HOST_BITMBW_16)
Kojto 39:d96aa62afc5b 2807 {
Kojto 39:d96aa62afc5b 2808 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2809 0,
Kojto 39:d96aa62afc5b 2810 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2811 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2812 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2813 0,
Kojto 39:d96aa62afc5b 2814 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2815 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2816 dfacc = 0;
Kojto 39:d96aa62afc5b 2817 }
Kojto 39:d96aa62afc5b 2818 else
Kojto 39:d96aa62afc5b 2819 {
Kojto 39:d96aa62afc5b 2820 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2821 0,
Kojto 39:d96aa62afc5b 2822 USB_DnFBCFG_DFACC_SHIFT,
Kojto 39:d96aa62afc5b 2823 USB_DnFBCFG_DFACC);
Kojto 39:d96aa62afc5b 2824 RZA_IO_RegWrite_16(&USB200.D1FBCFG,
Kojto 39:d96aa62afc5b 2825 0,
Kojto 39:d96aa62afc5b 2826 USB_DnFBCFG_TENDE_SHIFT,
Kojto 39:d96aa62afc5b 2827 USB_DnFBCFG_TENDE);
Kojto 39:d96aa62afc5b 2828 dfacc = 0;
Kojto 39:d96aa62afc5b 2829 }
Kojto 39:d96aa62afc5b 2830 #endif
Kojto 39:d96aa62afc5b 2831
Kojto 39:d96aa62afc5b 2832 return dfacc;
Kojto 39:d96aa62afc5b 2833 }
Kojto 39:d96aa62afc5b 2834
Kojto 39:d96aa62afc5b 2835 /* End of File */