1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef USB_HOST_SDK_API_SPEED_H 17094332d3Sopenharmony_ci#define USB_HOST_SDK_API_SPEED_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include "hdf_base.h" 20094332d3Sopenharmony_ci#include "hdf_device_desc.h" 21094332d3Sopenharmony_ci#include "osal_atomic.h" 22094332d3Sopenharmony_ci#include "usb_ddk.h" 23094332d3Sopenharmony_ci#include "usb_ddk_interface.h" 24094332d3Sopenharmony_ci#include "usb_session.h" 25094332d3Sopenharmony_ci#include "data_fifo.h" 26094332d3Sopenharmony_ci 27094332d3Sopenharmony_ci#define TEST_LENGTH 512 28094332d3Sopenharmony_ci#define TEST_CYCLE 30 29094332d3Sopenharmony_ci#define TEST_TIME 0xffffffff 30094332d3Sopenharmony_ci#define TEST_PRINT_TIME 2 31094332d3Sopenharmony_ci#define TEST_PRINT_TIME_UINT 1000 32094332d3Sopenharmony_ci#define TEST_RECV_COUNT 10000 33094332d3Sopenharmony_ci#define TEST_BYTE_COUNT 1024 34094332d3Sopenharmony_ci#define TEST_FLOAT_COUNT (1.0) 35094332d3Sopenharmony_ci#define TEST_SLEEP_TIME 10 36094332d3Sopenharmony_ci 37094332d3Sopenharmony_ci#define TEST_WRITE true 38094332d3Sopenharmony_ci#define TEST_READ false 39094332d3Sopenharmony_ci#define USB_MAX_INTERFACES 32 40094332d3Sopenharmony_ci#define DATARATE 9600 41094332d3Sopenharmony_ci#define DATA_BITS_LENGTH 8 42094332d3Sopenharmony_ci#define ACM_NW 30 43094332d3Sopenharmony_ci#define ACM_NR 30 44094332d3Sopenharmony_ci#define READ_BUF_SIZE 8192 45094332d3Sopenharmony_ci#define DIRECTION_MASK 0x1 46094332d3Sopenharmony_ci#define USB_CTRL_SET_TIMEOUT 0 47094332d3Sopenharmony_ci#define USB_PIPE_DIR_OFFSET 7 48094332d3Sopenharmony_ci 49094332d3Sopenharmony_citypedef enum { 50094332d3Sopenharmony_ci TEST_ZERO_TYPE = 0, 51094332d3Sopenharmony_ci TEST_ONE_TYPE, 52094332d3Sopenharmony_ci TEST_TWO_TYPE, 53094332d3Sopenharmony_ci TEST_THREE_TYPE, 54094332d3Sopenharmony_ci TEST_FOUR_TYPE, 55094332d3Sopenharmony_ci TEST_FIVE_TYPE, 56094332d3Sopenharmony_ci TEST_SIX_TYPE, 57094332d3Sopenharmony_ci} TestCountType; 58094332d3Sopenharmony_ci 59094332d3Sopenharmony_citypedef enum { 60094332d3Sopenharmony_ci CMD_OPEN_PARM = 0, 61094332d3Sopenharmony_ci CMD_CLOSE_PARM, 62094332d3Sopenharmony_ci CMD_WRITE_PARM, 63094332d3Sopenharmony_ci CMD_READ_PARM, 64094332d3Sopenharmony_ci CMD_GET_BAUDRATE, 65094332d3Sopenharmony_ci CMD_SET_BAUDRATE, 66094332d3Sopenharmony_ci CMD_WRITE_DATA_SYNC, 67094332d3Sopenharmony_ci CMD_READ_DATA_SYNC, 68094332d3Sopenharmony_ci CMD_CLASS_CTRL_SYNC, 69094332d3Sopenharmony_ci CMD_STD_CTRL_GET_DESCRIPTOR_CMD, 70094332d3Sopenharmony_ci CMD_STD_CTRL_GET_STATUS_CMD, 71094332d3Sopenharmony_ci CMD_STD_CTRL_GET_CONFIGURATION, 72094332d3Sopenharmony_ci CMD_STD_CTRL_GET_INTERFACE, 73094332d3Sopenharmony_ci CMD_STD_CTRL_GET_DESCRIPTOR_ASYNC, 74094332d3Sopenharmony_ci CMD_ADD_INTERFACE, 75094332d3Sopenharmony_ci CMD_REMOVE_INTERFACE, 76094332d3Sopenharmony_ci} SerialOPCmd; 77094332d3Sopenharmony_ci 78094332d3Sopenharmony_cistruct AcmDevice; 79094332d3Sopenharmony_cistruct AcmDb { 80094332d3Sopenharmony_ci int32_t dbNum; 81094332d3Sopenharmony_ci struct UsbRequest *request; 82094332d3Sopenharmony_ci struct AcmDevice *instance; 83094332d3Sopenharmony_ci uint8_t *buf; 84094332d3Sopenharmony_ci int32_t len; 85094332d3Sopenharmony_ci int32_t use; 86094332d3Sopenharmony_ci}; 87094332d3Sopenharmony_ci 88094332d3Sopenharmony_cistruct SerialDevice { 89094332d3Sopenharmony_ci struct AcmDevice *acm; 90094332d3Sopenharmony_ci struct UsbCdcLineCoding lineCoding; 91094332d3Sopenharmony_ci struct OsalMutex lock; 92094332d3Sopenharmony_ci struct DataFifo readFifo; 93094332d3Sopenharmony_ci}; 94094332d3Sopenharmony_ci 95094332d3Sopenharmony_cistruct AcmDevice { 96094332d3Sopenharmony_ci struct IDeviceIoService service; 97094332d3Sopenharmony_ci struct HdfDeviceObject *device; 98094332d3Sopenharmony_ci struct UsbInterface *ctrIface; 99094332d3Sopenharmony_ci struct UsbPipeInfo *ctrPipe; 100094332d3Sopenharmony_ci struct UsbPipeInfo *intPipe; 101094332d3Sopenharmony_ci struct UsbPipeInfo *dataInPipe; 102094332d3Sopenharmony_ci struct UsbPipeInfo *dataOutPipe; 103094332d3Sopenharmony_ci struct UsbPipeInfo *dataPipe; 104094332d3Sopenharmony_ci struct AcmDb db[TEST_CYCLE]; 105094332d3Sopenharmony_ci struct UsbPipeInfo wPipeInfo; 106094332d3Sopenharmony_ci struct OsalMutex writeLock; 107094332d3Sopenharmony_ci struct OsalMutex readLock; 108094332d3Sopenharmony_ci struct UsbRequest *notifyReq; 109094332d3Sopenharmony_ci struct UsbRequest *readReq[ACM_NR]; 110094332d3Sopenharmony_ci struct UsbRequest *writeReq; 111094332d3Sopenharmony_ci struct UsbRequest *ctrlReq; 112094332d3Sopenharmony_ci struct OsalMutex lock; 113094332d3Sopenharmony_ci struct UsbInterface *itface; 114094332d3Sopenharmony_ci UsbInterfaceHandle *devHandle[USB_MAX_INTERFACES]; 115094332d3Sopenharmony_ci UsbInterfaceHandle *ctrDevHandle; 116094332d3Sopenharmony_ci struct UsbSession *session; 117094332d3Sopenharmony_ci struct SerialDevice *port; 118094332d3Sopenharmony_ci uint32_t nbIndex; 119094332d3Sopenharmony_ci uint32_t nbSize; 120094332d3Sopenharmony_ci int32_t transmitting; 121094332d3Sopenharmony_ci int32_t ctrlReqNum; 122094332d3Sopenharmony_ci uint8_t busNum; 123094332d3Sopenharmony_ci uint8_t devAddr; 124094332d3Sopenharmony_ci uint8_t interfaceCnt; 125094332d3Sopenharmony_ci uint8_t *notificationBuffer; 126094332d3Sopenharmony_ci uint8_t interfaceIndex[USB_MAX_INTERFACES]; 127094332d3Sopenharmony_ci struct UsbInterface *iface[USB_MAX_INTERFACES]; 128094332d3Sopenharmony_ci uint32_t ctrlSize; 129094332d3Sopenharmony_ci uint32_t intSize; 130094332d3Sopenharmony_ci uint32_t writeSize; 131094332d3Sopenharmony_ci uint32_t readSize; 132094332d3Sopenharmony_ci uint32_t dataSize; 133094332d3Sopenharmony_ci struct UsbCdcLineCoding lineCoding; 134094332d3Sopenharmony_ci}; 135094332d3Sopenharmony_ci 136094332d3Sopenharmony_ci#endif /* USB_HOST_SDK_API_SPEED_H */ 137