USBDevice with MAX32620HSP platform support

Fork of USBDevice by mbed official

Committer:
mbed_official
Date:
Fri Apr 29 01:16:25 2016 +0100
Revision:
62:c1549af978d6
Synchronized with git revision fe9720f24b1adc71ab6962506ec51290f6afd270

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

[Renesas RZ/A1H] Enable asynchronous communications

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 62:c1549af978d6 1 /*******************************************************************************
mbed_official 62:c1549af978d6 2 * DISCLAIMER
mbed_official 62:c1549af978d6 3 * This software is supplied by Renesas Electronics Corporation and is only
mbed_official 62:c1549af978d6 4 * intended for use with Renesas products. No other uses are authorized. This
mbed_official 62:c1549af978d6 5 * software is owned by Renesas Electronics Corporation and is protected under
mbed_official 62:c1549af978d6 6 * all applicable laws, including copyright laws.
mbed_official 62:c1549af978d6 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
mbed_official 62:c1549af978d6 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
mbed_official 62:c1549af978d6 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
mbed_official 62:c1549af978d6 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
mbed_official 62:c1549af978d6 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
mbed_official 62:c1549af978d6 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
mbed_official 62:c1549af978d6 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
mbed_official 62:c1549af978d6 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
mbed_official 62:c1549af978d6 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
mbed_official 62:c1549af978d6 16 * Renesas reserves the right, without notice, to make changes to this software
mbed_official 62:c1549af978d6 17 * and to discontinue the availability of this software. By using this software,
mbed_official 62:c1549af978d6 18 * you agree to the additional terms and conditions found by accessing the
mbed_official 62:c1549af978d6 19 * following link:
mbed_official 62:c1549af978d6 20 * http://www.renesas.com/disclaimer
mbed_official 62:c1549af978d6 21 * Copyright (C) 2012 - 2014 Renesas Electronics Corporation. All rights reserved.
mbed_official 62:c1549af978d6 22 *******************************************************************************/
mbed_official 62:c1549af978d6 23 /*******************************************************************************
mbed_official 62:c1549af978d6 24 * File Name : usb0_function_userdef.c
mbed_official 62:c1549af978d6 25 * $Rev: 1116 $
mbed_official 62:c1549af978d6 26 * $Date:: 2014-07-09 16:29:19 +0900#$
mbed_official 62:c1549af978d6 27 * Device(s) : RZ/A1H
mbed_official 62:c1549af978d6 28 * Tool-Chain :
mbed_official 62:c1549af978d6 29 * OS : None
mbed_official 62:c1549af978d6 30 * H/W Platform :
mbed_official 62:c1549af978d6 31 * Description : RZ/A1H R7S72100 USB Sample Program
mbed_official 62:c1549af978d6 32 * Operation :
mbed_official 62:c1549af978d6 33 * Limitations :
mbed_official 62:c1549af978d6 34 *******************************************************************************/
mbed_official 62:c1549af978d6 35
mbed_official 62:c1549af978d6 36
mbed_official 62:c1549af978d6 37 /*******************************************************************************
mbed_official 62:c1549af978d6 38 Includes <System Includes> , "Project Includes"
mbed_official 62:c1549af978d6 39 *******************************************************************************/
mbed_official 62:c1549af978d6 40 #include <stdio.h>
mbed_official 62:c1549af978d6 41 #include "r_typedefs.h"
mbed_official 62:c1549af978d6 42 #include "iodefine.h"
mbed_official 62:c1549af978d6 43 #include "devdrv_usb_function_api.h"
mbed_official 62:c1549af978d6 44 #include "usb0_function_dmacdrv.h" /* common DMAC driver for USB */
mbed_official 62:c1549af978d6 45
mbed_official 62:c1549af978d6 46
mbed_official 62:c1549af978d6 47 /*******************************************************************************
mbed_official 62:c1549af978d6 48 Typedef definitions
mbed_official 62:c1549af978d6 49 *******************************************************************************/
mbed_official 62:c1549af978d6 50
mbed_official 62:c1549af978d6 51
mbed_official 62:c1549af978d6 52 /*******************************************************************************
mbed_official 62:c1549af978d6 53 Macro definitions
mbed_official 62:c1549af978d6 54 *******************************************************************************/
mbed_official 62:c1549af978d6 55 #define DUMMY_ACCESS OSTM0CNT
mbed_official 62:c1549af978d6 56
mbed_official 62:c1549af978d6 57 /* #define CACHE_WRITEBACK */
mbed_official 62:c1549af978d6 58
mbed_official 62:c1549af978d6 59
mbed_official 62:c1549af978d6 60 /*******************************************************************************
mbed_official 62:c1549af978d6 61 Imported global variables and functions (from other files)
mbed_official 62:c1549af978d6 62 *******************************************************************************/
mbed_official 62:c1549af978d6 63 extern int32_t io_cwb(unsigned long start, unsigned long end);
mbed_official 62:c1549af978d6 64
mbed_official 62:c1549af978d6 65
mbed_official 62:c1549af978d6 66 /*******************************************************************************
mbed_official 62:c1549af978d6 67 Exported global variables and functions (to be accessed by other files)
mbed_official 62:c1549af978d6 68 *******************************************************************************/
mbed_official 62:c1549af978d6 69 static void usb0_function_enable_dmac0(uint32_t src, uint32_t dst, uint32_t count,
mbed_official 62:c1549af978d6 70 uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc);
mbed_official 62:c1549af978d6 71 static void usb0_function_enable_dmac1(uint32_t src, uint32_t dst, uint32_t count,
mbed_official 62:c1549af978d6 72 uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc);
mbed_official 62:c1549af978d6 73 static void Userdef_USB_usb0_function_delay_10us_2(void);
mbed_official 62:c1549af978d6 74
mbed_official 62:c1549af978d6 75
mbed_official 62:c1549af978d6 76 /*******************************************************************************
mbed_official 62:c1549af978d6 77 Private global variables and functions
mbed_official 62:c1549af978d6 78 *******************************************************************************/
mbed_official 62:c1549af978d6 79
mbed_official 62:c1549af978d6 80
mbed_official 62:c1549af978d6 81 /*******************************************************************************
mbed_official 62:c1549af978d6 82 * Function Name: Userdef_USB_usb0_function_d0fifo_dmaintid
mbed_official 62:c1549af978d6 83 * Description : get D0FIFO DMA Interrupt ID
mbed_official 62:c1549af978d6 84 * Arguments : none
mbed_official 62:c1549af978d6 85 * Return Value : D0FIFO DMA Interrupt ID
mbed_official 62:c1549af978d6 86 *******************************************************************************/
mbed_official 62:c1549af978d6 87 IRQn_Type Userdef_USB_usb0_function_d0fifo_dmaintid (void)
mbed_official 62:c1549af978d6 88 {
mbed_official 62:c1549af978d6 89 #if 0
mbed_official 62:c1549af978d6 90 return DMAINT1_IRQn;
mbed_official 62:c1549af978d6 91 #else
mbed_official 62:c1549af978d6 92 return 0xFFFF;
mbed_official 62:c1549af978d6 93 #endif
mbed_official 62:c1549af978d6 94 }
mbed_official 62:c1549af978d6 95
mbed_official 62:c1549af978d6 96 /*******************************************************************************
mbed_official 62:c1549af978d6 97 * Function Name: Userdef_USB_usb0_function_d1fifo_dmaintid
mbed_official 62:c1549af978d6 98 * Description : get D1FIFO DMA Interrupt ID
mbed_official 62:c1549af978d6 99 * Arguments : none
mbed_official 62:c1549af978d6 100 * Return Value : D1FIFO DMA Interrupt ID
mbed_official 62:c1549af978d6 101 *******************************************************************************/
mbed_official 62:c1549af978d6 102 IRQn_Type Userdef_USB_usb0_function_d1fifo_dmaintid (void)
mbed_official 62:c1549af978d6 103 {
mbed_official 62:c1549af978d6 104 #if 0
mbed_official 62:c1549af978d6 105 return DMAINT1_IRQn;
mbed_official 62:c1549af978d6 106 #else
mbed_official 62:c1549af978d6 107 return 0xFFFF;
mbed_official 62:c1549af978d6 108 #endif
mbed_official 62:c1549af978d6 109 }
mbed_official 62:c1549af978d6 110
mbed_official 62:c1549af978d6 111 /*******************************************************************************
mbed_official 62:c1549af978d6 112 * Function Name: Userdef_USB_usb0_function_attach
mbed_official 62:c1549af978d6 113 * Description : Wait for the software of 1ms.
mbed_official 62:c1549af978d6 114 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 115 * Arguments : none
mbed_official 62:c1549af978d6 116 * Return Value : none
mbed_official 62:c1549af978d6 117 *******************************************************************************/
mbed_official 62:c1549af978d6 118 void Userdef_USB_usb0_function_attach (void)
mbed_official 62:c1549af978d6 119 {
mbed_official 62:c1549af978d6 120 printf("\n");
mbed_official 62:c1549af978d6 121 printf("channel 0 attach device\n");
mbed_official 62:c1549af978d6 122 printf("\n");
mbed_official 62:c1549af978d6 123 }
mbed_official 62:c1549af978d6 124
mbed_official 62:c1549af978d6 125 /*******************************************************************************
mbed_official 62:c1549af978d6 126 * Function Name: Userdef_USB_usb0_function_detach
mbed_official 62:c1549af978d6 127 * Description : Wait for the software of 1ms.
mbed_official 62:c1549af978d6 128 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 129 * Arguments : none
mbed_official 62:c1549af978d6 130 * Return Value : none
mbed_official 62:c1549af978d6 131 *******************************************************************************/
mbed_official 62:c1549af978d6 132 void Userdef_USB_usb0_function_detach (void)
mbed_official 62:c1549af978d6 133 {
mbed_official 62:c1549af978d6 134 printf("\n");
mbed_official 62:c1549af978d6 135 printf("channel 0 detach device\n");
mbed_official 62:c1549af978d6 136 printf("\n");
mbed_official 62:c1549af978d6 137 }
mbed_official 62:c1549af978d6 138
mbed_official 62:c1549af978d6 139 /*******************************************************************************
mbed_official 62:c1549af978d6 140 * Function Name: Userdef_USB_usb0_function_delay_1ms
mbed_official 62:c1549af978d6 141 * Description : Wait for the software of 1ms.
mbed_official 62:c1549af978d6 142 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 143 * Arguments : none
mbed_official 62:c1549af978d6 144 * Return Value : none
mbed_official 62:c1549af978d6 145 *******************************************************************************/
mbed_official 62:c1549af978d6 146 void Userdef_USB_usb0_function_delay_1ms (void)
mbed_official 62:c1549af978d6 147 {
mbed_official 62:c1549af978d6 148 volatile int i;
mbed_official 62:c1549af978d6 149 volatile unsigned long tmp;
mbed_official 62:c1549af978d6 150
mbed_official 62:c1549af978d6 151 /*
mbed_official 62:c1549af978d6 152 * Wait 1ms (Please change for your MCU).
mbed_official 62:c1549af978d6 153 */
mbed_official 62:c1549af978d6 154 for (i = 0; i < 1440; ++i)
mbed_official 62:c1549af978d6 155 {
mbed_official 62:c1549af978d6 156 tmp = DUMMY_ACCESS;
mbed_official 62:c1549af978d6 157 }
mbed_official 62:c1549af978d6 158 }
mbed_official 62:c1549af978d6 159
mbed_official 62:c1549af978d6 160 /*******************************************************************************
mbed_official 62:c1549af978d6 161 * Function Name: Userdef_USB_usb0_function_delay_xms
mbed_official 62:c1549af978d6 162 * Description : Wait for the software in the period of time specified by the
mbed_official 62:c1549af978d6 163 * : argument.
mbed_official 62:c1549af978d6 164 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 165 * Arguments : uint32_t msec ; Wait Time (msec)
mbed_official 62:c1549af978d6 166 * Return Value : none
mbed_official 62:c1549af978d6 167 *******************************************************************************/
mbed_official 62:c1549af978d6 168 void Userdef_USB_usb0_function_delay_xms (uint32_t msec)
mbed_official 62:c1549af978d6 169 {
mbed_official 62:c1549af978d6 170 volatile unsigned short i;
mbed_official 62:c1549af978d6 171
mbed_official 62:c1549af978d6 172 for (i = 0; i < msec; ++i)
mbed_official 62:c1549af978d6 173 {
mbed_official 62:c1549af978d6 174 Userdef_USB_usb0_function_delay_1ms();
mbed_official 62:c1549af978d6 175 }
mbed_official 62:c1549af978d6 176 }
mbed_official 62:c1549af978d6 177
mbed_official 62:c1549af978d6 178 /*******************************************************************************
mbed_official 62:c1549af978d6 179 * Function Name: Userdef_USB_usb0_function_delay_10us
mbed_official 62:c1549af978d6 180 * Description : Waits for software for the period specified by the argument.
mbed_official 62:c1549af978d6 181 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 182 * Arguments : uint32_t usec ; Wait Time(x 10usec)
mbed_official 62:c1549af978d6 183 * Return Value : none
mbed_official 62:c1549af978d6 184 *******************************************************************************/
mbed_official 62:c1549af978d6 185 void Userdef_USB_usb0_function_delay_10us (uint32_t usec)
mbed_official 62:c1549af978d6 186 {
mbed_official 62:c1549af978d6 187 volatile int i;
mbed_official 62:c1549af978d6 188
mbed_official 62:c1549af978d6 189 /* Wait 10us (Please change for your MCU) */
mbed_official 62:c1549af978d6 190 for (i = 0; i < usec; ++i)
mbed_official 62:c1549af978d6 191 {
mbed_official 62:c1549af978d6 192 Userdef_USB_usb0_function_delay_10us_2();
mbed_official 62:c1549af978d6 193 }
mbed_official 62:c1549af978d6 194 }
mbed_official 62:c1549af978d6 195
mbed_official 62:c1549af978d6 196 /*******************************************************************************
mbed_official 62:c1549af978d6 197 * Function Name: Userdef_USB_usb0_function_delay_10us_2
mbed_official 62:c1549af978d6 198 * Description : Waits for software for the period specified by the argument.
mbed_official 62:c1549af978d6 199 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 200 * Arguments : none
mbed_official 62:c1549af978d6 201 * Return Value : none
mbed_official 62:c1549af978d6 202 *******************************************************************************/
mbed_official 62:c1549af978d6 203 static void Userdef_USB_usb0_function_delay_10us_2 (void)
mbed_official 62:c1549af978d6 204 {
mbed_official 62:c1549af978d6 205 volatile int i;
mbed_official 62:c1549af978d6 206 volatile unsigned long tmp;
mbed_official 62:c1549af978d6 207
mbed_official 62:c1549af978d6 208 /* Wait 1us (Please change for your MCU) */
mbed_official 62:c1549af978d6 209 for (i = 0; i < 14; ++i)
mbed_official 62:c1549af978d6 210 {
mbed_official 62:c1549af978d6 211 tmp = DUMMY_ACCESS;
mbed_official 62:c1549af978d6 212 }
mbed_official 62:c1549af978d6 213 }
mbed_official 62:c1549af978d6 214
mbed_official 62:c1549af978d6 215 /*******************************************************************************
mbed_official 62:c1549af978d6 216 * Function Name: Userdef_USB_usb0_function_delay_500ns
mbed_official 62:c1549af978d6 217 * Description : Wait for software for 500ns.
mbed_official 62:c1549af978d6 218 * : Alter this function according to the user's system.
mbed_official 62:c1549af978d6 219 * Arguments : none
mbed_official 62:c1549af978d6 220 * Return Value : none
mbed_official 62:c1549af978d6 221 *******************************************************************************/
mbed_official 62:c1549af978d6 222 void Userdef_USB_usb0_function_delay_500ns (void)
mbed_official 62:c1549af978d6 223 {
mbed_official 62:c1549af978d6 224 volatile int i;
mbed_official 62:c1549af978d6 225 volatile unsigned long tmp;
mbed_official 62:c1549af978d6 226
mbed_official 62:c1549af978d6 227 /* Wait 500ns (Please change for your MCU) */
mbed_official 62:c1549af978d6 228 /* Wait 500ns I clock 266MHz */
mbed_official 62:c1549af978d6 229 tmp = DUMMY_ACCESS;
mbed_official 62:c1549af978d6 230 }
mbed_official 62:c1549af978d6 231
mbed_official 62:c1549af978d6 232 /*******************************************************************************
mbed_official 62:c1549af978d6 233 * Function Name: Userdef_USB_usb0_function_start_dma
mbed_official 62:c1549af978d6 234 * Description : Enables DMA transfer on the information specified by the argument.
mbed_official 62:c1549af978d6 235 * : Set DMAC register by this function to enable DMA transfer.
mbed_official 62:c1549af978d6 236 * : After executing this function, USB module is set to start DMA
mbed_official 62:c1549af978d6 237 * : transfer. DMA transfer should not wait for DMA transfer complete.
mbed_official 62:c1549af978d6 238 * Arguments : USB_FUNCTION_DMA_t *dma : DMA parameter
mbed_official 62:c1549af978d6 239 * : typedef struct{
mbed_official 62:c1549af978d6 240 * : uint32_t fifo; FIFO for using
mbed_official 62:c1549af978d6 241 * : uint32_t buffer; Start address of transfer source/destination
mbed_official 62:c1549af978d6 242 * : uint32_t bytes; Transfer size(Byte)
mbed_official 62:c1549af978d6 243 * : uint32_t dir; Transfer direction(0:Buffer->FIFO, 1:FIFO->Buffer)
mbed_official 62:c1549af978d6 244 * : uint32_t size; DMA transfer size
mbed_official 62:c1549af978d6 245 * : } USB_FUNCTION_DMA_t;
mbed_official 62:c1549af978d6 246 * : uint16_t dfacc ; 0 : cycle steal mode
mbed_official 62:c1549af978d6 247 * : 1 : 16byte continuous mode
mbed_official 62:c1549af978d6 248 * : 2 : 32byte continuous mode
mbed_official 62:c1549af978d6 249 * Return Value : none
mbed_official 62:c1549af978d6 250 *******************************************************************************/
mbed_official 62:c1549af978d6 251 void Userdef_USB_usb0_function_start_dma (USB_FUNCTION_DMA_t * dma, uint16_t dfacc)
mbed_official 62:c1549af978d6 252 {
mbed_official 62:c1549af978d6 253 uint32_t trncount;
mbed_official 62:c1549af978d6 254 uint32_t src;
mbed_official 62:c1549af978d6 255 uint32_t dst;
mbed_official 62:c1549af978d6 256 uint32_t size;
mbed_official 62:c1549af978d6 257 uint32_t dir;
mbed_official 62:c1549af978d6 258 #ifdef CACHE_WRITEBACK
mbed_official 62:c1549af978d6 259 uint32_t ptr;
mbed_official 62:c1549af978d6 260 #endif
mbed_official 62:c1549af978d6 261
mbed_official 62:c1549af978d6 262 trncount = dma->bytes;
mbed_official 62:c1549af978d6 263 dir = dma->dir;
mbed_official 62:c1549af978d6 264
mbed_official 62:c1549af978d6 265 if (dir == USB_FUNCTION_FIFO2BUF)
mbed_official 62:c1549af978d6 266 {
mbed_official 62:c1549af978d6 267 /* DxFIFO determination */
mbed_official 62:c1549af978d6 268 dst = dma->buffer;
mbed_official 62:c1549af978d6 269 #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
mbed_official 62:c1549af978d6 270 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 271 {
mbed_official 62:c1549af978d6 272 src = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 273 }
mbed_official 62:c1549af978d6 274 else
mbed_official 62:c1549af978d6 275 {
mbed_official 62:c1549af978d6 276 src = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 277 }
mbed_official 62:c1549af978d6 278 size = dma->size;
mbed_official 62:c1549af978d6 279
mbed_official 62:c1549af978d6 280 if (size == 0)
mbed_official 62:c1549af978d6 281 {
mbed_official 62:c1549af978d6 282 src += 3; /* byte access */
mbed_official 62:c1549af978d6 283 }
mbed_official 62:c1549af978d6 284 else if (size == 1)
mbed_official 62:c1549af978d6 285 {
mbed_official 62:c1549af978d6 286 src += 2; /* short access */
mbed_official 62:c1549af978d6 287 }
mbed_official 62:c1549af978d6 288 else
mbed_official 62:c1549af978d6 289 {
mbed_official 62:c1549af978d6 290 /* Do Nothing */
mbed_official 62:c1549af978d6 291 }
mbed_official 62:c1549af978d6 292 #else
mbed_official 62:c1549af978d6 293 size = dma->size;
mbed_official 62:c1549af978d6 294
mbed_official 62:c1549af978d6 295 if (size == 2)
mbed_official 62:c1549af978d6 296 {
mbed_official 62:c1549af978d6 297 /* 32bit access */
mbed_official 62:c1549af978d6 298 if (dfacc == 2)
mbed_official 62:c1549af978d6 299 {
mbed_official 62:c1549af978d6 300 /* 32byte access */
mbed_official 62:c1549af978d6 301 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 302 {
mbed_official 62:c1549af978d6 303 src = (uint32_t)(&USB200.D0FIFOB0);
mbed_official 62:c1549af978d6 304 }
mbed_official 62:c1549af978d6 305 else
mbed_official 62:c1549af978d6 306 {
mbed_official 62:c1549af978d6 307 src = (uint32_t)(&USB200.D1FIFOB0);
mbed_official 62:c1549af978d6 308 }
mbed_official 62:c1549af978d6 309 }
mbed_official 62:c1549af978d6 310 else if (dfacc == 1)
mbed_official 62:c1549af978d6 311 {
mbed_official 62:c1549af978d6 312 /* 16byte access */
mbed_official 62:c1549af978d6 313 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 314 {
mbed_official 62:c1549af978d6 315 src = (uint32_t)(&USB200.D0FIFOB0);
mbed_official 62:c1549af978d6 316 }
mbed_official 62:c1549af978d6 317 else
mbed_official 62:c1549af978d6 318 {
mbed_official 62:c1549af978d6 319 src = (uint32_t)(&USB200.D1FIFOB0);
mbed_official 62:c1549af978d6 320 }
mbed_official 62:c1549af978d6 321 }
mbed_official 62:c1549af978d6 322 else
mbed_official 62:c1549af978d6 323 {
mbed_official 62:c1549af978d6 324 /* normal access */
mbed_official 62:c1549af978d6 325 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 326 {
mbed_official 62:c1549af978d6 327 src = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 328 }
mbed_official 62:c1549af978d6 329 else
mbed_official 62:c1549af978d6 330 {
mbed_official 62:c1549af978d6 331 src = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 332 }
mbed_official 62:c1549af978d6 333 }
mbed_official 62:c1549af978d6 334 }
mbed_official 62:c1549af978d6 335 else if (size == 1)
mbed_official 62:c1549af978d6 336 {
mbed_official 62:c1549af978d6 337 /* 16bit access */
mbed_official 62:c1549af978d6 338 dfacc = 0; /* force normal access */
mbed_official 62:c1549af978d6 339
mbed_official 62:c1549af978d6 340 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 341 {
mbed_official 62:c1549af978d6 342 src = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 343 }
mbed_official 62:c1549af978d6 344 else
mbed_official 62:c1549af978d6 345 {
mbed_official 62:c1549af978d6 346 src = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 347 }
mbed_official 62:c1549af978d6 348 src += 2; /* short access */
mbed_official 62:c1549af978d6 349 }
mbed_official 62:c1549af978d6 350 else
mbed_official 62:c1549af978d6 351 {
mbed_official 62:c1549af978d6 352 /* 8bit access */
mbed_official 62:c1549af978d6 353 dfacc = 0; /* force normal access */
mbed_official 62:c1549af978d6 354
mbed_official 62:c1549af978d6 355 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 356 {
mbed_official 62:c1549af978d6 357 src = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 358 }
mbed_official 62:c1549af978d6 359 else
mbed_official 62:c1549af978d6 360 {
mbed_official 62:c1549af978d6 361 src = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 362 }
mbed_official 62:c1549af978d6 363 src += 3; /* byte access */
mbed_official 62:c1549af978d6 364 }
mbed_official 62:c1549af978d6 365 #endif
mbed_official 62:c1549af978d6 366 }
mbed_official 62:c1549af978d6 367 else
mbed_official 62:c1549af978d6 368 {
mbed_official 62:c1549af978d6 369 /* DxFIFO determination */
mbed_official 62:c1549af978d6 370 src = dma->buffer;
mbed_official 62:c1549af978d6 371 #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
mbed_official 62:c1549af978d6 372 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 373 {
mbed_official 62:c1549af978d6 374 dst = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 375 }
mbed_official 62:c1549af978d6 376 else
mbed_official 62:c1549af978d6 377 {
mbed_official 62:c1549af978d6 378 dst = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 379 }
mbed_official 62:c1549af978d6 380 size = dma->size;
mbed_official 62:c1549af978d6 381
mbed_official 62:c1549af978d6 382 if (size == 0)
mbed_official 62:c1549af978d6 383 {
mbed_official 62:c1549af978d6 384 dst += 3; /* byte access */
mbed_official 62:c1549af978d6 385 }
mbed_official 62:c1549af978d6 386 else if (size == 1)
mbed_official 62:c1549af978d6 387 {
mbed_official 62:c1549af978d6 388 dst += 2; /* short access */
mbed_official 62:c1549af978d6 389 }
mbed_official 62:c1549af978d6 390 else
mbed_official 62:c1549af978d6 391 {
mbed_official 62:c1549af978d6 392 /* Do Nothing */
mbed_official 62:c1549af978d6 393 }
mbed_official 62:c1549af978d6 394 #else
mbed_official 62:c1549af978d6 395 size = dma->size;
mbed_official 62:c1549af978d6 396
mbed_official 62:c1549af978d6 397 if (size == 2)
mbed_official 62:c1549af978d6 398 {
mbed_official 62:c1549af978d6 399 /* 32bit access */
mbed_official 62:c1549af978d6 400 if (dfacc == 2)
mbed_official 62:c1549af978d6 401 {
mbed_official 62:c1549af978d6 402 /* 32byte access */
mbed_official 62:c1549af978d6 403 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 404 {
mbed_official 62:c1549af978d6 405 dst = (uint32_t)(&USB200.D0FIFOB0);
mbed_official 62:c1549af978d6 406 }
mbed_official 62:c1549af978d6 407 else
mbed_official 62:c1549af978d6 408 {
mbed_official 62:c1549af978d6 409 dst = (uint32_t)(&USB200.D1FIFOB0);
mbed_official 62:c1549af978d6 410 }
mbed_official 62:c1549af978d6 411 }
mbed_official 62:c1549af978d6 412 else if (dfacc == 1)
mbed_official 62:c1549af978d6 413 {
mbed_official 62:c1549af978d6 414 /* 16byte access */
mbed_official 62:c1549af978d6 415 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 416 {
mbed_official 62:c1549af978d6 417 dst = (uint32_t)(&USB200.D0FIFOB0);
mbed_official 62:c1549af978d6 418 }
mbed_official 62:c1549af978d6 419 else
mbed_official 62:c1549af978d6 420 {
mbed_official 62:c1549af978d6 421 dst = (uint32_t)(&USB200.D1FIFOB0);
mbed_official 62:c1549af978d6 422 }
mbed_official 62:c1549af978d6 423 }
mbed_official 62:c1549af978d6 424 else
mbed_official 62:c1549af978d6 425 {
mbed_official 62:c1549af978d6 426 /* normal access */
mbed_official 62:c1549af978d6 427 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 428 {
mbed_official 62:c1549af978d6 429 dst = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 430 }
mbed_official 62:c1549af978d6 431 else
mbed_official 62:c1549af978d6 432 {
mbed_official 62:c1549af978d6 433 dst = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 434 }
mbed_official 62:c1549af978d6 435 }
mbed_official 62:c1549af978d6 436 }
mbed_official 62:c1549af978d6 437 else if (size == 1)
mbed_official 62:c1549af978d6 438 {
mbed_official 62:c1549af978d6 439 /* 16bit access */
mbed_official 62:c1549af978d6 440 dfacc = 0; /* force normal access */
mbed_official 62:c1549af978d6 441 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 442 {
mbed_official 62:c1549af978d6 443 dst = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 444 }
mbed_official 62:c1549af978d6 445 else
mbed_official 62:c1549af978d6 446 {
mbed_official 62:c1549af978d6 447 dst = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 448 }
mbed_official 62:c1549af978d6 449 dst += 2; /* short access */
mbed_official 62:c1549af978d6 450 }
mbed_official 62:c1549af978d6 451 else
mbed_official 62:c1549af978d6 452 {
mbed_official 62:c1549af978d6 453 /* 8bit access */
mbed_official 62:c1549af978d6 454 dfacc = 0; /* force normal access */
mbed_official 62:c1549af978d6 455
mbed_official 62:c1549af978d6 456 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 457 {
mbed_official 62:c1549af978d6 458 dst = (uint32_t)(&USB200.D0FIFO.UINT32);
mbed_official 62:c1549af978d6 459 }
mbed_official 62:c1549af978d6 460 else
mbed_official 62:c1549af978d6 461 {
mbed_official 62:c1549af978d6 462 dst = (uint32_t)(&USB200.D1FIFO.UINT32);
mbed_official 62:c1549af978d6 463 }
mbed_official 62:c1549af978d6 464 dst += 3; /* byte access */
mbed_official 62:c1549af978d6 465 }
mbed_official 62:c1549af978d6 466 #endif
mbed_official 62:c1549af978d6 467 }
mbed_official 62:c1549af978d6 468
mbed_official 62:c1549af978d6 469 #ifdef CACHE_WRITEBACK
mbed_official 62:c1549af978d6 470 ptr = (uint32_t)dma->buffer;
mbed_official 62:c1549af978d6 471
mbed_official 62:c1549af978d6 472 if ((ptr & 0x20000000ul) == 0)
mbed_official 62:c1549af978d6 473 {
mbed_official 62:c1549af978d6 474 io_cwb((uint32_t)ptr, (uint32_t)(ptr) + trncount);
mbed_official 62:c1549af978d6 475 }
mbed_official 62:c1549af978d6 476 #endif
mbed_official 62:c1549af978d6 477
mbed_official 62:c1549af978d6 478 if (dma->fifo == USB_FUNCTION_D0FIFO_DMA)
mbed_official 62:c1549af978d6 479 {
mbed_official 62:c1549af978d6 480 usb0_function_enable_dmac0(src, dst, trncount, size, dir, dma->fifo, dfacc);
mbed_official 62:c1549af978d6 481 }
mbed_official 62:c1549af978d6 482 else
mbed_official 62:c1549af978d6 483 {
mbed_official 62:c1549af978d6 484 usb0_function_enable_dmac1(src, dst, trncount, size, dir, dma->fifo, dfacc);
mbed_official 62:c1549af978d6 485 }
mbed_official 62:c1549af978d6 486 }
mbed_official 62:c1549af978d6 487
mbed_official 62:c1549af978d6 488 /*******************************************************************************
mbed_official 62:c1549af978d6 489 * Function Name: usb0_function_enable_dmac0
mbed_official 62:c1549af978d6 490 * Description : Enables DMA transfer on the information specified by the argument.
mbed_official 62:c1549af978d6 491 * Arguments : uint32_t src : src address
mbed_official 62:c1549af978d6 492 * : uint32_t dst : dst address
mbed_official 62:c1549af978d6 493 * : uint32_t count : transfer byte
mbed_official 62:c1549af978d6 494 * : uint32_t size : transfer size
mbed_official 62:c1549af978d6 495 * : uint32_t dir : direction
mbed_official 62:c1549af978d6 496 * : uint32_t fifo : FIFO(D0FIFO or D1FIFO)
mbed_official 62:c1549af978d6 497 * : uint16_t dfacc : 0 : normal access
mbed_official 62:c1549af978d6 498 * : : 1 : 16byte access
mbed_official 62:c1549af978d6 499 * : : 2 : 32byte access
mbed_official 62:c1549af978d6 500 * Return Value : none
mbed_official 62:c1549af978d6 501 *******************************************************************************/
mbed_official 62:c1549af978d6 502 static void usb0_function_enable_dmac0 (uint32_t src, uint32_t dst, uint32_t count,
mbed_official 62:c1549af978d6 503 uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc)
mbed_official 62:c1549af978d6 504 {
mbed_official 62:c1549af978d6 505 dmac_transinfo_t trans_info;
mbed_official 62:c1549af978d6 506 uint32_t request_factor = 0;
mbed_official 62:c1549af978d6 507 int32_t ret;
mbed_official 62:c1549af978d6 508
mbed_official 62:c1549af978d6 509 /* ==== Variable setting for DMAC initialization ==== */
mbed_official 62:c1549af978d6 510 trans_info.src_addr = (uint32_t)src; /* Start address of transfer source */
mbed_official 62:c1549af978d6 511 trans_info.dst_addr = (uint32_t)dst; /* Start address of transfer destination */
mbed_official 62:c1549af978d6 512 trans_info.count = (uint32_t)count; /* Total byte count to be transferred */
mbed_official 62:c1549af978d6 513 #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
mbed_official 62:c1549af978d6 514 if (size == 0)
mbed_official 62:c1549af978d6 515 {
mbed_official 62:c1549af978d6 516 trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 517 trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 518 }
mbed_official 62:c1549af978d6 519 else if (size == 1)
mbed_official 62:c1549af978d6 520 {
mbed_official 62:c1549af978d6 521 trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 522 trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 523 }
mbed_official 62:c1549af978d6 524 else if (size == 2)
mbed_official 62:c1549af978d6 525 {
mbed_official 62:c1549af978d6 526 trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 527 trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 528 }
mbed_official 62:c1549af978d6 529 else
mbed_official 62:c1549af978d6 530 {
mbed_official 62:c1549af978d6 531 printf("size error!!\n");
mbed_official 62:c1549af978d6 532 }
mbed_official 62:c1549af978d6 533 #else
mbed_official 62:c1549af978d6 534 if (dfacc == 2)
mbed_official 62:c1549af978d6 535 {
mbed_official 62:c1549af978d6 536 /* 32byte access */
mbed_official 62:c1549af978d6 537 trans_info.src_size = DMAC_TRANS_SIZE_256; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 538 trans_info.dst_size = DMAC_TRANS_SIZE_256; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 539 }
mbed_official 62:c1549af978d6 540 else if (dfacc == 1)
mbed_official 62:c1549af978d6 541 {
mbed_official 62:c1549af978d6 542 /* 16byte access */
mbed_official 62:c1549af978d6 543 trans_info.src_size = DMAC_TRANS_SIZE_128; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 544 trans_info.dst_size = DMAC_TRANS_SIZE_128; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 545 }
mbed_official 62:c1549af978d6 546 else
mbed_official 62:c1549af978d6 547 {
mbed_official 62:c1549af978d6 548 /* normal access */
mbed_official 62:c1549af978d6 549 if (size == 0)
mbed_official 62:c1549af978d6 550 {
mbed_official 62:c1549af978d6 551 trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 552 trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 553 }
mbed_official 62:c1549af978d6 554 else if (size == 1)
mbed_official 62:c1549af978d6 555 {
mbed_official 62:c1549af978d6 556 trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 557 trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 558 }
mbed_official 62:c1549af978d6 559 else if (size == 2)
mbed_official 62:c1549af978d6 560 {
mbed_official 62:c1549af978d6 561 trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 562 trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 563 }
mbed_official 62:c1549af978d6 564 else
mbed_official 62:c1549af978d6 565 {
mbed_official 62:c1549af978d6 566 printf("size error!!\n");
mbed_official 62:c1549af978d6 567 }
mbed_official 62:c1549af978d6 568 }
mbed_official 62:c1549af978d6 569 #endif
mbed_official 62:c1549af978d6 570
mbed_official 62:c1549af978d6 571 if (dir == USB_FUNCTION_FIFO2BUF)
mbed_official 62:c1549af978d6 572 {
mbed_official 62:c1549af978d6 573 request_factor =DMAC_REQ_USB0_DMA0_RX; /* USB_0 channel 0 receive FIFO full */
mbed_official 62:c1549af978d6 574 trans_info.saddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer source address */
mbed_official 62:c1549af978d6 575 trans_info.daddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer destination address */
mbed_official 62:c1549af978d6 576 }
mbed_official 62:c1549af978d6 577 else if (dir == USB_FUNCTION_BUF2FIFO)
mbed_official 62:c1549af978d6 578 {
mbed_official 62:c1549af978d6 579 request_factor =DMAC_REQ_USB0_DMA0_TX; /* USB_0 channel 0 receive FIFO empty */
mbed_official 62:c1549af978d6 580 trans_info.saddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer source address */
mbed_official 62:c1549af978d6 581 trans_info.daddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer destination address */
mbed_official 62:c1549af978d6 582 }
mbed_official 62:c1549af978d6 583 else
mbed_official 62:c1549af978d6 584 {
mbed_official 62:c1549af978d6 585 /* Do Nothing */
mbed_official 62:c1549af978d6 586 }
mbed_official 62:c1549af978d6 587
mbed_official 62:c1549af978d6 588 /* ==== DMAC initialization ==== */
mbed_official 62:c1549af978d6 589 usb0_function_DMAC1_PeriReqInit((const dmac_transinfo_t *)&trans_info,
mbed_official 62:c1549af978d6 590 DMAC_MODE_REGISTER,
mbed_official 62:c1549af978d6 591 DMAC_SAMPLE_SINGLE,
mbed_official 62:c1549af978d6 592 request_factor,
mbed_official 62:c1549af978d6 593 0); /* Don't care DMAC_REQ_REQD is setting in
mbed_official 62:c1549af978d6 594 usb0_function_DMAC1_PeriReqInit() */
mbed_official 62:c1549af978d6 595
mbed_official 62:c1549af978d6 596 /* ==== DMAC startup ==== */
mbed_official 62:c1549af978d6 597 ret = usb0_function_DMAC1_Open(DMAC_REQ_MODE_PERI);
mbed_official 62:c1549af978d6 598 if (ret != 0)
mbed_official 62:c1549af978d6 599 {
mbed_official 62:c1549af978d6 600 printf("DMAC1 Open error!!\n");
mbed_official 62:c1549af978d6 601 }
mbed_official 62:c1549af978d6 602
mbed_official 62:c1549af978d6 603 return;
mbed_official 62:c1549af978d6 604 }
mbed_official 62:c1549af978d6 605
mbed_official 62:c1549af978d6 606 /*******************************************************************************
mbed_official 62:c1549af978d6 607 * Function Name: usb0_function_enable_dmac1
mbed_official 62:c1549af978d6 608 * Description : Enables DMA transfer on the information specified by the argument.
mbed_official 62:c1549af978d6 609 * Arguments : uint32_t src : src address
mbed_official 62:c1549af978d6 610 * : uint32_t dst : dst address
mbed_official 62:c1549af978d6 611 * : uint32_t count : transfer byte
mbed_official 62:c1549af978d6 612 * : uint32_t size : transfer size
mbed_official 62:c1549af978d6 613 * : uint32_t dir : direction
mbed_official 62:c1549af978d6 614 * : uint32_t fifo : FIFO(D0FIFO or D1FIFO)
mbed_official 62:c1549af978d6 615 * : uint16_t dfacc : 0 : normal access
mbed_official 62:c1549af978d6 616 * : : 1 : 16byte access
mbed_official 62:c1549af978d6 617 * : : 2 : 32byte access
mbed_official 62:c1549af978d6 618 * Return Value : none
mbed_official 62:c1549af978d6 619 *******************************************************************************/
mbed_official 62:c1549af978d6 620 static void usb0_function_enable_dmac1 (uint32_t src, uint32_t dst, uint32_t count,
mbed_official 62:c1549af978d6 621 uint32_t size, uint32_t dir, uint32_t fifo, uint16_t dfacc)
mbed_official 62:c1549af978d6 622 {
mbed_official 62:c1549af978d6 623 dmac_transinfo_t trans_info;
mbed_official 62:c1549af978d6 624 uint32_t request_factor = 0;
mbed_official 62:c1549af978d6 625 int32_t ret;
mbed_official 62:c1549af978d6 626
mbed_official 62:c1549af978d6 627 /* ==== Variable setting for DMAC initialization ==== */
mbed_official 62:c1549af978d6 628 trans_info.src_addr = (uint32_t)src; /* Start address of transfer source */
mbed_official 62:c1549af978d6 629 trans_info.dst_addr = (uint32_t)dst; /* Start address of transfer destination */
mbed_official 62:c1549af978d6 630 trans_info.count = (uint32_t)count; /* Total byte count to be transferred */
mbed_official 62:c1549af978d6 631 #ifndef __USB_FUNCTION_DF_ACC_ENABLE__
mbed_official 62:c1549af978d6 632 if (size == 0)
mbed_official 62:c1549af978d6 633 {
mbed_official 62:c1549af978d6 634 trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 635 trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 636 }
mbed_official 62:c1549af978d6 637 else if (size == 1)
mbed_official 62:c1549af978d6 638 {
mbed_official 62:c1549af978d6 639 trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 640 trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 641 }
mbed_official 62:c1549af978d6 642 else if (size == 2)
mbed_official 62:c1549af978d6 643 {
mbed_official 62:c1549af978d6 644 trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 645 trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 646 }
mbed_official 62:c1549af978d6 647 else
mbed_official 62:c1549af978d6 648 {
mbed_official 62:c1549af978d6 649 printf("size error!!\n");
mbed_official 62:c1549af978d6 650 }
mbed_official 62:c1549af978d6 651 #else
mbed_official 62:c1549af978d6 652 if (dfacc == 2)
mbed_official 62:c1549af978d6 653 {
mbed_official 62:c1549af978d6 654 /* 32byte access */
mbed_official 62:c1549af978d6 655 trans_info.src_size = DMAC_TRANS_SIZE_256; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 656 trans_info.dst_size = DMAC_TRANS_SIZE_256; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 657 }
mbed_official 62:c1549af978d6 658 else if (dfacc == 1)
mbed_official 62:c1549af978d6 659 {
mbed_official 62:c1549af978d6 660 /* 16byte access */
mbed_official 62:c1549af978d6 661 trans_info.src_size = DMAC_TRANS_SIZE_128; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 662 trans_info.dst_size = DMAC_TRANS_SIZE_128; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 663 }
mbed_official 62:c1549af978d6 664 else
mbed_official 62:c1549af978d6 665 {
mbed_official 62:c1549af978d6 666 /* normal access */
mbed_official 62:c1549af978d6 667 if (size == 0)
mbed_official 62:c1549af978d6 668 {
mbed_official 62:c1549af978d6 669 trans_info.src_size = DMAC_TRANS_SIZE_8; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 670 trans_info.dst_size = DMAC_TRANS_SIZE_8; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 671 }
mbed_official 62:c1549af978d6 672 else if (size == 1)
mbed_official 62:c1549af978d6 673 {
mbed_official 62:c1549af978d6 674 trans_info.src_size = DMAC_TRANS_SIZE_16; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 675 trans_info.dst_size = DMAC_TRANS_SIZE_16; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 676 }
mbed_official 62:c1549af978d6 677 else if (size == 2)
mbed_official 62:c1549af978d6 678 {
mbed_official 62:c1549af978d6 679 trans_info.src_size = DMAC_TRANS_SIZE_32; /* Transfer source transfer size */
mbed_official 62:c1549af978d6 680 trans_info.dst_size = DMAC_TRANS_SIZE_32; /* Transfer destination transfer size */
mbed_official 62:c1549af978d6 681 }
mbed_official 62:c1549af978d6 682 else
mbed_official 62:c1549af978d6 683 {
mbed_official 62:c1549af978d6 684 printf("size error!!\n");
mbed_official 62:c1549af978d6 685 }
mbed_official 62:c1549af978d6 686 }
mbed_official 62:c1549af978d6 687 #endif
mbed_official 62:c1549af978d6 688
mbed_official 62:c1549af978d6 689 if (dir == USB_FUNCTION_FIFO2BUF)
mbed_official 62:c1549af978d6 690 {
mbed_official 62:c1549af978d6 691 request_factor =DMAC_REQ_USB0_DMA1_RX; /* USB_0 channel 0 receive FIFO full */
mbed_official 62:c1549af978d6 692 trans_info.saddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer source address */
mbed_official 62:c1549af978d6 693 trans_info.daddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer destination address */
mbed_official 62:c1549af978d6 694 }
mbed_official 62:c1549af978d6 695 else if (dir == USB_FUNCTION_BUF2FIFO)
mbed_official 62:c1549af978d6 696 {
mbed_official 62:c1549af978d6 697 request_factor =DMAC_REQ_USB0_DMA1_TX; /* USB_0 channel 0 receive FIFO empty */
mbed_official 62:c1549af978d6 698 trans_info.saddr_dir = DMAC_TRANS_ADR_INC; /* Count direction of transfer source address */
mbed_official 62:c1549af978d6 699 trans_info.daddr_dir = DMAC_TRANS_ADR_NO_INC; /* Count direction of transfer destination address */
mbed_official 62:c1549af978d6 700 }
mbed_official 62:c1549af978d6 701 else
mbed_official 62:c1549af978d6 702 {
mbed_official 62:c1549af978d6 703 /* Do Nothing */
mbed_official 62:c1549af978d6 704 }
mbed_official 62:c1549af978d6 705
mbed_official 62:c1549af978d6 706 /* ==== DMAC initialization ==== */
mbed_official 62:c1549af978d6 707 usb0_function_DMAC2_PeriReqInit((const dmac_transinfo_t *)&trans_info,
mbed_official 62:c1549af978d6 708 DMAC_MODE_REGISTER,
mbed_official 62:c1549af978d6 709 DMAC_SAMPLE_SINGLE,
mbed_official 62:c1549af978d6 710 request_factor,
mbed_official 62:c1549af978d6 711 0); /* Don't care DMAC_REQ_REQD is setting in
mbed_official 62:c1549af978d6 712 usb0_function_DMAC1_PeriReqInit() */
mbed_official 62:c1549af978d6 713
mbed_official 62:c1549af978d6 714 /* ==== DMAC startup ==== */
mbed_official 62:c1549af978d6 715 ret = usb0_function_DMAC2_Open(DMAC_REQ_MODE_PERI);
mbed_official 62:c1549af978d6 716 if (ret != 0)
mbed_official 62:c1549af978d6 717 {
mbed_official 62:c1549af978d6 718 printf("DMAC2 Open error!!\n");
mbed_official 62:c1549af978d6 719 }
mbed_official 62:c1549af978d6 720
mbed_official 62:c1549af978d6 721 return;
mbed_official 62:c1549af978d6 722 }
mbed_official 62:c1549af978d6 723
mbed_official 62:c1549af978d6 724 /*******************************************************************************
mbed_official 62:c1549af978d6 725 * Function Name: Userdef_USB_usb0_function_stop_dma0
mbed_official 62:c1549af978d6 726 * Description : Disables DMA transfer.
mbed_official 62:c1549af978d6 727 * : This function should be executed to DMAC executed at the time
mbed_official 62:c1549af978d6 728 * : of specification of D0_FIF0_DMA in dma->fifo.
mbed_official 62:c1549af978d6 729 * Arguments : none
mbed_official 62:c1549af978d6 730 * Return Value : uint32_t return Transfer Counter register(DMATCRn) value
mbed_official 62:c1549af978d6 731 * : regarding to the bus width.
mbed_official 62:c1549af978d6 732 *******************************************************************************/
mbed_official 62:c1549af978d6 733 uint32_t Userdef_USB_usb0_function_stop_dma0 (void)
mbed_official 62:c1549af978d6 734 {
mbed_official 62:c1549af978d6 735 uint32_t remain;
mbed_official 62:c1549af978d6 736
mbed_official 62:c1549af978d6 737 /* ==== DMAC release ==== */
mbed_official 62:c1549af978d6 738 usb0_function_DMAC1_Close(&remain);
mbed_official 62:c1549af978d6 739
mbed_official 62:c1549af978d6 740 return remain;
mbed_official 62:c1549af978d6 741 }
mbed_official 62:c1549af978d6 742
mbed_official 62:c1549af978d6 743 /*******************************************************************************
mbed_official 62:c1549af978d6 744 * Function Name: Userdef_USB_usb0_function_stop_dma1
mbed_official 62:c1549af978d6 745 * Description : Disables DMA transfer.
mbed_official 62:c1549af978d6 746 * : This function should be executed to DMAC executed at the time
mbed_official 62:c1549af978d6 747 * : of specification of D1_FIF0_DMA in dma->fifo.
mbed_official 62:c1549af978d6 748 * Arguments : none
mbed_official 62:c1549af978d6 749 * Return Value : uint32_t return Transfer Counter register(DMATCRn) value
mbed_official 62:c1549af978d6 750 * : regarding to the bus width.
mbed_official 62:c1549af978d6 751 *******************************************************************************/
mbed_official 62:c1549af978d6 752 uint32_t Userdef_USB_usb0_function_stop_dma1 (void)
mbed_official 62:c1549af978d6 753 {
mbed_official 62:c1549af978d6 754 uint32_t remain;
mbed_official 62:c1549af978d6 755
mbed_official 62:c1549af978d6 756 /* ==== DMAC release ==== */
mbed_official 62:c1549af978d6 757 usb0_function_DMAC2_Close(&remain);
mbed_official 62:c1549af978d6 758
mbed_official 62:c1549af978d6 759 return remain;
mbed_official 62:c1549af978d6 760 }
mbed_official 62:c1549af978d6 761
mbed_official 62:c1549af978d6 762 /* End of File */