USB BARCODE READER

Fork of USBHOST by ST

Committer:
shivanandgowdakr
Date:
Mon Jul 02 12:10:45 2018 +0000
Revision:
7:ccd0ac9ae1c9
Parent:
5:fc157e6bd5a5
USB BARCODE READER ;

Who changed what in which revision?

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