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