I changed one line of code in the file with path name: USBDeviceHT/targets/TARGET_Maxim
Fork of USBDeviceHT by
targets/TARGET_Silicon_Labs/src/em_usbhal.c@6:c1f162fd7777, 2018-06-01 (annotated)
- Committer:
- dev_alexander
- Date:
- Fri Jun 01 21:43:55 2018 +0000
- Revision:
- 6:c1f162fd7777
- Parent:
- 0:a3ea811f80f2
Fixed Error with code not compiling due to an issue with there not being a (uint32_t) cast of a (void) pointer. Maxim was the only mbed vendor to not have this one (uint32_t) cast in the spot it was added to. Look into public repos for similar cases.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:a3ea811f80f2 | 1 | /**************************************************************************//** |
Helmut64 | 0:a3ea811f80f2 | 2 | * @file em_usbhal.c |
Helmut64 | 0:a3ea811f80f2 | 3 | * @brief USB protocol stack library, low level USB peripheral access. |
Helmut64 | 0:a3ea811f80f2 | 4 | * @version 3.20.14 |
Helmut64 | 0:a3ea811f80f2 | 5 | ****************************************************************************** |
Helmut64 | 0:a3ea811f80f2 | 6 | * @section License |
Helmut64 | 0:a3ea811f80f2 | 7 | * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> |
Helmut64 | 0:a3ea811f80f2 | 8 | ******************************************************************************* |
Helmut64 | 0:a3ea811f80f2 | 9 | * |
Helmut64 | 0:a3ea811f80f2 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Helmut64 | 0:a3ea811f80f2 | 11 | * you may not use this file except in compliance with the License. |
Helmut64 | 0:a3ea811f80f2 | 12 | * You may obtain a copy of the License at |
Helmut64 | 0:a3ea811f80f2 | 13 | * |
Helmut64 | 0:a3ea811f80f2 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
Helmut64 | 0:a3ea811f80f2 | 15 | * |
Helmut64 | 0:a3ea811f80f2 | 16 | * Unless required by applicable law or agreed to in writing, software |
Helmut64 | 0:a3ea811f80f2 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
Helmut64 | 0:a3ea811f80f2 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Helmut64 | 0:a3ea811f80f2 | 19 | * See the License for the specific language governing permissions and |
Helmut64 | 0:a3ea811f80f2 | 20 | * limitations under the License. |
Helmut64 | 0:a3ea811f80f2 | 21 | * |
Helmut64 | 0:a3ea811f80f2 | 22 | ******************************************************************************/ |
Helmut64 | 0:a3ea811f80f2 | 23 | |
Helmut64 | 0:a3ea811f80f2 | 24 | #include "em_device.h" |
Helmut64 | 0:a3ea811f80f2 | 25 | #if defined( USB_PRESENT ) && ( USB_COUNT == 1 ) |
Helmut64 | 0:a3ea811f80f2 | 26 | #include "em_usb.h" |
Helmut64 | 0:a3ea811f80f2 | 27 | #if defined( USB_DEVICE ) || defined( USB_HOST ) |
Helmut64 | 0:a3ea811f80f2 | 28 | |
Helmut64 | 0:a3ea811f80f2 | 29 | #include "em_usbtypes.h" |
Helmut64 | 0:a3ea811f80f2 | 30 | #include "em_usbhal.h" |
Helmut64 | 0:a3ea811f80f2 | 31 | #if defined( USB_DEVICE ) |
Helmut64 | 0:a3ea811f80f2 | 32 | #include "em_usbd.h" |
Helmut64 | 0:a3ea811f80f2 | 33 | #endif |
Helmut64 | 0:a3ea811f80f2 | 34 | #if defined( USB_HOST ) |
Helmut64 | 0:a3ea811f80f2 | 35 | #include "em_usbh.h" |
Helmut64 | 0:a3ea811f80f2 | 36 | #endif |
Helmut64 | 0:a3ea811f80f2 | 37 | #include "em_cmu.h" |
Helmut64 | 0:a3ea811f80f2 | 38 | #include "em_gpio.h" |
Helmut64 | 0:a3ea811f80f2 | 39 | |
Helmut64 | 0:a3ea811f80f2 | 40 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
Helmut64 | 0:a3ea811f80f2 | 41 | |
Helmut64 | 0:a3ea811f80f2 | 42 | #define EPABORT_BREAK_LOOP_COUNT 15000 /* Approx. 100 ms */ |
Helmut64 | 0:a3ea811f80f2 | 43 | |
Helmut64 | 0:a3ea811f80f2 | 44 | /* NOTE: The sequence of error message strings must agree with the */ |
Helmut64 | 0:a3ea811f80f2 | 45 | /* definition of USB_Status_TypeDef enum. */ |
Helmut64 | 0:a3ea811f80f2 | 46 | static const char * const errMsg[] = |
Helmut64 | 0:a3ea811f80f2 | 47 | { |
Helmut64 | 0:a3ea811f80f2 | 48 | [ USB_STATUS_OK ] = "No errors", |
Helmut64 | 0:a3ea811f80f2 | 49 | [ -USB_STATUS_REQ_ERR ] = "Setup request error", |
Helmut64 | 0:a3ea811f80f2 | 50 | [ -USB_STATUS_EP_BUSY ] = "Endpoint is busy", |
Helmut64 | 0:a3ea811f80f2 | 51 | [ -USB_STATUS_REQ_UNHANDLED ] = "Setup request not handled", |
Helmut64 | 0:a3ea811f80f2 | 52 | [ -USB_STATUS_ILLEGAL ] = "Illegal operation attempted", |
Helmut64 | 0:a3ea811f80f2 | 53 | [ -USB_STATUS_EP_STALLED ] = "Endpoint is stalled", |
Helmut64 | 0:a3ea811f80f2 | 54 | [ -USB_STATUS_EP_ABORTED ] = "Transfer aborted", |
Helmut64 | 0:a3ea811f80f2 | 55 | [ -USB_STATUS_EP_ERROR ] = "Transfer error", |
Helmut64 | 0:a3ea811f80f2 | 56 | [ -USB_STATUS_EP_NAK ] = "Endpoint NAK", |
Helmut64 | 0:a3ea811f80f2 | 57 | [ -USB_STATUS_DEVICE_UNCONFIGURED ] = "Device is not configured", |
Helmut64 | 0:a3ea811f80f2 | 58 | [ -USB_STATUS_DEVICE_SUSPENDED ] = "Device is suspended", |
Helmut64 | 0:a3ea811f80f2 | 59 | [ -USB_STATUS_DEVICE_RESET ] = "Device has been reset", |
Helmut64 | 0:a3ea811f80f2 | 60 | [ -USB_STATUS_TIMEOUT ] = "Transfer timeout", |
Helmut64 | 0:a3ea811f80f2 | 61 | [ -USB_STATUS_DEVICE_REMOVED ] = "Device removed", |
Helmut64 | 0:a3ea811f80f2 | 62 | [ -USB_STATUS_HC_BUSY ] = "Host channel is busy", |
Helmut64 | 0:a3ea811f80f2 | 63 | [ -USB_STATUS_DEVICE_MALFUNCTION ] = "Device malfunction", |
Helmut64 | 0:a3ea811f80f2 | 64 | [ -USB_STATUS_PORT_OVERCURRENT ] = "VBUS overcurrent", |
Helmut64 | 0:a3ea811f80f2 | 65 | }; |
Helmut64 | 0:a3ea811f80f2 | 66 | /** @endcond */ |
Helmut64 | 0:a3ea811f80f2 | 67 | |
Helmut64 | 0:a3ea811f80f2 | 68 | |
Helmut64 | 0:a3ea811f80f2 | 69 | /***************************************************************************//** |
Helmut64 | 0:a3ea811f80f2 | 70 | * @brief |
Helmut64 | 0:a3ea811f80f2 | 71 | * Return an error message string for a given error code. |
Helmut64 | 0:a3ea811f80f2 | 72 | * |
Helmut64 | 0:a3ea811f80f2 | 73 | * @param[in] error |
Helmut64 | 0:a3ea811f80f2 | 74 | * Error code, see \ref USB_Status_TypeDef. |
Helmut64 | 0:a3ea811f80f2 | 75 | * |
Helmut64 | 0:a3ea811f80f2 | 76 | * @return |
Helmut64 | 0:a3ea811f80f2 | 77 | * Error message string pointer. |
Helmut64 | 0:a3ea811f80f2 | 78 | ******************************************************************************/ |
Helmut64 | 0:a3ea811f80f2 | 79 | char *USB_GetErrorMsgString( int error ) |
Helmut64 | 0:a3ea811f80f2 | 80 | { |
Helmut64 | 0:a3ea811f80f2 | 81 | if ( error >= 0 ) |
Helmut64 | 0:a3ea811f80f2 | 82 | return (char*)errMsg[ 0 ]; |
Helmut64 | 0:a3ea811f80f2 | 83 | |
Helmut64 | 0:a3ea811f80f2 | 84 | return (char*)errMsg[ -error ]; |
Helmut64 | 0:a3ea811f80f2 | 85 | } |
Helmut64 | 0:a3ea811f80f2 | 86 | |
Helmut64 | 0:a3ea811f80f2 | 87 | |
Helmut64 | 0:a3ea811f80f2 | 88 | #if defined( USB_USE_PRINTF ) |
Helmut64 | 0:a3ea811f80f2 | 89 | /***************************************************************************//** |
Helmut64 | 0:a3ea811f80f2 | 90 | * @brief |
Helmut64 | 0:a3ea811f80f2 | 91 | * Format and print a text string given an error code, prepends an optional user |
Helmut64 | 0:a3ea811f80f2 | 92 | * supplied leader string. |
Helmut64 | 0:a3ea811f80f2 | 93 | * |
Helmut64 | 0:a3ea811f80f2 | 94 | * @param[in] pre |
Helmut64 | 0:a3ea811f80f2 | 95 | * Optional leader string to prepend to error message string. |
Helmut64 | 0:a3ea811f80f2 | 96 | * |
Helmut64 | 0:a3ea811f80f2 | 97 | * @param[in] error |
Helmut64 | 0:a3ea811f80f2 | 98 | * Error code, see \ref USB_Status_TypeDef. |
Helmut64 | 0:a3ea811f80f2 | 99 | ******************************************************************************/ |
Helmut64 | 0:a3ea811f80f2 | 100 | void USB_PrintErrorMsgString( char *pre, int error ) |
Helmut64 | 0:a3ea811f80f2 | 101 | { |
Helmut64 | 0:a3ea811f80f2 | 102 | if ( pre ) |
Helmut64 | 0:a3ea811f80f2 | 103 | { |
Helmut64 | 0:a3ea811f80f2 | 104 | USB_PRINTF( "%s", pre ); |
Helmut64 | 0:a3ea811f80f2 | 105 | } |
Helmut64 | 0:a3ea811f80f2 | 106 | |
Helmut64 | 0:a3ea811f80f2 | 107 | if ( error > USB_STATUS_OK ) |
Helmut64 | 0:a3ea811f80f2 | 108 | { |
Helmut64 | 0:a3ea811f80f2 | 109 | USB_PRINTF( "%d", error ); |
Helmut64 | 0:a3ea811f80f2 | 110 | } |
Helmut64 | 0:a3ea811f80f2 | 111 | else |
Helmut64 | 0:a3ea811f80f2 | 112 | { |
Helmut64 | 0:a3ea811f80f2 | 113 | USB_PRINTF( "%s", USB_GetErrorMsgString( error ) ); |
Helmut64 | 0:a3ea811f80f2 | 114 | } |
Helmut64 | 0:a3ea811f80f2 | 115 | } |
Helmut64 | 0:a3ea811f80f2 | 116 | #endif /* defined( USB_USE_PRINTF ) */ |
Helmut64 | 0:a3ea811f80f2 | 117 | |
Helmut64 | 0:a3ea811f80f2 | 118 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
Helmut64 | 0:a3ea811f80f2 | 119 | |
Helmut64 | 0:a3ea811f80f2 | 120 | #if defined( DEBUG_EFM_USER ) |
Helmut64 | 0:a3ea811f80f2 | 121 | static void PrintI( int i ) |
Helmut64 | 0:a3ea811f80f2 | 122 | { |
Helmut64 | 0:a3ea811f80f2 | 123 | #if !defined ( USER_PUTCHAR ) |
Helmut64 | 0:a3ea811f80f2 | 124 | (void)i; |
Helmut64 | 0:a3ea811f80f2 | 125 | #else |
Helmut64 | 0:a3ea811f80f2 | 126 | if ( i >= 10 ) |
Helmut64 | 0:a3ea811f80f2 | 127 | { |
Helmut64 | 0:a3ea811f80f2 | 128 | PrintI( i / 10 ); |
Helmut64 | 0:a3ea811f80f2 | 129 | } |
Helmut64 | 0:a3ea811f80f2 | 130 | |
Helmut64 | 0:a3ea811f80f2 | 131 | DEBUG_USB_API_PUTCHAR( ( i % 10 ) + '0' ); |
Helmut64 | 0:a3ea811f80f2 | 132 | #endif |
Helmut64 | 0:a3ea811f80f2 | 133 | } |
Helmut64 | 0:a3ea811f80f2 | 134 | |
Helmut64 | 0:a3ea811f80f2 | 135 | void assertEFM( const char *file, int line ) |
Helmut64 | 0:a3ea811f80f2 | 136 | { |
Helmut64 | 0:a3ea811f80f2 | 137 | #if !defined ( USER_PUTCHAR ) |
Helmut64 | 0:a3ea811f80f2 | 138 | (void)file; |
Helmut64 | 0:a3ea811f80f2 | 139 | #endif |
Helmut64 | 0:a3ea811f80f2 | 140 | |
Helmut64 | 0:a3ea811f80f2 | 141 | DEBUG_USB_API_PUTS( "\nASSERT " ); |
Helmut64 | 0:a3ea811f80f2 | 142 | DEBUG_USB_API_PUTS( file ); |
Helmut64 | 0:a3ea811f80f2 | 143 | DEBUG_USB_API_PUTCHAR( ' ' ); |
Helmut64 | 0:a3ea811f80f2 | 144 | PrintI( line ); |
Helmut64 | 0:a3ea811f80f2 | 145 | for(;;){} |
Helmut64 | 0:a3ea811f80f2 | 146 | } |
Helmut64 | 0:a3ea811f80f2 | 147 | #endif /* defined( DEBUG_EFM_USER ) */ |
Helmut64 | 0:a3ea811f80f2 | 148 | |
Helmut64 | 0:a3ea811f80f2 | 149 | #if defined ( USER_PUTCHAR ) |
Helmut64 | 0:a3ea811f80f2 | 150 | void USB_Puts( const char *p ) |
Helmut64 | 0:a3ea811f80f2 | 151 | { |
Helmut64 | 0:a3ea811f80f2 | 152 | while( *p ) |
Helmut64 | 0:a3ea811f80f2 | 153 | USB_PUTCHAR( *p++ ); |
Helmut64 | 0:a3ea811f80f2 | 154 | } |
Helmut64 | 0:a3ea811f80f2 | 155 | #endif /* defined ( USER_PUTCHAR ) */ |
Helmut64 | 0:a3ea811f80f2 | 156 | |
Helmut64 | 0:a3ea811f80f2 | 157 | void USBHAL_CoreReset( void ) |
Helmut64 | 0:a3ea811f80f2 | 158 | { |
Helmut64 | 0:a3ea811f80f2 | 159 | USB->PCGCCTL &= ~USB_PCGCCTL_STOPPCLK; |
Helmut64 | 0:a3ea811f80f2 | 160 | USB->PCGCCTL &= ~(USB_PCGCCTL_PWRCLMP | USB_PCGCCTL_RSTPDWNMODULE); |
Helmut64 | 0:a3ea811f80f2 | 161 | |
Helmut64 | 0:a3ea811f80f2 | 162 | /* Core Soft Reset */ |
Helmut64 | 0:a3ea811f80f2 | 163 | USB->GRSTCTL |= USB_GRSTCTL_CSFTRST; |
Helmut64 | 0:a3ea811f80f2 | 164 | while ( USB->GRSTCTL & USB_GRSTCTL_CSFTRST ) {} |
Helmut64 | 0:a3ea811f80f2 | 165 | |
Helmut64 | 0:a3ea811f80f2 | 166 | USBTIMER_DelayUs( 1 ); |
Helmut64 | 0:a3ea811f80f2 | 167 | |
Helmut64 | 0:a3ea811f80f2 | 168 | /* Wait for AHB master IDLE state. */ |
Helmut64 | 0:a3ea811f80f2 | 169 | while ( !( USB->GRSTCTL & USB_GRSTCTL_AHBIDLE ) ) {} |
Helmut64 | 0:a3ea811f80f2 | 170 | } |
Helmut64 | 0:a3ea811f80f2 | 171 | |
Helmut64 | 0:a3ea811f80f2 | 172 | #ifdef USB_DEVICE |
Helmut64 | 0:a3ea811f80f2 | 173 | void USBDHAL_Connect( void ) |
Helmut64 | 0:a3ea811f80f2 | 174 | { |
Helmut64 | 0:a3ea811f80f2 | 175 | USB->DCTL &= ~( DCTL_WO_BITMASK | USB_DCTL_SFTDISCON ); |
Helmut64 | 0:a3ea811f80f2 | 176 | } |
Helmut64 | 0:a3ea811f80f2 | 177 | |
Helmut64 | 0:a3ea811f80f2 | 178 | USB_Status_TypeDef USBDHAL_CoreInit( uint32_t totalRxFifoSize, |
Helmut64 | 0:a3ea811f80f2 | 179 | uint32_t totalTxFifoSize ) |
Helmut64 | 0:a3ea811f80f2 | 180 | { |
Helmut64 | 0:a3ea811f80f2 | 181 | uint8_t i, j; |
Helmut64 | 0:a3ea811f80f2 | 182 | uint16_t start, depth; |
Helmut64 | 0:a3ea811f80f2 | 183 | USBD_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 184 | |
Helmut64 | 0:a3ea811f80f2 | 185 | #if !defined( USB_VBUS_SWITCH_NOT_PRESENT ) |
Helmut64 | 0:a3ea811f80f2 | 186 | CMU_ClockEnable( cmuClock_GPIO, true ); |
Helmut64 | 0:a3ea811f80f2 | 187 | GPIO_PinModeSet( gpioPortF, 5, gpioModePushPull, 0 ); /* Enable VBUSEN pin */ |
Helmut64 | 0:a3ea811f80f2 | 188 | USB->ROUTE = USB_ROUTE_PHYPEN | USB_ROUTE_VBUSENPEN; /* Enable PHY pins. */ |
Helmut64 | 0:a3ea811f80f2 | 189 | #else |
Helmut64 | 0:a3ea811f80f2 | 190 | USB->ROUTE = USB_ROUTE_PHYPEN; /* Enable PHY pins. */ |
Helmut64 | 0:a3ea811f80f2 | 191 | #endif |
Helmut64 | 0:a3ea811f80f2 | 192 | |
Helmut64 | 0:a3ea811f80f2 | 193 | USBHAL_CoreReset(); /* Reset USB core */ |
Helmut64 | 0:a3ea811f80f2 | 194 | |
Helmut64 | 0:a3ea811f80f2 | 195 | #if defined( USB_GUSBCFG_FORCEHSTMODE ) |
Helmut64 | 0:a3ea811f80f2 | 196 | /* Force Device Mode */ |
Helmut64 | 0:a3ea811f80f2 | 197 | USB->GUSBCFG = ( USB->GUSBCFG & |
Helmut64 | 0:a3ea811f80f2 | 198 | ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEHSTMODE ) ) | |
Helmut64 | 0:a3ea811f80f2 | 199 | USB_GUSBCFG_FORCEDEVMODE; |
Helmut64 | 0:a3ea811f80f2 | 200 | #endif |
Helmut64 | 0:a3ea811f80f2 | 201 | |
Helmut64 | 0:a3ea811f80f2 | 202 | USBTIMER_DelayMs( 50 ); |
Helmut64 | 0:a3ea811f80f2 | 203 | |
Helmut64 | 0:a3ea811f80f2 | 204 | /* Set device speed */ |
Helmut64 | 0:a3ea811f80f2 | 205 | USB->DCFG = ( USB->DCFG & ~_USB_DCFG_DEVSPD_MASK ) | 3; /* Full speed PHY */ |
Helmut64 | 0:a3ea811f80f2 | 206 | |
Helmut64 | 0:a3ea811f80f2 | 207 | /* Stall on non-zero len status OUT packets (ctrl transfers). */ |
Helmut64 | 0:a3ea811f80f2 | 208 | USB->DCFG |= USB_DCFG_NZSTSOUTHSHK; |
Helmut64 | 0:a3ea811f80f2 | 209 | |
Helmut64 | 0:a3ea811f80f2 | 210 | /* Set periodic frame interval to 80% */ |
Helmut64 | 0:a3ea811f80f2 | 211 | USB->DCFG &= ~_USB_DCFG_PERFRINT_MASK; |
Helmut64 | 0:a3ea811f80f2 | 212 | |
Helmut64 | 0:a3ea811f80f2 | 213 | USB->GAHBCFG = ( USB->GAHBCFG & ~_USB_GAHBCFG_HBSTLEN_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 214 | USB_GAHBCFG_DMAEN | USB_GAHBCFG_HBSTLEN_INCR; |
Helmut64 | 0:a3ea811f80f2 | 215 | |
Helmut64 | 0:a3ea811f80f2 | 216 | /* Ignore frame numbers on ISO transfers. */ |
Helmut64 | 0:a3ea811f80f2 | 217 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_IGNRFRMNUM; |
Helmut64 | 0:a3ea811f80f2 | 218 | |
Helmut64 | 0:a3ea811f80f2 | 219 | /* Set Rx FIFO size */ |
Helmut64 | 0:a3ea811f80f2 | 220 | start = EFM32_MAX( totalRxFifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
Helmut64 | 0:a3ea811f80f2 | 221 | USB->GRXFSIZ = ( start << _USB_GRXFSIZ_RXFDEP_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 222 | _USB_GRXFSIZ_RXFDEP_MASK; |
Helmut64 | 0:a3ea811f80f2 | 223 | |
Helmut64 | 0:a3ea811f80f2 | 224 | /* Set Tx EP0 FIFO size */ |
Helmut64 | 0:a3ea811f80f2 | 225 | depth = EFM32_MAX( dev->ep[ 0 ].fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
Helmut64 | 0:a3ea811f80f2 | 226 | USB->GNPTXFSIZ = ( ( depth << _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 227 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 228 | ( ( start << _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 229 | _USB_GNPTXFSIZ_NPTXFSTADDR_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 230 | |
Helmut64 | 0:a3ea811f80f2 | 231 | |
Helmut64 | 0:a3ea811f80f2 | 232 | /* Set Tx EP FIFO sizes for all IN ep's */ |
Helmut64 | 0:a3ea811f80f2 | 233 | for ( j = 1; j <= MAX_NUM_TX_FIFOS; j++ ) |
Helmut64 | 0:a3ea811f80f2 | 234 | { |
Helmut64 | 0:a3ea811f80f2 | 235 | for ( i = 1; i <= MAX_NUM_IN_EPS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 236 | { |
Helmut64 | 0:a3ea811f80f2 | 237 | ep = USBD_GetEpFromAddr( USB_SETUP_DIR_MASK | i ); |
Helmut64 | 0:a3ea811f80f2 | 238 | if ( ep ) /* Is EP in use ? */ |
Helmut64 | 0:a3ea811f80f2 | 239 | { |
Helmut64 | 0:a3ea811f80f2 | 240 | if ( ep->txFifoNum == j ) /* Is it correct FIFO number ? */ |
Helmut64 | 0:a3ea811f80f2 | 241 | { |
Helmut64 | 0:a3ea811f80f2 | 242 | start += depth; |
Helmut64 | 0:a3ea811f80f2 | 243 | depth = EFM32_MAX( ep->fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
Helmut64 | 0:a3ea811f80f2 | 244 | USB_DIEPTXFS[ ep->txFifoNum - 1 ] = |
Helmut64 | 0:a3ea811f80f2 | 245 | ( depth << _USB_DIEPTXF1_INEPNTXFDEP_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 246 | ( start & _USB_DIEPTXF1_INEPNTXFSTADDR_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 247 | } |
Helmut64 | 0:a3ea811f80f2 | 248 | } |
Helmut64 | 0:a3ea811f80f2 | 249 | } |
Helmut64 | 0:a3ea811f80f2 | 250 | } |
Helmut64 | 0:a3ea811f80f2 | 251 | |
Helmut64 | 0:a3ea811f80f2 | 252 | if ( totalRxFifoSize + totalTxFifoSize > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
Helmut64 | 0:a3ea811f80f2 | 253 | return USB_STATUS_ILLEGAL; |
Helmut64 | 0:a3ea811f80f2 | 254 | |
Helmut64 | 0:a3ea811f80f2 | 255 | if ( start > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
Helmut64 | 0:a3ea811f80f2 | 256 | return USB_STATUS_ILLEGAL; |
Helmut64 | 0:a3ea811f80f2 | 257 | |
Helmut64 | 0:a3ea811f80f2 | 258 | /* Flush the FIFO's */ |
Helmut64 | 0:a3ea811f80f2 | 259 | USBHAL_FlushTxFifo( 0x10 ); /* All Tx FIFO's */ |
Helmut64 | 0:a3ea811f80f2 | 260 | USBHAL_FlushRxFifo(); /* The Rx FIFO */ |
Helmut64 | 0:a3ea811f80f2 | 261 | |
Helmut64 | 0:a3ea811f80f2 | 262 | /* Disable all device interrupts */ |
Helmut64 | 0:a3ea811f80f2 | 263 | USB->DIEPMSK = 0; |
Helmut64 | 0:a3ea811f80f2 | 264 | USB->DOEPMSK = 0; |
Helmut64 | 0:a3ea811f80f2 | 265 | USB->DAINTMSK = 0; |
Helmut64 | 0:a3ea811f80f2 | 266 | USB->DIEPEMPMSK = 0; |
Helmut64 | 0:a3ea811f80f2 | 267 | |
Helmut64 | 0:a3ea811f80f2 | 268 | /* Disable all EP's, clear all EP ints. */ |
Helmut64 | 0:a3ea811f80f2 | 269 | for ( i = 0; i <= MAX_NUM_IN_EPS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 270 | { |
Helmut64 | 0:a3ea811f80f2 | 271 | USB_DINEPS[ i ].CTL = 0; |
Helmut64 | 0:a3ea811f80f2 | 272 | USB_DINEPS[ i ].TSIZ = 0; |
Helmut64 | 0:a3ea811f80f2 | 273 | USB_DINEPS[ i ].INT = 0xFFFFFFFF; |
Helmut64 | 0:a3ea811f80f2 | 274 | } |
Helmut64 | 0:a3ea811f80f2 | 275 | |
Helmut64 | 0:a3ea811f80f2 | 276 | for ( i = 0; i <= MAX_NUM_OUT_EPS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 277 | { |
Helmut64 | 0:a3ea811f80f2 | 278 | USB_DOUTEPS[ i ].CTL = 0; |
Helmut64 | 0:a3ea811f80f2 | 279 | USB_DOUTEPS[ i ].TSIZ = 0; |
Helmut64 | 0:a3ea811f80f2 | 280 | USB_DOUTEPS[ i ].INT = 0xFFFFFFFF; |
Helmut64 | 0:a3ea811f80f2 | 281 | } |
Helmut64 | 0:a3ea811f80f2 | 282 | |
Helmut64 | 0:a3ea811f80f2 | 283 | #if ( USB_DCTL_SFTDISCON_DEFAULT != 0 ) |
Helmut64 | 0:a3ea811f80f2 | 284 | USBD_Connect(); |
Helmut64 | 0:a3ea811f80f2 | 285 | #endif |
Helmut64 | 0:a3ea811f80f2 | 286 | |
Helmut64 | 0:a3ea811f80f2 | 287 | /* Enable VREGO sense. */ |
Helmut64 | 0:a3ea811f80f2 | 288 | USB->CTRL |= USB_CTRL_VREGOSEN; |
Helmut64 | 0:a3ea811f80f2 | 289 | USB->IFC = USB_IFC_VREGOSH | USB_IFC_VREGOSL; |
Helmut64 | 0:a3ea811f80f2 | 290 | USB->IEN = USB_IFC_VREGOSH | USB_IFC_VREGOSL; |
Helmut64 | 0:a3ea811f80f2 | 291 | /* Force a VREGO interrupt. */ |
Helmut64 | 0:a3ea811f80f2 | 292 | if ( USB->STATUS & USB_STATUS_VREGOS) |
Helmut64 | 0:a3ea811f80f2 | 293 | USB->IFS = USB_IFS_VREGOSH; |
Helmut64 | 0:a3ea811f80f2 | 294 | else |
Helmut64 | 0:a3ea811f80f2 | 295 | USB->IFS = USB_IFS_VREGOSL; |
Helmut64 | 0:a3ea811f80f2 | 296 | |
Helmut64 | 0:a3ea811f80f2 | 297 | return USB_STATUS_OK; |
Helmut64 | 0:a3ea811f80f2 | 298 | } |
Helmut64 | 0:a3ea811f80f2 | 299 | |
Helmut64 | 0:a3ea811f80f2 | 300 | USB_Status_TypeDef USBDHAL_ReconfigureFifos( uint32_t totalRxFifoSize, |
Helmut64 | 0:a3ea811f80f2 | 301 | uint32_t totalTxFifoSize ) |
Helmut64 | 0:a3ea811f80f2 | 302 | { |
Helmut64 | 0:a3ea811f80f2 | 303 | uint8_t i, j; |
Helmut64 | 0:a3ea811f80f2 | 304 | uint16_t start, depth; |
Helmut64 | 0:a3ea811f80f2 | 305 | USBD_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 306 | |
Helmut64 | 0:a3ea811f80f2 | 307 | /* Set Rx FIFO size */ |
Helmut64 | 0:a3ea811f80f2 | 308 | start = EFM32_MAX( totalRxFifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
Helmut64 | 0:a3ea811f80f2 | 309 | USB->GRXFSIZ = ( start << _USB_GRXFSIZ_RXFDEP_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 310 | _USB_GRXFSIZ_RXFDEP_MASK; |
Helmut64 | 0:a3ea811f80f2 | 311 | |
Helmut64 | 0:a3ea811f80f2 | 312 | /* Set Tx EP0 FIFO size */ |
Helmut64 | 0:a3ea811f80f2 | 313 | depth = EFM32_MAX( dev->ep[ 0 ].fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
Helmut64 | 0:a3ea811f80f2 | 314 | USB->GNPTXFSIZ = ( ( depth << _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 315 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 316 | ( ( start << _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 317 | _USB_GNPTXFSIZ_NPTXFSTADDR_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 318 | |
Helmut64 | 0:a3ea811f80f2 | 319 | |
Helmut64 | 0:a3ea811f80f2 | 320 | /* Set Tx EP FIFO sizes for all IN ep's */ |
Helmut64 | 0:a3ea811f80f2 | 321 | for ( j = 1; j <= MAX_NUM_TX_FIFOS; j++ ) |
Helmut64 | 0:a3ea811f80f2 | 322 | { |
Helmut64 | 0:a3ea811f80f2 | 323 | for ( i = 1; i <= MAX_NUM_IN_EPS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 324 | { |
Helmut64 | 0:a3ea811f80f2 | 325 | ep = USBD_GetEpFromAddr( USB_SETUP_DIR_MASK | i ); |
Helmut64 | 0:a3ea811f80f2 | 326 | if ( ep ) /* Is EP in use ? */ |
Helmut64 | 0:a3ea811f80f2 | 327 | { |
Helmut64 | 0:a3ea811f80f2 | 328 | if ( ep->txFifoNum == j ) /* Is it correct FIFO number ? */ |
Helmut64 | 0:a3ea811f80f2 | 329 | { |
Helmut64 | 0:a3ea811f80f2 | 330 | start += depth; |
Helmut64 | 0:a3ea811f80f2 | 331 | depth = EFM32_MAX( ep->fifoSize, MIN_EP_FIFO_SIZE_INWORDS ); |
Helmut64 | 0:a3ea811f80f2 | 332 | USB_DIEPTXFS[ ep->txFifoNum - 1 ] = |
Helmut64 | 0:a3ea811f80f2 | 333 | ( depth << _USB_DIEPTXF1_INEPNTXFDEP_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 334 | ( start & _USB_DIEPTXF1_INEPNTXFSTADDR_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 335 | } |
Helmut64 | 0:a3ea811f80f2 | 336 | } |
Helmut64 | 0:a3ea811f80f2 | 337 | } |
Helmut64 | 0:a3ea811f80f2 | 338 | } |
Helmut64 | 0:a3ea811f80f2 | 339 | |
Helmut64 | 0:a3ea811f80f2 | 340 | if ( totalRxFifoSize + totalTxFifoSize > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
Helmut64 | 0:a3ea811f80f2 | 341 | return USB_STATUS_ILLEGAL; |
Helmut64 | 0:a3ea811f80f2 | 342 | |
Helmut64 | 0:a3ea811f80f2 | 343 | if ( start > MAX_DEVICE_FIFO_SIZE_INWORDS ) |
Helmut64 | 0:a3ea811f80f2 | 344 | return USB_STATUS_ILLEGAL; |
Helmut64 | 0:a3ea811f80f2 | 345 | |
Helmut64 | 0:a3ea811f80f2 | 346 | /* Flush the FIFO's */ |
Helmut64 | 0:a3ea811f80f2 | 347 | USBHAL_FlushTxFifo( 0x10 ); /* All Tx FIFO's */ |
Helmut64 | 0:a3ea811f80f2 | 348 | USBHAL_FlushRxFifo(); /* The Rx FIFO */ |
Helmut64 | 0:a3ea811f80f2 | 349 | |
Helmut64 | 0:a3ea811f80f2 | 350 | return USB_STATUS_OK; |
Helmut64 | 0:a3ea811f80f2 | 351 | } |
Helmut64 | 0:a3ea811f80f2 | 352 | |
Helmut64 | 0:a3ea811f80f2 | 353 | void USBDHAL_Disconnect( void ) |
Helmut64 | 0:a3ea811f80f2 | 354 | { |
Helmut64 | 0:a3ea811f80f2 | 355 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_SFTDISCON; |
Helmut64 | 0:a3ea811f80f2 | 356 | } |
Helmut64 | 0:a3ea811f80f2 | 357 | |
Helmut64 | 0:a3ea811f80f2 | 358 | void USBDHAL_AbortEpIn( USBD_Ep_TypeDef *ep ) |
Helmut64 | 0:a3ea811f80f2 | 359 | { |
Helmut64 | 0:a3ea811f80f2 | 360 | /* Clear epdis & inepnakeff INT's */ |
Helmut64 | 0:a3ea811f80f2 | 361 | USB_DINEPS[ ep->num ].INT |= USB_DIEP_INT_EPDISBLD | |
Helmut64 | 0:a3ea811f80f2 | 362 | USB_DIEP_INT_INEPNAKEFF; |
Helmut64 | 0:a3ea811f80f2 | 363 | |
Helmut64 | 0:a3ea811f80f2 | 364 | /* Enable epdis & inepnakeff INT's */ |
Helmut64 | 0:a3ea811f80f2 | 365 | USB->DIEPMSK |= USB_DIEPMSK_EPDISBLDMSK | USB_DIEPMSK_INEPNAKEFFMSK; |
Helmut64 | 0:a3ea811f80f2 | 366 | USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL & |
Helmut64 | 0:a3ea811f80f2 | 367 | ~DEPCTL_WO_BITMASK ) | |
Helmut64 | 0:a3ea811f80f2 | 368 | USB_DIEP_CTL_SNAK; |
Helmut64 | 0:a3ea811f80f2 | 369 | |
Helmut64 | 0:a3ea811f80f2 | 370 | /* Wait for inepnakeff INT */ |
Helmut64 | 0:a3ea811f80f2 | 371 | while ( !( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_INEPNAKEFF ) ) {} |
Helmut64 | 0:a3ea811f80f2 | 372 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_INEPNAKEFF; |
Helmut64 | 0:a3ea811f80f2 | 373 | USB->DIEPMSK &= ~USB_DIEPMSK_INEPNAKEFFMSK; |
Helmut64 | 0:a3ea811f80f2 | 374 | |
Helmut64 | 0:a3ea811f80f2 | 375 | DEBUG_USB_INT_LO_PUTCHAR( '.' ); |
Helmut64 | 0:a3ea811f80f2 | 376 | |
Helmut64 | 0:a3ea811f80f2 | 377 | USBDHAL_SetEPDISNAK( ep ); |
Helmut64 | 0:a3ea811f80f2 | 378 | /* Wait for epdis INT */ |
Helmut64 | 0:a3ea811f80f2 | 379 | while ( !( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_EPDISBLD ) ) {} |
Helmut64 | 0:a3ea811f80f2 | 380 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_EPDISBLD; |
Helmut64 | 0:a3ea811f80f2 | 381 | USB->DIEPMSK &= ~USB_DIEPMSK_EPDISBLDMSK; |
Helmut64 | 0:a3ea811f80f2 | 382 | USBHAL_FlushTxFifo( ep->txFifoNum ); |
Helmut64 | 0:a3ea811f80f2 | 383 | |
Helmut64 | 0:a3ea811f80f2 | 384 | /* Clear any interrupts generated by the abort sequence. */ |
Helmut64 | 0:a3ea811f80f2 | 385 | NVIC_ClearPendingIRQ( USB_IRQn ); |
Helmut64 | 0:a3ea811f80f2 | 386 | |
Helmut64 | 0:a3ea811f80f2 | 387 | DEBUG_USB_INT_LO_PUTCHAR( '.' ); |
Helmut64 | 0:a3ea811f80f2 | 388 | } |
Helmut64 | 0:a3ea811f80f2 | 389 | |
Helmut64 | 0:a3ea811f80f2 | 390 | void USBDHAL_AbortEpOut( USBD_Ep_TypeDef *ep ) |
Helmut64 | 0:a3ea811f80f2 | 391 | { |
Helmut64 | 0:a3ea811f80f2 | 392 | int cnt; |
Helmut64 | 0:a3ea811f80f2 | 393 | |
Helmut64 | 0:a3ea811f80f2 | 394 | /* Clear epdis INT's */ |
Helmut64 | 0:a3ea811f80f2 | 395 | USB_DOUTEPS[ ep->num ].INT |= USB_DOEP_INT_EPDISBLD; |
Helmut64 | 0:a3ea811f80f2 | 396 | |
Helmut64 | 0:a3ea811f80f2 | 397 | /* Clear Global OUT NAK if already set */ |
Helmut64 | 0:a3ea811f80f2 | 398 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
Helmut64 | 0:a3ea811f80f2 | 399 | USB->GINTMSK |= USB_GINTMSK_GOUTNAKEFFMSK; /* Enable GOUTNAKEFF int */ |
Helmut64 | 0:a3ea811f80f2 | 400 | |
Helmut64 | 0:a3ea811f80f2 | 401 | /* Set Global OUT NAK */ |
Helmut64 | 0:a3ea811f80f2 | 402 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_SGOUTNAK; |
Helmut64 | 0:a3ea811f80f2 | 403 | |
Helmut64 | 0:a3ea811f80f2 | 404 | /* Wait for goutnakeff */ |
Helmut64 | 0:a3ea811f80f2 | 405 | cnt = EPABORT_BREAK_LOOP_COUNT; |
Helmut64 | 0:a3ea811f80f2 | 406 | while ( !( USB->GINTSTS & USB_GINTSTS_GOUTNAKEFF ) && cnt ) |
Helmut64 | 0:a3ea811f80f2 | 407 | { |
Helmut64 | 0:a3ea811f80f2 | 408 | cnt--; |
Helmut64 | 0:a3ea811f80f2 | 409 | } |
Helmut64 | 0:a3ea811f80f2 | 410 | |
Helmut64 | 0:a3ea811f80f2 | 411 | USB->GINTMSK &= ~USB_GINTMSK_GOUTNAKEFFMSK; /* Disable GOUTNAKEFF int */ |
Helmut64 | 0:a3ea811f80f2 | 412 | USB->DOEPMSK |= USB_DOEPMSK_EPDISBLDMSK; /* Enable EPDIS interrupt */ |
Helmut64 | 0:a3ea811f80f2 | 413 | |
Helmut64 | 0:a3ea811f80f2 | 414 | DEBUG_USB_INT_LO_PUTCHAR( ',' ); |
Helmut64 | 0:a3ea811f80f2 | 415 | |
Helmut64 | 0:a3ea811f80f2 | 416 | USBDHAL_SetEPDISNAK( ep ); /* Disable ep */ |
Helmut64 | 0:a3ea811f80f2 | 417 | |
Helmut64 | 0:a3ea811f80f2 | 418 | /* Wait for epdis INT */ |
Helmut64 | 0:a3ea811f80f2 | 419 | cnt = EPABORT_BREAK_LOOP_COUNT; |
Helmut64 | 0:a3ea811f80f2 | 420 | while ( !( USBDHAL_GetOutEpInts( ep ) & USB_DOEP_INT_EPDISBLD ) && cnt ) |
Helmut64 | 0:a3ea811f80f2 | 421 | { |
Helmut64 | 0:a3ea811f80f2 | 422 | cnt--; |
Helmut64 | 0:a3ea811f80f2 | 423 | } |
Helmut64 | 0:a3ea811f80f2 | 424 | |
Helmut64 | 0:a3ea811f80f2 | 425 | USB_DOUTEPS[ ep->num ].INT = USB_DOEP_INT_EPDISBLD; |
Helmut64 | 0:a3ea811f80f2 | 426 | USB->DOEPMSK &= ~USB_DOEPMSK_EPDISBLDMSK; /* Disable EPDIS interrupt */ |
Helmut64 | 0:a3ea811f80f2 | 427 | |
Helmut64 | 0:a3ea811f80f2 | 428 | /* Clear Global OUT NAK */ |
Helmut64 | 0:a3ea811f80f2 | 429 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
Helmut64 | 0:a3ea811f80f2 | 430 | |
Helmut64 | 0:a3ea811f80f2 | 431 | /* Clear any interrupts generated by the abort sequence. */ |
Helmut64 | 0:a3ea811f80f2 | 432 | NVIC_ClearPendingIRQ( USB_IRQn ); |
Helmut64 | 0:a3ea811f80f2 | 433 | |
Helmut64 | 0:a3ea811f80f2 | 434 | DEBUG_USB_INT_LO_PUTCHAR( ',' ); |
Helmut64 | 0:a3ea811f80f2 | 435 | } |
Helmut64 | 0:a3ea811f80f2 | 436 | |
Helmut64 | 0:a3ea811f80f2 | 437 | void USBDHAL_AbortAllEps( void ) |
Helmut64 | 0:a3ea811f80f2 | 438 | { |
Helmut64 | 0:a3ea811f80f2 | 439 | int i, cnt; |
Helmut64 | 0:a3ea811f80f2 | 440 | USBD_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 441 | uint16_t im, om, inmask=0, outmask=0; |
Helmut64 | 0:a3ea811f80f2 | 442 | |
Helmut64 | 0:a3ea811f80f2 | 443 | /* Clear epdis & inepnakeff INT's */ |
Helmut64 | 0:a3ea811f80f2 | 444 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 445 | { |
Helmut64 | 0:a3ea811f80f2 | 446 | ep = &dev->ep[i]; |
Helmut64 | 0:a3ea811f80f2 | 447 | if ( ep->state != D_EP_IDLE ) |
Helmut64 | 0:a3ea811f80f2 | 448 | { |
Helmut64 | 0:a3ea811f80f2 | 449 | if ( ep->in ) |
Helmut64 | 0:a3ea811f80f2 | 450 | { |
Helmut64 | 0:a3ea811f80f2 | 451 | inmask |= ep->mask; |
Helmut64 | 0:a3ea811f80f2 | 452 | USB_DINEPS[ ep->num ].INT |= USB_DIEP_INT_EPDISBLD | |
Helmut64 | 0:a3ea811f80f2 | 453 | USB_DIEP_INT_INEPNAKEFF; |
Helmut64 | 0:a3ea811f80f2 | 454 | } |
Helmut64 | 0:a3ea811f80f2 | 455 | else |
Helmut64 | 0:a3ea811f80f2 | 456 | { |
Helmut64 | 0:a3ea811f80f2 | 457 | outmask |= ep->mask; |
Helmut64 | 0:a3ea811f80f2 | 458 | USB_DOUTEPS[ ep->num ].INT |= USB_DOEP_INT_EPDISBLD; |
Helmut64 | 0:a3ea811f80f2 | 459 | } |
Helmut64 | 0:a3ea811f80f2 | 460 | } |
Helmut64 | 0:a3ea811f80f2 | 461 | } |
Helmut64 | 0:a3ea811f80f2 | 462 | |
Helmut64 | 0:a3ea811f80f2 | 463 | if ( inmask ) |
Helmut64 | 0:a3ea811f80f2 | 464 | { |
Helmut64 | 0:a3ea811f80f2 | 465 | /* Enable epdis & inepnakeff INT's */ |
Helmut64 | 0:a3ea811f80f2 | 466 | USB->DIEPMSK |= USB_DIEPMSK_EPDISBLDMSK | USB_DIEPMSK_INEPNAKEFFMSK; |
Helmut64 | 0:a3ea811f80f2 | 467 | |
Helmut64 | 0:a3ea811f80f2 | 468 | /* Set NAK on all IN ep's */ |
Helmut64 | 0:a3ea811f80f2 | 469 | im = inmask; |
Helmut64 | 0:a3ea811f80f2 | 470 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 471 | { |
Helmut64 | 0:a3ea811f80f2 | 472 | ep = &dev->ep[i]; |
Helmut64 | 0:a3ea811f80f2 | 473 | if ( im & ep->mask ) |
Helmut64 | 0:a3ea811f80f2 | 474 | { |
Helmut64 | 0:a3ea811f80f2 | 475 | USB_DINEPS[ ep->num ].CTL = ( USB_DINEPS[ ep->num ].CTL & |
Helmut64 | 0:a3ea811f80f2 | 476 | ~DEPCTL_WO_BITMASK ) | |
Helmut64 | 0:a3ea811f80f2 | 477 | USB_DIEP_CTL_SNAK; |
Helmut64 | 0:a3ea811f80f2 | 478 | } |
Helmut64 | 0:a3ea811f80f2 | 479 | } |
Helmut64 | 0:a3ea811f80f2 | 480 | } |
Helmut64 | 0:a3ea811f80f2 | 481 | |
Helmut64 | 0:a3ea811f80f2 | 482 | if ( outmask ) |
Helmut64 | 0:a3ea811f80f2 | 483 | { |
Helmut64 | 0:a3ea811f80f2 | 484 | /* Clear Global OUT NAK if already set */ |
Helmut64 | 0:a3ea811f80f2 | 485 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
Helmut64 | 0:a3ea811f80f2 | 486 | |
Helmut64 | 0:a3ea811f80f2 | 487 | USB->GINTMSK |= USB_GINTMSK_GOUTNAKEFFMSK; /* Enable GOUTNAKEFF int */ |
Helmut64 | 0:a3ea811f80f2 | 488 | |
Helmut64 | 0:a3ea811f80f2 | 489 | /* Set Global OUT NAK */ |
Helmut64 | 0:a3ea811f80f2 | 490 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_SGOUTNAK; |
Helmut64 | 0:a3ea811f80f2 | 491 | |
Helmut64 | 0:a3ea811f80f2 | 492 | /* Wait for goutnakeff */ |
Helmut64 | 0:a3ea811f80f2 | 493 | cnt = EPABORT_BREAK_LOOP_COUNT; |
Helmut64 | 0:a3ea811f80f2 | 494 | while ( !( USB->GINTSTS & USB_GINTSTS_GOUTNAKEFF ) && cnt ) |
Helmut64 | 0:a3ea811f80f2 | 495 | { |
Helmut64 | 0:a3ea811f80f2 | 496 | cnt--; |
Helmut64 | 0:a3ea811f80f2 | 497 | } |
Helmut64 | 0:a3ea811f80f2 | 498 | USB->GINTMSK &= ~USB_GINTMSK_GOUTNAKEFFMSK; /* Disable GOUTNAKEFF int */ |
Helmut64 | 0:a3ea811f80f2 | 499 | USB->DOEPMSK |= USB_DOEPMSK_EPDISBLDMSK; /* Enable EPDIS interrupt */ |
Helmut64 | 0:a3ea811f80f2 | 500 | } |
Helmut64 | 0:a3ea811f80f2 | 501 | |
Helmut64 | 0:a3ea811f80f2 | 502 | if ( inmask ) |
Helmut64 | 0:a3ea811f80f2 | 503 | { |
Helmut64 | 0:a3ea811f80f2 | 504 | /* Wait for inepnakeff INT on all IN ep's */ |
Helmut64 | 0:a3ea811f80f2 | 505 | im = inmask; |
Helmut64 | 0:a3ea811f80f2 | 506 | cnt = EPABORT_BREAK_LOOP_COUNT; |
Helmut64 | 0:a3ea811f80f2 | 507 | do |
Helmut64 | 0:a3ea811f80f2 | 508 | { |
Helmut64 | 0:a3ea811f80f2 | 509 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 510 | { |
Helmut64 | 0:a3ea811f80f2 | 511 | ep = &dev->ep[i]; |
Helmut64 | 0:a3ea811f80f2 | 512 | if ( im & ep->mask ) |
Helmut64 | 0:a3ea811f80f2 | 513 | { |
Helmut64 | 0:a3ea811f80f2 | 514 | if ( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_INEPNAKEFF ) |
Helmut64 | 0:a3ea811f80f2 | 515 | { |
Helmut64 | 0:a3ea811f80f2 | 516 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_INEPNAKEFF; |
Helmut64 | 0:a3ea811f80f2 | 517 | im &= ~ep->mask; |
Helmut64 | 0:a3ea811f80f2 | 518 | } |
Helmut64 | 0:a3ea811f80f2 | 519 | } |
Helmut64 | 0:a3ea811f80f2 | 520 | } |
Helmut64 | 0:a3ea811f80f2 | 521 | cnt--; |
Helmut64 | 0:a3ea811f80f2 | 522 | } while ( im && cnt ); |
Helmut64 | 0:a3ea811f80f2 | 523 | USB->DIEPMSK &= ~USB_DIEPMSK_INEPNAKEFFMSK; |
Helmut64 | 0:a3ea811f80f2 | 524 | } |
Helmut64 | 0:a3ea811f80f2 | 525 | |
Helmut64 | 0:a3ea811f80f2 | 526 | DEBUG_USB_INT_LO_PUTCHAR( '\'' ); |
Helmut64 | 0:a3ea811f80f2 | 527 | |
Helmut64 | 0:a3ea811f80f2 | 528 | /* Disable ep's */ |
Helmut64 | 0:a3ea811f80f2 | 529 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 530 | { |
Helmut64 | 0:a3ea811f80f2 | 531 | ep = &dev->ep[i]; |
Helmut64 | 0:a3ea811f80f2 | 532 | if ( ep->state != D_EP_IDLE ) |
Helmut64 | 0:a3ea811f80f2 | 533 | { |
Helmut64 | 0:a3ea811f80f2 | 534 | USBDHAL_SetEPDISNAK( ep ); |
Helmut64 | 0:a3ea811f80f2 | 535 | } |
Helmut64 | 0:a3ea811f80f2 | 536 | } |
Helmut64 | 0:a3ea811f80f2 | 537 | |
Helmut64 | 0:a3ea811f80f2 | 538 | /* Wait for epdis INT */ |
Helmut64 | 0:a3ea811f80f2 | 539 | im = inmask; |
Helmut64 | 0:a3ea811f80f2 | 540 | om = outmask; |
Helmut64 | 0:a3ea811f80f2 | 541 | cnt = EPABORT_BREAK_LOOP_COUNT; |
Helmut64 | 0:a3ea811f80f2 | 542 | do |
Helmut64 | 0:a3ea811f80f2 | 543 | { |
Helmut64 | 0:a3ea811f80f2 | 544 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 545 | { |
Helmut64 | 0:a3ea811f80f2 | 546 | ep = &dev->ep[i]; |
Helmut64 | 0:a3ea811f80f2 | 547 | if ( ep->in && ( im & ep->mask ) ) |
Helmut64 | 0:a3ea811f80f2 | 548 | { |
Helmut64 | 0:a3ea811f80f2 | 549 | if ( USBDHAL_GetInEpInts( ep ) & USB_DIEP_INT_EPDISBLD ) |
Helmut64 | 0:a3ea811f80f2 | 550 | { |
Helmut64 | 0:a3ea811f80f2 | 551 | USB_DINEPS[ ep->num ].INT = USB_DIEP_INT_EPDISBLD; |
Helmut64 | 0:a3ea811f80f2 | 552 | im &= ~ep->mask; |
Helmut64 | 0:a3ea811f80f2 | 553 | } |
Helmut64 | 0:a3ea811f80f2 | 554 | } |
Helmut64 | 0:a3ea811f80f2 | 555 | |
Helmut64 | 0:a3ea811f80f2 | 556 | if ( !ep->in && ( om & ep->mask ) ) |
Helmut64 | 0:a3ea811f80f2 | 557 | { |
Helmut64 | 0:a3ea811f80f2 | 558 | if ( USBDHAL_GetOutEpInts( ep ) & USB_DOEP_INT_EPDISBLD ) |
Helmut64 | 0:a3ea811f80f2 | 559 | { |
Helmut64 | 0:a3ea811f80f2 | 560 | USB_DOUTEPS[ ep->num ].INT = USB_DOEP_INT_EPDISBLD; |
Helmut64 | 0:a3ea811f80f2 | 561 | om &= ~ep->mask; |
Helmut64 | 0:a3ea811f80f2 | 562 | } |
Helmut64 | 0:a3ea811f80f2 | 563 | } |
Helmut64 | 0:a3ea811f80f2 | 564 | } |
Helmut64 | 0:a3ea811f80f2 | 565 | cnt--; |
Helmut64 | 0:a3ea811f80f2 | 566 | } while ( ( im || om ) && cnt ); |
Helmut64 | 0:a3ea811f80f2 | 567 | |
Helmut64 | 0:a3ea811f80f2 | 568 | if ( inmask ) |
Helmut64 | 0:a3ea811f80f2 | 569 | { |
Helmut64 | 0:a3ea811f80f2 | 570 | USB->DIEPMSK &= ~USB_DIEPMSK_EPDISBLDMSK; /* Disable EPDIS interrupt */ |
Helmut64 | 0:a3ea811f80f2 | 571 | USBHAL_FlushTxFifo( 0x10 ); /* Flush all Tx FIFO's */ |
Helmut64 | 0:a3ea811f80f2 | 572 | } |
Helmut64 | 0:a3ea811f80f2 | 573 | |
Helmut64 | 0:a3ea811f80f2 | 574 | if ( outmask ) |
Helmut64 | 0:a3ea811f80f2 | 575 | { |
Helmut64 | 0:a3ea811f80f2 | 576 | USB->DOEPMSK &= ~USB_DOEPMSK_EPDISBLDMSK; /* Disable EPDIS interrupt */ |
Helmut64 | 0:a3ea811f80f2 | 577 | /* Clear Global OUT NAK */ |
Helmut64 | 0:a3ea811f80f2 | 578 | USB->DCTL = ( USB->DCTL & ~DCTL_WO_BITMASK ) | USB_DCTL_CGOUTNAK; |
Helmut64 | 0:a3ea811f80f2 | 579 | } |
Helmut64 | 0:a3ea811f80f2 | 580 | |
Helmut64 | 0:a3ea811f80f2 | 581 | DEBUG_USB_INT_LO_PUTCHAR( '\'' ); |
Helmut64 | 0:a3ea811f80f2 | 582 | } |
Helmut64 | 0:a3ea811f80f2 | 583 | |
Helmut64 | 0:a3ea811f80f2 | 584 | void USBDHAL_AbortAllTransfers( USB_Status_TypeDef reason ) |
Helmut64 | 0:a3ea811f80f2 | 585 | { |
Helmut64 | 0:a3ea811f80f2 | 586 | int i; |
Helmut64 | 0:a3ea811f80f2 | 587 | USBD_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 588 | USB_XferCompleteCb_TypeDef callback; |
Helmut64 | 0:a3ea811f80f2 | 589 | |
Helmut64 | 0:a3ea811f80f2 | 590 | if ( reason != USB_STATUS_DEVICE_RESET ) |
Helmut64 | 0:a3ea811f80f2 | 591 | { |
Helmut64 | 0:a3ea811f80f2 | 592 | USBDHAL_AbortAllEps(); |
Helmut64 | 0:a3ea811f80f2 | 593 | } |
Helmut64 | 0:a3ea811f80f2 | 594 | |
Helmut64 | 0:a3ea811f80f2 | 595 | for ( i = 1; i <= NUM_EP_USED; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 596 | { |
Helmut64 | 0:a3ea811f80f2 | 597 | ep = &(dev->ep[i]); |
Helmut64 | 0:a3ea811f80f2 | 598 | if ( ep->state != D_EP_IDLE ) |
Helmut64 | 0:a3ea811f80f2 | 599 | { |
Helmut64 | 0:a3ea811f80f2 | 600 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 601 | if ( ep->xferCompleteCb ) |
Helmut64 | 0:a3ea811f80f2 | 602 | { |
Helmut64 | 0:a3ea811f80f2 | 603 | callback = ep->xferCompleteCb; |
Helmut64 | 0:a3ea811f80f2 | 604 | ep->xferCompleteCb = NULL; |
Helmut64 | 0:a3ea811f80f2 | 605 | |
Helmut64 | 0:a3ea811f80f2 | 606 | if ( ( dev->lastState == USBD_STATE_CONFIGURED ) && |
Helmut64 | 0:a3ea811f80f2 | 607 | ( dev->state == USBD_STATE_ADDRESSED ) ) |
Helmut64 | 0:a3ea811f80f2 | 608 | { |
Helmut64 | 0:a3ea811f80f2 | 609 | USBDHAL_DeactivateEp( ep ); |
Helmut64 | 0:a3ea811f80f2 | 610 | } |
Helmut64 | 0:a3ea811f80f2 | 611 | |
Helmut64 | 0:a3ea811f80f2 | 612 | DEBUG_TRACE_ABORT( reason ); |
Helmut64 | 0:a3ea811f80f2 | 613 | callback( reason, ep->xferred, ep->remaining ); |
Helmut64 | 0:a3ea811f80f2 | 614 | } |
Helmut64 | 0:a3ea811f80f2 | 615 | } |
Helmut64 | 0:a3ea811f80f2 | 616 | } |
Helmut64 | 0:a3ea811f80f2 | 617 | |
Helmut64 | 0:a3ea811f80f2 | 618 | /* Clear any interrupts generated by the abort sequence. */ |
Helmut64 | 0:a3ea811f80f2 | 619 | NVIC_ClearPendingIRQ( USB_IRQn ); |
Helmut64 | 0:a3ea811f80f2 | 620 | } |
Helmut64 | 0:a3ea811f80f2 | 621 | #endif /* defined( USB_DEVICE ) */ |
Helmut64 | 0:a3ea811f80f2 | 622 | |
Helmut64 | 0:a3ea811f80f2 | 623 | #if defined( USB_HOST ) |
Helmut64 | 0:a3ea811f80f2 | 624 | USB_Status_TypeDef USBHHAL_CoreInit( uint32_t rxFifoSize, |
Helmut64 | 0:a3ea811f80f2 | 625 | uint32_t nptxFifoSize, |
Helmut64 | 0:a3ea811f80f2 | 626 | uint32_t ptxFifoSize ) |
Helmut64 | 0:a3ea811f80f2 | 627 | { |
Helmut64 | 0:a3ea811f80f2 | 628 | uint8_t i; |
Helmut64 | 0:a3ea811f80f2 | 629 | |
Helmut64 | 0:a3ea811f80f2 | 630 | rxFifoSize /= 4; /* Convert from byte count to word count. */ |
Helmut64 | 0:a3ea811f80f2 | 631 | nptxFifoSize /= 4; |
Helmut64 | 0:a3ea811f80f2 | 632 | ptxFifoSize /= 4; |
Helmut64 | 0:a3ea811f80f2 | 633 | |
Helmut64 | 0:a3ea811f80f2 | 634 | CMU_ClockEnable( cmuClock_GPIO, true ); |
Helmut64 | 0:a3ea811f80f2 | 635 | GPIO_PinModeSet( gpioPortF, 5, gpioModePushPull, 0 ); /* Enable VBUSEN pin */ |
Helmut64 | 0:a3ea811f80f2 | 636 | |
Helmut64 | 0:a3ea811f80f2 | 637 | #if ( USB_VBUSOVRCUR_PORT != USB_VBUSOVRCUR_PORT_NONE ) |
Helmut64 | 0:a3ea811f80f2 | 638 | /* Enable VBUS overcurrent flag pin. */ |
Helmut64 | 0:a3ea811f80f2 | 639 | GPIO_PinModeSet( USB_VBUSOVRCUR_PORT, USB_VBUSOVRCUR_PIN, gpioModeInput, 0 ); |
Helmut64 | 0:a3ea811f80f2 | 640 | #endif |
Helmut64 | 0:a3ea811f80f2 | 641 | |
Helmut64 | 0:a3ea811f80f2 | 642 | USB->ROUTE = USB_ROUTE_PHYPEN | USB_ROUTE_VBUSENPEN; /* Enable PHY pins. */ |
Helmut64 | 0:a3ea811f80f2 | 643 | USBHAL_CoreReset(); /* Reset USB core */ |
Helmut64 | 0:a3ea811f80f2 | 644 | |
Helmut64 | 0:a3ea811f80f2 | 645 | /* Force Host Mode */ |
Helmut64 | 0:a3ea811f80f2 | 646 | USB->GUSBCFG = ( USB->GUSBCFG & |
Helmut64 | 0:a3ea811f80f2 | 647 | ~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEDEVMODE ) ) | |
Helmut64 | 0:a3ea811f80f2 | 648 | USB_GUSBCFG_FORCEHSTMODE; |
Helmut64 | 0:a3ea811f80f2 | 649 | |
Helmut64 | 0:a3ea811f80f2 | 650 | USBTIMER_DelayMs( 100 ); |
Helmut64 | 0:a3ea811f80f2 | 651 | |
Helmut64 | 0:a3ea811f80f2 | 652 | /* Set 48 MHz PHY clock, FS/LS mode */ |
Helmut64 | 0:a3ea811f80f2 | 653 | USB->HCFG = ( USB->HCFG & ~_USB_HCFG_FSLSPCLKSEL_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 654 | ( 1 << _USB_HCFG_FSLSPCLKSEL_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 655 | ( USB_HCFG_FSLSSUPP ); |
Helmut64 | 0:a3ea811f80f2 | 656 | |
Helmut64 | 0:a3ea811f80f2 | 657 | USB->GAHBCFG = ( USB->GAHBCFG & ~_USB_GAHBCFG_HBSTLEN_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 658 | USB_GAHBCFG_DMAEN | USB_GAHBCFG_HBSTLEN_INCR; |
Helmut64 | 0:a3ea811f80f2 | 659 | |
Helmut64 | 0:a3ea811f80f2 | 660 | /* Set Rx FIFO size */ |
Helmut64 | 0:a3ea811f80f2 | 661 | USB->GRXFSIZ = ( rxFifoSize << _USB_GRXFSIZ_RXFDEP_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 662 | _USB_GRXFSIZ_RXFDEP_MASK; |
Helmut64 | 0:a3ea811f80f2 | 663 | |
Helmut64 | 0:a3ea811f80f2 | 664 | /* Set Tx FIFO sizes */ |
Helmut64 | 0:a3ea811f80f2 | 665 | USB->GNPTXFSIZ = ( ( nptxFifoSize << |
Helmut64 | 0:a3ea811f80f2 | 666 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 667 | _USB_GNPTXFSIZ_NPTXFINEPTXF0DEP_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 668 | ( ( rxFifoSize << |
Helmut64 | 0:a3ea811f80f2 | 669 | _USB_GNPTXFSIZ_NPTXFSTADDR_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 670 | _USB_GNPTXFSIZ_NPTXFSTADDR_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 671 | |
Helmut64 | 0:a3ea811f80f2 | 672 | USB->HPTXFSIZ = ( ( ptxFifoSize << _USB_HPTXFSIZ_PTXFSIZE_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 673 | _USB_HPTXFSIZ_PTXFSIZE_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 674 | ( ( ( rxFifoSize + nptxFifoSize ) |
Helmut64 | 0:a3ea811f80f2 | 675 | << _USB_HPTXFSIZ_PTXFSTADDR_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 676 | _USB_HPTXFSIZ_PTXFSTADDR_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 677 | |
Helmut64 | 0:a3ea811f80f2 | 678 | /* Flush Tx and Rx FIFO's */ |
Helmut64 | 0:a3ea811f80f2 | 679 | USBHAL_FlushTxFifo( 0x10 ); |
Helmut64 | 0:a3ea811f80f2 | 680 | USBHAL_FlushRxFifo(); |
Helmut64 | 0:a3ea811f80f2 | 681 | |
Helmut64 | 0:a3ea811f80f2 | 682 | for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 683 | { |
Helmut64 | 0:a3ea811f80f2 | 684 | USB->HC[ i ].CHAR = USB_HC_CHAR_CHDIS; /* Disable channel */ |
Helmut64 | 0:a3ea811f80f2 | 685 | USB->HC[ i ].INT = 0xFFFFFFFF; /* Clear pending interrupts */ |
Helmut64 | 0:a3ea811f80f2 | 686 | } |
Helmut64 | 0:a3ea811f80f2 | 687 | |
Helmut64 | 0:a3ea811f80f2 | 688 | /* Enable and halt all channels */ |
Helmut64 | 0:a3ea811f80f2 | 689 | for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 690 | { |
Helmut64 | 0:a3ea811f80f2 | 691 | USB->HC[ i ].CHAR |= USB_HC_CHAR_CHDIS | USB_HC_CHAR_CHENA; |
Helmut64 | 0:a3ea811f80f2 | 692 | do |
Helmut64 | 0:a3ea811f80f2 | 693 | { |
Helmut64 | 0:a3ea811f80f2 | 694 | __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); __NOP(); |
Helmut64 | 0:a3ea811f80f2 | 695 | } |
Helmut64 | 0:a3ea811f80f2 | 696 | while ( USB->HC[ i ].CHAR & USB_HC_CHAR_CHENA ); |
Helmut64 | 0:a3ea811f80f2 | 697 | } |
Helmut64 | 0:a3ea811f80f2 | 698 | |
Helmut64 | 0:a3ea811f80f2 | 699 | /* Disable all interrupts */ |
Helmut64 | 0:a3ea811f80f2 | 700 | for ( i = 0; i < MAX_NUM_HOSTCHANNELS; i++ ) |
Helmut64 | 0:a3ea811f80f2 | 701 | { |
Helmut64 | 0:a3ea811f80f2 | 702 | USB->HC[ i ].INTMSK = 0; |
Helmut64 | 0:a3ea811f80f2 | 703 | } |
Helmut64 | 0:a3ea811f80f2 | 704 | |
Helmut64 | 0:a3ea811f80f2 | 705 | USB->HAINTMSK = 0; |
Helmut64 | 0:a3ea811f80f2 | 706 | |
Helmut64 | 0:a3ea811f80f2 | 707 | return USB_STATUS_OK; |
Helmut64 | 0:a3ea811f80f2 | 708 | } |
Helmut64 | 0:a3ea811f80f2 | 709 | |
Helmut64 | 0:a3ea811f80f2 | 710 | void USBHHAL_HCHalt( int hcnum, uint32_t hcchar ) |
Helmut64 | 0:a3ea811f80f2 | 711 | { |
Helmut64 | 0:a3ea811f80f2 | 712 | hcchar |= USB_HC_CHAR_CHENA | USB_HC_CHAR_CHDIS; |
Helmut64 | 0:a3ea811f80f2 | 713 | USB->HC[ hcnum ].CHAR = hcchar; |
Helmut64 | 0:a3ea811f80f2 | 714 | } |
Helmut64 | 0:a3ea811f80f2 | 715 | |
Helmut64 | 0:a3ea811f80f2 | 716 | void USBHHAL_HCInit( int hcnum ) |
Helmut64 | 0:a3ea811f80f2 | 717 | { |
Helmut64 | 0:a3ea811f80f2 | 718 | USBH_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 719 | |
Helmut64 | 0:a3ea811f80f2 | 720 | ep = hcs[ hcnum ].ep; |
Helmut64 | 0:a3ea811f80f2 | 721 | USB->HC[ hcnum ].INT = 0xFFFFFFFF; /* Clear all interrupt flags */ |
Helmut64 | 0:a3ea811f80f2 | 722 | |
Helmut64 | 0:a3ea811f80f2 | 723 | switch ( ep->type ) /* Enable host channel int. types */ |
Helmut64 | 0:a3ea811f80f2 | 724 | { |
Helmut64 | 0:a3ea811f80f2 | 725 | case USB_EPTYPE_CTRL: |
Helmut64 | 0:a3ea811f80f2 | 726 | case USB_EPTYPE_BULK: |
Helmut64 | 0:a3ea811f80f2 | 727 | case USB_EPTYPE_INTR: |
Helmut64 | 0:a3ea811f80f2 | 728 | USB->HC[ hcnum ].INTMSK = USB_HC_INT_CHHLTD; |
Helmut64 | 0:a3ea811f80f2 | 729 | break; |
Helmut64 | 0:a3ea811f80f2 | 730 | } |
Helmut64 | 0:a3ea811f80f2 | 731 | |
Helmut64 | 0:a3ea811f80f2 | 732 | hcs[ hcnum ].errorCnt = 0; |
Helmut64 | 0:a3ea811f80f2 | 733 | |
Helmut64 | 0:a3ea811f80f2 | 734 | USB->HAINTMSK |= 1 << hcnum; /* Enable host channel interrupt */ |
Helmut64 | 0:a3ea811f80f2 | 735 | |
Helmut64 | 0:a3ea811f80f2 | 736 | USB->HC[ hcnum ].CHAR = /* Program HCCHAR register */ |
Helmut64 | 0:a3ea811f80f2 | 737 | ( ep->parentDevice->addr << _USB_HC_CHAR_DEVADDR_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 738 | ( ( ep->addr & USB_EPNUM_MASK ) << _USB_HC_CHAR_EPNUM_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 739 | ( ep->type << _USB_HC_CHAR_EPTYPE_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 740 | ( ep->packetSize << _USB_HC_CHAR_MPS_SHIFT ) | |
Helmut64 | 0:a3ea811f80f2 | 741 | ( ep->in ? USB_HC_CHAR_EPDIR : 0 ) | |
Helmut64 | 0:a3ea811f80f2 | 742 | ( ep->parentDevice->speed == |
Helmut64 | 0:a3ea811f80f2 | 743 | HPRT_L_SPEED >> _USB_HPRT_PRTSPD_SHIFT |
Helmut64 | 0:a3ea811f80f2 | 744 | ? USB_HC_CHAR_LSPDDEV : 0 ); |
Helmut64 | 0:a3ea811f80f2 | 745 | } |
Helmut64 | 0:a3ea811f80f2 | 746 | |
Helmut64 | 0:a3ea811f80f2 | 747 | void USBHHAL_HCStart( int hcnum ) |
Helmut64 | 0:a3ea811f80f2 | 748 | { |
Helmut64 | 0:a3ea811f80f2 | 749 | USBH_Hc_TypeDef *hc; |
Helmut64 | 0:a3ea811f80f2 | 750 | uint16_t packets, len; |
Helmut64 | 0:a3ea811f80f2 | 751 | |
Helmut64 | 0:a3ea811f80f2 | 752 | hc = &hcs[ hcnum ]; |
Helmut64 | 0:a3ea811f80f2 | 753 | hc->status = 0; |
Helmut64 | 0:a3ea811f80f2 | 754 | hc->idle = false; |
Helmut64 | 0:a3ea811f80f2 | 755 | |
Helmut64 | 0:a3ea811f80f2 | 756 | if ( hc->remaining > 0 ) |
Helmut64 | 0:a3ea811f80f2 | 757 | { |
Helmut64 | 0:a3ea811f80f2 | 758 | packets = ( hc->remaining + hc->ep->packetSize - 1 ) / hc->ep->packetSize; |
Helmut64 | 0:a3ea811f80f2 | 759 | } |
Helmut64 | 0:a3ea811f80f2 | 760 | else |
Helmut64 | 0:a3ea811f80f2 | 761 | { |
Helmut64 | 0:a3ea811f80f2 | 762 | packets = 1; |
Helmut64 | 0:a3ea811f80f2 | 763 | } |
Helmut64 | 0:a3ea811f80f2 | 764 | |
Helmut64 | 0:a3ea811f80f2 | 765 | if ( hc->ep->in ) |
Helmut64 | 0:a3ea811f80f2 | 766 | { |
Helmut64 | 0:a3ea811f80f2 | 767 | len = packets * hc->ep->packetSize; |
Helmut64 | 0:a3ea811f80f2 | 768 | } |
Helmut64 | 0:a3ea811f80f2 | 769 | else |
Helmut64 | 0:a3ea811f80f2 | 770 | { |
Helmut64 | 0:a3ea811f80f2 | 771 | len = hc->remaining; |
Helmut64 | 0:a3ea811f80f2 | 772 | } |
Helmut64 | 0:a3ea811f80f2 | 773 | |
Helmut64 | 0:a3ea811f80f2 | 774 | /* Initialize the HCTSIZn register */ |
Helmut64 | 0:a3ea811f80f2 | 775 | hc->hwXferSize = len; |
Helmut64 | 0:a3ea811f80f2 | 776 | USB->HC[ hcnum ].TSIZ = |
Helmut64 | 0:a3ea811f80f2 | 777 | ( ( len << _USB_HC_TSIZ_XFERSIZE_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 778 | _USB_HC_TSIZ_XFERSIZE_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 779 | ( ( packets << _USB_HC_TSIZ_PKTCNT_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 780 | _USB_HC_TSIZ_PKTCNT_MASK ) | |
Helmut64 | 0:a3ea811f80f2 | 781 | ( ( hc->ep->toggle << _USB_HC_TSIZ_PID_SHIFT ) & |
Helmut64 | 0:a3ea811f80f2 | 782 | _USB_HC_TSIZ_PID_MASK ); |
Helmut64 | 0:a3ea811f80f2 | 783 | |
Helmut64 | 0:a3ea811f80f2 | 784 | USB->HC[ hcnum ].DMAADDR = (uint32_t)hc->buf; |
Helmut64 | 0:a3ea811f80f2 | 785 | |
Helmut64 | 0:a3ea811f80f2 | 786 | USBHHAL_HCActivate( hcnum, |
Helmut64 | 0:a3ea811f80f2 | 787 | USB->HC[ hcnum ].CHAR, |
Helmut64 | 0:a3ea811f80f2 | 788 | hc->ep->type == USB_EPTYPE_INTR ); |
Helmut64 | 0:a3ea811f80f2 | 789 | } |
Helmut64 | 0:a3ea811f80f2 | 790 | #endif /* defined( USB_HOST ) */ |
Helmut64 | 0:a3ea811f80f2 | 791 | |
Helmut64 | 0:a3ea811f80f2 | 792 | /** @endcond */ |
Helmut64 | 0:a3ea811f80f2 | 793 | |
Helmut64 | 0:a3ea811f80f2 | 794 | #endif /* defined( USB_DEVICE ) || defined( USB_HOST ) */ |
Helmut64 | 0:a3ea811f80f2 | 795 | #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */ |