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_SDK_API_SPEED_H
17 #define USB_HOST_SDK_API_SPEED_H
18 
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 #include "data_fifo.h"
26 
27 #define TEST_LENGTH             512
28 #define TEST_CYCLE              30
29 #define TEST_TIME               0xffffffff
30 #define TEST_PRINT_TIME         2
31 #define TEST_PRINT_TIME_UINT    1000
32 #define TEST_RECV_COUNT         10000
33 #define TEST_BYTE_COUNT         1024
34 #define TEST_FLOAT_COUNT        (1.0)
35 #define TEST_SLEEP_TIME         10
36 
37 #define TEST_WRITE              true
38 #define TEST_READ               false
39 #define USB_MAX_INTERFACES      32
40 #define DATARATE                9600
41 #define DATA_BITS_LENGTH        8
42 #define ACM_NW                  30
43 #define ACM_NR                  30
44 #define READ_BUF_SIZE           8192
45 #define DIRECTION_MASK          0x1
46 #define USB_CTRL_SET_TIMEOUT    0
47 #define USB_PIPE_DIR_OFFSET     7
48 #define USB_DEVICE_VENDOR_ID 0x12D1
49 #define USB_DEVICE_PRODUCT_ID 0x5000
50 
51 typedef enum {
52     TEST_ZERO_TYPE = 0,
53     TEST_ONE_TYPE,
54     TEST_TWO_TYPE,
55     TEST_THREE_TYPE,
56     TEST_FOUR_TYPE,
57     TEST_FIVE_TYPE,
58     TEST_SIX_TYPE,
59 } TestCountType;
60 
61 enum UsbSerialCmd {
62     USB_SERIAL_OPEN = 0,
63     USB_SERIAL_CLOSE,
64     USB_SERIAL_SPEED,
65 };
66 struct UsbSpeedTest {
67     int32_t busNum;
68     int32_t devAddr;
69     int32_t ifaceNum;
70     int32_t writeOrRead;
71     bool printData;
72     int32_t paramNum;
73 };
74 
75 struct AcmDevice;
76 struct AcmDb {
77     int32_t dbNum;
78     struct UsbRequest *request;
79     struct AcmDevice *instance;
80     uint8_t *buf;
81     int32_t len;
82     int32_t use;
83 };
84 
85 struct SerialDevice {
86     struct AcmDevice *acm;
87     struct UsbCdcLineCoding lineCoding;
88     struct OsalMutex lock;
89     struct DataFifo readFifo;
90 };
91 
92 struct AcmDevice {
93     struct IDeviceIoService service;
94     struct HdfDeviceObject *device;
95     struct UsbInterface *ctrIface;
96     struct UsbPipeInfo  *ctrPipe;
97     struct UsbPipeInfo  *intPipe;
98     struct UsbPipeInfo  *dataInPipe;
99     struct UsbPipeInfo  *dataOutPipe;
100     struct UsbPipeInfo  *dataPipe;
101     struct AcmDb  db[TEST_CYCLE];
102     struct UsbPipeInfo wPipeInfo;
103     struct OsalMutex writeLock;
104     struct OsalMutex readLock;
105     struct UsbRequest *notifyReq;
106     struct UsbRequest *readReq[ACM_NR];
107     struct UsbRequest *writeReq;
108     struct UsbRequest *ctrlReq;
109     struct OsalMutex lock;
110     struct UsbInterface *itface;
111     UsbInterfaceHandle *devHandle[USB_MAX_INTERFACES];
112     UsbInterfaceHandle *ctrDevHandle;
113     struct UsbSession *session;
114     struct SerialDevice *port;
115     uint32_t nbIndex;
116     uint32_t nbSize;
117     int32_t transmitting;
118     int32_t ctrlReqNum;
119     uint8_t busNum;
120     uint8_t devAddr;
121     uint8_t interfaceCnt;
122     uint8_t *notificationBuffer;
123     uint8_t interfaceIndex[USB_MAX_INTERFACES];
124     struct UsbInterface *iface[USB_MAX_INTERFACES];
125     uint32_t ctrlSize;
126     uint32_t intSize;
127     uint32_t writeSize;
128     uint32_t readSize;
129     uint32_t dataSize;
130     struct UsbCdcLineCoding lineCoding;
131     bool busy;
132 };
133 
134 #endif  /* USB_HOST_SDK_API_SPEED_H */
135