only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
targets/TARGET_STM/USBHALHost_STM.cpp@0:dae1ac0c0a7b, 2019-08-07 (annotated)
- Committer:
- kenjiArai
- Date:
- Wed Aug 07 05:33:53 2019 +0000
- Revision:
- 0:dae1ac0c0a7b
only for STM32F769NI-DISCOVERY, porting from mbed OS5 unsupport functions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 0:dae1ac0c0a7b | 1 | /* mbed USBHost Library |
kenjiArai | 0:dae1ac0c0a7b | 2 | * Copyright (c) 2006-2013 ARM Limited |
kenjiArai | 0:dae1ac0c0a7b | 3 | * |
kenjiArai | 0:dae1ac0c0a7b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kenjiArai | 0:dae1ac0c0a7b | 5 | * you may not use this file except in compliance with the License. |
kenjiArai | 0:dae1ac0c0a7b | 6 | * You may obtain a copy of the License at |
kenjiArai | 0:dae1ac0c0a7b | 7 | * |
kenjiArai | 0:dae1ac0c0a7b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kenjiArai | 0:dae1ac0c0a7b | 9 | * |
kenjiArai | 0:dae1ac0c0a7b | 10 | * Unless required by applicable law or agreed to in writing, software |
kenjiArai | 0:dae1ac0c0a7b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kenjiArai | 0:dae1ac0c0a7b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kenjiArai | 0:dae1ac0c0a7b | 13 | * See the License for the specific language governing permissions and |
kenjiArai | 0:dae1ac0c0a7b | 14 | * limitations under the License. |
kenjiArai | 0:dae1ac0c0a7b | 15 | */ |
kenjiArai | 0:dae1ac0c0a7b | 16 | |
kenjiArai | 0:dae1ac0c0a7b | 17 | #ifdef TARGET_STM |
kenjiArai | 0:dae1ac0c0a7b | 18 | #include "mbed.h" |
kenjiArai | 0:dae1ac0c0a7b | 19 | #include "USBHALHost.h" |
kenjiArai | 0:dae1ac0c0a7b | 20 | #include "dbg.h" |
kenjiArai | 0:dae1ac0c0a7b | 21 | #include "pinmap.h" |
kenjiArai | 0:dae1ac0c0a7b | 22 | |
kenjiArai | 0:dae1ac0c0a7b | 23 | #include "USBHALHost_STM.h" |
kenjiArai | 0:dae1ac0c0a7b | 24 | |
kenjiArai | 0:dae1ac0c0a7b | 25 | void HAL_HCD_Connect_Callback(HCD_HandleTypeDef *hhcd) |
kenjiArai | 0:dae1ac0c0a7b | 26 | { |
kenjiArai | 0:dae1ac0c0a7b | 27 | USBHALHost_Private_t *priv = (USBHALHost_Private_t *)(hhcd->pData); |
kenjiArai | 0:dae1ac0c0a7b | 28 | USBHALHost *obj = priv->inst; |
kenjiArai | 0:dae1ac0c0a7b | 29 | void (USBHALHost::*func)(int hub, int port, bool lowSpeed, USBHostHub * hub_parent) = priv->deviceConnected; |
kenjiArai | 0:dae1ac0c0a7b | 30 | (obj->*func)(0, 1, 0, NULL); |
kenjiArai | 0:dae1ac0c0a7b | 31 | } |
kenjiArai | 0:dae1ac0c0a7b | 32 | void HAL_HCD_Disconnect_Callback(HCD_HandleTypeDef *hhcd) |
kenjiArai | 0:dae1ac0c0a7b | 33 | { |
kenjiArai | 0:dae1ac0c0a7b | 34 | USBHALHost_Private_t *priv = (USBHALHost_Private_t *)(hhcd->pData); |
kenjiArai | 0:dae1ac0c0a7b | 35 | USBHALHost *obj = priv->inst; |
kenjiArai | 0:dae1ac0c0a7b | 36 | void (USBHALHost::*func1)(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) = priv->deviceDisconnected; |
kenjiArai | 0:dae1ac0c0a7b | 37 | (obj->*func1)(0, 1, (USBHostHub *)NULL, 0); |
kenjiArai | 0:dae1ac0c0a7b | 38 | } |
kenjiArai | 0:dae1ac0c0a7b | 39 | int HAL_HCD_HC_GetDirection(HCD_HandleTypeDef *hhcd, uint8_t chnum) |
kenjiArai | 0:dae1ac0c0a7b | 40 | { |
kenjiArai | 0:dae1ac0c0a7b | 41 | /* useful for transmission */ |
kenjiArai | 0:dae1ac0c0a7b | 42 | return hhcd->hc[chnum].ep_is_in; |
kenjiArai | 0:dae1ac0c0a7b | 43 | } |
kenjiArai | 0:dae1ac0c0a7b | 44 | |
kenjiArai | 0:dae1ac0c0a7b | 45 | uint32_t HAL_HCD_HC_GetMaxPacket(HCD_HandleTypeDef *hhcd, uint8_t chnum) |
kenjiArai | 0:dae1ac0c0a7b | 46 | { |
kenjiArai | 0:dae1ac0c0a7b | 47 | /* useful for transmission */ |
kenjiArai | 0:dae1ac0c0a7b | 48 | return hhcd->hc[chnum].max_packet; |
kenjiArai | 0:dae1ac0c0a7b | 49 | } |
kenjiArai | 0:dae1ac0c0a7b | 50 | |
kenjiArai | 0:dae1ac0c0a7b | 51 | void HAL_HCD_EnableInt(HCD_HandleTypeDef *hhcd, uint8_t chnum) |
kenjiArai | 0:dae1ac0c0a7b | 52 | { |
kenjiArai | 0:dae1ac0c0a7b | 53 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
kenjiArai | 0:dae1ac0c0a7b | 54 | USBx_HOST->HAINTMSK |= (1 << chnum); |
kenjiArai | 0:dae1ac0c0a7b | 55 | } |
kenjiArai | 0:dae1ac0c0a7b | 56 | |
kenjiArai | 0:dae1ac0c0a7b | 57 | |
kenjiArai | 0:dae1ac0c0a7b | 58 | void HAL_HCD_DisableInt(HCD_HandleTypeDef *hhcd, uint8_t chnum) |
kenjiArai | 0:dae1ac0c0a7b | 59 | { |
kenjiArai | 0:dae1ac0c0a7b | 60 | USB_OTG_GlobalTypeDef *USBx = hhcd->Instance; |
kenjiArai | 0:dae1ac0c0a7b | 61 | USBx_HOST->HAINTMSK &= ~(1 << chnum); |
kenjiArai | 0:dae1ac0c0a7b | 62 | } |
kenjiArai | 0:dae1ac0c0a7b | 63 | uint32_t HAL_HCD_HC_GetType(HCD_HandleTypeDef *hhcd, uint8_t chnum) |
kenjiArai | 0:dae1ac0c0a7b | 64 | { |
kenjiArai | 0:dae1ac0c0a7b | 65 | /* useful for transmission */ |
kenjiArai | 0:dae1ac0c0a7b | 66 | return hhcd->hc[chnum].ep_type; |
kenjiArai | 0:dae1ac0c0a7b | 67 | } |
kenjiArai | 0:dae1ac0c0a7b | 68 | |
kenjiArai | 0:dae1ac0c0a7b | 69 | void HAL_HCD_HC_NotifyURBChange_Callback(HCD_HandleTypeDef *hhcd, uint8_t chnum, HCD_URBStateTypeDef urb_state) |
kenjiArai | 0:dae1ac0c0a7b | 70 | { |
kenjiArai | 0:dae1ac0c0a7b | 71 | USBHALHost_Private_t *priv = (USBHALHost_Private_t *)(hhcd->pData); |
kenjiArai | 0:dae1ac0c0a7b | 72 | USBHALHost *obj = priv->inst; |
kenjiArai | 0:dae1ac0c0a7b | 73 | void (USBHALHost::*func)(volatile uint32_t addr) = priv->transferCompleted; |
kenjiArai | 0:dae1ac0c0a7b | 74 | |
kenjiArai | 0:dae1ac0c0a7b | 75 | uint32_t addr = priv->addr[chnum]; |
kenjiArai | 0:dae1ac0c0a7b | 76 | uint32_t max_size = HAL_HCD_HC_GetMaxPacket(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 77 | uint32_t type = HAL_HCD_HC_GetType(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 78 | uint32_t dir = HAL_HCD_HC_GetDirection(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 79 | uint32_t length; |
kenjiArai | 0:dae1ac0c0a7b | 80 | if ((addr != 0)) { |
kenjiArai | 0:dae1ac0c0a7b | 81 | HCTD *td = (HCTD *)addr; |
kenjiArai | 0:dae1ac0c0a7b | 82 | |
kenjiArai | 0:dae1ac0c0a7b | 83 | if ((type == EP_TYPE_BULK) || (type == EP_TYPE_CTRL)) { |
kenjiArai | 0:dae1ac0c0a7b | 84 | switch (urb_state) { |
kenjiArai | 0:dae1ac0c0a7b | 85 | case URB_DONE: |
kenjiArai | 0:dae1ac0c0a7b | 86 | #if defined(MAX_NYET_RETRY) |
kenjiArai | 0:dae1ac0c0a7b | 87 | td->retry = 0; |
kenjiArai | 0:dae1ac0c0a7b | 88 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 89 | if (td->size > max_size) { |
kenjiArai | 0:dae1ac0c0a7b | 90 | /* enqueue another request */ |
kenjiArai | 0:dae1ac0c0a7b | 91 | td->currBufPtr += max_size; |
kenjiArai | 0:dae1ac0c0a7b | 92 | td->size -= max_size; |
kenjiArai | 0:dae1ac0c0a7b | 93 | length = td->size <= max_size ? td->size : max_size; |
kenjiArai | 0:dae1ac0c0a7b | 94 | MBED_ASSERT(HAL_HCD_HC_SubmitRequest(hhcd, chnum, dir, type, !td->setup, (uint8_t *) td->currBufPtr, length, 0) == HAL_OK); |
kenjiArai | 0:dae1ac0c0a7b | 95 | HAL_HCD_EnableInt(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 96 | return; |
kenjiArai | 0:dae1ac0c0a7b | 97 | } |
kenjiArai | 0:dae1ac0c0a7b | 98 | break; |
kenjiArai | 0:dae1ac0c0a7b | 99 | case URB_NOTREADY: |
kenjiArai | 0:dae1ac0c0a7b | 100 | /* try again */ |
kenjiArai | 0:dae1ac0c0a7b | 101 | /* abritary limit , to avoid dead lock if other error than |
kenjiArai | 0:dae1ac0c0a7b | 102 | * slow response is */ |
kenjiArai | 0:dae1ac0c0a7b | 103 | #if defined(MAX_NYET_RETRY) |
kenjiArai | 0:dae1ac0c0a7b | 104 | if (td->retry < MAX_NYET_RETRY) { |
kenjiArai | 0:dae1ac0c0a7b | 105 | /* increment retry counter */ |
kenjiArai | 0:dae1ac0c0a7b | 106 | td->retry++; |
kenjiArai | 0:dae1ac0c0a7b | 107 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 108 | length = td->size <= max_size ? td->size : max_size; |
kenjiArai | 0:dae1ac0c0a7b | 109 | MBED_ASSERT(HAL_HCD_HC_SubmitRequest(hhcd, chnum, dir, type, !td->setup, (uint8_t *) td->currBufPtr, length, 0) == HAL_OK); |
kenjiArai | 0:dae1ac0c0a7b | 110 | HAL_HCD_EnableInt(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 111 | return; |
kenjiArai | 0:dae1ac0c0a7b | 112 | #if defined(MAX_NYET_RETRY) |
kenjiArai | 0:dae1ac0c0a7b | 113 | } else { |
kenjiArai | 0:dae1ac0c0a7b | 114 | USB_ERR("urb_state != URB_NOTREADY"); |
kenjiArai | 0:dae1ac0c0a7b | 115 | } |
kenjiArai | 0:dae1ac0c0a7b | 116 | #endif |
kenjiArai | 0:dae1ac0c0a7b | 117 | break; |
kenjiArai | 0:dae1ac0c0a7b | 118 | } |
kenjiArai | 0:dae1ac0c0a7b | 119 | } |
kenjiArai | 0:dae1ac0c0a7b | 120 | if ((type == EP_TYPE_INTR)) { |
kenjiArai | 0:dae1ac0c0a7b | 121 | /* reply a packet of length NULL, this will be analyse in call back |
kenjiArai | 0:dae1ac0c0a7b | 122 | * for mouse or hub */ |
kenjiArai | 0:dae1ac0c0a7b | 123 | td->state = USB_TYPE_IDLE ; |
kenjiArai | 0:dae1ac0c0a7b | 124 | HAL_HCD_DisableInt(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 125 | |
kenjiArai | 0:dae1ac0c0a7b | 126 | } else { |
kenjiArai | 0:dae1ac0c0a7b | 127 | td->state = (urb_state == URB_DONE) ? USB_TYPE_IDLE : USB_TYPE_ERROR; |
kenjiArai | 0:dae1ac0c0a7b | 128 | } |
kenjiArai | 0:dae1ac0c0a7b | 129 | td->currBufPtr += HAL_HCD_HC_GetXferCount(hhcd, chnum); |
kenjiArai | 0:dae1ac0c0a7b | 130 | (obj->*func)(addr); |
kenjiArai | 0:dae1ac0c0a7b | 131 | } else { |
kenjiArai | 0:dae1ac0c0a7b | 132 | if (urb_state != 0) { |
kenjiArai | 0:dae1ac0c0a7b | 133 | USB_DBG_EVENT("spurious %d %d", chnum, urb_state); |
kenjiArai | 0:dae1ac0c0a7b | 134 | } |
kenjiArai | 0:dae1ac0c0a7b | 135 | } |
kenjiArai | 0:dae1ac0c0a7b | 136 | } |
kenjiArai | 0:dae1ac0c0a7b | 137 | |
kenjiArai | 0:dae1ac0c0a7b | 138 | USBHALHost *USBHALHost::instHost; |
kenjiArai | 0:dae1ac0c0a7b | 139 | |
kenjiArai | 0:dae1ac0c0a7b | 140 | |
kenjiArai | 0:dae1ac0c0a7b | 141 | void USBHALHost::init() |
kenjiArai | 0:dae1ac0c0a7b | 142 | { |
kenjiArai | 0:dae1ac0c0a7b | 143 | |
kenjiArai | 0:dae1ac0c0a7b | 144 | NVIC_DisableIRQ(USBHAL_IRQn); |
kenjiArai | 0:dae1ac0c0a7b | 145 | NVIC_SetVector(USBHAL_IRQn, (uint32_t)(_usbisr)); |
kenjiArai | 0:dae1ac0c0a7b | 146 | HAL_HCD_Init((HCD_HandleTypeDef *) usb_hcca); |
kenjiArai | 0:dae1ac0c0a7b | 147 | NVIC_EnableIRQ(USBHAL_IRQn); |
kenjiArai | 0:dae1ac0c0a7b | 148 | control_disable = 0; |
kenjiArai | 0:dae1ac0c0a7b | 149 | HAL_HCD_Start((HCD_HandleTypeDef *) usb_hcca); |
kenjiArai | 0:dae1ac0c0a7b | 150 | usb_vbus(1); |
kenjiArai | 0:dae1ac0c0a7b | 151 | } |
kenjiArai | 0:dae1ac0c0a7b | 152 | |
kenjiArai | 0:dae1ac0c0a7b | 153 | uint32_t USBHALHost::controlHeadED() |
kenjiArai | 0:dae1ac0c0a7b | 154 | { |
kenjiArai | 0:dae1ac0c0a7b | 155 | return 0xffffffff; |
kenjiArai | 0:dae1ac0c0a7b | 156 | } |
kenjiArai | 0:dae1ac0c0a7b | 157 | |
kenjiArai | 0:dae1ac0c0a7b | 158 | uint32_t USBHALHost::bulkHeadED() |
kenjiArai | 0:dae1ac0c0a7b | 159 | { |
kenjiArai | 0:dae1ac0c0a7b | 160 | return 0xffffffff; |
kenjiArai | 0:dae1ac0c0a7b | 161 | } |
kenjiArai | 0:dae1ac0c0a7b | 162 | |
kenjiArai | 0:dae1ac0c0a7b | 163 | uint32_t USBHALHost::interruptHeadED() |
kenjiArai | 0:dae1ac0c0a7b | 164 | { |
kenjiArai | 0:dae1ac0c0a7b | 165 | return 0xffffffff; |
kenjiArai | 0:dae1ac0c0a7b | 166 | } |
kenjiArai | 0:dae1ac0c0a7b | 167 | |
kenjiArai | 0:dae1ac0c0a7b | 168 | void USBHALHost::updateBulkHeadED(uint32_t addr) |
kenjiArai | 0:dae1ac0c0a7b | 169 | { |
kenjiArai | 0:dae1ac0c0a7b | 170 | } |
kenjiArai | 0:dae1ac0c0a7b | 171 | |
kenjiArai | 0:dae1ac0c0a7b | 172 | |
kenjiArai | 0:dae1ac0c0a7b | 173 | void USBHALHost::updateControlHeadED(uint32_t addr) |
kenjiArai | 0:dae1ac0c0a7b | 174 | { |
kenjiArai | 0:dae1ac0c0a7b | 175 | } |
kenjiArai | 0:dae1ac0c0a7b | 176 | |
kenjiArai | 0:dae1ac0c0a7b | 177 | void USBHALHost::updateInterruptHeadED(uint32_t addr) |
kenjiArai | 0:dae1ac0c0a7b | 178 | { |
kenjiArai | 0:dae1ac0c0a7b | 179 | } |
kenjiArai | 0:dae1ac0c0a7b | 180 | |
kenjiArai | 0:dae1ac0c0a7b | 181 | |
kenjiArai | 0:dae1ac0c0a7b | 182 | void USBHALHost::enableList(ENDPOINT_TYPE type) |
kenjiArai | 0:dae1ac0c0a7b | 183 | { |
kenjiArai | 0:dae1ac0c0a7b | 184 | /* react when the 3 lists are requested to be disabled */ |
kenjiArai | 0:dae1ac0c0a7b | 185 | if (type == CONTROL_ENDPOINT) { |
kenjiArai | 0:dae1ac0c0a7b | 186 | control_disable--; |
kenjiArai | 0:dae1ac0c0a7b | 187 | if (control_disable == 0) { |
kenjiArai | 0:dae1ac0c0a7b | 188 | NVIC_EnableIRQ(USBHAL_IRQn); |
kenjiArai | 0:dae1ac0c0a7b | 189 | } else { |
kenjiArai | 0:dae1ac0c0a7b | 190 | printf("reent\n"); |
kenjiArai | 0:dae1ac0c0a7b | 191 | } |
kenjiArai | 0:dae1ac0c0a7b | 192 | } |
kenjiArai | 0:dae1ac0c0a7b | 193 | } |
kenjiArai | 0:dae1ac0c0a7b | 194 | |
kenjiArai | 0:dae1ac0c0a7b | 195 | |
kenjiArai | 0:dae1ac0c0a7b | 196 | bool USBHALHost::disableList(ENDPOINT_TYPE type) |
kenjiArai | 0:dae1ac0c0a7b | 197 | { |
kenjiArai | 0:dae1ac0c0a7b | 198 | if (type == CONTROL_ENDPOINT) { |
kenjiArai | 0:dae1ac0c0a7b | 199 | NVIC_DisableIRQ(USBHAL_IRQn); |
kenjiArai | 0:dae1ac0c0a7b | 200 | control_disable++; |
kenjiArai | 0:dae1ac0c0a7b | 201 | if (control_disable > 1) { |
kenjiArai | 0:dae1ac0c0a7b | 202 | printf("disable reentrance !!!\n"); |
kenjiArai | 0:dae1ac0c0a7b | 203 | } |
kenjiArai | 0:dae1ac0c0a7b | 204 | return true; |
kenjiArai | 0:dae1ac0c0a7b | 205 | } |
kenjiArai | 0:dae1ac0c0a7b | 206 | return false; |
kenjiArai | 0:dae1ac0c0a7b | 207 | } |
kenjiArai | 0:dae1ac0c0a7b | 208 | |
kenjiArai | 0:dae1ac0c0a7b | 209 | |
kenjiArai | 0:dae1ac0c0a7b | 210 | void USBHALHost::memInit() |
kenjiArai | 0:dae1ac0c0a7b | 211 | { |
kenjiArai | 0:dae1ac0c0a7b | 212 | usb_hcca = (volatile HCD_HandleTypeDef *)usb_buf; |
kenjiArai | 0:dae1ac0c0a7b | 213 | usb_edBuf = usb_buf + HCCA_SIZE; |
kenjiArai | 0:dae1ac0c0a7b | 214 | usb_tdBuf = usb_buf + HCCA_SIZE + (MAX_ENDPOINT * ED_SIZE); |
kenjiArai | 0:dae1ac0c0a7b | 215 | /* init channel */ |
kenjiArai | 0:dae1ac0c0a7b | 216 | memset((void *)usb_buf, 0, TOTAL_SIZE); |
kenjiArai | 0:dae1ac0c0a7b | 217 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 218 | HCED *hced = (HCED *)(usb_edBuf + i * ED_SIZE); |
kenjiArai | 0:dae1ac0c0a7b | 219 | hced->ch_num = i; |
kenjiArai | 0:dae1ac0c0a7b | 220 | hced->hhcd = (HCCA *) usb_hcca; |
kenjiArai | 0:dae1ac0c0a7b | 221 | } |
kenjiArai | 0:dae1ac0c0a7b | 222 | } |
kenjiArai | 0:dae1ac0c0a7b | 223 | |
kenjiArai | 0:dae1ac0c0a7b | 224 | volatile uint8_t *USBHALHost::getED() |
kenjiArai | 0:dae1ac0c0a7b | 225 | { |
kenjiArai | 0:dae1ac0c0a7b | 226 | for (int i = 0; i < MAX_ENDPOINT; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 227 | if (!edBufAlloc[i]) { |
kenjiArai | 0:dae1ac0c0a7b | 228 | edBufAlloc[i] = true; |
kenjiArai | 0:dae1ac0c0a7b | 229 | return (volatile uint8_t *)(usb_edBuf + i * ED_SIZE); |
kenjiArai | 0:dae1ac0c0a7b | 230 | } |
kenjiArai | 0:dae1ac0c0a7b | 231 | } |
kenjiArai | 0:dae1ac0c0a7b | 232 | perror("Could not allocate ED\r\n"); |
kenjiArai | 0:dae1ac0c0a7b | 233 | return NULL; //Could not alloc ED |
kenjiArai | 0:dae1ac0c0a7b | 234 | } |
kenjiArai | 0:dae1ac0c0a7b | 235 | |
kenjiArai | 0:dae1ac0c0a7b | 236 | volatile uint8_t *USBHALHost::getTD() |
kenjiArai | 0:dae1ac0c0a7b | 237 | { |
kenjiArai | 0:dae1ac0c0a7b | 238 | int i; |
kenjiArai | 0:dae1ac0c0a7b | 239 | for (i = 0; i < MAX_TD; i++) { |
kenjiArai | 0:dae1ac0c0a7b | 240 | if (!tdBufAlloc[i]) { |
kenjiArai | 0:dae1ac0c0a7b | 241 | tdBufAlloc[i] = true; |
kenjiArai | 0:dae1ac0c0a7b | 242 | return (volatile uint8_t *)(usb_tdBuf + i * TD_SIZE); |
kenjiArai | 0:dae1ac0c0a7b | 243 | } |
kenjiArai | 0:dae1ac0c0a7b | 244 | } |
kenjiArai | 0:dae1ac0c0a7b | 245 | perror("Could not allocate TD\r\n"); |
kenjiArai | 0:dae1ac0c0a7b | 246 | return NULL; //Could not alloc TD |
kenjiArai | 0:dae1ac0c0a7b | 247 | } |
kenjiArai | 0:dae1ac0c0a7b | 248 | |
kenjiArai | 0:dae1ac0c0a7b | 249 | |
kenjiArai | 0:dae1ac0c0a7b | 250 | void USBHALHost::freeED(volatile uint8_t *ed) |
kenjiArai | 0:dae1ac0c0a7b | 251 | { |
kenjiArai | 0:dae1ac0c0a7b | 252 | int i; |
kenjiArai | 0:dae1ac0c0a7b | 253 | i = (ed - usb_edBuf) / ED_SIZE; |
kenjiArai | 0:dae1ac0c0a7b | 254 | edBufAlloc[i] = false; |
kenjiArai | 0:dae1ac0c0a7b | 255 | } |
kenjiArai | 0:dae1ac0c0a7b | 256 | |
kenjiArai | 0:dae1ac0c0a7b | 257 | void USBHALHost::freeTD(volatile uint8_t *td) |
kenjiArai | 0:dae1ac0c0a7b | 258 | { |
kenjiArai | 0:dae1ac0c0a7b | 259 | int i; |
kenjiArai | 0:dae1ac0c0a7b | 260 | i = (td - usb_tdBuf) / TD_SIZE; |
kenjiArai | 0:dae1ac0c0a7b | 261 | tdBufAlloc[i] = false; |
kenjiArai | 0:dae1ac0c0a7b | 262 | } |
kenjiArai | 0:dae1ac0c0a7b | 263 | |
kenjiArai | 0:dae1ac0c0a7b | 264 | |
kenjiArai | 0:dae1ac0c0a7b | 265 | void USBHALHost::resetRootHub() |
kenjiArai | 0:dae1ac0c0a7b | 266 | { |
kenjiArai | 0:dae1ac0c0a7b | 267 | // Initiate port reset |
kenjiArai | 0:dae1ac0c0a7b | 268 | wait(0.2); |
kenjiArai | 0:dae1ac0c0a7b | 269 | HAL_HCD_ResetPort((HCD_HandleTypeDef *)usb_hcca); |
kenjiArai | 0:dae1ac0c0a7b | 270 | } |
kenjiArai | 0:dae1ac0c0a7b | 271 | |
kenjiArai | 0:dae1ac0c0a7b | 272 | |
kenjiArai | 0:dae1ac0c0a7b | 273 | void USBHALHost::_usbisr(void) |
kenjiArai | 0:dae1ac0c0a7b | 274 | { |
kenjiArai | 0:dae1ac0c0a7b | 275 | if (instHost) { |
kenjiArai | 0:dae1ac0c0a7b | 276 | instHost->UsbIrqhandler(); |
kenjiArai | 0:dae1ac0c0a7b | 277 | } |
kenjiArai | 0:dae1ac0c0a7b | 278 | } |
kenjiArai | 0:dae1ac0c0a7b | 279 | |
kenjiArai | 0:dae1ac0c0a7b | 280 | void USBHALHost::UsbIrqhandler() |
kenjiArai | 0:dae1ac0c0a7b | 281 | { |
kenjiArai | 0:dae1ac0c0a7b | 282 | HAL_HCD_IRQHandler((HCD_HandleTypeDef *)usb_hcca); |
kenjiArai | 0:dae1ac0c0a7b | 283 | } |
kenjiArai | 0:dae1ac0c0a7b | 284 | #endif |