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_RAW_SPEED_H
17 #define USB_HOST_SDK_RAW_SPEED_H
18 
19 #include "hdf_base.h"
20 #include "hdf_device_desc.h"
21 #include "osal_atomic.h"
22 #include "usb_raw_api.h"
23 #include "data_fifo.h"
24 
25 #define TEST_LENGTH             512
26 #define TEST_CYCLE              30
27 #define TEST_TIME               0xffffffff
28 #define TEST_PRINT_TIME         2
29 #define TEST_PRINT_TIME_UINT    1000
30 
31 #define TEST_BYTE_COUNT         1024
32 #define TEST_FLOAT_COUNT        (1.0)
33 #define TEST_SLEEP_TIME         10
34 
35 #define TEST_WRITE              true
36 #define TEST_READ               false
37 #define USB_MAX_INTERFACES      32
38 #define DATARATE                9600
39 #define DATA_BITS_LENGTH        8
40 #define ACM_NW                  30
41 #define ACM_NR                  30
42 #define READ_BUF_SIZE           8192
43 #define USB_CTRL_SET_TIMEOUT    0
44 #define USB_PIPE_DIR_OFFSET     7
45 
46 typedef enum {
47     TEST_ZERO_TYPE = 0,
48     TEST_ONE_TYPE,
49     TEST_TWO_TYPE,
50     TEST_THREE_TYPE,
51     TEST_FOUR_TYPE,
52     TEST_FIVE_TYPE,
53     TEST_SIX_TYPE,
54 } TestCountType;
55 
56 enum UsbSerialCmd {
57     USB_SERIAL_OPEN = 0,
58     USB_SERIAL_CLOSE,
59     USB_SERIAL_SPEED,
60 };
61 struct UsbSpeedTest {
62     int32_t busNum;
63     int32_t devAddr;
64     int32_t ifaceNum;
65     int32_t writeOrRead;
66     bool printData;
67     int32_t paramNum;
68 };
69 
70 struct AcmDevice;
71 struct AcmDb {
72     struct UsbRawRequest *request;
73     struct AcmDevice *instance;
74     uint8_t *buf;
75     int32_t len;
76     int32_t use;
77 };
78 
79 struct SerialDevice {
80     struct AcmDevice *acm;
81     struct UsbCdcLineCoding lineCoding;
82     struct OsalMutex lock;
83     struct DataFifo readFifo;
84 };
85 
86 struct UsbEndpoint {
87     uint8_t addr;
88     uint8_t interval;
89     uint16_t maxPacketSize;
90 };
91 
92 struct AcmDevice {
93     struct IDeviceIoService service;
94     struct HdfDeviceObject *device;
95     uint8_t ctrlIface;
96     uint8_t dataIface;
97     struct UsbEndpoint *notifyEp;
98     struct UsbEndpoint *dataInEp;
99     struct UsbEndpoint *dataOutEp;
100     struct UsbEndpoint *dataEp;
101     struct UsbRawConfigDescriptor *config;
102     struct AcmDb db[TEST_CYCLE];
103     struct OsalMutex writeLock;
104     struct OsalMutex readLock;
105     struct UsbRawRequest *notifyReq;
106     struct UsbRawRequest *readReq[ACM_NR];
107     struct UsbRawRequest *writeReq;
108     struct UsbRawRequest *ctrlReq;
109     uint32_t dataSize;
110     struct OsalMutex lock;
111     UsbRawHandle *devHandle;
112     struct UsbSession *session;
113     struct SerialDevice *port;
114     uint32_t nbIndex;
115     uint32_t nbSize;
116     int32_t transmitting;
117     uint8_t busNum;
118     uint8_t devAddr;
119     uint8_t interfaceCnt;
120     uint8_t *notificationBuffer;
121     uint8_t interfaceIndex[USB_MAX_INTERFACES];
122     struct UsbCdcLineCoding lineCoding;
123     struct OsalThread ioThread;
124     struct OsalThread ioSendThread;
125     bool busy;
126 };
127 
128 #endif /* USB_HOST_SDK_RAW_SPEED_H */
129