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#define TEST_RECV_COUNT         10000
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
46typedef 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
56typedef enum {
57    CMD_OPEN_PARM = 0,
58    CMD_CLOSE_PARM,
59    CMD_WRITE_PARM,
60    CMD_READ_PARM,
61    CMD_GET_BAUDRATE,
62    CMD_SET_BAUDRATE,
63    CMD_WRITE_DATA_SYNC,
64    CMD_READ_DATA_SYNC,
65    CMD_CLASS_CTRL_SYNC,
66    CMD_STD_CTRL_GET_DESCRIPTOR_CMD,
67    CMD_STD_CTRL_GET_STATUS_CMD,
68    CMD_STD_CTRL_GET_CONFIGURATION,
69    CMD_STD_CTRL_GET_INTERFACE,
70    CMD_STD_CTRL_GET_DESCRIPTOR_ASYNC,
71    CMD_ADD_INTERFACE,
72    CMD_REMOVE_INTERFACE,
73} SerialOPCmd;
74
75struct AcmDevice;
76struct AcmDb {
77    struct UsbRawRequest *request;
78    struct AcmDevice *instance;
79    uint8_t *buf;
80    int32_t len;
81    int32_t use;
82};
83
84struct SerialDevice {
85    struct AcmDevice *acm;
86    struct UsbCdcLineCoding lineCoding;
87    struct OsalMutex lock;
88    struct DataFifo readFifo;
89};
90
91struct UsbEndpoint {
92    uint8_t addr;
93    uint8_t interval;
94    uint16_t maxPacketSize;
95};
96
97struct AcmDevice {
98    struct IDeviceIoService service;
99    struct HdfDeviceObject *device;
100    uint8_t ctrlIface;
101    uint8_t dataIface;
102    struct UsbEndpoint *notifyEp;
103    struct UsbEndpoint *dataInEp;
104    struct UsbEndpoint *dataOutEp;
105    struct UsbEndpoint *dataEp;
106    struct UsbRawConfigDescriptor *config;
107    struct AcmDb db[TEST_CYCLE];
108    struct OsalMutex writeLock;
109    struct OsalMutex readLock;
110    struct UsbRawRequest *notifyReq;
111    struct UsbRawRequest *readReq[ACM_NR];
112    struct UsbRawRequest *writeReq;
113    struct UsbRawRequest *ctrlReq;
114    uint32_t dataSize;
115    struct OsalMutex lock;
116    UsbRawHandle *devHandle;
117    struct UsbSession *session;
118    struct SerialDevice *port;
119    uint32_t nbIndex;
120    uint32_t nbSize;
121    int32_t transmitting;
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 UsbCdcLineCoding lineCoding;
128    struct OsalThread ioThread;
129    struct OsalThread ioSendThread;
130};
131
132#endif /* USB_HOST_SDK_RAW_SPEED_H */
133