From 1096478e71864e8b64f691bd0f31f6d1a97e6a4d Mon Sep 17 00:00:00 2001 From: bigA2021 Date: Tue, 14 Sep 2021 11:14:16 +0800 Subject: [PATCH] usb 0914 commit Signed-off-by: bigA2021 Change-Id: I9c5a0b98e45d8950f2c204d92b27777a0b65dd10 --- model/usb/src/usb_ddk_pnp_loader.c | 6 +- test/unittest/model/usb/host/src/usb_raw_io.c | 118 ++++++++++-------- test/unittest/model/usb/host/src/usb_test.c | 50 +++++--- 3 files changed, 99 insertions(+), 75 deletions(-) diff --git a/model/usb/src/usb_ddk_pnp_loader.c b/model/usb/src/usb_ddk_pnp_loader.c index affbd0489..c8be7990e 100755 --- a/model/usb/src/usb_ddk_pnp_loader.c +++ b/model/usb/src/usb_ddk_pnp_loader.c @@ -721,7 +721,7 @@ error: static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct IDevmgrService *devmgrSvc, const struct UsbPnpNotifyMatchInfoTable *infoTable, struct UsbPnpMatchIdTable **matchIdTable) { - int ret = HDF_FAILURE; + int ret; struct UsbPnpMatchIdTable *idTable = NULL; int32_t tableCount; @@ -743,8 +743,6 @@ static void UsbDdkPnpLoaderAddDevice(uint32_t cmdId, uint8_t index, const struct continue; } } - - HDF_LOGD("%s:%d AddDevice end, index=%d, ret=%d", __func__, __LINE__, index, ret); } static int UsbDdkPnpLoaderRemoveHandle(const struct IDevmgrService *devmgrSvc, @@ -1008,7 +1006,7 @@ int UsbDdkPnpLoaderEventHandle(void) } return status; error: - for (idTable = g_usbPnpMatchIdTable[0]; idTable != NULL; ) { + for (idTable = g_usbPnpMatchIdTable[0]; idTable != NULL;) { tableCount++; idTable = g_usbPnpMatchIdTable[tableCount]; } diff --git a/test/unittest/model/usb/host/src/usb_raw_io.c b/test/unittest/model/usb/host/src/usb_raw_io.c index ac9cbe35d..dc0da48c6 100755 --- a/test/unittest/model/usb/host/src/usb_raw_io.c +++ b/test/unittest/model/usb/host/src/usb_raw_io.c @@ -35,7 +35,7 @@ int UsbIoThread(void *data) int ret; struct AcmRawDevice *acm = (struct AcmRawDevice *)data; - for (; ;) { + for (;;) { printf("%s:%d\n", __func__, __LINE__); if (acm == NULL) { printf("%s:%d acm is NULL\n", __func__, __LINE__); @@ -167,7 +167,6 @@ void AcmReadBulkCallback(const void *requestArg) if (size) { uint8_t *data = req->buffer; printf("rcv:%s\n", (char *)data); - } break; case USB_REQUEST_CANCELLED: @@ -207,28 +206,38 @@ void AcmNotifyReqCallback(const void *requestArg) printf("Irqstatus:%d,actualLength:%u\n", req->status, currentSize); } -int AcmWriteBufAlloc(struct AcmRawDevice *acm) +static int AcmWriteBufAllocHandle(struct AcmRawDevice *acm) { int i; - if (!g_writeBufFlag) { - struct RawWb *wb; - for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { - wb->buf = OsalMemCalloc(acm->dataOutEp.maxPacketSize); - if (!wb->buf) { - while (i != 0) { - --i; - --wb; - OsalMemFree(wb->buf); - wb->buf = NULL; - } - return -HDF_ERR_MALLOC_FAIL; + struct RawWb *wb; + for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { + wb->buf = OsalMemCalloc(acm->dataOutEp.maxPacketSize); + if (!wb->buf) { + while (i != 0) { + --i; + --wb; + OsalMemFree(wb->buf); + wb->buf = NULL; } - g_writeBufFlag = true; + return -HDF_ERR_MALLOC_FAIL; } + g_writeBufFlag = true; } + return HDF_SUCCESS; } +int AcmWriteBufAlloc(struct AcmRawDevice *acm) +{ + int ret = HDF_SUCCESS; + + if (!g_writeBufFlag) { + ret = AcmWriteBufAllocHandle(acm); + } + + return ret; +} + void AcmWriteBufFree(struct AcmRawDevice *acm) { int i; @@ -248,22 +257,58 @@ void AcmCtrlReqCallback(const void *requestArg) printf("%s:%d entry!", __func__, __LINE__); } +static void AcmParaseInterfaceClass(struct AcmRawDevice *acm, const struct UsbRawInterface *interface, uint8_t number) +{ + uint8_t ifaceClass; + uint8_t numEndpoints; + + ifaceClass = interface->altsetting->interfaceDescriptor.bInterfaceClass; + numEndpoints = interface->altsetting->interfaceDescriptor.bNumEndpoints; + + switch (ifaceClass) { + case USB_DDK_CLASS_COMM: + acm->ctrlIface = number; + /* get the first endpoint by default */ + acm->notifyEp.addr = interface->altsetting->endPoint[0].endpointDescriptor.bEndpointAddress; + acm->notifyEp.interval = interface->altsetting->endPoint[0].endpointDescriptor.bInterval; + acm->notifyEp.maxPacketSize = interface->altsetting->endPoint[0].endpointDescriptor.wMaxPacketSize; + break; + case USB_DDK_CLASS_CDC_DATA: + acm->dataIface = number; + for (uint8_t j = 0; j < numEndpoints; j++) { + const struct UsbRawEndpointDescriptor *endPoint = &interface->altsetting->endPoint[j]; + + /* get bulk in endpoint */ + if ((endPoint->endpointDescriptor.bEndpointAddress + & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN) { + acm->dataInEp.addr = endPoint->endpointDescriptor.bEndpointAddress; + acm->dataInEp.interval = endPoint->endpointDescriptor.bInterval; + acm->dataInEp.maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize; + } else { /* get bulk out endpoint */ + acm->dataOutEp.addr = endPoint->endpointDescriptor.bEndpointAddress; + acm->dataOutEp.interval = endPoint->endpointDescriptor.bInterval; + acm->dataOutEp.maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize; + } + } + break; + default: + printf("%s:%d wrong descriptor type\n", __func__, __LINE__); + break; + } + +} + int UsbParseConfigDescriptor(struct AcmRawDevice *acm, struct UsbRawConfigDescriptor *config) { uint8_t numInterfaces; uint8_t i; - uint8_t j; int ret; - uint8_t ifaceClass; - uint8_t numEndpoints; const struct UsbRawInterface *interface = NULL; numInterfaces = config->configDescriptor.bNumInterfaces; printf("------numInterfaces = [%d]------\n", numInterfaces); for (i = 0; i < numInterfaces; i++) { interface = config->interface[i]; - ifaceClass = interface->altsetting->interfaceDescriptor.bInterfaceClass; - numEndpoints = interface->altsetting->interfaceDescriptor.bNumEndpoints; printf("------UsbRawClaimInterface start------\n"); ret = UsbRawClaimInterface(acm->devHandle, i); @@ -272,36 +317,7 @@ int UsbParseConfigDescriptor(struct AcmRawDevice *acm, struct UsbRawConfigDescri continue; } printf("------UsbRawClaimInterface end------\n"); - switch (ifaceClass) { - case USB_DDK_CLASS_COMM: - acm->ctrlIface = i; - /* get the first endpoint by default */ - acm->notifyEp.addr = interface->altsetting->endPoint[0].endpointDescriptor.bEndpointAddress; - acm->notifyEp.interval = interface->altsetting->endPoint[0].endpointDescriptor.bInterval; - acm->notifyEp.maxPacketSize = interface->altsetting->endPoint[0].endpointDescriptor.wMaxPacketSize; - break; - case USB_DDK_CLASS_CDC_DATA: - acm->dataIface = i; - for (j = 0; j < numEndpoints; j++) { - const struct UsbRawEndpointDescriptor *endPoint = &interface->altsetting->endPoint[j]; - - /* get bulk in endpoint */ - if ((endPoint->endpointDescriptor.bEndpointAddress - & USB_DDK_ENDPOINT_DIR_MASK) == USB_DDK_DIR_IN) { - acm->dataInEp.addr = endPoint->endpointDescriptor.bEndpointAddress; - acm->dataInEp.interval = endPoint->endpointDescriptor.bInterval; - acm->dataInEp.maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize; - } else { /* get bulk out endpoint */ - acm->dataOutEp.addr = endPoint->endpointDescriptor.bEndpointAddress; - acm->dataOutEp.interval = endPoint->endpointDescriptor.bInterval; - acm->dataOutEp.maxPacketSize = endPoint->endpointDescriptor.wMaxPacketSize; - } - } - break; - default: - printf("%s:%d wrong descriptor type\n", __func__, __LINE__); - break; - } + AcmParaseInterfaceClass(acm, interface, i); } return HDF_SUCCESS; diff --git a/test/unittest/model/usb/host/src/usb_test.c b/test/unittest/model/usb/host/src/usb_test.c index 68eb621f5..60ffe422c 100755 --- a/test/unittest/model/usb/host/src/usb_test.c +++ b/test/unittest/model/usb/host/src/usb_test.c @@ -21,7 +21,7 @@ #define HDF_LOG_TAG USB_TEST_C static struct UsbSession *g_session = NULL; -static struct AcmDevice g_deviceService; +static struct AcmDevice g_deviceService = {0}; static struct AcmDevice *g_acm = &g_deviceService; static struct UsbInterface *g_ecmDataIface = NULL; static struct UsbInterface *g_ecmIntIface = NULL; @@ -84,28 +84,38 @@ static void AcmWriteIsoCallback(struct UsbRequest *requestArg) printf("%s:%d status:%d\n", __func__, __LINE__, req->compInfo.status); } -static int AcmWriteBufAlloc(struct AcmDevice *acm) +static int AcmWriteBufAllocHandle(struct AcmDevice *acm) { int i; - if (!g_writeBufFlag) { - struct AcmWb *wb; - for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { - wb->buf = (uint8_t *)OsalMemCalloc(acm->writeSize); - if (!wb->buf) { - while (i != 0) { - --i; - --wb; - OsalMemFree(wb->buf); - wb->buf = NULL; - } - return -HDF_ERR_MALLOC_FAIL; + struct AcmWb *wb; + for (wb = &acm->wb[0], i = 0; i < ACM_NW; i++, wb++) { + wb->buf = (uint8_t *)OsalMemCalloc(acm->writeSize); + if (!wb->buf) { + while (i != 0) { + --i; + --wb; + OsalMemFree(wb->buf); + wb->buf = NULL; } - g_writeBufFlag = true; + return -HDF_ERR_MALLOC_FAIL; } + g_writeBufFlag = true; } + return HDF_SUCCESS; } +static int AcmWriteBufAlloc(struct AcmDevice *acm) +{ + int ret = HDF_SUCCESS; + + if (!g_writeBufFlag) { + ret = AcmWriteBufAllocHandle(acm); + } + + return ret; +} + static void AcmWriteBufFree(struct AcmDevice *acm) { int i; @@ -1124,7 +1134,7 @@ static int32_t CheckHostSdkIfFreeRequest006(void) static int32_t CheckHostSdkIfFillIsoRequest001(void) { int ret; - struct UsbRequestParams parmas; + struct UsbRequestParams parmas = {0}; int i; char sendData[] = {"abcde\0"}; uint32_t size = strlen(sendData) + 1; @@ -1378,8 +1388,8 @@ static int32_t CheckHostSdkIfFillRequest001(void) readParmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE; readParmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS; readParmas.dataReq.numIsoPackets = 0; - readParmas.dataReq.directon = (UsbRequestDirection)(((uint32_t)g_acm->dataInPipe->pipeDirection >> USB_DIR_OFFSET) - & DIRECTION_MASK); + readParmas.dataReq.directon = + (UsbRequestDirection)(((uint32_t)g_acm->dataInPipe->pipeDirection >> USB_DIR_OFFSET) & DIRECTION_MASK); readParmas.dataReq.length = g_acm->readSize; ret = UsbFillRequest(g_acm->readReq[i], g_acm->data_devHandle, &readParmas); if (ret) { @@ -1558,8 +1568,8 @@ static int32_t CheckHostSdkIfFillRequest005(void) readParmas.requestType = USB_REQUEST_PARAMS_DATA_TYPE; readParmas.timeout = USB_RAW_REQUEST_TIME_ZERO_MS; readParmas.dataReq.numIsoPackets = 0; - readParmas.dataReq.directon = (UsbRequestDirection)(((uint32_t)g_acm->dataInPipe->pipeDirection >> USB_DIR_OFFSET) - & DIRECTION_MASK); + readParmas.dataReq.directon = + (UsbRequestDirection)(((uint32_t)g_acm->dataInPipe->pipeDirection >> USB_DIR_OFFSET) & DIRECTION_MASK); readParmas.dataReq.length = g_acm->readSize; ret = UsbFillRequest(g_acm->readReq[i], g_acm->data_devHandle, &readParmas); if (ret) { -- Gitee