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