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:
Mon Jan 19 14:30:37 2015 +0000
Revision:
27:4206883f4cb7
Synchronized with git revision 0ab8d2e6b3d884137dcb5c62d29a07abe132bac7

Full URL: https://github.com/mbedmicro/mbed/commit/0ab8d2e6b3d884137dcb5c62d29a07abe132bac7/

RZ_A1H - Implement some USB functions and fix some bugs about USBHost common codes.

Who changed what in which revision?

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