• 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 };
49 
50 struct UsbSerial {
51     struct UsbAcmDevice         *acm;
52     struct UsbCdcLineCoding     lineCoding;
53     struct OsalMutex            lock;
54 
55     struct DListHead            readPool;
56     struct DListHead            readQueue;
57     int32_t                     readStarted;
58     int32_t                     readAllocated;
59     struct DataFifo             readFifo;
60     struct DListHead            writePool;
61     int32_t                     writeStarted;
62     int32_t                     writeAllocated;
63     struct DataFifo             writeFifo;
64     bool                        writeBusy;
65 
66     bool                        suspended;
67     bool                        startDelayed;
68     int                         refCount;
69 };
70 
71 struct AcmNotifyMethod {
72     void (*Connect)(struct UsbAcmDevice *acm);
73     void (*Disconnect)(struct UsbAcmDevice *acm);
74     int (*SendBreak)(struct UsbAcmDevice *acm, int duration);
75 };
76 
77 struct UsbAcmPipe {
78     uint8_t                     id;
79     uint16_t                    maxPacketSize;
80     struct UsbFnInterface       *ctrlIface;
81 };
82 
83 struct UsbAcmInterface {
84     struct UsbFnInterface       *fn;
85     UsbFnInterfaceHandle                   handle;
86 };
87 
88 struct UsbAcmDevice {
89     struct IDeviceIoService     service;
90     struct HdfDeviceObject      *device;
91     struct UsbFnDevice          *fnDev;
92     struct UsbAcmInterface      ctrlIface;
93     struct UsbAcmInterface      dataIface;
94     struct UsbAcmPipe           notifyPipe;
95     struct UsbAcmPipe           dataInPipe;
96     struct UsbAcmPipe           dataOutPipe;
97 
98     struct DListHead            ctrlPool;
99     int32_t                     ctrlReqNum;
100     struct UsbFnRequest         *notifyReq;
101     struct OsalMutex            lock;
102     bool                        pending;
103     uint32_t                    enableEvtCnt;
104     char                        *udcName;
105     struct UsbSerial            *port;
106     struct UsbCdcLineCoding     lineCoding;
107     uint16_t                    serialState;
108 #define SERIAL_STATE_DCD        (1 << 0)
109 #define SERIAL_STATE_DSR        (1 << 1)
110 #define SERIAL_STATE_BREAK      (1 << 2)
111 #define SERIAL_STATE_RING       (1 << 3)
112 #define SERIAL_STATE_FRAMING    (1 << 4)
113 #define SERIAL_STATE_PARITY     (1 << 5)
114 #define SERIAL_STATE_OVERRUN    (1 << 6)
115 
116     uint16_t                    handshakeBits;
117     /* notification callbacks */
118     struct AcmNotifyMethod      *notify;
119 };
120 
121 struct CtrlInfo {
122     uint8_t                     request;
123     struct UsbAcmDevice         *acm;
124 };
125 
126 #endif /* HDF_USB_CDCACM_H */
127