1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef USB_HOST_NO_SDK_SPEED_H 17 #define USB_HOST_NO_SDK_SPEED_H 18 #include "data_fifo.h" 19 #include "hdf_base.h" 20 #include "hdf_device_desc.h" 21 #include "osal_atomic.h" 22 #include "usb_ddk.h" 23 #include "usb_ddk_interface.h" 24 #include "usb_session.h" 25 26 #define TEST_LENGTH 512 27 #define TEST_CYCLE 30 28 #define TEST_TIME 0xffffffff 29 #define TEST_PRINT_TIME 2 30 #define TEST_PRINT_TIME_UINT 1000 31 #define TEST_PRINT_MAX_RANGE 10000 32 #define TEST_DOUBLE_COUNT (1.0) 33 #define TEST_BYTE_COUNT_UINT 1024 34 #define INPUT_COMPARE_PARAMNUM 6 35 #define INPUT_COMPARE_NUMONE 3 36 #define INPUT_COMPARE_NUMTWO 5 37 38 #define TEST_WRITE true 39 #define TEST_READ false 40 #define USB_MAX_INTERFACES 32 41 #define DATARATE 9600 42 #define DATA_BITS_LENGTH 8 43 #define ACM_NW 30 44 #define ACM_NR 30 45 #define READ_BUF_SIZE 8192 46 #define DIRECTION_MASK 0x1 47 #define USB_CTRL_SET_TIMEOUT 0 48 #define USB_PIPE_DIR_OFFSET 7 49 #define USB_DEVICE_VENDOR_ID 0x12D1 50 #define USB_DEVICE_PRODUCT_ID 0x5000 51 52 struct UsbAdapterUrbs { 53 struct urb *urb; 54 int32_t inUse; 55 int32_t urbNum; 56 }; 57 58 enum UsbSerialCmd { 59 USB_SERIAL_OPEN = 0, 60 USB_SERIAL_CLOSE, 61 USB_SERIAL_SPEED, 62 }; 63 struct UsbSpeedTest { 64 int32_t busNum; 65 int32_t devAddr; 66 int32_t ifaceNum; 67 int32_t writeOrRead; 68 bool printData; 69 int32_t paramNum; 70 }; 71 72 struct AcmDevice; 73 struct AcmDb { 74 int32_t dbNum; 75 struct UsbRequest *request; 76 struct AcmDevice *instance; 77 uint8_t *buf; 78 int32_t len; 79 int32_t use; 80 }; 81 82 struct SerialDevice { 83 struct AcmDevice *acm; 84 struct UsbCdcLineCoding lineCoding; 85 struct OsalMutex lock; 86 struct DataFifo readFifo; 87 }; 88 89 struct AcmDevice { 90 struct IDeviceIoService service; 91 struct HdfDeviceObject *device; 92 struct UsbInterface *ctrIface; 93 struct UsbPipeInfo *ctrPipe; 94 struct UsbPipeInfo *intPipe; 95 struct UsbPipeInfo *dataInPipe; 96 struct UsbPipeInfo *dataOutPipe; 97 struct UsbPipeInfo *dataPipe; 98 struct AcmDb db[TEST_CYCLE]; 99 struct UsbPipeInfo wPipeInfo; 100 struct OsalMutex writeLock; 101 struct OsalMutex readLock; 102 struct UsbRequest *notifyReq; 103 struct UsbRequest *readReq[ACM_NR]; 104 struct UsbRequest *writeReq; 105 struct UsbRequest *ctrlReq; 106 struct OsalMutex lock; 107 struct UsbInterface *itface; 108 UsbInterfaceHandle *devHandle[USB_MAX_INTERFACES]; 109 UsbInterfaceHandle *ctrDevHandle; 110 struct UsbSession *session; 111 struct SerialDevice *port; 112 uint32_t nbIndex; 113 uint32_t nbSize; 114 int32_t transmitting; 115 int32_t ctrlReqNum; 116 uint8_t busNum; 117 uint8_t devAddr; 118 uint8_t interfaceCnt; 119 uint8_t *notificationBuffer; 120 uint8_t interfaceIndex[USB_MAX_INTERFACES]; 121 struct UsbInterface *iface[USB_MAX_INTERFACES]; 122 uint32_t ctrlSize; 123 uint32_t intSize; 124 uint32_t writeSize; 125 uint32_t readSize; 126 uint32_t dataSize; 127 struct UsbCdcLineCoding lineCoding; 128 bool busy; 129 }; 130 131 #endif /* USB_HOST_NO_SDK_SPEED_H */ 132