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:
mbed_official
Date:
Fri Apr 29 01:16:38 2016 +0100
Revision:
35:f72ccc6892ee
Synchronized with git revision fe9720f24b1adc71ab6962506ec51290f6afd270

Full URL: https://github.com/mbedmicro/mbed/commit/fe9720f24b1adc71ab6962506ec51290f6afd270/

[Renesas RZ/A1H] Enable asynchronous communications

Who changed what in which revision?

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