USB device stack - Added support for the logo/windows key to USB keyboard.

Dependents:   randomSearch

Fork of USBDevice by mbed official

Committer:
mbed_official
Date:
Tue Mar 31 16:15:39 2015 +0100
Revision:
46:378357d7e90d
Parent:
USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/src/common/usb0_function_dataio.c@35:a8484e16c2f3
Synchronized with git revision 251f3f8b55a4dc98b831c80e032464ed45cce309

Full URL: https://github.com/mbedmicro/mbed/commit/251f3f8b55a4dc98b831c80e032464ed45cce309/

[RZ/A1H]Add some function(USB 2port, NVIC wrapper) and modify some settings(OS, Terminal).

Who changed what in which revision?

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