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
49typedef enum {
50    TEST_ZERO_TYPE = 0,
51    TEST_ONE_TYPE,
52    TEST_TWO_TYPE,
53    TEST_THREE_TYPE,
54    TEST_FOUR_TYPE,
55    TEST_FIVE_TYPE,
56    TEST_SIX_TYPE,
57} TestCountType;
58
59typedef enum {
60    CMD_OPEN_PARM = 0,
61    CMD_CLOSE_PARM,
62    CMD_WRITE_PARM,
63    CMD_READ_PARM,
64    CMD_GET_BAUDRATE,
65    CMD_SET_BAUDRATE,
66    CMD_WRITE_DATA_SYNC,
67    CMD_READ_DATA_SYNC,
68    CMD_CLASS_CTRL_SYNC,
69    CMD_STD_CTRL_GET_DESCRIPTOR_CMD,
70    CMD_STD_CTRL_GET_STATUS_CMD,
71    CMD_STD_CTRL_GET_CONFIGURATION,
72    CMD_STD_CTRL_GET_INTERFACE,
73    CMD_STD_CTRL_GET_DESCRIPTOR_ASYNC,
74    CMD_ADD_INTERFACE,
75    CMD_REMOVE_INTERFACE,
76} SerialOPCmd;
77
78struct AcmDevice;
79struct AcmDb {
80    int32_t dbNum;
81    struct UsbRequest *request;
82    struct AcmDevice *instance;
83    uint8_t *buf;
84    int32_t len;
85    int32_t use;
86};
87
88struct SerialDevice {
89    struct AcmDevice *acm;
90    struct UsbCdcLineCoding lineCoding;
91    struct OsalMutex lock;
92    struct DataFifo readFifo;
93};
94
95struct AcmDevice {
96    struct IDeviceIoService service;
97    struct HdfDeviceObject *device;
98    struct UsbInterface *ctrIface;
99    struct UsbPipeInfo  *ctrPipe;
100    struct UsbPipeInfo  *intPipe;
101    struct UsbPipeInfo  *dataInPipe;
102    struct UsbPipeInfo  *dataOutPipe;
103    struct UsbPipeInfo  *dataPipe;
104    struct AcmDb  db[TEST_CYCLE];
105    struct UsbPipeInfo wPipeInfo;
106    struct OsalMutex writeLock;
107    struct OsalMutex readLock;
108    struct UsbRequest *notifyReq;
109    struct UsbRequest *readReq[ACM_NR];
110    struct UsbRequest *writeReq;
111    struct UsbRequest *ctrlReq;
112    struct OsalMutex lock;
113    struct UsbInterface *itface;
114    UsbInterfaceHandle *devHandle[USB_MAX_INTERFACES];
115    UsbInterfaceHandle *ctrDevHandle;
116    struct UsbSession *session;
117    struct SerialDevice *port;
118    uint32_t nbIndex;
119    uint32_t nbSize;
120    int32_t transmitting;
121    int32_t ctrlReqNum;
122    uint8_t busNum;
123    uint8_t devAddr;
124    uint8_t interfaceCnt;
125    uint8_t *notificationBuffer;
126    uint8_t interfaceIndex[USB_MAX_INTERFACES];
127    struct UsbInterface *iface[USB_MAX_INTERFACES];
128    uint32_t ctrlSize;
129    uint32_t intSize;
130    uint32_t writeSize;
131    uint32_t readSize;
132    uint32_t dataSize;
133    struct UsbCdcLineCoding lineCoding;
134};
135
136#endif  /* USB_HOST_SDK_API_SPEED_H */
137