• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CDCACM_H
17 #define HDF_USB_CDCACM_H
18 
19 #include "data_fifo.h"
20 #include "hdf_base.h"
21 #include "hdf_device_desc.h"
22 #include "osal_atomic.h"
23 #include "osal_mutex.h"
24 #include "usbfn_request.h"
25 #include "usb_ddk.h"
26 #include "usb_object.h"
27 
28 #define USB_MAX_PACKET_SIZE     0x40
29 
30 enum UsbSerialCmd {
31     USB_SERIAL_OPEN = 0,
32     USB_SERIAL_CLOSE,
33     USB_SERIAL_READ,
34     USB_SERIAL_WRITE,
35     USB_SERIAL_GET_BAUDRATE,
36     USB_SERIAL_SET_BAUDRATE,
37     USB_SERIAL_SET_PROP,
38     USB_SERIAL_GET_PROP,
39     USB_SERIAL_REGIST_PROP,
40     USB_SERIAL_WRITE_SPEED,
41     USB_SERIAL_WRITE_GET_TEMP_SPEED,
42     USB_SERIAL_WRITE_SPEED_DONE,
43     USB_SERIAL_WRITE_GET_TEMP_SPEED_UINT32,
44     USB_SERIAL_READ_SPEED,
45     USB_SERIAL_READ_GET_TEMP_SPEED,
46     USB_SERIAL_READ_SPEED_DONE,
47     USB_SERIAL_READ_GET_TEMP_SPEED_UINT32,
48     USB_SERIAL_INIT = 100,
49     USB_SERIAL_RELEASE = 101,
50 };
51 
52 struct UsbSerial {
53     struct UsbAcmDevice         *acm;
54     struct UsbCdcLineCoding     lineCoding;
55     struct OsalMutex            lock;
56 
57     struct DListHead            readPool;
58     struct DListHead            readQueue;
59     int32_t                     readStarted;
60     int32_t                     readAllocated;
61     struct DataFifo             readFifo;
62     struct DListHead            writePool;
63     int32_t                     writeStarted;
64     int32_t                     writeAllocated;
65     struct DataFifo             writeFifo;
66     bool                        writeBusy;
67 
68     bool                        suspended;
69     bool                        startDelayed;
70     int32_t                         refCount;
71 };
72 
73 struct AcmNotifyMethod {
74     void (*Connect)(struct UsbAcmDevice *acm);
75     void (*Disconnect)(struct UsbAcmDevice *acm);
76     int32_t (*SendBreak)(struct UsbAcmDevice *acm, int32_t duration);
77 };
78 
79 struct UsbAcmPipe {
80     uint8_t                     id;
81     uint16_t                    maxPacketSize;
82     struct UsbFnInterface       *ctrlIface;
83 };
84 
85 struct UsbAcmInterface {
86     struct UsbFnInterface       *fn;
87     UsbFnInterfaceHandle        handle;
88 };
89 
90 struct UsbAcmDevice {
91     struct IDeviceIoService     service;
92     struct HdfDeviceObject      *device;
93     struct UsbFnDevice          *fnDev;
94     struct UsbAcmInterface      ctrlIface;
95     struct UsbAcmInterface      dataIface;
96     struct UsbAcmPipe           notifyPipe;
97     struct UsbAcmPipe           dataInPipe;
98     struct UsbAcmPipe           dataOutPipe;
99 
100     struct DListHead            ctrlPool;
101     int32_t                     ctrlReqNum;
102     struct UsbFnRequest         *notifyReq;
103     struct OsalMutex            lock;
104     bool                        pending;
105     bool                        initFlag;
106     uint32_t                    enableEvtCnt;
107     char                        *udcName;
108     struct UsbSerial            *port;
109     struct UsbCdcLineCoding     lineCoding;
110     uint16_t                    serialState;
111 #define SERIAL_STATE_DCD        (1 << 0)
112 #define SERIAL_STATE_DSR        (1 << 1)
113 #define SERIAL_STATE_BREAK      (1 << 2)
114 #define SERIAL_STATE_RING       (1 << 3)
115 #define SERIAL_STATE_FRAMING    (1 << 4)
116 #define SERIAL_STATE_PARITY     (1 << 5)
117 #define SERIAL_STATE_OVERRUN    (1 << 6)
118 
119     uint16_t                    handshakeBits;
120     /* notification callbacks */
121     struct AcmNotifyMethod      *notify;
122 };
123 
124 struct CtrlInfo {
125     uint8_t                     request;
126     struct UsbAcmDevice         *acm;
127 };
128 
129 #endif /* HDF_USB_CDCACM_H */
130