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 HDF_USB_SERIAL_RAWAPI_H 17 #define HDF_USB_SERIAL_RAWAPI_H 18 19 #include "data_fifo.h" 20 #include "hdf_device_desc.h" 21 #include "usb_raw_api.h" 22 23 #define USB_MAX_INTERFACES 32 24 #define DATARATE 9600 25 #define DATA_BITS_LENGTH 8 26 #define ACM_NW 16 27 #define ACM_NR 16 28 #define READ_BUF_SIZE 8192 29 #define USB_CTRL_SET_TIMEOUT 5000 30 #define USB_PIPE_DIR_OFFSET 7 31 32 typedef enum { 33 CMD_OPEN_PARM = 0, 34 CMD_CLOSE_PARM, 35 CMD_WRITE_PARM, 36 CMD_READ_PARM, 37 CMD_GET_BAUDRATE, 38 CMD_SET_BAUDRATE, 39 CMD_WRITE_DATA_SYNC, 40 CMD_READ_DATA_SYNC, 41 CMD_CLASS_CTRL_SYNC, 42 CMD_STD_CTRL_GET_DESCRIPTOR_CMD, 43 CMD_STD_CTRL_GET_STATUS_CMD, 44 CMD_STD_CTRL_GET_CONFIGURATION, 45 CMD_STD_CTRL_GET_INTERFACE, 46 CMD_STD_CTRL_GET_DESCRIPTOR_ASYNC, 47 CMD_ADD_INTERFACE, 48 CMD_REMOVE_INTERFACE, 49 } SerialOPCmd; 50 51 typedef enum { 52 HOST_ACM_SYNC_READ = 1, 53 HOST_ACM_SYNC_WRITE, 54 HOST_ACM_ASYNC_READ, 55 HOST_ACM_ASYNC_WRITE, 56 HOST_ACM_CTRL_READ, 57 HOST_ACM_CTRL_WRITE, 58 HOST_ACM_CTRL_CLASS_SYNC, 59 HOST_ACM_CTRL_GET_STATUS, 60 HOST_ACM_CTRL_SYNC_DESCRIPTOR, 61 HOST_ACM_CTRL_ASYNC_DESCRIPTOR, 62 HOST_ACM_CTRL_GET_CONFIGURATION, 63 HOST_ACM_CTRL_GET_INTERFACE, 64 HOST_ACM_SPEED_TEST, 65 HOST_ACM_SET_BAUDRATE, 66 HOST_ACM_GET_BAUDRATE, 67 HOST_ACM_ADD_INTERFACE, 68 HOST_ACM_REMOVE_INTERFACE, 69 } AcmModuleTestCmdType; 70 71 typedef enum { 72 USB_RAW_IO_PROCESS_RUNNING, 73 USB_RAW_IO_PROCESS_STOP, 74 USB_RAW_IO_PROCESS_STOPED 75 } UsbRawIoProcessStatusType; 76 77 struct AcmDevice; 78 struct AcmWb { 79 struct UsbRawRequest *request; 80 struct AcmDevice *instance; 81 uint8_t *buf; 82 uint32_t len; 83 int32_t use; 84 }; 85 86 struct AcmRb { 87 uint8_t *base; 88 int32_t size; 89 int32_t index; 90 int32_t use; 91 struct AcmDevice *instance; 92 }; 93 94 struct SerialDevice { 95 struct AcmDevice *acm; 96 struct UsbCdcLineCoding lineCoding; 97 struct OsalMutex lock; 98 struct DataFifo readFifo; 99 }; 100 101 struct UsbEndpoint { 102 uint8_t addr; 103 uint8_t interval; 104 uint16_t maxPacketSize; 105 }; 106 107 struct AcmDevice { 108 struct IDeviceIoService service; 109 struct HdfDeviceObject *device; 110 uint8_t ctrlIface; 111 uint8_t dataIface; 112 struct UsbEndpoint *notifyEp; 113 struct UsbEndpoint *dataInEp; 114 struct UsbEndpoint *dataOutEp; 115 struct UsbRawConfigDescriptor *config; 116 struct AcmWb wb[ACM_NW]; 117 struct AcmRb rb[ACM_NR]; 118 struct OsalMutex writeLock; 119 struct OsalMutex readLock; 120 struct UsbRawRequest *notifyReq; 121 struct UsbRawRequest *readReq[ACM_NR]; 122 struct UsbRawRequest *writeReq; 123 struct UsbRawRequest *ctrlReq; 124 struct OsalMutex lock; 125 UsbRawHandle *devHandle; 126 struct UsbSession *session; 127 struct SerialDevice *port; 128 uint32_t nbIndex; 129 uint32_t nbSize; 130 int32_t transmitting; 131 uint8_t busNum; 132 uint8_t devAddr; 133 uint8_t interfaceCnt; 134 uint8_t *notificationBuffer; 135 uint8_t interfaceIndex[USB_MAX_INTERFACES]; 136 struct UsbCdcLineCoding lineCoding; 137 struct OsalThread ioThread; 138 bool initFlag; 139 }; 140 141 #endif /* HDF_USB_SERIAL_RAWAPI_H */ 142