USBDevice with MAX32620HSP platform support

Fork of USBDevice by mbed official

Committer:
mbed_official
Date:
Tue Mar 31 16:15:39 2015 +0100
Revision:
46:378357d7e90d
Parent:
USBDevice/TARGET_RENESAS/TARGET_RZ_A1H/src/userdef/usb0_function_userdef.c@42:4f589e246b9e
Synchronized with git revision 251f3f8b55a4dc98b831c80e032464ed45cce309

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

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

Who changed what in which revision?

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